fsstudio-team / ZeroSimROSUnity

Robotic simulation in Unity with ROS integration.
https://roboticsimulationservices.com/
MIT License
168 stars 21 forks source link

Unity Left Handed Coordinate System #7

Open EdvardGrodem opened 3 years ago

EdvardGrodem commented 3 years ago

Hi, after trying to run SLAM from the simulator we have some trouble with the coordinate frames from Unity. I know Unity uses a left handed coordinate system. Does ZeroSim account for this when publishing transforms?

EdvardGrodem commented 3 years ago

From what I can tell form the code the conversion is implemented, but not used by the transform publisher. https://github.com/fsstudio-team/ZeroSimROSUnity/blob/ead163a96296c3b3dbd83315e050941c259b3892/Runtime/Scripts/ROS/MessageTypes/Geometry/ZOROSGeometryMessages.cs#L36-L67

micahpearlman commented 3 years ago

So I tried this out by creating a simple scene with a TF Publisher with coordinates (1, 2, 3) and looked at the result in RViz and the TF position is (3, -1, 2) as expected. See attached images.

We have run ROS gmapper successfully. What SLAM system are you using?

unity_tf rviz_tf

micahpearlman commented 3 years ago

@EdvardGrodem are you still having issues? Found a major issue with converting Unity Quaternion to ROS. v0.1.14 should fix that.

FYI: Specifically the issue was that roll and pitch were swapped and yaw was fine. Because yaw was fine we never noticed it because all the mobile robot we worked with roll and pitch didn't matter only yaw.

EdvardGrodem commented 3 years ago

Hi, we are still struggeling with running SLAM, however I do not think it's due to the left handed coordinate system anymore. I think the initial confusion was due to the cameras not having the z-axis pointing into the image as is common convention. We found the settings for correcting this.

micahpearlman commented 3 years ago

@EdvardGrodem can you elaborate on the camera coordinate system and how it was fixed? Is there a patch or pull request that you can provide?

EdvardGrodem commented 3 years ago

Hi, sorry for not coming back to this sooner. In ZOROSRBGDepthPublisher we used the Camera Rotation Degrees to align the camera with our preferred coordinate system.

szandara commented 2 years ago

On this note, I am struggling to understand the vector conversion. I am expecting

FromUnityVector(ToUnityVector3([0.1, 0.2, 0.3])) == [0.1, 0.2, 0.3]

but it does not seem to be true

Is this method correct? It looks to me that this is wrong.

     /// ROS Coordinate System (See: https://www.ros.org/reps/rep-0103.html) 
     /// x forward 
     /// y left  
     /// z up 
     ///  
     /// Unity Coordinate System: 
     /// x right 
     /// y up 
     /// z forward  
     public UnityEngine.Vector3 ToUnityVector3() { 
         return new UnityEngine.Vector3((float)-this.x, (float)this.z, (float)this.y); 
     } 

Using your comment on the coordinate system, shouldn't the method be rather as below? Am I missing something?

     public UnityEngine.Vector3 ToUnityVector3() { 
         return new UnityEngine.Vector3((float)-this.y, (float)this.z, (float)this.x); 
     }