Apollo 10.0
自动驾驶开放平台
throttle_command_100.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
19#include "glog/logging.h"
20
23
24namespace apollo {
25namespace canbus {
26namespace devkit {
27
28using ::apollo::drivers::canbus::Byte;
29
30const int32_t Throttlecommand100::ID = 0x100;
31
32// public
34
36 // TODO(All) : modify every protocol's period manually
37 static const uint32_t PERIOD = 20 * 1000;
38 return PERIOD;
39}
40
41void Throttlecommand100::Parse(const std::uint8_t* bytes, int32_t length,
42 Devkit* chassis) const {
43 chassis->mutable_throttle_command_100()->set_throttle_en_ctrl(
44 throttle_en_ctrl(bytes, length));
45 chassis->mutable_throttle_command_100()->set_throttle_acc(
46 throttle_acc(bytes, length));
47 chassis->mutable_throttle_command_100()->set_throttle_pedal_target(
48 throttle_pedal_target(bytes, length));
49 chassis->mutable_throttle_command_100()->set_speed_target(
50 speed_target(bytes, length));
51 chassis->mutable_throttle_command_100()->set_checksum_100(
52 checksum_100(bytes, length));
53}
54
55void Throttlecommand100::UpdateData(uint8_t* data) {
56 set_p_speed_target(data, speed_target_);
57 set_p_throttle_acc(data, throttle_acc_);
58 set_p_throttle_pedal_target(data, throttle_pedal_target_);
59 set_p_throttle_en_ctrl(data, throttle_en_ctrl_);
60 checksum_100_ =
61 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
62 set_p_checksum_100(data, checksum_100_);
63}
64
66 // TODO(All) : you should check this manually
68 throttle_acc_ = 0.0;
69 throttle_pedal_target_ = 0.0;
70 speed_target_ = 0.0;
71 checksum_100_ = 0;
72}
73
76 throttle_en_ctrl_ = throttle_en_ctrl;
77 return this;
78}
79
80// config detail: {'name': 'Throttle_EN_CTRL', 'enum': {0:
81// 'THROTTLE_EN_CTRL_DISABLE', 1: 'THROTTLE_EN_CTRL_ENABLE'}, 'precision': 1.0,
82// 'len': 1, 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]',
83// 'bit': 0, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''}
84void Throttlecommand100::set_p_throttle_en_ctrl(
85 uint8_t* data,
87 int x = throttle_en_ctrl;
88
89 Byte to_set(data + 0);
90 to_set.set_value(x, 0, 1);
91}
92
94 throttle_acc_ = throttle_acc;
95 return this;
96}
97
98// config detail: {'name': 'Throttle_Acc', 'offset': 0.0, 'precision': 0.01,
99// 'len': 10, 'is_signed_var': False, 'physical_range': '[0|10]', 'bit': 15,
100// 'type': 'double', 'order': 'motorola', 'physical_unit': 'm/s^2'}
101void Throttlecommand100::set_p_throttle_acc(uint8_t* data,
102 double throttle_acc) {
103 throttle_acc = ProtocolData::BoundedValue(0.0, 10.0, throttle_acc);
104 int x = throttle_acc / 0.010000;
105 uint8_t t = 0;
106
107 t = x & 0x3;
108 Byte to_set0(data + 2);
109 to_set0.set_value(t, 6, 2);
110 x >>= 2;
111
112 t = x & 0xFF;
113 Byte to_set1(data + 1);
114 to_set1.set_value(t, 0, 8);
115}
116
118 double throttle_pedal_target) {
119 throttle_pedal_target_ = throttle_pedal_target;
120 return this;
121}
122
123// config detail: {'name': 'Throttle_Pedal_Target', 'offset': 0.0, 'precision':
124// 0.1, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|100]', 'bit':
125// 31, 'type': 'double', 'order': 'motorola', 'physical_unit': '%'}
126void Throttlecommand100::set_p_throttle_pedal_target(
127 uint8_t* data, double throttle_pedal_target) {
128 throttle_pedal_target =
129 ProtocolData::BoundedValue(0.0, 100.0, throttle_pedal_target);
130 int x = throttle_pedal_target / 0.100000;
131 uint8_t t = 0;
132
133 t = x & 0xFF;
134 Byte to_set0(data + 4);
135 to_set0.set_value(t, 0, 8);
136 x >>= 8;
137
138 t = x & 0xFF;
139 Byte to_set1(data + 3);
140 to_set1.set_value(t, 0, 8);
141}
142
144 speed_target_ = speed_target;
145 return this;
146}
147
148// config detail: {'bit': 47, 'is_signed_var': False, 'len': 10, 'name':
149// 'Speed_Target', 'offset': 0.0, 'order': 'motorola', 'physical_range':
150// '[0|10.23]', 'physical_unit': 'm/s', 'precision': 0.01, 'type': 'double'}
151void Throttlecommand100::set_p_speed_target(uint8_t* data,
152 double speed_target) {
153 speed_target = ProtocolData::BoundedValue(0.0, 10.23, speed_target);
154 int x = speed_target / 0.010000;
155 uint8_t t = 0;
156
157 t = x & 0x3;
158 Byte to_set0(data + 6);
159 to_set0.set_value(t, 6, 2);
160 x >>= 2;
161
162 t = x & 0xFF;
163 Byte to_set1(data + 5);
164 to_set1.set_value(t, 0, 8);
165}
166
168 checksum_100_ = checksum_100;
169 return this;
170}
171
172// config detail: {'name': 'CheckSum_100', 'offset': 0.0, 'precision': 1.0,
173// 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63,
174// 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
175void Throttlecommand100::set_p_checksum_100(uint8_t* data, int checksum_100) {
176 checksum_100 = ProtocolData::BoundedValue(0, 255, checksum_100);
177 int x = checksum_100;
178
179 Byte to_set(data + 7);
180 to_set.set_value(x, 0, 8);
181}
182
183Throttle_command_100::Throttle_en_ctrlType Throttlecommand100::throttle_en_ctrl(
184 const std::uint8_t* bytes, int32_t length) const {
185 Byte t0(bytes + 0);
186 int32_t x = t0.get_byte(0, 1);
187
190 return ret;
191}
192
193double Throttlecommand100::throttle_acc(const std::uint8_t* bytes,
194 int32_t length) const {
195 Byte t0(bytes + 1);
196 int32_t x = t0.get_byte(0, 8);
197
198 Byte t1(bytes + 2);
199 int32_t t = t1.get_byte(6, 2);
200 x <<= 8;
201 x |= t;
202
203 double ret = x * 0.01;
204 return ret;
205}
206
207double Throttlecommand100::throttle_pedal_target(const std::uint8_t* bytes,
208 int32_t length) const {
209 Byte t0(bytes + 3);
210 int32_t x = t0.get_byte(0, 8);
211
212 Byte t1(bytes + 4);
213 int32_t t = t1.get_byte(0, 8);
214 x <<= 8;
215 x |= t;
216
217 double ret = x * 0.100000;
218 return ret;
219}
220
221double Throttlecommand100::speed_target(const std::uint8_t* bytes,
222 int32_t length) const {
223 Byte t0(bytes + 5);
224 int32_t x = t0.get_byte(0, 8);
225
226 Byte t1(bytes + 6);
227 int32_t t = t1.get_byte(6, 2);
228 x <<= 8;
229 x |= t;
230
231 double ret = x * 0.100000;
232 return ret;
233}
234
235int Throttlecommand100::checksum_100(const std::uint8_t* bytes,
236 int32_t length) const {
237 Byte t0(bytes + 7);
238 int32_t x = t0.get_byte(0, 8);
239
240 int ret = x;
241 return ret;
242}
243
244} // namespace devkit
245} // namespace canbus
246} // namespace apollo
Defines the Byte class.
Throttlecommand100 * set_speed_target(double speed_target)
Throttlecommand100 * set_throttle_en_ctrl(Throttle_command_100::Throttle_en_ctrlType throttle_en_ctrl)
Throttlecommand100 * set_throttle_acc(double throttle_acc)
Throttlecommand100 * set_checksum_100(int checksum_100)
void Parse(const std::uint8_t *bytes, int32_t length, Devkit *chassis) const override
Throttlecommand100 * set_throttle_pedal_target(double throttle_pedal_target)
class register implement
Definition arena_queue.h:37