#[cfg(feature = "protobuf")]
use crate::protobuf::{ProtobufData, controller::*, geometry2d::*, geometry3d::*, kinematics::*, plant::*, spline::*, system::*, trajectory::*, wpimath::*};
#[cfg(feature = "protobuf")]
use nt_client_macros::ProtobufData;
#[cfg(feature = "struct")]
use crate::{schema::PublishSchemaError, r#struct::{StructData, StructSchema, byte::{ByteBuffer, ByteReader}}};
#[cfg(feature = "struct")]
use nt_client_macros::StructData;
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double ks;double kg;double kv;double ka;double dt"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufArmFeedforward))
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ArmFeedforward {
#[cfg_attr(feature = "protobuf", protobuf(field(ks)))]
pub k_s: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kg)))]
pub k_g: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kv)))]
pub k_v: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ka)))]
pub k_a: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(dt)))]
pub d_t: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double vx;double vy;double omega"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufChassisSpeeds)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ChassisSpeeds {
#[cfg_attr(feature = "protobuf", protobuf(field(vx)))]
pub velocity_x: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(vy)))]
pub velocity_y: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(omega)))]
pub omega: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double xInitial[2];double xFinal[2];double yInitial[2];double yFinal[2]"),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CubicHermiteSpline {
pub x_initial_control_vector: [f64; 2],
pub x_final_control_vector: [f64; 2],
pub y_initial_control_vector: [f64; 2],
pub y_final_control_vector: [f64; 2],
}
#[cfg(feature = "protobuf")]
impl ProtobufData for CubicHermiteSpline {
type Proto = ProtobufCubicHermiteSpline;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
x_initial_control_vector: proto.x_initial.try_into().ok()?,
x_final_control_vector: proto.x_final.try_into().ok()?,
y_initial_control_vector: proto.y_initial.try_into().ok()?,
y_final_control_vector: proto.y_final.try_into().ok()?,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
x_initial: self.x_initial_control_vector.into(),
x_final: self.x_final_control_vector.into(),
y_initial: self.y_initial_control_vector.into(),
y_final: self.y_final_control_vector.into(),
..Default::default()
}
}
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double ks;double kv;double ka;double dt"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDCMotor)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DCMotor {
pub nominal_voltage: f64,
pub stall_torque: f64,
pub stall_current: f64,
pub free_current: f64,
pub free_speed: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double kVLinear;double kALinear;double kVAngular;double kAAngular"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDifferentialDriveFeedforward)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DifferentialDriveFeedforward {
#[cfg_attr(feature = "protobuf", protobuf(field(kv_linear)))]
pub velocity_linear: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ka_linear)))]
pub acceleration_linear: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kv_angular)))]
pub velocity_angular: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ka_angular)))]
pub acceleration_angular: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double track_width"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDifferentialDriveKinematics)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DifferentialDriveKinematics {
pub track_width: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double left;double right")
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDifferentialDriveWheelPositions)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DifferentialDriveWheelPositions {
pub left: f64,
pub right: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double left;double right"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDifferentialDriveWheelSpeeds)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DifferentialDriveWheelSpeeds {
pub left: f64,
pub right: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double left;double right"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufDifferentialDriveWheelVoltages)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DifferentialDriveWheelVoltages {
pub left: f64,
pub right: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double ks;double kg;double kv;double ka;double dt"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufElevatorFeedforward)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ElevatorFeedforward {
#[cfg_attr(feature = "protobuf", protobuf(field(ks)))]
pub k_s: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kg)))]
pub k_g: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kv)))]
pub k_v: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ka)))]
pub k_a: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(dt)))]
pub d_t: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Pose2d center;double xSemiAxis;double ySemiAxis"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufEllipse2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Ellipse2d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub center: Pose2d,
#[cfg_attr(feature = "protobuf", protobuf(field(xSemiAxis)))]
pub x_semi_axis: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ySemiAxis)))]
pub y_semi_axis: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double position;double velocity"),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExponentialProfileState {
pub position: f64,
pub velocity: f64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LinearSystem<const S: usize, const I: usize, const O: usize> {
pub a: Matrix<S, S>,
pub b: Matrix<S, I>,
pub c: Matrix<O, S>,
pub d: Matrix<O, I>,
}
#[cfg(feature = "struct")]
impl<const S: usize, const I: usize, const O: usize> StructData for LinearSystem<S, I, O,> {
fn schema() -> StructSchema {
StructSchema(format!(
"{} a;{} b;{} c;{} d",
<Matrix<S, S>>::struct_type_name(),
<Matrix<S, I>>::struct_type_name(),
<Matrix<O, S>>::struct_type_name(),
<Matrix<O, I>>::struct_type_name(),
))
}
fn struct_type_name() -> String {
format!("LinearSystem__{}_{}_{}", S, I, O)
}
async fn publish_dependencies(manager: &mut crate::schema::SchemaManager) -> Result<(), PublishSchemaError> {
manager.publish_struct::<Matrix<S, S>>().await?;
manager.publish_struct::<Matrix<S, I>>().await?;
manager.publish_struct::<Matrix<O, S>>().await?;
manager.publish_struct::<Matrix<O, I>>().await
}
fn pack(self, buf: &mut ByteBuffer) {
self.a.pack(buf);
self.b.pack(buf);
self.c.pack(buf);
self.d.pack(buf);
}
fn unpack(read: &mut ByteReader) -> Option<Self> where Self: Sized {
let a = Matrix::unpack(read)?;
let b = Matrix::unpack(read)?;
let c = Matrix::unpack(read)?;
let d = Matrix::unpack(read)?;
Some(Self { a, b, c, d })
}
}
#[cfg(feature = "protobuf")]
impl<const S: usize, const I: usize, const O: usize> ProtobufData for LinearSystem<S, I, O> {
type Proto = ProtobufLinearSystem;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
a: Matrix::from_proto(proto.a.into_option().unwrap_or_default())?,
b: Matrix::from_proto(proto.b.into_option().unwrap_or_default())?,
c: Matrix::from_proto(proto.c.into_option().unwrap_or_default())?,
d: Matrix::from_proto(proto.d.into_option().unwrap_or_default())?,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
num_states: S as u32,
num_inputs: I as u32,
num_outputs: O as u32,
a: protobuf::MessageField::some(self.a.into_proto()),
b: protobuf::MessageField::some(self.a.into_proto()),
c: protobuf::MessageField::some(self.a.into_proto()),
d: protobuf::MessageField::some(self.a.into_proto()),
..Default::default()
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Matrix<const R: usize, const C: usize> {
pub data: [[f64; C]; R],
}
#[cfg(feature = "struct")]
impl<const R: usize, const C: usize> StructData for Matrix<R, C> {
fn schema() -> StructSchema {
StructSchema(format!("double data[{}]", R * C))
}
fn struct_type_name() -> String {
format!("Matrix__{}_{}", R, C)
}
async fn publish_dependencies(_: &mut crate::schema::SchemaManager) -> Result<(), PublishSchemaError> {
Ok(())
}
fn pack(self, buf: &mut ByteBuffer) {
self.data.into_iter().flatten().for_each(|value| {
buf.write_f64(value);
});
}
fn unpack(read: &mut ByteReader) -> Option<Self> {
let mut data = [[0.0; C]; R];
for value in data.iter_mut().flatten() {
*value = read.read_f64()?;
}
Some(Self { data })
}
}
#[cfg(feature = "protobuf")]
impl<const R: usize, const C: usize> ProtobufData for Matrix<R, C> {
type Proto = ProtobufMatrix;
fn from_proto(proto: Self::Proto) -> Option<Self> {
let mut data = [[0.0; C]; R];
if proto.data.len() != C * R { return None; };
proto.data.into_iter()
.enumerate()
.for_each(|(i, num)| {
data[i / C][i % C] = num;
});
Some(Self {
data,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
num_rows: R as u32,
num_cols: C as u32,
data: self.data.into_iter().flatten().collect(),
..Default::default()
}
}
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Translation2d front_left;Translation2d front_right;Translation2d rear_left;Translation2d rear_right"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufMecanumDriveKinematics))
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MecanumDriveKinematics {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub front_left: Translation2d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub front_right: Translation2d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rear_left: Translation2d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rear_right: Translation2d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double front_left;double front_right;double rear_left;double rear_right"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufMecanumDriveWheelPositions)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MecanumDriveWheelPositions {
pub front_left: f64,
pub front_right: f64,
pub rear_left: f64,
pub rear_right: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double front_left;double front_right;double rear_left;double rear_right"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufMecanumDriveWheelSpeeds)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MecanumDriveWheelSpeeds {
pub front_left: f64,
pub front_right: f64,
pub rear_left: f64,
pub rear_right: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Translation2d translation;Rotation2d rotation"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufPose2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Pose2d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub translation: Translation2d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rotation: Rotation2d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Translation3d translation;Rotation3d rotation"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufPose3d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Pose3d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub translation: Translation3d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rotation: Rotation3d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double w;double x;double y;double z"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufQuaternion)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Quaternion {
pub w: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double xInitial[3];double xFinal[3];double yInitial[3];double yFinal[3]"),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct QuinticHermiteSpline {
pub x_initial: [f64; 3],
pub x_final: [f64; 3],
pub y_initial: [f64; 3],
pub y_final: [f64; 3],
}
#[cfg(feature = "protobuf")]
impl ProtobufData for QuinticHermiteSpline {
type Proto = ProtobufQuinticHermiteSpline;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
x_initial: proto.x_initial.try_into().ok()?,
x_final: proto.x_final.try_into().ok()?,
y_initial: proto.y_initial.try_into().ok()?,
y_final: proto.y_final.try_into().ok()?,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
x_initial: self.x_initial.into(),
x_final: self.x_final.into(),
y_initial: self.y_initial.into(),
y_final: self.y_final.into(),
..Default::default()
}
}
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Pose2d center;double xWidth;double yWidth"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufRectangle2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rectangle2d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub center: Pose2d,
#[cfg_attr(feature = "protobuf", protobuf(field(xWidth)))]
pub x_width: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(yWidth)))]
pub y_width: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double value"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufRotation2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rotation2d {
pub value: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(type_name = "Rotation3d", schema = "Quaternion q"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufRotation3d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rotation3d {
#[cfg_attr(feature = "protobuf", protobuf(field(q), nested))]
#[cfg_attr(feature = "struct", structdata(nested))]
pub quaternion: Quaternion,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double ks;double kv;double ka;double dt"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufSimpleMotorFeedforward)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SimpleMotorFeedforward {
#[cfg_attr(feature = "protobuf", protobuf(field(ks)))]
pub k_s: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(kv)))]
pub k_v: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(ka)))]
pub k_a: f64,
#[cfg_attr(feature = "protobuf", protobuf(field(dt)))]
pub d_t: f64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SwerveDriveKinematics<const N: usize> {
pub modules: [Translation2d; N],
}
#[cfg(feature = "struct")]
impl<const N: usize> StructData for SwerveDriveKinematics<N> {
fn schema() -> StructSchema {
StructSchema(format!("Translation2d modules[{N}]"))
}
fn struct_type_name() -> String {
format!("SwerveDriveKinematics__{}", N)
}
async fn publish_dependencies(manager: &mut crate::schema::SchemaManager) -> Result<(), PublishSchemaError> {
manager.publish_struct::<Translation2d>().await
}
fn pack(self, buf: &mut ByteBuffer) {
Translation2d::pack_iter(self.modules, buf);
}
fn unpack(read: &mut ByteReader) -> Option<Self> {
let modules = Translation2d::unpack_array(read)?;
Some(Self { modules })
}
}
#[cfg(feature = "protobuf")]
impl<const N: usize> ProtobufData for SwerveDriveKinematics<N> {
type Proto = ProtobufSwerveDriveKinematics;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
modules: proto.modules.into_iter()
.map(Translation2d::from_proto)
.collect::<Option<Vec<_>>>()?
.try_into()
.ok()?,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
modules: self.modules.into_iter()
.map(|module| module.into_proto())
.collect(),
..Default::default()
}
}
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double distance;Rotation2d angle"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufSwerveModulePosition)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SwerveModulePosition {
pub distance: f64,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub angle: Rotation2d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double speed;Rotation2d angle"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufSwerveModuleState)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SwerveModuleState {
pub speed: f64,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub angle: Rotation2d,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Trajectory {
pub states: Vec<TrajectoryState>,
}
#[cfg(feature = "protobuf")]
impl ProtobufData for Trajectory {
type Proto = ProtobufTrajectory;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
states: proto.states.into_iter()
.map(TrajectoryState::from_proto)
.collect::<Option<_>>()?
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
states: self.states.into_iter()
.map(|state| state.into_proto())
.collect(),
..Default::default()
}
}
}
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTrajectoryState)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TrajectoryState {
pub time: f64,
pub velocity: f64,
pub acceleration: f64,
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub pose: Pose2d,
pub curvature: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Translation2d translation;Rotation2d rotation"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTransform2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Transform2d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub translation: Translation2d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rotation: Rotation2d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "Translation3d translation;Rotation3d rotation"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTransform3d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Transform3d {
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub translation: Translation3d,
#[cfg_attr(feature = "struct", structdata(nested))]
#[cfg_attr(feature = "protobuf", protobuf(nested))]
pub rotation: Rotation3d,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double x;double y"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTranslation2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Translation2d {
pub x: f64,
pub y: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double x;double y;double z"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTranslation3d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Translation3d {
pub x: f64,
pub y: f64,
pub z: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double position;double velocity"),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TrapezoidProfileState {
pub position: f64,
pub velocity: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double dx;double dy;double dtheta"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTwist2d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Twist2d {
pub dx: f64,
pub dy: f64,
pub dtheta: f64,
}
#[cfg_attr(feature = "struct",
derive(StructData),
structdata(schema = "double dx;double dy;double dz;double rx;double ry;double rz"),
)]
#[cfg_attr(feature = "protobuf",
derive(ProtobufData),
protobuf(from(ProtobufTwist3d)),
)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Twist3d {
pub dx: f64,
pub dy: f64,
pub dz: f64,
pub rx: f64,
pub ry: f64,
pub rz: f64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vector<const N: usize> {
pub rows: [f64; N],
}
#[cfg(feature = "struct")]
impl<const N: usize> StructData for Vector<N> {
fn schema() -> StructSchema {
StructSchema(format!("double data[{N}]"))
}
fn struct_type_name() -> String {
format!("Vector__{}", N)
}
async fn publish_dependencies(_: &mut crate::schema::SchemaManager) -> Result<(), PublishSchemaError> {
Ok(())
}
fn pack(self, buf: &mut ByteBuffer) {
for value in self.rows {
buf.write_f64(value);
}
}
fn unpack(read: &mut ByteReader) -> Option<Self> {
let mut rows = [0.0; N];
for value in rows.iter_mut() {
*value = read.read_f64()?;
}
Some(Self { rows })
}
}
#[cfg(feature = "protobuf")]
impl<const N: usize> ProtobufData for Vector<N> {
type Proto = ProtobufVector;
fn from_proto(proto: Self::Proto) -> Option<Self> {
Some(Self {
rows: proto.rows.try_into().ok()?,
})
}
fn into_proto(self) -> Self::Proto {
Self::Proto {
rows: self.rows.into(),
..Default::default()
}
}
}