Apollo 10.0
自动驾驶开放平台
steering_command_102.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 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 Devkit* chassis) const {
40 chassis->mutable_steering_command_102()->set_steer_en_ctrl(
41 steer_en_ctrl(bytes, length));
42 chassis->mutable_steering_command_102() ->set_steer_angle_target(
43 steer_angle_target(bytes, length));
44 chassis->mutable_steering_command_102()->set_steer_angle_spd_target(
45 steer_angle_spd_target(bytes, length));
46 chassis->mutable_steering_command_102()->set_checksum_102(
47 checksum_102(bytes, length));
48}
49
50void Steeringcommand102::UpdateData(uint8_t* data) {
51 set_p_steer_en_ctrl(data, steer_en_ctrl_);
52 set_p_steer_angle_target(data, steer_angle_target_);
53 set_p_steer_angle_spd_target(data, steer_angle_spd_target_);
54 checksum_102_ =
55 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
56 set_p_checksum_102(data, checksum_102_);
57}
58
60 // TODO(All) : you should check this manually
62 steer_angle_target_ = 0;
63 steer_angle_spd_target_ = 0;
64 checksum_102_ = 0;
65}
66
69 steer_en_ctrl_ = steer_en_ctrl;
70 return this;
71}
72
73// config detail: {'bit': 0, 'enum': {0: 'STEER_EN_CTRL_DISABLE', 1:
74// 'STEER_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name':
75// 'Steer_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range':
76// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
77void Steeringcommand102::set_p_steer_en_ctrl(
78 uint8_t* data, Steering_command_102::Steer_en_ctrlType steer_en_ctrl) {
79 int x = steer_en_ctrl;
80
81 Byte to_set(data + 0);
82 to_set.set_value(x, 0, 1);
83}
84
86 int steer_angle_target) {
87 steer_angle_target_ = steer_angle_target;
88 return this;
89}
90
91// config detail: {'bit': 31, 'is_signed_var': False, 'len': 16, 'name':
92// 'Steer_ANGLE_Target', 'offset': -500.0, 'order': 'motorola',
93// 'physical_range': '[-500|500]''right -, left +', 'physical_unit': 'deg',
94// 'precision': 1.0, 'type': 'int'}
95void Steeringcommand102::set_p_steer_angle_target(uint8_t* data,
96 int steer_angle_target) {
97 steer_angle_target =
98 ProtocolData::BoundedValue(-500, 500, steer_angle_target);
99 int x = (steer_angle_target - -500.000000);
100 uint8_t t = 0;
101
102 t = x & 0xFF;
103 Byte to_set0(data + 4);
104 to_set0.set_value(t, 0, 8);
105 x >>= 8;
106
107 t = x & 0xFF;
108 Byte to_set1(data + 3);
109 to_set1.set_value(t, 0, 8);
110}
111
113 int steer_angle_spd_target) {
114 steer_angle_spd_target_ = steer_angle_spd_target;
115 return this;
116}
117
118// config detail: {'bit': 15, 'is_signed_var': False, 'len': 8, 'name':
119// 'Steer_ANGLE_SPD_Target', 'offset': 0.0, 'order': 'motorola',
120// 'physical_range': '[0|250]', 'physical_unit': 'deg/s', 'precision': 1.0,
121// 'type': 'int'}
122void Steeringcommand102::set_p_steer_angle_spd_target(
123 uint8_t* data, int steer_angle_spd_target) {
124 steer_angle_spd_target =
125 ProtocolData::BoundedValue(0, 250, steer_angle_spd_target);
126 int x = steer_angle_spd_target;
127
128 Byte to_set(data + 1);
129 to_set.set_value(x, 0, 8);
130}
131
133 checksum_102_ = checksum_102;
134 return this;
135}
136
137// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
138// 'CheckSum_102', 'offset': 0.0, 'order': 'motorola', 'physical_range':
139// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
140void Steeringcommand102::set_p_checksum_102(uint8_t* data, int checksum_102) {
141 checksum_102 = ProtocolData::BoundedValue(0, 255, checksum_102);
142 int x = checksum_102;
143
144 Byte to_set(data + 7);
145 to_set.set_value(x, 0, 8);
146}
147
148Steering_command_102::Steer_en_ctrlType Steeringcommand102::steer_en_ctrl(
149 const std::uint8_t* bytes, int32_t length) const {
150 Byte t0(bytes + 0);
151 int32_t x = t0.get_byte(0, 1);
152
155 return ret;
156}
157
158double Steeringcommand102::steer_angle_target(const std::uint8_t* bytes,
159 int32_t length) const {
160 Byte t0(bytes + 3);
161 int32_t x = t0.get_byte(0, 8);
162
163 Byte t1(bytes + 4);
164 int32_t t = t1.get_byte(0, 8);
165 x <<= 8;
166 x |= t;
167
168 double ret = x * 1 + -500.000000;
169 return ret;
170}
171
172double Steeringcommand102::steer_angle_spd_target(const std::uint8_t* bytes,
173 int32_t length) const {
174 Byte t0(bytes + 1);
175 int32_t x = t0.get_byte(0, 8);
176
177 double ret = x * 1;
178 return ret;
179}
180
181int Steeringcommand102::checksum_102(const std::uint8_t* bytes,
182 int32_t length) const {
183 Byte t0(bytes + 7);
184 int32_t x = t0.get_byte(0, 8);
185
186 int ret = x;
187 return ret;
188}
189
190} // namespace devkit
191} // namespace canbus
192} // namespace apollo
Defines the Byte class.
Steeringcommand102 * set_steer_angle_spd_target(int steer_angle_spd_target)
Steeringcommand102 * set_checksum_102(int checksum_102)
void Parse(const std::uint8_t *bytes, int32_t length, Devkit *chassis) const override
Steeringcommand102 * set_steer_en_ctrl(Steering_command_102::Steer_en_ctrlType steer_en_ctrl)
Steeringcommand102 * set_steer_angle_target(int steer_angle_target)
class register implement
Definition arena_queue.h:37