Why my control function is called more than one time per step? #2383
-
IntroHi! I am a master student at UNED, I use MuJoCo for my research on generative human motion. My setupMuJoCo python My questionI've found a behaviour, maybe due to my mistake, where the controller function callback is called several times per step. Why is this happening? If I only load a model, as you can see in the attached script, the function seem to be called 2 times per step. To identify this situation I print
As you can see the same timestep is printed two times. Note: I've renamed the attached file to .txt to avoid the Github limitation but it is a python script. Minimal model and/or code that explain my questionNo response Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I noticed similar behavior when using RK4 integrator. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the point about RK @shogan50 My doubt now is: why is this 4 calls needed? I'm implementing a PD controller so I'm not sure which one of these 4 calls should use to apply the torque. |
Beta Was this translation helpful? Give feedback.
Thanks for the point about RK @shogan50
Answering to myself from doc :
The control callback is called from within mj_forward and mj_step, just before the controls and applied forces are needed. When using the RK integrator, it will be called 4 times per step. The alternative way of specifying controls and applied forces is to set them before mj_step, or use mj_step1 and mj_step2. The latter approach allows setting the controls after the position and velocity computations have been performed by mj_step1, allowing these results to be utilized in computing the control (similar to using mjcb_control). However, the only way to change the controls between sub-steps of the RK integrator is to de…