rohanpsingh / mujoco-python-viewer

Simple renderer for use with MuJoCo (>=2.1.2) Python Bindings.
BSD 2-Clause "Simplified" License
163 stars 24 forks source link

Added graph rendering, Actuator force visualization[no sites], Sim reset method(backspace) and window positioning #23

Open rohit-kumar-j opened 1 year ago

rohit-kumar-j commented 1 year ago

Graph preview (KEY: G)

Unfortunately, the time at the bottom of the graph was not recorded in the video. It gives a time-based graph The red line is a random signal(sine in this case)

https://user-images.githubusercontent.com/37873142/190720262-22f09c46-363b-4dc3-8c37-b340ed66a69b.mp4

Actuator Force visualization via graphs

The sites are used to get the location and orientation of the body at the actuator location only.

https://user-images.githubusercontent.com/37873142/190720353-2cf6e5d8-a1d5-4c67-8757-a5c2f8d6cbd6.mp4

... and added examples

rohanpsingh commented 1 year ago

Hi @rohit-kumar-j thanks for the PR. A small question - does the actuator force visualization work even if there are no sites added at each joint in the XML?

rohit-kumar-j commented 1 year ago

Not as of now. I was hoping to ask for suggestions for that. We need the position and orientation of the joint at which point we need to render the force arrow.

Asked for the same. However, getting the orientation in njnt x 9 like xmat is not available without a reference site/geom.

rohit-kumar-j commented 1 year ago

@rohanpsingh, created force rendering without sites. inputs:

[Tested only for hinge and slide joints]

f_render_list = [
    # fmt: ["jnt_name", "actuator_name", "label_name"]
    ["hinge_1", "pos_servo_1", "force_at_hinge_1"],
    ["hinge_2", "pos_servo_2", "force_at_hinge_2"],
    ["hinge_3", "pos_servo_3", "force_at_hinge_3"],
]

viewer.show_actuator_forces(
        f_render_list=f_render_list,
        show_force_labels=True
        rgba_list=[1, 0.5, 1, 0.5], # common color
        force_scale=0.05,           # common arrow length scale
        arrow_radius=0.05,         # common arrow radius
        show_force_labels=True,   # Needs to be true for showing the labels and the force values
    )

https://user-images.githubusercontent.com/37873142/191341548-92ed0445-58c4-4aaa-9d1a-3ef17fc47864.mp4

PS: Do not use all the force rendering labels simultaneously if your robot has many actuators. The simulation will run very slow. (You can show the arrows, but not the labels and values)

rohit-kumar-j commented 1 year ago

Added sim reset method with backspace:

https://user-images.githubusercontent.com/37873142/192137966-e240963d-6fde-45ea-91bf-33f1237ad96c.mp4

rohit-kumar-j commented 1 year ago

@rohanpsingh, is the default window_positioning (top left of screen) too much in the viewer.__init__() method?