Apollo 10.0
自动驾驶开放平台
brake_command_101.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 devkit {
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 Devkit* chassis) const {
40 chassis->mutable_brake_command_101()->set_brake_en_ctrl(
41 brake_en_ctrl(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(
45 brake_dec(bytes, length));
46 chassis->mutable_brake_command_101()->set_brake_pedal_target(
47 brake_pedal_target(bytes, length));
48 chassis->mutable_brake_command_101()->set_checksum_101(
49 checksum_101(bytes, length));
50}
51
52void Brakecommand101::UpdateData(uint8_t* data) {
53 set_p_aeb_en_ctrl(data, aeb_en_ctrl_);
54 set_p_brake_dec(data, brake_dec_);
55 set_p_brake_pedal_target(data, brake_pedal_target_);
56 set_p_brake_en_ctrl(data, brake_en_ctrl_);
57 checksum_101_ =
58 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
59 set_p_checksum_101(data, checksum_101_);
60}
61
63 // TODO(All) : you should check this manually
65 brake_dec_ = 0.0;
66 checksum_101_ = 0;
67 brake_pedal_target_ = 0.0;
69}
70
73 brake_en_ctrl_ = brake_en_ctrl;
74 return this;
75}
76
77// config detail: {'bit': 0, 'enum': {0: 'BRAKE_EN_CTRL_DISABLE', 1:
78// 'BRAKE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name':
79// 'Brake_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range':
80// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
81void Brakecommand101::set_p_brake_en_ctrl(
82 uint8_t* data, Brake_command_101::Brake_en_ctrlType brake_en_ctrl) {
83 int x = brake_en_ctrl;
84
85 Byte to_set(data + 0);
86 to_set.set_value(x, 0, 1);
87}
88
91 aeb_en_ctrl_ = aeb_en_ctrl;
92 return this;
93}
94
95// config detail: {'bit': 1, 'enum': {0: 'AEB_EN_CTRL_DISABLE_AEB', 1:
96// 'AEB_EN_CTRL_ENABLE_AEB'}, 'is_signed_var': False, 'len': 1, 'name':
97// 'AEB_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]',
98// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
99void Brakecommand101::set_p_aeb_en_ctrl(
100 uint8_t* data, Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl) {
101 int x = aeb_en_ctrl;
102
103 Byte to_set(data + 0);
104 to_set.set_value(x, 1, 1);
105}
106
108 brake_dec_ = brake_dec;
109 return this;
110}
111
112// config detail: {'bit': 15, 'is_signed_var': False, 'len': 10, 'name':
113// 'Brake_Dec', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|10]',
114// 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'}
115void Brakecommand101::set_p_brake_dec(uint8_t* data, double brake_dec) {
116 brake_dec = ProtocolData::BoundedValue(0.0, 10.0, brake_dec);
117 int x = brake_dec / 0.010000;
118 uint8_t t = 0;
119
120 t = x & 0x3;
121 Byte to_set0(data + 2);
122 to_set0.set_value(t, 6, 2);
123 x >>= 2;
124
125 t = x & 0xFF;
126 Byte to_set1(data + 1);
127 to_set1.set_value(t, 0, 8);
128}
129
131 double brake_pedal_target) {
132 brake_pedal_target_ = brake_pedal_target;
133 return this;
134}
135
136// config detail: {'bit': 31, 'is_signed_var': False, 'len': 16, 'name':
137// 'Brake_Pedal_Target', 'offset': 0.0, 'order': 'motorola', 'physical_range':
138// '[0|100]', 'physical_unit': '%', 'precision': 0.1, 'type': 'double'}
139void Brakecommand101::set_p_brake_pedal_target(uint8_t* data,
140 double brake_pedal_target) {
141 brake_pedal_target =
142 ProtocolData::BoundedValue(0.0, 100.0, brake_pedal_target);
143 int x = brake_pedal_target / 0.100000;
144 uint8_t t = 0;
145
146 t = x & 0xFF;
147 Byte to_set0(data + 4);
148 to_set0.set_value(t, 0, 8);
149 x >>= 8;
150
151 t = x & 0xFF;
152 Byte to_set1(data + 3);
153 to_set1.set_value(t, 0, 8);
154}
155
157 checksum_101_ = checksum_101;
158 return this;
159}
160
161// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
162// 'CheckSum_101', 'offset': 0.0, 'order': 'motorola', 'physical_range':
163// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
164void Brakecommand101::set_p_checksum_101(uint8_t* data, int checksum_101) {
165 checksum_101 = ProtocolData::BoundedValue(0, 255, checksum_101);
166 int x = checksum_101;
167
168 Byte to_set(data + 7);
169 to_set.set_value(x, 0, 8);
170}
171
172Brake_command_101::Brake_en_ctrlType Brakecommand101::brake_en_ctrl(
173 const std::uint8_t* bytes, int32_t length) const {
174 Byte t0(bytes + 0);
175 int32_t x = t0.get_byte(0, 1);
176
179 return ret;
180}
181
182Brake_command_101::Aeb_en_ctrlType Brakecommand101::aeb_en_ctrl(
183 const std::uint8_t* bytes, int32_t length) const {
184 Byte t0(bytes + 0);
185 int32_t x = t0.get_byte(1, 1);
186
189 return ret;
190}
191
192double Brakecommand101::brake_dec(const std::uint8_t* bytes,
193 int32_t length) const {
194 Byte t0(bytes + 1);
195 int32_t x = t0.get_byte(0, 8);
196
197 Byte t1(bytes + 2);
198 int32_t t = t1.get_byte(6, 2);
199 x <<= 8;
200 x |= t;
201
202 double ret = x * 0.01;
203 return ret;
204}
205
206double Brakecommand101::brake_pedal_target(const std::uint8_t* bytes,
207 const int32_t length) const {
208 Byte t0(bytes + 3);
209 int32_t x = t0.get_byte(0, 8);
210
211 Byte t1(bytes + 4);
212 int32_t t = t1.get_byte(0, 8);
213 x <<= 8;
214 x |= t;
215
216 double ret = x * 0.1;
217 return ret;
218}
219
220int Brakecommand101::checksum_101(const std::uint8_t* bytes,
221 int32_t length) const {
222 Byte t0(bytes + 7);
223 int32_t x = t0.get_byte(0, 8);
224
225 int ret = x;
226 return ret;
227}
228
229} // namespace devkit
230} // namespace canbus
231} // namespace apollo
Defines the Byte class.
Brakecommand101 * set_brake_pedal_target(double brake_pedal_target)
void UpdateData(uint8_t *data) override
Brakecommand101 * set_aeb_en_ctrl(Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl)
void Parse(const std::uint8_t *bytes, int32_t length, Devkit *chassis) const override
Brakecommand101 * set_brake_dec(double brake_dec)
Brakecommand101 * set_brake_en_ctrl(Brake_command_101::Brake_en_ctrlType brake_en_ctrl)
Brakecommand101 * set_checksum_101(int checksum_101)
class register implement
Definition arena_queue.h:37