Closed right-chan closed 3 hours ago
WAI.
Carefully read the sections here for an explanation, though we should make this clearer somewhere in the docs.
TL;DR, everything in mjData is always wrt the previous state (or rather, the state transition). This is unavoidable. If you want up to date values you need to call mj_forward
.
Also, please try to do a better search next time 🙂
Intro
Hi!
I am a graduate student, I use MuJoCo to practice control theory in my research.
My setup
MuJoCo - 3.2.3
Python - 3.10.14 | packaged by Anaconda, Inc. | (main, Mar 21 2024, 16:20:14) [MSC v.1916 64 bit (AMD64)]
OS - Windows-10-10.0.22631-SP0
What's happening? What did you expect?
When calculating kinetic energy in a simulation, I noticed a consistent one-step delay between the manually calculated kinetic energy (
calc_kinetic_energy
) and the kinetic energy stored indata.energy[1]
provided by the simulation.Specifically, the value at step N for
calc_kinetic_energy
matches the value at step N+1 fordata.energy[1]
, causing a mismatch at every step.Interestingly, while the potential energy returned by
data.energy[0]
remains consistent at each step, the kinetic energy seems to be delayed.Additionally, even when accounting for the one-step delay, there is still a slight discrepancy between the manually calculated kinetic energy and the simulation-provided value. I apologize for the confusion if this is due to a mistake in my calculations or my approach.
Steps for reproduction
zip(calc_kinetic_energy, data_kinetic_energy)
zip(calc_kinetic_energy, data_kinetic_energy[1:])
Minimal model for reproduction
No response
Code required for reproduction
Confirmations