Apollo 10.0
自动驾驶开放平台
steering_command_102.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 Steeringcommand102::ID = 0x102;
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 Steeringcommand102::Parse(const std::uint8_t* bytes, int32_t length,
39 Demo* chassis) const {
40 chassis->mutable_steering_command_102()->set_heartbeat_102(
41 heartbeat_102(bytes, length));
42 chassis->mutable_steering_command_102()->set_steer_en_ctrl(
43 steer_en_ctrl(bytes, length));
44 chassis->mutable_steering_command_102()->set_steer_angle_target(
45 steer_angle_target(bytes, length));
46 chassis->mutable_steering_command_102()->set_steer_angle_spd_target(
47 steer_angle_spd_target(bytes, length));
48 chassis->mutable_steering_command_102()->set_checksum_102(
49 checksum_102(bytes, length));
50}
51
53 // TODO(All) : you should add the heartbeat manually
54 ++heartbeat_102_;
55 heartbeat_102_ = (heartbeat_102_) % 16;
56 set_p_heartbeat_102(data, heartbeat_102_);
57 checksum_102_ =
58 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
59 set_p_checksum_102(data, checksum_102_);
60}
61
62void Steeringcommand102::UpdateData(uint8_t* data) {
63 set_p_steer_en_ctrl(data, steer_en_ctrl_);
64 set_p_steer_angle_target(data, steer_angle_target_);
65 set_p_steer_angle_spd_target(data, steer_angle_spd_target_);
66}
67
69 // TODO(All) : you should check this manually
70 heartbeat_102_ = 0;
72 steer_angle_target_ = 0;
73 steer_angle_spd_target_ = 0;
74 checksum_102_ = 0;
75}
76
78 heartbeat_102_ = heartbeat_102;
79 return this;
80}
81
82// config detail: {'bit': 7, 'is_signed_var': False, 'len': 4, 'name':
83// 'Heartbeat_102', 'offset': 0.0, 'order': 'motorola', 'physical_range':
84// '[0|15]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
85void Steeringcommand102::set_p_heartbeat_102(uint8_t* data, int heartbeat_102) {
86 heartbeat_102 = ProtocolData::BoundedValue(0, 15, heartbeat_102);
87 int x = heartbeat_102;
88
89 Byte to_set(data + 0);
90 to_set.set_value(x, 4, 4);
91}
92
95 steer_en_ctrl_ = steer_en_ctrl;
96 return this;
97}
98
99// config detail: {'bit': 0, 'description': 'enable', 'enum': {0:
100// 'STEER_EN_CTRL_DISABLE', 1: 'STEER_EN_CTRL_ENABLE'}, 'is_signed_var': False,
101// 'len': 1, 'name': 'Steer_EN_CTRL', 'offset': 0.0, 'order': 'motorola',
102// 'physical_range':
103// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'signal_type': 'enable',
104// 'type': 'enum'}
105void Steeringcommand102::set_p_steer_en_ctrl(
106 uint8_t* data, Steering_command_102::Steer_en_ctrlType steer_en_ctrl) {
107 int x = steer_en_ctrl;
108
109 Byte to_set(data + 0);
110 to_set.set_value(x, 0, 1);
111}
112
114 int steer_angle_target) {
115 steer_angle_target_ = steer_angle_target;
116 return this;
117}
118
119// config detail: {'bit': 31, 'description': 'command', 'is_signed_var': False,
120// 'len': 16, 'name': 'Steer_ANGLE_Target', 'offset': -500.0, 'order':
121// 'motorola', 'physical_range': '[-500|500]', 'physical_unit': 'deg',
122// 'precision': 1.0, 'signal_type': 'command', 'type': 'int'}
123void Steeringcommand102::set_p_steer_angle_target(uint8_t* data,
124 int steer_angle_target) {
125 steer_angle_target =
126 ProtocolData::BoundedValue(-500, 500, steer_angle_target);
127 int x = (steer_angle_target - -500.000000);
128 uint8_t t = 0;
129
130 t = x & 0xFF;
131 Byte to_set0(data + 4);
132 to_set0.set_value(t, 0, 8);
133 x >>= 8;
134
135 t = x & 0xFF;
136 Byte to_set1(data + 3);
137 to_set1.set_value(t, 0, 8);
138}
139
141 int steer_angle_spd_target) {
142 steer_angle_spd_target_ = steer_angle_spd_target;
143 return this;
144}
145
146// config detail: {'bit': 15, 'is_signed_var': False, 'len': 8, 'name':
147// 'Steer_ANGLE_SPD_Target', 'offset': 0.0, 'order': 'motorola',
148// 'physical_range': '[0|250]', 'physical_unit': 'deg/s', 'precision': 1.0,
149// 'type': 'int'}
150void Steeringcommand102::set_p_steer_angle_spd_target(
151 uint8_t* data, int steer_angle_spd_target) {
152 steer_angle_spd_target =
153 ProtocolData::BoundedValue(0, 250, steer_angle_spd_target);
154 int x = steer_angle_spd_target;
155
156 Byte to_set(data + 1);
157 to_set.set_value(x, 0, 8);
158}
159
161 checksum_102_ = checksum_102;
162 return this;
163}
164
165// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
166// 'CheckSum_102', 'offset': 0.0, 'order': 'motorola', 'physical_range':
167// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
168void Steeringcommand102::set_p_checksum_102(uint8_t* data, int checksum_102) {
169 checksum_102 = ProtocolData::BoundedValue(0, 255, checksum_102);
170 int x = checksum_102;
171
172 Byte to_set(data + 7);
173 to_set.set_value(x, 0, 8);
174}
175
176int Steeringcommand102::heartbeat_102(const std::uint8_t* bytes,
177 int32_t length) const {
178 Byte t0(bytes + 0);
179 int32_t x = t0.get_byte(4, 4);
180
181 int ret = x;
182 return ret;
183}
184
185Steering_command_102::Steer_en_ctrlType Steeringcommand102::steer_en_ctrl(
186 const std::uint8_t* bytes, int32_t length) const {
187 Byte t0(bytes + 0);
188 int32_t x = t0.get_byte(0, 1);
189
192 return ret;
193}
194
195int Steeringcommand102::steer_angle_target(const std::uint8_t* bytes,
196 int32_t length) const {
197 Byte t0(bytes + 3);
198 int32_t x = t0.get_byte(0, 8);
199
200 Byte t1(bytes + 4);
201 int32_t t = t1.get_byte(0, 8);
202 x <<= 8;
203 x |= t;
204
205 int ret = x + -500.000000;
206 return ret;
207}
208
209int Steeringcommand102::steer_angle_spd_target(const std::uint8_t* bytes,
210 int32_t length) const {
211 Byte t0(bytes + 1);
212 int32_t x = t0.get_byte(0, 8);
213
214 int ret = x;
215 return ret;
216}
217
218int Steeringcommand102::checksum_102(const std::uint8_t* bytes,
219 int32_t length) const {
220 Byte t0(bytes + 7);
221 int32_t x = t0.get_byte(0, 8);
222
223 int ret = x;
224 return ret;
225}
226} // namespace demo
227} // namespace canbus
228} // namespace apollo
Defines the Byte class.
Steeringcommand102 * set_steer_angle_target(int steer_angle_target)
void UpdateData_Heartbeat(uint8_t *data) override
Steeringcommand102 * set_checksum_102(int checksum_102)
Steeringcommand102 * set_steer_angle_spd_target(int steer_angle_spd_target)
Steeringcommand102 * set_heartbeat_102(int heartbeat_102)
void Parse(const std::uint8_t *bytes, int32_t length, Demo *chassis) const override
Steeringcommand102 * set_steer_en_ctrl(Steering_command_102::Steer_en_ctrlType steer_en_ctrl)
class register implement
Definition arena_queue.h:37