Apollo 10.0
自动驾驶开放平台
throttle_command_100.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
20
21namespace apollo {
22namespace canbus {
23namespace demo {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Throttlecommand100::ID = 0x100;
28
29// public
31
33 // TODO(All) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Throttlecommand100::Parse(const std::uint8_t* bytes, int32_t length,
39 Demo* chassis) const {
40 chassis->mutable_throttle_command_100()->set_heartbeat_100(
41 heartbeat_100(bytes, length));
42 chassis->mutable_throttle_command_100()->set_speed_target(
43 speed_target(bytes, length));
44 chassis->mutable_throttle_command_100()->set_throttle_acc(
45 throttle_acc(bytes, length));
46 chassis->mutable_throttle_command_100()->set_checksum_100(
47 checksum_100(bytes, length));
48 chassis->mutable_throttle_command_100()->set_throttle_pedal_target(
49 throttle_pedal_target(bytes, length));
50 chassis->mutable_throttle_command_100()->set_throttle_en_ctrl(
51 throttle_en_ctrl(bytes, length));
52}
53
55 // TODO(All) : you should add the heartbeat manually
56 ++heartbeat_100_;
57 heartbeat_100_ = (heartbeat_100_) % 16;
58 set_p_heartbeat_100(data, heartbeat_100_);
59 checksum_100_ =
60 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
61 set_p_checksum_100(data, checksum_100_);
62}
63
64void Throttlecommand100::UpdateData(uint8_t* data) {
65 set_p_heartbeat_100(data, heartbeat_100_);
66 set_p_throttle_acc(data, throttle_acc_);
67 set_p_throttle_pedal_target(data, throttle_pedal_target_);
68 set_p_throttle_en_ctrl(data, throttle_en_ctrl_);
69}
70
72 // TODO(All) : you should check this manually
73 heartbeat_100_ = 0;
74 speed_target_ = 0.0;
75 throttle_acc_ = 0.0;
76 checksum_100_ = 0;
77 throttle_pedal_target_ = 0.0;
79}
80
82 heartbeat_100_ = heartbeat_100;
83 return this;
84}
85
86// config detail: {'bit': 7, 'is_signed_var': False, 'len': 4, 'name':
87// 'Heartbeat_100', 'offset': 0.0, 'order': 'motorola', 'physical_range':
88// '[0|15]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
89void Throttlecommand100::set_p_heartbeat_100(uint8_t* data, int heartbeat_100) {
90 heartbeat_100 = ProtocolData::BoundedValue(0, 15, heartbeat_100);
91 int x = heartbeat_100;
92
93 Byte to_set(data + 0);
94 to_set.set_value(x, 4, 4);
95}
96
98 speed_target_ = speed_target;
99 return this;
100}
101
102// config detail: {'bit': 47, 'is_signed_var': False, 'len': 12, 'name':
103// 'Speed_Target', 'offset': 0.0, 'order': 'motorola', 'physical_range':
104// '[0|40.95]', 'physical_unit': 'm/s', 'precision': 0.01, 'type': 'double'}
105void Throttlecommand100::set_p_speed_target(uint8_t* data,
106 double speed_target) {
107 speed_target = ProtocolData::BoundedValue(0.0, 40.95, speed_target);
108 int x = speed_target / 0.010000;
109 uint8_t t = 0;
110
111 t = x & 0xF;
112 Byte to_set0(data + 6);
113 to_set0.set_value(t, 4, 4);
114 x >>= 4;
115
116 t = x & 0xFF;
117 Byte to_set1(data + 5);
118 to_set1.set_value(t, 0, 8);
119}
120
122 throttle_acc_ = throttle_acc;
123 return this;
124}
125
126// config detail: {'bit': 15, 'is_signed_var': False, 'len': 10, 'name':
127// 'Throttle_Acc', 'offset': 0.0, 'order': 'motorola', 'physical_range':
128// '[0|10]', 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'}
129void Throttlecommand100::set_p_throttle_acc(uint8_t* data,
130 double throttle_acc) {
131 throttle_acc = ProtocolData::BoundedValue(0.0, 10.0, throttle_acc);
132 int x = throttle_acc / 0.010000;
133 uint8_t t = 0;
134
135 t = x & 0x3;
136 Byte to_set0(data + 2);
137 to_set0.set_value(t, 6, 2);
138 x >>= 2;
139
140 t = x & 0xFF;
141 Byte to_set1(data + 1);
142 to_set1.set_value(t, 0, 8);
143}
144
146 checksum_100_ = checksum_100;
147 return this;
148}
149
150// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
151// 'CheckSum_100', 'offset': 0.0, 'order': 'motorola', 'physical_range':
152// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
153void Throttlecommand100::set_p_checksum_100(uint8_t* data, int checksum_100) {
154 checksum_100 = ProtocolData::BoundedValue(0, 255, checksum_100);
155 int x = checksum_100;
156
157 Byte to_set(data + 7);
158 to_set.set_value(x, 0, 8);
159}
160
162 double throttle_pedal_target) {
163 throttle_pedal_target_ = throttle_pedal_target;
164 return this;
165}
166
167// config detail: {'bit': 31, 'description': 'command', 'is_signed_var': False,
168// 'len': 16, 'name': 'Throttle_Pedal_Target', 'offset': 0.0, 'order':
169// 'motorola', 'physical_range': '[0|100]', 'physical_unit': '%', 'precision':
170// 0.1, 'signal_type': 'command', 'type': 'double'}
171void Throttlecommand100::set_p_throttle_pedal_target(
172 uint8_t* data, double throttle_pedal_target) {
173 throttle_pedal_target =
174 ProtocolData::BoundedValue(0.0, 100.0, throttle_pedal_target);
175 int x = throttle_pedal_target / 0.100000;
176 uint8_t t = 0;
177
178 t = x & 0xFF;
179 Byte to_set0(data + 4);
180 to_set0.set_value(t, 0, 8);
181 x >>= 8;
182
183 t = x & 0xFF;
184 Byte to_set1(data + 3);
185 to_set1.set_value(t, 0, 8);
186}
187
190 throttle_en_ctrl_ = throttle_en_ctrl;
191 return this;
192}
193
194// config detail: {'bit': 0, 'description': 'enable', 'enum': {0:
195// 'THROTTLE_EN_CTRL_DISABLE', 1: 'THROTTLE_EN_CTRL_ENABLE'}, 'is_signed_var':
196// False, 'len': 1, 'name': 'Throttle_EN_CTRL', 'offset': 0.0, 'order':
197// 'motorola', 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0,
198// 'signal_type': 'enable', 'type': 'enum'}
199void Throttlecommand100::set_p_throttle_en_ctrl(
200 uint8_t* data,
202 int x = throttle_en_ctrl;
203
204 Byte to_set(data + 0);
205 to_set.set_value(x, 0, 1);
206}
207
208int Throttlecommand100::heartbeat_100(const std::uint8_t* bytes,
209 int32_t length) const {
210 Byte t0(bytes + 0);
211 int32_t x = t0.get_byte(4, 4);
212
213 int ret = x;
214 return ret;
215}
216
217double Throttlecommand100::speed_target(const std::uint8_t* bytes,
218 int32_t length) const {
219 Byte t0(bytes + 5);
220 int32_t x = t0.get_byte(0, 8);
221
222 Byte t1(bytes + 6);
223 int32_t t = t1.get_byte(4, 4);
224 x <<= 4;
225 x |= t;
226
227 double ret = x * 0.010000;
228 return ret;
229}
230
231double Throttlecommand100::throttle_acc(const std::uint8_t* bytes,
232 int32_t length) const {
233 Byte t0(bytes + 1);
234 int32_t x = t0.get_byte(0, 8);
235
236 Byte t1(bytes + 2);
237 int32_t t = t1.get_byte(6, 2);
238 x <<= 2;
239 x |= t;
240
241 double ret = x * 0.010000;
242 return ret;
243}
244
245int Throttlecommand100::checksum_100(const std::uint8_t* bytes,
246 int32_t length) const {
247 Byte t0(bytes + 7);
248 int32_t x = t0.get_byte(0, 8);
249
250 int ret = x;
251 return ret;
252}
253
254double Throttlecommand100::throttle_pedal_target(const std::uint8_t* bytes,
255 int32_t length) const {
256 Byte t0(bytes + 3);
257 int32_t x = t0.get_byte(0, 8);
258
259 Byte t1(bytes + 4);
260 int32_t t = t1.get_byte(0, 8);
261 x <<= 8;
262 x |= t;
263
264 double ret = x * 0.100000;
265 return ret;
266}
267
268Throttle_command_100::Throttle_en_ctrlType Throttlecommand100::throttle_en_ctrl(
269 const std::uint8_t* bytes, int32_t length) const {
270 Byte t0(bytes + 0);
271 int32_t x = t0.get_byte(0, 1);
272
275 return ret;
276}
277} // namespace demo
278} // namespace canbus
279} // namespace apollo
Defines the Byte class.
void UpdateData_Heartbeat(uint8_t *data) override
Throttlecommand100 * set_heartbeat_100(int heartbeat_100)
Throttlecommand100 * set_throttle_en_ctrl(Throttle_command_100::Throttle_en_ctrlType throttle_en_ctrl)
void Parse(const std::uint8_t *bytes, int32_t length, Demo *chassis) const override
Throttlecommand100 * set_throttle_pedal_target(double throttle_pedal_target)
Throttlecommand100 * set_checksum_100(int checksum_100)
Throttlecommand100 * set_speed_target(double speed_target)
Throttlecommand100 * set_throttle_acc(double throttle_acc)
class register implement
Definition arena_queue.h:37