agentic_robotics_core/
message.rs1use serde::{Deserialize, Serialize};
4use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
5
6pub trait Message: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
8 fn type_name() -> &'static str;
10
11 fn version() -> &'static str {
13 "1.0"
14 }
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)]
19pub struct RobotState {
20 pub position: [f64; 3],
21 pub velocity: [f64; 3],
22 pub timestamp: i64,
23}
24
25impl Message for RobotState {
26 fn type_name() -> &'static str {
27 "ros3_msgs/RobotState"
28 }
29}
30
31impl Default for RobotState {
32 fn default() -> Self {
33 Self {
34 position: [0.0; 3],
35 velocity: [0.0; 3],
36 timestamp: 0,
37 }
38 }
39}
40
41#[derive(Debug, Clone, Copy, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)]
43pub struct Point3D {
44 pub x: f32,
45 pub y: f32,
46 pub z: f32,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)]
51pub struct PointCloud {
52 pub points: Vec<Point3D>,
53 pub intensities: Vec<f32>,
54 pub timestamp: i64,
55}
56
57impl Message for PointCloud {
58 fn type_name() -> &'static str {
59 "ros3_msgs/PointCloud"
60 }
61}
62
63impl Default for PointCloud {
64 fn default() -> Self {
65 Self {
66 points: Vec::new(),
67 intensities: Vec::new(),
68 timestamp: 0,
69 }
70 }
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)]
75pub struct Pose {
76 pub position: [f64; 3],
77 pub orientation: [f64; 4], }
79
80impl Message for Pose {
81 fn type_name() -> &'static str {
82 "ros3_msgs/Pose"
83 }
84}
85
86impl Default for Pose {
87 fn default() -> Self {
88 Self {
89 position: [0.0; 3],
90 orientation: [0.0, 0.0, 0.0, 1.0], }
92 }
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98
99 #[test]
100 fn test_robot_state() {
101 let state = RobotState::default();
102 assert_eq!(state.position, [0.0; 3]);
103 assert_eq!(RobotState::type_name(), "ros3_msgs/RobotState");
104 }
105
106 #[test]
107 fn test_point_cloud() {
108 let cloud = PointCloud::default();
109 assert_eq!(cloud.points.len(), 0);
110 assert_eq!(PointCloud::type_name(), "ros3_msgs/PointCloud");
111 }
112}