Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Commit d71358e

Browse files
committed
bug fix in ft transformation
1 parent 81f80cd commit d71358e

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/bullet_panda/bullet_robot.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,28 @@ def ee_velocity(self):
193193

194194
return self.get_link_velocity(link_id=self._ee_link_idx)
195195

196-
def get_ee_wrench(self, local=False):
196+
def get_link_state(self, link_idx, as_tuple=False):
197+
"""
198+
returns orientation in bullet format quaternion [x,y,z,w]
199+
"""
200+
201+
link_state = pb.getLinkState(
202+
self._id, link_idx, computeLinkVelocity=1, physicsClientId=self._uid)
203+
204+
if not as_tuple:
205+
ee_pos = np.asarray(link_state[0])
206+
ee_ori = np.asarray(link_state[1])
207+
ee_vel = np.asarray(link_state[2])
208+
ee_omg = np.asarray(link_state[3])
209+
else:
210+
ee_pos = link_state[0]
211+
ee_ori = link_state[1]
212+
ee_vel = link_state[2]
213+
ee_omg = link_state[3]
214+
215+
return ee_pos, ee_ori, ee_vel, ee_omg
216+
217+
def get_ee_wrench(self, local=False, verbose=False):
197218
'''
198219
:param local: if True, computes reaction forces in local sensor frame, else in base frame of robot
199220
:type local: bool
@@ -203,21 +224,15 @@ def get_ee_wrench(self, local=False):
203224

204225
_, _, jnt_reaction_force, _ = self.get_joint_state(self._ft_joints[-1])
205226

206-
if local:
207-
ee_pos, ee_ori = self.ee_pose()
208-
227+
if not local:
209228
jnt_reaction_force = np.asarray(jnt_reaction_force)
210-
force = tuple(jnt_reaction_force[:3])
211-
torque = tuple(jnt_reaction_force[3:])
212-
213-
inv_ee_pos, inv_ee_ori = pb.invertTransform(
214-
ee_pos, [ee_ori.x, ee_ori.y, ee_ori.z, ee_ori.w])
215-
216-
force, _ = pb.multiplyTransforms(
217-
inv_ee_pos, inv_ee_ori, force, (0, 0, 0, 1))
218-
torque, _ = pb.multiplyTransforms(
219-
inv_ee_pos, inv_ee_ori, torque, (0, 0, 0, 1))
220-
jnt_reaction_force = force + torque
229+
ee_pos, ee_ori = self.get_link_pose(self._ft_joints[-1])
230+
rot_mat = quaternion.as_rotation_matrix(ee_ori)
231+
f = np.dot(rot_mat, np.asarray(
232+
[-jnt_reaction_force[0], -jnt_reaction_force[1], -jnt_reaction_force[2]]))
233+
t = np.dot(rot_mat, np.asarray(
234+
[-jnt_reaction_force[0+3], -jnt_reaction_force[1+3], -jnt_reaction_force[2+3]]))
235+
jnt_reaction_force = np.append(f, t).flatten()
221236

222237
return jnt_reaction_force
223238

0 commit comments

Comments
 (0)