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

[RSDK-732] orientation vector and rotation matrices #20

Merged

Conversation

gvaradarajan
Copy link
Member

this will be the last PR for the spatialmath library until Jan, at which point we might start importing it into the SDKs

@gvaradarajan gvaradarajan requested a review from a team as a code owner December 5, 2022 23:21
OrientationVector{o_vector, theta}
}

pub fn from_quaternion(quat: &Quaternion<f64>) -> Self {
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

@npmenard npmenard left a 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...)?

@gvaradarajan gvaradarajan requested a review from npmenard December 7, 2022 15:54
@npmenard npmenard removed their request for review December 9, 2022 19:24
@@ -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();
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

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.

src/spatialmath/utils.rs Outdated Show resolved Hide resolved
src/spatialmath/utils.rs Outdated Show resolved Hide resolved
Copy link
Member

@biotinker biotinker left a 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
Copy link
Member

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

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

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?

Copy link
Member Author

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);
Copy link
Member

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.

@gvaradarajan gvaradarajan requested a review from randhid December 12, 2022 19:43
Copy link
Member

@randhid randhid left a 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.

@gvaradarajan gvaradarajan merged commit 2849c01 into viamrobotics:main Dec 14, 2022
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

Successfully merging this pull request may close these issues.

4 participants