Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain the gripper status from robot0_gripper_qpos #406

Open
GilgameshD opened this issue May 25, 2023 · 1 comment
Open

Obtain the gripper status from robot0_gripper_qpos #406

GilgameshD opened this issue May 25, 2023 · 1 comment

Comments

@GilgameshD
Copy link

Hi, I find that the observation dict contains the robot0_gripper_qpos, which is a 6-dimensional vector representing the angles of 6 joints. Is it possible to use this qpos to calculate the distance between two fingers of the gripper?

@abhihjoshi
Copy link
Contributor

I think you can do something like the following to get the distance between two fingers of the grippers:

finger1_col = env.sim.data.geom_xpos[env.sim.model.geom_name2id("gripper0_finger1_collision")]
finger2_col = env.sim.data.geom_xpos[env.sim.model.geom_name2id("gripper0_finger2_collision")]
distance = np.sum((finger1_col - finger2_col) ** 2, axis=0)

This code is basically accessing the simulation data for the geoms in the environment and directly calculating the distance between them using the Euclidean distance. You can also find the position of any of the geoms by replace the string passed into geom_name2id.

Some other side notes:

  • To find a list of all the valid geom names, you can use this: print(env.sim.model.geom_names)
  • You can also find get get the position or rotation matrix for body elements instead of only geom elements. Just replace geom_xpos with <geom/body>_x<pos/xmat>

Let me know if this helped answer your question or if you have any further questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants