Skip to content
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

Unity Left Handed Coordinate System #7

Open
EdvardGrodem opened this issue Jul 9, 2021 · 7 comments
Open

Unity Left Handed Coordinate System #7

EdvardGrodem opened this issue Jul 9, 2021 · 7 comments

Comments

@EdvardGrodem
Copy link

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
Copy link
Author

From what I can tell form the code the conversion is implemented, but not used by the transform publisher.

public void FromUnityVector3(UnityEngine.Vector3 v) {
this.x = (double)v.z;
this.y = -(double)v.x;
this.z = (double)v.y;
}
/// <summary>
/// Convert from ROS Vector3 to Unity Vector3 and convert coordinate system:
///
/// 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
/// </summary>
/// <returns>Unity Vector3</returns>
public UnityEngine.Vector3 ToUnityVector3() {
return new UnityEngine.Vector3((float)-this.x, (float)this.z, (float)this.y);
}
[Newtonsoft.Json.JsonIgnore]
public UnityEngine.Vector3 UnityVector3 {
get { return ToUnityVector3(); }
set { FromUnityVector3(value); }
}
}

@micahpearlman
Copy link
Contributor

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
Copy link
Contributor

micahpearlman commented Jul 28, 2021

@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
Copy link
Author

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
Copy link
Contributor

@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
Copy link
Author

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
Copy link

szandara commented Dec 16, 2021

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); 
     } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants