Skip to content

Commit

Permalink
Compute Jac using pyBullet
Browse files Browse the repository at this point in the history
Signed-off-by: An Thai Le <an.thai.le97@gmail.com>
  • Loading branch information
anindex committed Aug 19, 2021
1 parent d386661 commit 66bee9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions examples/example_environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import numpy as np
from os.path import join, dirname, abspath


Expand All @@ -12,4 +13,9 @@

task = PalletizingBoxes()
env = Environment(task=task, disp=True)
# test compute jacobian
J_pos, J_rot = env.compute_ee_jacobian()
J_pos, J_rot = np.array(J_pos), np.array(J_rot)
print(J_pos)
print(J_rot)
input()
17 changes: 13 additions & 4 deletions tprmp/envs/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def __init__(self, **kwargs):
self.set_task(task) # TODO: implement set_task function
self.reset()

def get_joint_states(self):
joint_states = p.getJointStates(self.ur5, self.joints)
j = [state[0] for state in joint_states]
j_vel = [state[1] for state in joint_states]
j_torque = [state[3] for state in joint_states]
return j, j_vel, j_torque

def compute_ee_jacobian(self):
j, j_vel, j_torque = self.get_joint_states()
return p.calculateJacobian(self.ur5, self.ee_tip, np.zeros(3), j, j_vel, j_torque)

def set_task(self, task):
self.task = task

Expand Down Expand Up @@ -356,10 +367,8 @@ def robot_state(self):
ee_state = p.getLinkState(self.ur5, self.ee_tip, computeLinkVelocity=True, computeForwardKinematics=True) # index of gripper is NUM_LINKS
ee = np.array(ee_state[0] + ee_state[1]) # [x, y, z, x, y, z, w]
ee_vel = np.array(ee_state[6] + ee_state[7]) # ee velocity
config_state = [p.getJointState(self.ur5, i) for i in self.joints]
config = np.array([config_state[i][0] for i in range(len(config_state))])
config_vel = np.array([config_state[i][1] for i in range(len(config_state))])
state = {'ee_pose': ee, 'ee_vel': ee_vel, 'config': config, 'config_vel': config_vel}
j, j_vel, _ = self.get_joint_states()
state = {'ee_pose': ee, 'ee_vel': ee_vel, 'config': j, 'config_vel': j_vel}
return state

@property
Expand Down

0 comments on commit 66bee9a

Please sign in to comment.