@@ -96,6 +96,9 @@ def __init__(self, node, timestep):
9696 # gravity and feet friction
9797 pybullet .setGravity (0 , 0 , - 9.81 )
9898
99+ # Locked base constraint ID
100+ self .fixed_base_constraint = None
101+
99102 # Finite differences to compute acceleration
100103 self .dt = timestep
101104 self .v_last = None
@@ -121,20 +124,23 @@ def reset(self):
121124
122125 # Lock torso (as if the robot was hanged)
123126 pos , orn = pybullet .getBasePositionAndOrientation (self .robot )
124- self .fixed_base_constraint = pybullet .createConstraint (
125- parentBodyUniqueId = self .robot ,
126- parentLinkIndex = - 1 ,
127- childBodyUniqueId = - 1 ,
128- childLinkIndex = - 1 ,
129- jointType = pybullet .JOINT_FIXED ,
130- jointAxis = [0 , 0 , 0 ],
131- parentFramePosition = [0 , 0 , 0 ],
132- childFramePosition = pos ,
133- childFrameOrientation = orn ,
134- )
127+ if self .fixed_base_constraint is None :
128+ self .fixed_base_constraint = pybullet .createConstraint (
129+ parentBodyUniqueId = self .robot ,
130+ parentLinkIndex = - 1 ,
131+ childBodyUniqueId = - 1 ,
132+ childLinkIndex = - 1 ,
133+ jointType = pybullet .JOINT_FIXED ,
134+ jointAxis = [0 , 0 , 0 ],
135+ parentFramePosition = [0 , 0 , 0 ],
136+ childFramePosition = pos ,
137+ childFrameOrientation = orn ,
138+ )
135139
136140 def unlock_base (self ):
137- pybullet .removeConstraint (self .fixed_base_constraint )
141+ if self .fixed_base_constraint is not None :
142+ pybullet .removeConstraint (self .fixed_base_constraint )
143+ self .fixed_base_constraint = None
138144
139145 def get_joint_id (self , joint_name ):
140146 """
0 commit comments