-
Notifications
You must be signed in to change notification settings - Fork 24
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
[RSDK-732] orientation vector and rotation matrices #20
[RSDK-732] orientation vector and rotation matrices #20
Conversation
src/spatialmath/utils.rs
Outdated
OrientationVector{o_vector, theta} | ||
} | ||
|
||
pub fn from_quaternion(quat: &Quaternion<f64>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also implement the To and From traits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it for the custom structs I created, but for quaternion and rotation matrix I would have to create wrappers. Is it fine to skip those two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with first pass I am testing the FFI a bit on the side :). Is there any plans to generate bindings for at least C (header file with exported function etc...)?
@@ -204,7 +252,7 @@ mod tests { | |||
let expected_ov = OrientationVector::new( | |||
0.0, -1.0, 0.0, 1.5707963267948966 | |||
); | |||
let calc_ov = OrientationVector::from_quaternion(&quat); | |||
let calc_ov: OrientationVector = quat.into(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] round-trip test might be good if it makes sense in this PR, rather than your next ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't these two tests essentially provide the equivalent of a round-trip test? (the expected quaternion in one test is one of the input quaternions in the other and for the same case the opposite is true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show me where in person? Approving to unblock you, but I'm not sure I'm seeing that round trip logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know Rust so I'm not going to be super useful regarding the actual code, but based on descriptions of how things work and my understanding of how Rust probably works for the math, this looks good.
/// but the canonical "right-hand rule" is used to select one consistently). Then, | ||
/// a clockwise-rotation of theta is applied about the new-z axis | ||
/// | ||
/// It is highly recommended not to attempt any mathematics with the orientation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Euler angles should also have this warning
/// theta (in radians). However, unlike an axis-angle, an orientation vector alters | ||
/// the axes of the given frame of reference by rotating the z-axis to the | ||
/// vector axis provided. The new x-axis is the vector that is both orthogonal to | ||
/// the vector axis provided anc co-planar with both the old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anc -> and
let j = c[0]*s[1]*c[2] + s[0]*s[1]*s[2]; | ||
let k = s[0]*c[1]*c[2] + c[0]*c[1]*s[2]; | ||
|
||
Quaternion::new(real, i, j, k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not familiar with Rust, but would it be faster to put this math directly in the new()
call and not initialize the variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, I think Rust ownership rules make both ways essentially equivalent
// and must calculate roll based on the real rotation and yaw | ||
if pitch_sin.abs() >= 1.0 { | ||
pitch = (std::f64::consts::PI / 2.0).copysign(pitch_sin); | ||
roll = (2.0 * norm_quat.i.atan2(norm_quat.w)) + yaw.copysign(pitch_sin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: We should make this change in rdk as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one little comment for my own knowledge to be addressed in-person.
this will be the last PR for the spatialmath library until Jan, at which point we might start importing it into the SDKs