siemens / ros-sharp

ROS# is a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D
Apache License 2.0
975 stars 371 forks source link

Robot links seperated with UrdfImporter #18

Closed Gongkaka closed 6 years ago

Gongkaka commented 7 years ago

When I try to import my own robot URDF file into Unity, all the links are separated. This may be due to the wrong transformation between links. However, the model works well after MoveIt! setup and interacting in RViz...any reasons that may cause that issue?

MartinBischoff commented 7 years ago

Hello Gongkaka, thank you for working with ROS#! What do you mean with "all the links are separated"? Please send us a clear description and if helpful screenshot(s). Best regards, Martin

Gongkaka commented 7 years ago

Hi Martin, Thanks for your reply! Below is the screenshot of my robot model imported from ROS to Unity.

urdf_gameobject

Those links are not in the correct position among each other...but the transformations are already defined in URDF file and works well in RViz..

MartinBischoff commented 7 years ago

Thanks for the screenshot. Please do the following:

  1. Please make sure that your robot model is strictly according to the URDF format as specified here: http://wiki.ros.org/urdf/XML. See the Joint and Link sections in particular.

  2. Please make sure that you included the complete RosSharp.unitypackage in your Asset folder https://github.com/siemens/ros-sharp/blob/master/Release/RosSharp.unitypackage. If not, please delete your robot model data from the Unity Assets Folder, import RosSharp.unitypackage (select all files for import) and re-import the robot.

  3. If this does not help, could you please send me your URDF+resource files, so that I can reproduce this error?

Did I undertand you right that the model looks correct in Unity3d after moveit setup and rviz interaction? Which mesh file type are you using? Are you using any unconventional mesh orientation? Have you tried importing some other ROS robot?

Gongkaka commented 7 years ago

Hi, Following your solution tips:

  1. URDF format is correct as it works well in rviz interaction.
  2. I tried again including the complete RosSharp.unitypackage in my Asset folder but the issue still exists.
  3. Attached is my URDF resouce files I'm using. I am really appreciate if you can help inspect the error.. abb_irb140.zip
MartinBischoff commented 7 years ago

Hi Gongkaka,

thanks for providing the urdf and the meshes. I can confirm the error on my side, and that it is a bug in the URDF importer.

Though I have no solution yet, I can explain the problem:

In ColladaAssetPostProcessor.cs we specify how the Collada meshes will be oriented in Unity3D. Unity3D is using a left-handed coordinate system with Y up. Collada meshes, by contrast, are based on right-handed coordinate systems. The upward-axis is specified in the .dae file itself in the xml tag <up_axis>. In your files we have Z_UP, i.e. Z-axis pointing upwards.

Thus, for your files a rotation specified in line 58 of ColladaAssetPostProcessor.cs is applied, which is obviously wrong. When playing around I noticed that gameObject.transform.Rotate(new Vector3(0, 0, -90)); does a better job but is still not correct. We need some coordinate transformation similar to that specified in method UnityCoordTrafo in file StlImporter.cs.

Some of your meshes additionally have an initial offset, which must also be transformed into Unity3d coordiante system but is currently taken as is. Additionally, gripper opened2 has multiple child meshes. We must ensure that the transformation is not only applied to the parent object of the mesh, but also all child gameobjects.

Though I have not tired it myself I presume that one workaround for this version is to export the meshes as stl files in blender and use those in the urdf rather than dae files.

Although I am looking forward to personally resolve this bug, I will probably not find time in the next two weeks and therefore I ask the community for support.

MartinBischoff commented 6 years ago

Hi Gongkaka, commit https://github.com/siemens/ros-sharp/commit/4919380e6d1491dc42c5f8d49729d243d5c6d2a0 provides a new RosSharp.unitypackage with fixes for your robot.

The problem was that the Collada files linked in the URDF have rather complex mesh structures, some with child sub-meshes, some with offsets and/or rotations.

Here is a screenshot of the result: screenshot

I used this URDF abb_irb140_mb.zip which corresponds to your URDF file abb_irb140_mb with the difference that I included the origins of the colliders as given in your urdf abb_irb140_collision.urdf.

Note that you have to re-import all meshes in your asset folder after inmporting the new RosSharp.unitypackage for the orientation fixes to take effect.

Note that no Rigidbody and Joint Components will be created for your robot in Unity3D as there exist no Inertials in the URDF yet. See issue #19 for further info.

I hope these fixes work on your side as they do on mine. Please let me know if you have any additional problems.

I'd be glad if you can share also your completed urdf model with us.