mecha10-core 0.6.2

Mecha10 core runtime and foundational types
Documentation
//! Shared sensor message types
//!
//! This module contains common sensor message types used across drivers and nodes.
//! Previously these were duplicated in each driver, now they are centralized here.

use crate::messages::Message;
use serde::{Deserialize, Serialize};

// ============================================================================
// Camera Types
// ============================================================================

/// RGB image message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RgbImage {
    pub timestamp: u64,
    pub frame_id: u64,
    pub width: u32,
    pub height: u32,
    pub encoding: String,
    pub data: Vec<u8>,
}

impl Message for RgbImage {}

/// Depth image message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DepthImage {
    pub timestamp: u64,
    pub frame_id: u64,
    pub width: u32,
    pub height: u32,
    pub data: Vec<f32>,
}

impl Message for DepthImage {}

/// Camera info message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CameraInfo {
    pub timestamp: u64,
    pub width: u32,
    pub height: u32,
    pub fps: f32,
}

impl Message for CameraInfo {}

// ============================================================================
// LiDAR Types
// ============================================================================

/// Laser scan message (2D LiDAR)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LaserScan {
    pub timestamp: u64,
    pub scan_id: u64,
    pub angle_min: f32,
    pub angle_max: f32,
    pub angle_increment: f32,
    pub range_min: f32,
    pub range_max: f32,
    pub ranges: Vec<f32>,
    pub intensities: Vec<f32>,
}

impl Message for LaserScan {}

// ============================================================================
// Odometry Types
// ============================================================================

/// Odometry message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Odometry {
    pub timestamp: u64,
    pub x: f32,
    pub y: f32,
    pub theta: f32,
    pub linear_vel: f32,
    pub angular_vel: f32,
}

impl Message for Odometry {}

// ============================================================================
// IMU Types
// ============================================================================

/// IMU data message
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImuData {
    /// IMU sensor identifier
    #[serde(default = "default_imu_id")]
    pub imu_id: String,
    pub timestamp: u64,
    // Orientation (Euler angles in radians)
    pub roll: f32,
    pub pitch: f32,
    pub yaw: f32,
    // Angular velocity (rad/s)
    pub angular_velocity_x: f32,
    pub angular_velocity_y: f32,
    pub angular_velocity_z: f32,
    // Linear acceleration (m/s²)
    pub linear_acceleration_x: f32,
    pub linear_acceleration_y: f32,
    pub linear_acceleration_z: f32,
}

fn default_imu_id() -> String {
    "imu-0".to_string()
}

impl Message for ImuData {}