google-deepmind / mujoco

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

MJX: pd control with target velocity in actuator/position #1891

Closed Rian-Jo closed 3 months ago

Rian-Jo commented 3 months ago

How to ask for help

Hi,

https://github.com/google-deepmind/mujoco/blob/d72f01bad4b535acdeb8cb6a5560fd4e0dc0cfab/mjx/mujoco/mjx/_src/forward.py#L93

I'm looking for some help with MJX actuator/position for the pd control. As far as i know, mujoco uses qfrc_actuator = kp(q_d - q) - kd(qdot) . I just want to add target velocity qdot_d to form qfrc_actuator = kp(q_d - q) - kd(qdot_d - qdot). I've confirmed that a PID plugin exists in MuJoCo, but it seems that MJX does not.

Is there any method to simply add target velocity or to implement pid plugin? and if user can add actuator plugin, other low level control may be implemented.

Thank you.

kevinzakka commented 3 months ago

What's stopping you from just using motor actuators and setting the torque directly using the PD control law you defined above?

Rian-Jo commented 3 months ago

@kevinzakka hi, thank you for the reply.

how can you handel n_frame? in my knowledge, if mujoco opt.timestep is 1ms and mjx env timestep 5ms, which means that pipelinestep(mujoco step) is run 5 times per 1 mjx environment step. if one uses the motor actuator and write the pd control in mjx step function, pd control is updated in 5ms but i want it is run in 1ms with 5ms of policy updates. do you have any menthod to resolve this?

thank you.

yuvaltassa commented 3 months ago

If you put two actuators on the same joint their outputs are summed. So make seperate P (position) and D (velocity) actuators, done.

Rian-Jo commented 2 months ago

@yuvaltassa thank you!!

@kevinzakka hi, firstly, i tried to use motor auctuator for pd control but the training result was too bad to keep working on. have you tried to train the agent with motor in 1khz envrionment timestep?

thank you!!