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
mod error;
pub use error::IncompleteTransmissionError;
pub use error::ReceiveError;
pub use error::SendError;
mod generated;
pub mod msg {
pub use super::generated::*;
}
pub mod sync_peer;
#[cfg(feature = "tokio")]
pub mod tokio_peer;
#[cfg(feature = "nalgebra")]
mod nalgebra;
impl msg::EgmRobot {
pub fn sequence_number(&self) -> Option<u32> {
self.header.as_ref()?.seqno
}
pub fn timestamp_ms(&self) -> Option<u32> {
self.header.as_ref()?.tm
}
pub fn feedback_joints(&self) -> Option<&Vec<f64>> {
Some(&self.feed_back.as_ref()?.joints.as_ref()?.joints)
}
pub fn feedback_cartesion(&self) -> Option<&msg::EgmPose> {
self.feed_back.as_ref()?.cartesian.as_ref()
}
pub fn feedback_extenal_joints(&self) -> Option<&Vec<f64>> {
Some(&self.feed_back.as_ref()?.external_joints.as_ref()?.joints)
}
pub fn feedback_time(&self) -> Option<msg::EgmClock> {
self.feed_back.as_ref()?.time.clone()
}
pub fn planned_joints(&self) -> Option<&Vec<f64>> {
Some(&self.planned.as_ref()?.joints.as_ref()?.joints)
}
pub fn planned_cartesion(&self) -> Option<&msg::EgmPose> {
self.planned.as_ref()?.cartesian.as_ref()
}
pub fn planned_extenal_joints(&self) -> Option<&Vec<f64>> {
Some(&self.planned.as_ref()?.external_joints.as_ref()?.joints)
}
pub fn planned_time(&self) -> Option<msg::EgmClock> {
self.planned.as_ref()?.time.clone()
}
pub fn is_motors_on(&self) -> Option<bool> {
use msg::egm_motor_state::MotorStateType;
match self.motor_state.as_ref()?.state() {
MotorStateType::MotorsUndefined => None,
MotorStateType::MotorsOn => Some(true),
MotorStateType::MotorsOff => Some(false),
}
}
pub fn is_rapid_running(&self) -> Option<bool> {
use msg::egm_rapid_ctrl_exec_state::RapidCtrlExecStateType;
match self.rapid_exec_state.as_ref()?.state() {
RapidCtrlExecStateType::RapidUndefined => None,
RapidCtrlExecStateType::RapidRunning => Some(true),
RapidCtrlExecStateType::RapidStopped => Some(false),
}
}
pub fn test_signals(&self) -> Option<&Vec<f64>> {
Some(&self.test_signals.as_ref()?.signals)
}
pub fn measured_force(&self) -> Option<&Vec<f64>> {
Some(&self.measured_force.as_ref()?.force)
}
}
fn encode_to_vec(msg: &impl prost::Message) -> Result<Vec<u8>, prost::EncodeError> {
let encoded_len = msg.encoded_len();
let mut buffer = Vec::<u8>::with_capacity(encoded_len);
msg.encode(&mut buffer)?;
Ok(buffer)
}
#[cfg(test)]
#[test]
fn test_encode_to_vec() {
use assert2::assert;
use prost::Message;
assert!(encode_to_vec(&true).unwrap().len() == true.encoded_len());
assert!(encode_to_vec(&10).unwrap().len() == 10.encoded_len());
assert!(encode_to_vec(&String::from("aap noot mies")).unwrap().len() == String::from("aap noot mies").encoded_len());
}