raisimTech / raisimLib

Visit www.raisim.com
http://www.raisim.com
Other
341 stars 92 forks source link

Wrong computation of the contact force #301

Open fscafarto opened 2 years ago

fscafarto commented 2 years ago

Dear professor, Unfortunately I cannot post a minimal reproducible example for visualizing my problem, since my code is very huge. Anyway, I noticed that when my quadruped robot (Unitree A1) is still, so it is performing the stand phase and all of its feet (4) are in contact with the ground, the computed force at the calf is 0. In RaisimUnity I can see that all of its feet are in contact with the ground (red dots), but in one iteration of my control loop the function getImpulse returns 0 for one of this feet in a random way. Sometimes, this happens either for the Rear Right foot or for another foot randomly. I have verified that this happens when my controller is active, but I don't think that my controller works wrong since first of all in RaisimUnity all the feet are in contact (I can see the red dots below the feet) with the ground and the null force occurs for just one iteration. After this iteration everything works fine and the computed force is correct since it is quite similar to the desired one and it is not null. So, it is not a problem of the PD controller (which I use only at the start then I always use my controller) and I have verified that the forces are correct when I have applied the PD controller provided by Raisim. Another problem I have experienced is this one: passing from the swing phase to the stand phase, so one of the feet comes in contact with the ground, what happens is that once again the function getImpulse returns 0 for 15 iterations, like Raisim is not aware of the contact yet...finally after the 15 iterations getImpulse returns a huge force due to the impact and this is reasonable since there have been the impact, but the point is: why Raisim seems to be not aware of the contact and it takes 15 iterations to realize that the ground reaction forces are not null? And why the visualization does not show this behaviour? In one picture there is what I see in Raisim, in the second picture you can notice the null force 0 0 0 at the 42 row. Hope to figure out of this problem and thank you in advance. a1_stand

bug_raisim

jhwangbo commented 2 years ago

It is unavoidable in rigid body simulation. If the foot is on the ground and the computed force has 1 nN, the foot will lose contact.

I didn't get the second part of the question. So the foot is in contact but returns 0 for 15 iterations? This is unexpected. Did you check out this link?

https://raisim.com/sections/Contact.html

fscafarto commented 2 years ago

Thanks for the reply, I have checked the documentation about contacts and I have been inspired by the provided example. It is reasonable that when the computed force has 1nN the foot will lose contact, but what I want to stress is the fact that in RaisimUnity the foot doesn't lose the contact, since I can see the red dots under each of the 4 feet. About the second issue, I want to show you these 2 pictures. In the first one, you can see a comparison between the desired ground reaction forces computed by my whole body controller on the left side (f_des_file.txt on the top of the window) and the current ground reaction forces computed by Raisim (f_gr_file.txt). So, you can see that at the iteration 1886 the desired forces are different from 0, while the current forces become different from 0 at the iteration 1890, so 4 iterations later. This delay increases as the simulation goes on, in fact in the next step, this delay becomes bigger and results in 7 iterations. So, my purpose is to obtain a graph of the error which reasonable and of course when the current forces are null I get a huge spike. In order to mask this effect I tried to replace the null forces with the desired ones by using an if statement, so if the current forces are null replace them with the desired ones which are different from 0. Anyway, by means of this change, the behavior of Raisim changes completely. For understanding why it is so, look at the second picture where you can see that I have managed the delay of before since when the current forces are zero, the desired ones are zero too and when the current forces are different from zero this holds also for the desired ones, so there is no delay anymore (look at the iteration 1896, for both sides). Anyway, you can notice another interesting issue: in fact, the current forces are not null, but they are equal each other for some iterations (1896 to 1909), moreover that force is not equal to the desire one! It is equal to current force that I had before the forces become all 0, so before the start of the swing phase (in the swing phase forces are null), so Raisim is responsible of this computation, since the desired forces are always different each other and the current forces computed by Raisim are always equal to each other and different from 0 such that the condition of the if statement seen before is not respected and the "replacing operation" does not take place anymore. In few words, with this change (due to the introduction of the if statement) Raisim does not show the 0 forces, but passing from the swing to the stand phase it computes always the same forces for some iterations, in truth it computes the same force that I had before the leg lift up. bug_confronto bug_confronto_con_correzione