Skip to content

Commit c1e6d0d

Browse files
committed
Fix unlock base for pybullet
1 parent e77dfe2 commit c1e6d0d

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

go2_simulation/bullet_wrapper.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""

go2_simulation/simulation_node.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def __init__(self):
5454
exit()
5555

5656
if self.unlock_base_default:
57-
self.simulator.unlock_base()
57+
self.unlock_base()
5858
else:
59-
self.create_subscription(Empty, "/unlock_base", lambda msg: self.simulator.unlock_base(), 1)
59+
self.create_subscription(Empty, "/unlock_base", lambda msg: self.unlock_base(), 1)
6060

6161
self.create_subscription(Empty, "/reset", lambda msg: self.reset(), 1)
6262

@@ -172,6 +172,10 @@ def reset(self):
172172
if self.unlock_base_default:
173173
self.simulator.unlock_base()
174174

175+
def unlock_base(self):
176+
self.get_logger().info("Unlocking robot base")
177+
self.simulator.unlock_base()
178+
175179

176180
def main(args=None):
177181
rclpy.init(args=args)

0 commit comments

Comments
 (0)