Apollo 10.0
自动驾驶开放平台
brake_command_101.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 Brakecommand101::ID = 0x101;
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 Brakecommand101::Parse(const std::uint8_t* bytes, int32_t length,
39 Demo* chassis) const {
40 chassis->mutable_brake_command_101()->set_heartbeat_101(
41 heartbeat_101(bytes, length));
42 chassis->mutable_brake_command_101()->set_aeb_en_ctrl(
43 aeb_en_ctrl(bytes, length));
44 chassis->mutable_brake_command_101()->set_brake_dec(brake_dec(bytes, length));
45 chassis->mutable_brake_command_101()->set_checksum_101(
46 checksum_101(bytes, length));
47 chassis->mutable_brake_command_101()->set_brake_pedal_target(
48 brake_pedal_target(bytes, length));
49 chassis->mutable_brake_command_101()->set_brake_en_ctrl(
50 brake_en_ctrl(bytes, length));
51}
52
54 // TODO(All) : you should add the heartbeat manually
55 ++heartbeat_101_;
56 heartbeat_101_ = (heartbeat_101_) % 16;
57 set_p_heartbeat_101(data, heartbeat_101_);
58 checksum_101_ =
59 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
60 set_p_checksum_101(data, checksum_101_);
61}
62
63void Brakecommand101::UpdateData(uint8_t* data) {
64 set_p_aeb_en_ctrl(data, aeb_en_ctrl_);
65 set_p_brake_dec(data, brake_dec_);
66 set_p_brake_pedal_target(data, brake_pedal_target_);
67 set_p_brake_en_ctrl(data, brake_en_ctrl_);
68}
69
71 // TODO(All) : you should check this manually
72 heartbeat_101_ = 0;
74 brake_dec_ = 0.0;
75 checksum_101_ = 0;
76 brake_pedal_target_ = 0.0;
78}
79
81 heartbeat_101_ = heartbeat_101;
82 return this;
83}
84
85// config detail: {'bit': 7, 'is_signed_var': False, 'len': 4, 'name':
86// 'Heartbeat_101', 'offset': 0.0, 'order': 'motorola', 'physical_range':
87// '[0|15]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
88void Brakecommand101::set_p_heartbeat_101(uint8_t* data, int heartbeat_101) {
89 heartbeat_101 = ProtocolData::BoundedValue(0, 15, heartbeat_101);
90 int x = heartbeat_101;
91
92 Byte to_set(data + 0);
93 to_set.set_value(x, 4, 4);
94}
95
98 aeb_en_ctrl_ = aeb_en_ctrl;
99 return this;
100}
101
102// config detail: {'bit': 1, 'enum': {0: 'AEB_EN_CTRL_DISABLE_AEB', 1:
103// 'AEB_EN_CTRL_ENABLE_AEB'}, 'is_signed_var': False, 'len': 1, 'name':
104// 'AEB_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]',
105// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
106void Brakecommand101::set_p_aeb_en_ctrl(
107 uint8_t* data, Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl) {
108 int x = aeb_en_ctrl;
109
110 Byte to_set(data + 0);
111 to_set.set_value(x, 1, 1);
112}
113
115 brake_dec_ = brake_dec;
116 return this;
117}
118
119// config detail: {'bit': 15, 'is_signed_var': False, 'len': 10, 'name':
120// 'Brake_Dec', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|10]',
121// 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'}
122void Brakecommand101::set_p_brake_dec(uint8_t* data, double brake_dec) {
123 brake_dec = ProtocolData::BoundedValue(0.0, 10.0, brake_dec);
124 int x = brake_dec / 0.010000;
125 uint8_t t = 0;
126
127 t = x & 0x3;
128 Byte to_set0(data + 2);
129 to_set0.set_value(t, 6, 2);
130 x >>= 2;
131
132 t = x & 0xFF;
133 Byte to_set1(data + 1);
134 to_set1.set_value(t, 0, 8);
135}
136
138 checksum_101_ = checksum_101;
139 return this;
140}
141
142// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
143// 'CheckSum_101', 'offset': 0.0, 'order': 'motorola', 'physical_range':
144// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
145void Brakecommand101::set_p_checksum_101(uint8_t* data, int checksum_101) {
146 checksum_101 = ProtocolData::BoundedValue(0, 255, checksum_101);
147 int x = checksum_101;
148
149 Byte to_set(data + 7);
150 to_set.set_value(x, 0, 8);
151}
152
154 double brake_pedal_target) {
155 brake_pedal_target_ = brake_pedal_target;
156 return this;
157}
158
159// config detail: {'bit': 31, 'description': 'command', 'is_signed_var': False,
160// 'len': 16, 'name': 'Brake_Pedal_Target', 'offset': 0.0, 'order': 'motorola',
161// 'physical_range': '[0|100]', 'physical_unit': '%', 'precision': 0.1,
162// 'signal_type': 'command', 'type': 'double'}
163void Brakecommand101::set_p_brake_pedal_target(uint8_t* data,
164 double brake_pedal_target) {
165 brake_pedal_target =
166 ProtocolData::BoundedValue(0.0, 100.0, brake_pedal_target);
167 int x = brake_pedal_target / 0.100000;
168 uint8_t t = 0;
169
170 t = x & 0xFF;
171 Byte to_set0(data + 4);
172 to_set0.set_value(t, 0, 8);
173 x >>= 8;
174
175 t = x & 0xFF;
176 Byte to_set1(data + 3);
177 to_set1.set_value(t, 0, 8);
178}
179
182 brake_en_ctrl_ = brake_en_ctrl;
183 return this;
184}
185
186// config detail: {'bit': 0, 'description': 'enable', 'enum': {0:
187// 'BRAKE_EN_CTRL_DISABLE', 1: 'BRAKE_EN_CTRL_ENABLE'}, 'is_signed_var': False,
188// 'len': 1, 'name': 'Brake_EN_CTRL', 'offset': 0.0, 'order': 'motorola',
189// 'physical_range':
190// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'signal_type': 'enable',
191// 'type': 'enum'}
192void Brakecommand101::set_p_brake_en_ctrl(
193 uint8_t* data, Brake_command_101::Brake_en_ctrlType brake_en_ctrl) {
194 int x = brake_en_ctrl;
195
196 Byte to_set(data + 0);
197 to_set.set_value(x, 0, 1);
198}
199
200int Brakecommand101::heartbeat_101(const std::uint8_t* bytes,
201 int32_t length) const {
202 Byte t0(bytes + 0);
203 int32_t x = t0.get_byte(4, 4);
204
205 int ret = x;
206 return ret;
207}
208
209Brake_command_101::Aeb_en_ctrlType Brakecommand101::aeb_en_ctrl(
210 const std::uint8_t* bytes, int32_t length) const {
211 Byte t0(bytes + 0);
212 int32_t x = t0.get_byte(1, 1);
213
216 return ret;
217}
218
219double Brakecommand101::brake_dec(const std::uint8_t* bytes,
220 int32_t length) const {
221 Byte t0(bytes + 1);
222 int32_t x = t0.get_byte(0, 8);
223
224 Byte t1(bytes + 2);
225 int32_t t = t1.get_byte(6, 2);
226 x <<= 2;
227 x |= t;
228
229 double ret = x * 0.010000;
230 return ret;
231}
232
233int Brakecommand101::checksum_101(const std::uint8_t* bytes,
234 int32_t length) const {
235 Byte t0(bytes + 7);
236 int32_t x = t0.get_byte(0, 8);
237
238 int ret = x;
239 return ret;
240}
241
242double Brakecommand101::brake_pedal_target(const std::uint8_t* bytes,
243 int32_t length) const {
244 Byte t0(bytes + 3);
245 int32_t x = t0.get_byte(0, 8);
246
247 Byte t1(bytes + 4);
248 int32_t t = t1.get_byte(0, 8);
249 x <<= 8;
250 x |= t;
251
252 double ret = x * 0.100000;
253 return ret;
254}
255
256Brake_command_101::Brake_en_ctrlType Brakecommand101::brake_en_ctrl(
257 const std::uint8_t* bytes, int32_t length) const {
258 Byte t0(bytes + 0);
259 int32_t x = t0.get_byte(0, 1);
260
263 return ret;
264}
265} // namespace demo
266} // namespace canbus
267} // namespace apollo
Defines the Byte class.
Brakecommand101 * set_checksum_101(int checksum_101)
Brakecommand101 * set_brake_en_ctrl(Brake_command_101::Brake_en_ctrlType brake_en_ctrl)
void UpdateData_Heartbeat(uint8_t *data) override
void UpdateData(uint8_t *data) override
Brakecommand101 * set_heartbeat_101(int heartbeat_101)
void Parse(const std::uint8_t *bytes, int32_t length, Demo *chassis) const override
Brakecommand101 * set_brake_dec(double brake_dec)
Brakecommand101 * set_aeb_en_ctrl(Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl)
Brakecommand101 * set_brake_pedal_target(double brake_pedal_target)
class register implement
Definition arena_queue.h:37