-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contact normal changes randomly between two opposite directions in Gazebo #1425
Comments
DART doesn't do collision detection itself. Instead that job is outsourced to a choice of FCL, Bullet, or ODE, with FCL being the default. If there are collision detection errors it will either be in the underlying collision detection library or possibly in the way DART is using that library. But something to consider: If you're doing mesh-mesh collision it's pretty common for a collision detection engine to misinterpret which direction a normal is in. I recommend using primitive shapes as much as possible to get the most reliable results. |
thanks for the answer. I'm not sure if the collision detection itself is wrong. Indeed, the physics behavior looks ok when a contact occur. It's just the returned normal and force that sometimes have the wrong sign. Maybe dart is doing some frame transforms (or other post processing) that could be wrong ? I tested both mesh-primitive and primitive-primitive collisions in Gazebo. Both of them are ok with ODE physics engine, and both are wrong with dart physics engine. EDIT: in https://github.com/dartsim/dart/blob/master/dart/collision/fcl/FCLCollisionDetector.cpp, what is the difference between postProcessDART and postProcessFCL ? And which one is called by default ? I'm not sure to understand what is happening in those functions, but as they manipulate contacts, the bug may be somewhere here, no ? |
You are correct that FCL will be the default collision detector when DART is used by Gazebo. The post-processing is related to this comment which refers to this issue. Basically there are known issues in FCL where garbage contact points are reported. We do some post-processing to attempt to cut down on such points, but if I remember correctly it doesn't work perfectly, and it could explain some of the issues you're experiencing with getting the incorrect normal direction. DART also supports using Bullet collision detection and ODE collision detection. I've anecdotally found the ODE collision detection to be very reliable for my use cases with little or no surprising behavior. Unfortunately to change DART's underlying collision detection library in Gazebo there would need to be a few changes to both sdformat and Gazebo, and that may take some time to get finished upstream by the maintainers since it's not likely to be seen as a major priority. |
If you're okay with building Gazebo from source code, you could consider cloning the Gazebo source code and adding a line below this one to change the collision engine similar to this example. You would just add the following to
That will change the collision detection engine that DART uses within Gazebo to the ODE collision detection engine. If that continues to have the same issue whereas using the ODE physics engine does not have any problem, then I would definitely be suspicious of DART code. |
I tried really hard to find the bug, I think I read almost all the Gazebo and DART collision and contact related code, but I still couldn't find anything that could lead to my issue. So maybe the bug is only inside FCL. But if it's at such a low level, I don't understand how the physics behavior could still be good, with such inconsistant contact normal data ? Anyway, someone with a better understanding of DART (and maybe Gazebo) framework than me will have to look at it... If the bug is only related to FCL, a quick (but dirty) fix for me would be to compile a custom version of DART where the default behavior is to use ODE collision detection. I could then recompile Gazebo with this custom DART version. Can you tell me in which file this parameter is set ? EDIT: |
Oh in my last post I forgot that you'll need to have Gazebo find and link to the To do this switch from inside of DART instead, you could merge the After that you'll need to make ODE the default collision detector here. Whether you change the detector through Gazebo or through DART you'll have to do some CMake butchery. I personally think changing it in Gazebo might be easier, but I'll leave that to you to judge. |
Yes I think it is easier to do the switch from Gazebo. Concerning the cmake trick, I think it's already done here: SearchForStuff.cmake. Am I right ? |
Oh wow yes it's in there already. I wonder why since it's never been used as far as I'm aware 🤔 But yes, that should mean that my earlier post is all you have to change in Gazebo to try out the other collision detection engines. |
here a console log when I run cmake to configure the Gazebo compilation: My version of DART is the binary from apt. |
finally I compiled DART from source to make sure that Then, I was able to compile Gazebo (following the tutorial for installing from source). In the cmake phase it found but now, when I try to launch gazebo, I have this error: edit: |
just addressing the debian packages, |
There is now support for picking the collision detector for DART in Gazebo (https://bitbucket.org/osrf/gazebo/pull-requests/2956/dart-heightmap-with-bullet-and-ode/diff), but as you'll see in the PR, using ODE is not allowed because the ODE used by DART can clash with the ODE that ships with Gazebo. In my testing, it works for primitive shapes, but crashes with meshes. |
ok, thanks @azeey , it explains the crashes when trying to spawn a mesh. |
You could see if the Bullet collision detector works better, but there are currently some known issues with that one too, unfortunately. |
As I said in a previous comment, I already tested bullet collision detector. The contacts are unstable (maybe related to your issue as there were contacts with ground plane), and the simulation is really slow : 1 second in real time is 0.03 second in the simulator (!!!)... Should I report this issue (wrong contact normal direction) on FCL issue tracker ? |
hello, I have some updates from the issue I posted on fcl repo : issue 422. It has been suggested to check if the pointer to colliding objects returned by a fcl contact, o1 and o2, are in a given order. |
Does someone have any idea on that ? |
does anyone had the time to look into it ? |
I haven't the time to dig into dart, but if someone could tell me in which class/function the change should be made, I can do the coding & testing part and do a PR. For now I am using the ODE engine of Gazebo, which has correct normal information. But Dart is way faster and stable, so I would rather use dart... |
The only way I can think of addressing this issue, if it's really caused by the FCL broad phase issue, is modifying the FCL post-processing function to add something like a
which has the following behavior:
When a new combination of values for
We'll need to store One potential danger here is that this container needs to be cleared out as collision objects are deleted, because otherwise it could grow without any bound. That should probably be done here. Note that when we remove and object |
thanks for your answer ! there is still something that I can't figure out about this issue. As the physics is consistent, and only the "monitoring" is impacted, it means that somewhere else in DART code, the mapping is made correctly, right ? regarding your solution, correct me if I'm wrong, you suggest to :
|
If I understand the issue you were describing, it sounds like the normal vector flips direction in sync with the force magnitude flipping sign. The actual force vector that physics uses when computing contact forces will be the normal vector multiplied by the force magnitude. Therefore the sign flip of the magnitude will give a direction flip of the vector. Perhaps one solution that could smooth this out without modifying DART would be to have the sensor plugin of Gazebo flip the sign of the normal vector when the force magnitude is negative, and always report a positive force magnitude.
And also switch
Yep, just put a reference to it into But I do recommend first considering whether the tweak I recommended to the sensor plugin could solve this problem, because this order mapping solution would add a lot of hashing and map lookups which aren't otherwise necessary. |
I already thought about that. The fact is that the force is reported in the world frame, and not in the contact frame. Therefore, it is not possible to know a priori if the force is toward the object or not. |
Is the sign of the force's magnitude supposed to represent whether the force is directed into/out of the sensor? If so, perhaps the force sensor is making a faulty assumption about which body is object 1 vs object 2. Presumably the force sensor plugin should be able to look at the contact information and identify which of the two contact bodies is the body that the sensor is related to, and then flip the sign accordingly. |
as the force is expressed in world frame, its sign is not supposed to represent the force direction relative to the object/sensor. The gazebo contact sensor just forward the contacts of a particular body to a particular gazebo topic. It does not decide which is object 1 or object 2, just forward existing information. |
I've looked over the contact sensor code, and it confirmed what I suspected. What I would recommend trying is changing this block of code to the following:
And then after this line you could modify the contact information by iterating through the contacts in |
yes I already had a similar idea. Unfortunately, the name in collision1 an collision2 doesn't flip at all. |
I'm not sure what you mean by "keep trace of the real ordering". Typically the normal vector reported by a collision detector refers to the vector pointing from object 1 to object 2 (or vice-versa, I can't remember) starting from the point of contact. DART will use whatever ordering is reported by FCL, and presumably the reported normal will be consistent with that. I haven't looked at the entire pipeline of how contact points move through Gazebo, but it's hard for me to imagine that the ordering of the collision objects would be getting non-deterministically flipped. Maybe it would be constructive to ask: How specifically are you wanting to use this contact information, and what is the current problem that you are encountering with it? I understand that the text printout on the terminal is messy, but is there a specific impact that you're seeing on any code that uses this information? Maybe this entire situation is actually a non-issue besides the jarring way the data reads out to human eyes. |
I am working on robotic grasping. I use the contact information, more specifically the contact normal and positions, to compute something called the Grasp map, a matrix which depend on the contact frames positions and orientations relative to the gasped object. For the computation to be consistent, the normal need to be always pointing toward the object.
This was extracted when my object, "coude" (french for elbow, as it is an elbow pipe), rely on the "conveyor" (in gazebo it is just a box). You can see that the normal are flipping, but not collision1 and collision2.
Maybe it's me that doesn't understand something. In convertContact line 1582 and 1584, the information put in collisionObject1 and collisionObject2 are not linked with the information provided by fcl::Contact: if o1 and o2 from fcl::Contact flip, collisionObject1 and collisionObject2 won't flip (at least I can't figure out how). |
Whatever FCL gives us as I think I understand the difficulty of the situation that you're in. I'm very very surprised that my recommendation here isn't working. Maybe if you can show me the changes that you made which you believe match my recommendation, then I can identify why that didn't work. |
instead of
I would expect
I don't understand how you can be sure that o1 and o2 from the function parameter match the ordering of o1 and o2 inside fclContact. You suggested earlier to check in the sensor code if collision1 and collision2 flipped or not. But as you can see on the terminal output, they don't flip, even if the normal change direction. Do you suggest that the terminal output doesn't represent the real state of the data (so a printing bug ?). |
oh, I just noticed that in the sensor there is some swapping between collision1 and collision2. I'm sorry, I didn't fully understood your suggestion. It should work ! I will test that as soon as possible, and keep you updated ! |
To be honest I'm very confused by what's happening. I'm sorry for not noticing that the printout keeps showing the object names in a consistent order; that does change my suspicions.
As I dig more into exactly what that code is doing, I think that should just make the sensor robust to whether the object of interest is specified as the first or second object in the contact data. I don't see any place in the sensor plugin code where the names would actually get swapped within the contact data. I'm honestly very perplexed about this situation, and it's making me wonder if you're onto something about the assumption that Somewhere in the pipeline someone is definitely swapping the object names in order for the contact data to print out like that 😵 |
I thought there was swapping here. But now after looking at it more closely, the contact is not modified, and as you said it seems to be a way to make the sensor robust to where the object of interest appear. But still it is a confusing way to do it in my opinion...
This could be tricky because o1 and o2 in fcl::Contact are not of the same type as o1 and o2 from function parameters (see here). Maybe the convertContact implementation is like that because of this difference. I'm still far from fully understanding this whole part of the code (how the pipeline from fcl to dart is working). Do you know who wrote the FCLCollisionDetector ? |
I believe it was @jslee02 that implemented the |
ok thanks, I will try to look into it soon ! |
Hello guys stuff here looks fairly recent, and I also want to get ODE collision detection working with DART. I have made the following issue #1535 (comment) . But I think the ODE used in DART conflicts with the ODE version used in gazebo. Is there a way to resolve this issue. I really want to avoid using FCL and bullet gives very poor results. |
Hi everyone, I have a similar issue as @ClementRolinat in that I work on robotic grasping and I am computing metrics based on the contact normals and forces. I am experiencing a very weird and, I think, related issue with Gazebo11 + DART6 + Bullet collision checking (Side note: I am using Bullet collision checking since ODE and FCL lead to weird "sticking" behavior and DART collision checking didn't seem to be properly integrated into Gazebo yet). My problem is that in different instances of my Gazebo simulation the contact normals (and forces) point in different directions. For example, in simulation 1 I am touching a cylinder with the finger and the contact normal points towards the object. In simulation 2 the contact normal and force points the other way. In one simulation session the contact normals seem to consistently point one way and don't change direction (like in @ClementRolinat's post). Does anyone have a clue how to solve this? @ClementRolinat did you find a solution in the end? Cheers, |
Hey @axkoenig not sure this will help, but try checking the collision order. For example just add a debug statement:
If my guess is correct you will see that the contact order switches between simulations. Which means when you try to check for for forces on body_1 between simulations the contact body switches. Worth a check. But as far as why the forces are not shown in both directions, I am not entirely sure. Hope this helps, Thomas |
Hello @axkoenig, sorry I don't have any solution, I finally decided to stay with the classic ode engine and don't use dart at all. |
Update: I noticed that the contact normal direction changes depending on which object is spawned first in Gazebo:
Also note that @trns1997's solution works! Cheers for that! |
Hey @ClementRolinat,
I know not super helpful. FCL does seem to continuously alternate but with the same magnitude but weirdly the contact order doesn't seem to change (atleast from the plugins POV). But I was just wondering is it "really wrong" to just absolute the contact force (I guess it would depend on the use case). But either way if someone has any idea on why this is happening it would be cool to resolve it. |
hello,
I am using DART as physics engine for Gazebo 9.
I found this bug when attaching a contact sensor to a model.
When I display the gazebo topic associated with this sensor, I can see that the normals of the contacts are not constant, even if the model is lying on the ground and is at rest (only gravity force is applied on it). More precisely, the directions of the normals oscillate between approximately (0, 0, 1), and (-0, -0, -1). The sign of the associated force also vary accordingly.
The bug is very easy to reproduce in Gazebo, you just need to attach a contact sensor to a model, and display the associated gazebo topic.
However, I don't know how to reproduce it with DART as a standalone, as I never used it.
I think the bug may be in dart code, as I already checked the gazebo code and didn't find the bug yet... Morevover, the contact normal behave correctly with ODE physics engine.
Does anyone has already seen this in dart ?
Or at the contrary, can confirm that the contacts are working properly in dart, and this issue is coming from Gazebo ?
The text was updated successfully, but these errors were encountered: