Apollo 10.0
自动驾驶开放平台
ads_eps_command_56.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 neolix_edu {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Adsepscommand56::ID = 0x56;
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 Adsepscommand56::Parse(const std::uint8_t* bytes, int32_t length,
39 Neolix_edu* chassis) const {
40 chassis->mutable_ads_eps_command_56()->set_drive_enable(
41 drive_enable(bytes, length));
42 chassis->mutable_ads_eps_command_56()->set_auto_target_angle(
43 auto_target_angle(bytes, length));
44}
45
46void Adsepscommand56::UpdateData(uint8_t* data) {
47 set_p_drive_enable(data, drive_enable_);
48 set_p_auto_target_angle(data, auto_target_angle_);
49 ++auto_drivercmd_alivecounter_;
50 auto_drivercmd_alivecounter_ = (auto_drivercmd_alivecounter_) % 16;
51 set_p_auto_drivercmd_alivecounter(data, auto_drivercmd_alivecounter_);
52 auto_drivercmd_checksum_ =
53 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
54 set_p_auto_drivercmd_checksum(data, auto_drivercmd_checksum_);
55}
56
58 // TODO(All) : you should check this manually
59 drive_enable_ = false;
60 auto_target_angle_ = 0.0;
61 auto_drivercmd_alivecounter_ = 0;
62 auto_drivercmd_checksum_ = 0;
63}
64
66 drive_enable_ = drive_enable;
67 return this;
68}
69
70// config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0,
71// 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False,
72// 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola',
73// 'physical_unit': ''}
74void Adsepscommand56::set_p_drive_enable(uint8_t* data, bool drive_enable) {
75 int x = drive_enable;
76
77 Byte to_set(data + 0);
78 to_set.set_value(x, 0, 1);
79}
80
81bool Adsepscommand56::drive_enable(const std::uint8_t* bytes,
82 int32_t length) const {
83 Byte t0(bytes + 0);
84 int32_t x = t0.get_byte(0, 1);
85
86 bool ret = x;
87 return ret;
88}
89
91 double auto_target_angle) {
92 auto_target_angle_ = -auto_target_angle;
93 return this;
94}
95
96// config detail: {'name': 'AUTO_Target_Angle', 'offset': -2048.0, 'precision':
97// 0.0625, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|0]', 'bit':
98// 23, 'type': 'double', 'order': 'motorola', 'physical_unit': ''}
99void Adsepscommand56::set_p_auto_target_angle(uint8_t* data,
100 double auto_target_angle) {
101 auto_target_angle =
102 ProtocolData::BoundedValue(-380.0, 380.0, auto_target_angle);
103 int x = (auto_target_angle - -2048.000000) / 0.062500;
104 uint8_t t = 0;
105
106 t = x & 0xFF;
107 Byte to_set0(data + 3);
108 to_set0.set_value(t, 0, 8);
109 x >>= 8;
110
111 t = x & 0xFF;
112 Byte to_set1(data + 2);
113 to_set1.set_value(t, 0, 8);
114}
115
116double Adsepscommand56::auto_target_angle(const std::uint8_t* bytes,
117 int32_t length) const {
118 Byte t0(bytes + 2);
119 int32_t x = t0.get_byte(0, 8);
120
121 Byte t1(bytes + 3);
122 int32_t t = t1.get_byte(0, 8);
123 x <<= 8;
124 x |= t;
125
126 double ret = 0.0625 * x + -2048;
127 return ret;
128}
129
131 int auto_drivercmd_alivecounter) {
132 auto_drivercmd_alivecounter_ = auto_drivercmd_alivecounter;
133 return this;
134}
135
136// config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0,
137// 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range':
138// '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
139void Adsepscommand56::set_p_auto_drivercmd_alivecounter(
140 uint8_t* data, int auto_drivercmd_alivecounter) {
141 auto_drivercmd_alivecounter =
142 ProtocolData::BoundedValue(0, 15, auto_drivercmd_alivecounter);
143 int x = auto_drivercmd_alivecounter;
144
145 Byte to_set(data + 6);
146 to_set.set_value(x, 0, 4);
147}
148
150 int auto_drivercmd_checksum) {
151 auto_drivercmd_checksum_ = auto_drivercmd_checksum;
152 return this;
153}
154
155// config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0,
156// 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range':
157// '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
158void Adsepscommand56::set_p_auto_drivercmd_checksum(
159 uint8_t* data, int auto_drivercmd_checksum) {
160 auto_drivercmd_checksum =
161 ProtocolData::BoundedValue(0, 255, auto_drivercmd_checksum);
162 int x = auto_drivercmd_checksum;
163
164 Byte to_set(data + 7);
165 to_set.set_value(x, 0, 8);
166}
167
168} // namespace neolix_edu
169} // namespace canbus
170} // namespace apollo
Defines the Byte class.
Adsepscommand56 * set_auto_drivercmd_alivecounter(int auto_drivercmd_alivecounter)
void Parse(const std::uint8_t *bytes, int32_t length, Neolix_edu *chassis) const override
Adsepscommand56 * set_auto_drivercmd_checksum(int auto_drivercmd_checksum)
Adsepscommand56 * set_drive_enable(bool drive_enable)
Adsepscommand56 * set_auto_target_angle(double auto_target_angle)
class register implement
Definition arena_queue.h:37