Skip to content
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
1 change: 1 addition & 0 deletions applications/autoware/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
nalgebra = { version = "0.35", default-features = false, features = ["libm"] }
30 changes: 18 additions & 12 deletions applications/autoware/common_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
//! This crate defines data types that are common to the Autoware project.
//!
//! For algebraic operations and transformations, this crate relies on nalgebra.
//! This implies some differences from the conventions used in ROS.
//!
//! For example, quaternions are represented using nalgebra's convention rather than ROS's.
//! `nalgebra`'s quaternion convention is `Quaternion::new(w, i, j, k)`.
//! On the other hand, ROS uses the `(x, y, z, w)` convention for quaternions.
//!
//! We will use nalgebra's convention throughout this crate,
//! and only convert to/from ROS's convention at I/O boundaries.
//! ROS compatibility functions are marked as deprecated, and should only be used for interfacing with ROS
//! or for maintaining compatibility with existing ROS-based code.

#![no_std]

extern crate alloc;

pub mod transform;

#[derive(Debug, Clone)]
pub struct Header {
pub frame_id: &'static str,
pub timestamp: u64,
}

#[derive(Debug, Clone)]
pub struct Vector3 {
pub x: f64,
pub y: f64,
pub z: f64,
}

impl Vector3 {
pub fn new(x: f64, y: f64, z: f64) -> Self {
Self { x, y, z }
}
}
pub use nalgebra::{Quaternion, UnitQuaternion, Vector3};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-exporting nalgebra's Quaternion changes the constructor order from the old field-named {x, y, z, w} (ROS order) to Quaternion::new(w, i, j, k). The TODO in imu_corrector/src/lib.rs L147-148 plans to hardcode a fixed TF next, and copying ROS values into new() would silently give a wrong rotation. Could we add a ROS-order constructor (e.g. Transform::from_ros_xyzw(t: [f64; 3], q: [f64; 4]), via Quaternion::from_vector(Vector4::new(x, y, z, w))) or at least document the order?

Loading