Validation of mj_contactForce in simulation different from theoretical calculation #2622
Unanswered
Chuanfang-Neptune
asked this question in
Asking for Help
Replies: 1 comment 1 reply
-
I don't know if that fixes the calculation but note that d is clamped to mjMAXIMP https://mujoco.readthedocs.io/en/latest/APIreference/APIglobals.html#glnumeric |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Intro
Hi!
I am a Phd student using MuJoCo to simulate some quadrupod robots. I want to reduce the reality gap between MuJoCo simulation and my real robot experiments, and I'm validating some metrics like the contact force to compare with real sensor readings.
I have one question about the contact force calculation in MuJoCo. I take a look at the solver parameters here. I also read this relevant issue #732, where the OP tried to validate the penetration at steady state and compared with real results (which was matching).
I'm more interested in getting the contact force during simulation at each step rather than looking at the end state because this allows me to make some comparison of my sensor data. From the documentation MuJoCo didn't explicitly compute contact force but computed a target acceleration with$a_1+d⋅(bv+kr)=(1−d)⋅a_0 $ . Meanwhile MuJoCo provides some function such as 'mj_contactForce' that put the data in 'physics.sensordata' that can be accessed later. But I didn't find how the mj_contactForce was exactly calculated. Code seemed to copy it from result of
mju_decodePyramid
.In the end, I tried to calculate it myself with the equation above. If$a_0$ is acceleration in absent of the contact, it should be -9.8 from gravity. And the $a_1$ should be the acceleration with contact. Therefore, I suppose, the contact force should be $m*(a_1-a_0)$ , which caused the change of acceleration (here only considering normal force (z)). If I take d is almost 1, the equation should downgrade to $F_{contact} = m*(bv+kr)$ and I wrote the script below to validate the result.
In the code I set a cube to start at a position below the ground with different mass, position and velocity. I do one
mj_step
and record the contact force to compare with the theoretical value and print the error.However, the result is different from the calculation. Do you have any ideas why it is off so much? What could be wrong in my calculation/code?
My setup
mujoco: 3.1.6
OS: result is same in Win/Ubuntu
My question
No response
Minimal model and/or code that explain my question
No response
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions