1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! `std_msgs`: header, string, colour and multi-arrays.
//!
//! This module defines a message named `String`; plain strings are therefore
//! spelled `::std::string::String` here.
use super::builtin_interfaces::Time;
crate::ros_message! {
/// Stamp and coordinate frame of a message (`std_msgs/msg/Header`).
pub struct Header("std_msgs/msg/Header") {
/// Acquisition time.
pub stamp: Time,
/// Coordinate frame the data is expressed in.
pub frame_id: ::std::string::String,
}
}
crate::ros_message! {
/// A single string (`std_msgs/msg/String`).
pub struct String("std_msgs/msg/String") {
/// The text.
pub data: ::std::string::String,
}
}
crate::ros_message! {
/// An RGBA colour with components in `0..=1` (`std_msgs/msg/ColorRGBA`).
pub struct ColorRGBA("std_msgs/msg/ColorRGBA") {
/// Red.
pub r: f32,
/// Green.
pub g: f32,
/// Blue.
pub b: f32,
/// Alpha.
pub a: f32,
}
}
crate::ros_message! {
/// One dimension of a multi-array layout (`std_msgs/msg/MultiArrayDimension`).
pub struct MultiArrayDimension("std_msgs/msg/MultiArrayDimension") {
/// Label of the dimension.
pub label: ::std::string::String,
/// Size of the dimension.
pub size: u32,
/// Stride of the dimension.
pub stride: u32,
}
}
crate::ros_message! {
/// Layout of a multi-array (`std_msgs/msg/MultiArrayLayout`).
pub struct MultiArrayLayout("std_msgs/msg/MultiArrayLayout") {
/// Dimensions, outermost first.
pub dim: Vec<MultiArrayDimension>,
/// Padding elements at the front of `data`.
pub data_offset: u32,
}
}
crate::ros_message! {
/// A multi-dimensional `float32` array (`std_msgs/msg/Float32MultiArray`).
pub struct Float32MultiArray("std_msgs/msg/Float32MultiArray") {
/// Layout of `data`.
pub layout: MultiArrayLayout,
/// Row-major data.
pub data: Vec<f32>,
}
}
impl ColorRGBA {
/// A colour from its components.
#[must_use]
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
Self { r, g, b, a }
}
}
impl Float32MultiArray {
/// A 2-D row-major array of `rows` × `cols` with the given labels.
#[must_use]
pub fn matrix(
row_label: &str,
col_label: &str,
rows: usize,
cols: usize,
data: Vec<f32>,
) -> Self {
Self {
layout: MultiArrayLayout {
dim: vec![
MultiArrayDimension {
label: row_label.to_owned(),
size: rows as u32,
stride: (rows * cols) as u32,
},
MultiArrayDimension {
label: col_label.to_owned(),
size: cols as u32,
stride: cols as u32,
},
],
data_offset: 0,
},
data,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ros::Message;
#[test]
fn hashes_match_jazzy() {
for (hash, expected) in [
(
Header::type_hash(),
"f49fb3ae2cf070f793645ff749683ac6b06203e41c891e17701b1cb597ce6a01",
),
(
String::type_hash(),
"df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18",
),
(
ColorRGBA::type_hash(),
"77a7a5b9ae477306097665106e0413ba74440245b1f3d0c6d6405fe5c7813fe8",
),
(
MultiArrayDimension::type_hash(),
"5e773a60a4c7fc8a54985f307c7837aa2994252a126c301957a24e31282c9cbe",
),
(
MultiArrayLayout::type_hash(),
"4c66e6f78e740ac103a94cf63259f968e48c617e7699e829b63c21a5cb50dac6",
),
(
Float32MultiArray::type_hash(),
"0599f6f85b4bfca379873a0b4375a0aca022156bd2d7021275d116ed1fa8bfe0",
),
] {
assert_eq!(hash, format!("RIHS01_{expected}"));
}
}
}