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

AIRO-1975 Nicer angular velocity accessors #283

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ROSGeometry.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ Hence, writing 3d data into a message can often be as simple as writing:
}
ros.Send("imu", msg);

Unity's standard Transform class also has a `To<C>()` extension method that returns a ROS Transform message. So creating a geometry_msgs/Transform message typically looks like this:
# Angular Velocity vectors

TransformMsg msg = myGameObject.transform.To<FLU>());
Although angular velocity values are stored using the same Vector3 structure as other vectors, they can't be converted the same way: to correctly convert an angular velocity between a left-handed and right-handed coordinate system, the vector needs to be negated.

To convert a vector that represents an angular velocity, instead of using To<FLU>() and From<FLU>(), you should use the AngularVelocityTo<FLU>() and AngularVelocityFrom<FLU>() methods.

# Internal details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public static Vector3<C> To<C>(this Vector3 self)
return new Vector3<C>(self);
}

public static Vector3<C> AngularVelocityTo<C>(this Vector3 self)
where C : ICoordinateSpace, new()
{
return Vector3<C>.FromUnityAngularVelocity(self);
}

public static Quaternion<C> To<C>(this Quaternion self)
where C : ICoordinateSpace, new()
{
Expand All @@ -269,7 +275,12 @@ public static Quaternion<C> To<C>(this Quaternion self)

public static Vector3 From<C>(this PointMsg self) where C : ICoordinateSpace, new()
{
return new Vector3<C>((float)self.x, (float)self.y, (float)self.z).toUnity;
return self.As<C>().toUnity;
}

public static Vector3 AngularVelocityFrom<C>(this PointMsg self) where C : ICoordinateSpace, new()
{
return self.As<C>().toUnityAngularVelocity;
}

public static Vector3<C> As<C>(this Point32Msg self) where C : ICoordinateSpace, new()
Expand All @@ -279,7 +290,12 @@ public static Quaternion<C> To<C>(this Quaternion self)

public static Vector3 From<C>(this Point32Msg self) where C : ICoordinateSpace, new()
{
return new Vector3<C>(self.x, self.y, self.z).toUnity;
return self.As<C>().toUnity;
}

public static Vector3 AngularVelocityFrom<C>(this Point32Msg self) where C : ICoordinateSpace, new()
{
return self.As<C>().toUnityAngularVelocity;
}

public static Vector3<C> As<C>(this Vector3Msg self) where C : ICoordinateSpace, new()
Expand All @@ -289,7 +305,11 @@ public static Quaternion<C> To<C>(this Quaternion self)

public static Vector3 From<C>(this Vector3Msg self) where C : ICoordinateSpace, new()
{
return new Vector3<C>((float)self.x, (float)self.y, (float)self.z).toUnity;
return self.As<C>().toUnity;
}
public static Vector3 AngularVelocityFrom<C>(this Vector3Msg self) where C : ICoordinateSpace, new()
{
return self.As<C>().toUnityAngularVelocity;
}

public static Quaternion<C> As<C>(this QuaternionMsg self) where C : ICoordinateSpace, new()
Expand All @@ -299,7 +319,7 @@ public static Quaternion<C> To<C>(this Quaternion self)

public static Quaternion From<C>(this QuaternionMsg self) where C : ICoordinateSpace, new()
{
return new Quaternion<C>((float)self.x, (float)self.y, (float)self.z, (float)self.w).toUnity;
return self.As<C>().toUnity;
}

public static TransformMsg To<C>(this Transform transform) where C : ICoordinateSpace, new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static explicit operator Vector3(Vector3<C> vec)

public static Vector3<C> FromUnityAngularVelocity(Vector3 angularVelocityRUF)
{
return new Vector3<C> { internalVector = s_CoordinateSpace.ConvertAngularVelocityFromRUF(angularVelocityRUF) };
return MakeInternal(s_CoordinateSpace.ConvertAngularVelocityFromRUF(angularVelocityRUF));
}

// for internal use only - this function does not convert coordinate spaces correctly
Expand Down