google-deepmind / mujoco

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

Advice Needed on Simulation Settings for Precision Task in MuJoCo #1728

Open kankanzheli opened 2 weeks ago

kankanzheli commented 2 weeks ago

Dear MuJoCo Support Team,

I am currently working on a robotic harvesting task using MuJoCo as my simulation environment. My goal is to enable a robotic joint to move precisely by 1 cm or 2 radians per simulation step. To achieve this, I am running 5 mj_step calls per step() in my simulation, adjusting the kp and kv parameters of the PD controller to ensure the joint reaches the desired position within the allotted step. However, I am facing several stability challenges with these settings:

Simulation Time Too Short: With the default mj_step, the total simulated time after 5 steps is only 0.01 seconds. This short duration requires the robot to achieve very high acceleration to reach the set position, leading to significant instability in the simulator.

Increasing the Timestep: I experimented with setting the option timestep to "0.01". While this helps reduce the acceleration demands on the robot, making it easier to reach the position, it severely affects the stability of the PD controller. This often results in the arm oscillating before reaching the target, as large velocity changes occur within a single mj_step.

Given these issues, I am seeking your advice on how to balance the simulation settings:

Is there a recommended approach to managing the number of mj_step calls per step() to optimize both simulation fidelity and training efficiency? How can I adjust the timestep to achieve better stability without compromising the controller's performance? Any guidance or recommendations you could provide would be greatly appreciated, especially any best practices for configuring MuJoCo for tasks requiring precise movement within limited simulation steps.

Thank you for your assistance.

Balint-H commented 2 weeks ago

It sounds to me that you could just reduce your requirements for the target position's increase. Instead of moving the joint e.g. 1cm per step, move it 1mm. Increasing the timestep like you have done also reduces the effective acceleration requirement, so keeping the timestep small and reducing the control update instead will get you the same effect while maintaining stability.

A related concept is the downsampling of the controller's execution with respect to physics steps. So, for every step of control update, you step the physics e.g. 10 times. During those period you can keep your control the same, or can interpolate it. The primary reason this is done is to reduce computational costs (e.g. so a neural network policy can be queried less often).