google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.19k stars 819 forks source link

How can I draw the trajectory of a robot's end-effector in mujoco viewer ? #88

Closed haoqiangyang1998 closed 2 years ago

haoqiangyang1998 commented 2 years ago

For example, I want to watch the trajectory of the end-effector in the FetchReach-v1 environment during an episode. How can I draw the trajectory in mujoco's popup window?

yuvaltassa commented 2 years ago

Are you using C/C++ or Python? Before calling render, you need to create visual geoms using e.g. mjvMakeConnector and then add them to the array of visual geoms in mjvScene.geoms.

lgkimjy commented 6 months ago

@yuvaltassa I am currently drawing the trajectories of the end-effectors by using

mjv_initGeom(test_geom, mjGEOM_SPHERE, size, NULL, NULL, color);
mjv_connector(test_geom, mjGEOM_LINE, 2, traj[i-1], traj[I]);

and the results of trajectories are shown as follows: image

what I am curious is, can I assign group using cpp or in simulate.cc? the reason why I want to do this is that I want to use the group enable -> geom enable buttons to enable/disable (to show/ not to show) the trajectory that I am drawing. (because sometimes too many trajectories might confuse)

yuvaltassa commented 6 months ago

No. Groups are used when filling the mjvScene (in mjv_updateScene) to decide what goes in it. I.e. by definition everything in the scene is visible and everything that is not visible is not in the scene. Does this make sense?