google-deepmind / mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control
https://github.com/deepmind/mujoco_mpc
Apache License 2.0
980 stars 148 forks source link

Control costs = 0 in demo #326

Closed mikezhang95 closed 4 months ago

mikezhang95 commented 4 months ago

Hi MJPC team:

When I am running the cartpole demo (https://github.com/google-deepmind/mujoco_mpc/blob/main/python/mujoco_mpc/demos/agent/cartpole.py), I find that the cost term of the control is always 0. Is it as designed?

thowell commented 4 months ago

The weighted control term is small. If you increase the weight (eg, to 1.0) in the GUI you can see this term in the Objective live plot.

mikezhang95 commented 4 months ago

Thank you very much for your quick reply! I am using cartpole.py in the demos. I think the variable cost_terms is achieved from the function get_cost_term_values, which is not weighted. I think the problem comes from the agent.planner_step doesn't update data.ctrl.

thowell commented 4 months ago

It looks like you are correct that we don't set data->ctrl in the gRPC interface with an action from the policy. The mjData object here needs to have the correct ctrl in order for the cost term to be computed correctly.

thowell commented 4 months ago

@mikezhang95 this bug should be addressed with #327.

mikezhang95 commented 4 months ago

Thank you for your great work!