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
//! `sensor_msgs`: point clouds and compressed images.
use super::std_msgs::Header;
crate::ros_message! {
/// One field of a [`PointCloud2`] point (`sensor_msgs/msg/PointField`).
pub struct PointField("sensor_msgs/msg/PointField") {
/// Field name, e.g. `x`.
pub name: String,
/// Byte offset within the point.
pub offset: u32,
/// Element datatype, one of the associated constants.
pub datatype: u8,
/// Number of elements.
pub count: u32,
}
}
crate::ros_message! {
/// A packed point cloud (`sensor_msgs/msg/PointCloud2`).
pub struct PointCloud2("sensor_msgs/msg/PointCloud2") {
/// Stamp and frame.
pub header: Header,
/// Rows; 1 for an unordered cloud.
pub height: u32,
/// Points per row.
pub width: u32,
/// Point-field definitions and byte offsets.
pub fields: Vec<PointField>,
/// Whether `data` is big-endian.
pub is_bigendian: bool,
/// Bytes per point.
pub point_step: u32,
/// Bytes per row.
pub row_step: u32,
/// Packed points.
pub data: Vec<u8>,
/// Whether there are no invalid points.
pub is_dense: bool,
}
}
crate::ros_message! {
/// A compressed image (`sensor_msgs/msg/CompressedImage`).
pub struct CompressedImage("sensor_msgs/msg/CompressedImage") {
/// Stamp and frame.
pub header: Header,
/// Compression format, e.g. `jpeg`.
pub format: String,
/// Compressed bytes.
pub data: Vec<u8>,
}
}
impl PointField {
/// `int8`.
pub const INT8: u8 = 1;
/// `uint8`.
pub const UINT8: u8 = 2;
/// `int16`.
pub const INT16: u8 = 3;
/// `uint16`.
pub const UINT16: u8 = 4;
/// `int32`.
pub const INT32: u8 = 5;
/// `uint32`.
pub const UINT32: u8 = 6;
/// `float32`.
pub const FLOAT32: u8 = 7;
/// `float64`.
pub const FLOAT64: u8 = 8;
/// A single-element channel.
#[must_use]
pub fn new(name: &str, offset: u32, datatype: u8) -> Self {
Self {
name: name.to_owned(),
offset,
datatype,
count: 1,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ros::Message;
#[test]
fn hashes_match_jazzy() {
assert_eq!(
PointField::type_hash(),
"RIHS01_5c6a4750728c2bcfbbf7037225b20b02d4429634732146b742dee1726637ef01"
);
assert_eq!(
PointCloud2::type_hash(),
"RIHS01_9198cabf7da3796ae6fe19c4cb3bdd3525492988c70522628af5daa124bae2b5"
);
assert_eq!(
CompressedImage::type_hash(),
"RIHS01_15640771531571185e2efc8a100baf923961a4d15d5569652e6cb6691e8e371a"
);
}
}