forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcmt_drake_signal_utils.cc
56 lines (46 loc) · 1.77 KB
/
lcmt_drake_signal_utils.cc
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
#include "drake/lcm/lcmt_drake_signal_utils.h"
#include "drake/common/drake_assert.h"
#include "drake/common/text_logging.h"
namespace drake {
namespace lcm {
// Compares two `drake::lcmt_drake_signal` messages are equal.
bool CompareLcmtDrakeSignalMessages(const lcmt_drake_signal& actual_message,
const lcmt_drake_signal& expected_message) {
bool result = true;
const int n = actual_message.dim;
if (n != expected_message.dim) {
drake::log()->trace(
"CompareLcmtDrakeSignalMessages: Dimensions mismatch ({} vs. {}).",
n, expected_message.dim);
result = false;
}
if (actual_message.timestamp != expected_message.timestamp) {
drake::log()->trace(
"CompareLcmtDrakeSignalMessages: timestamps mismatch ({} vs. {}).",
actual_message.timestamp, expected_message.timestamp);
result = false;
}
if (result) {
DRAKE_DEMAND(n == static_cast<int>(actual_message.val.size()));
DRAKE_DEMAND(n == static_cast<int>(actual_message.coord.size()));
DRAKE_DEMAND(n == static_cast<int>(expected_message.val.size()));
DRAKE_DEMAND(n == static_cast<int>(expected_message.coord.size()));
}
for (int i = 0; i < n && result; ++i) {
if (actual_message.val[i] != expected_message.val[i]) {
drake::log()->trace(
"CompareLcmtDrakeSignalMessages: val {} mismatch ({} vs. {}).",
i, actual_message.val[i], expected_message.val[i]);
result = false;
}
if (actual_message.coord[i] != expected_message.coord[i]) {
drake::log()->trace(
"CompareLcmtDrakeSignalMessages: coord {} mismatch ({} vs. {}).",
i, actual_message.coord[i], expected_message.coord[i]);
result = false;
}
}
return result;
}
} // namespace lcm
} // namespace drake