Apollo 10.0
自动驾驶开放平台
ads_drive_command_50.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 Adsdrivecommand50::ID = 0x50;
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 Adsdrivecommand50::Parse(const std::uint8_t* bytes, int32_t length,
39 Neolix_edu* chassis) const {
40 chassis->mutable_ads_drive_command_50()->set_drive_enable(
41 drive_enable(bytes, length));
42 chassis->mutable_ads_drive_command_50()->set_auto_shift_command(
43 auto_shift_command(bytes, length));
44 chassis->mutable_ads_drive_command_50()->set_auto_drive_torque(
45 auto_drive_torque(bytes, length));
46}
47
48void Adsdrivecommand50::UpdateData(uint8_t* data) {
49 set_p_drive_enable(data, drive_enable_);
50 set_p_auto_shift_command(data, auto_shift_command_);
51 set_p_auto_drive_torque(data, auto_drive_torque_);
52 ++auto_drivercmd_alivecounter_;
53 auto_drivercmd_alivecounter_ = (auto_drivercmd_alivecounter_) % 16;
54 set_p_auto_drivercmd_alivecounter(data, auto_drivercmd_alivecounter_);
55 auto_drivercmd_checksum_ =
56 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
57 set_p_auto_drivercmd_checksum(data, auto_drivercmd_checksum_);
58}
59
61 // TODO(All) : you should check this manually
62 drive_enable_ = false;
64 auto_drive_torque_ = 0.0;
65 auto_drivercmd_alivecounter_ = 0;
66 auto_drivercmd_checksum_ = 0;
67}
68
70 drive_enable_ = drive_enable;
71 return this;
72}
73
74// config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0,
75// 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False,
76// 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola',
77// 'physical_unit': ''}
78void Adsdrivecommand50::set_p_drive_enable(uint8_t* data, bool drive_enable) {
79 int x = drive_enable;
80
81 Byte to_set(data + 0);
82 to_set.set_value(x, 0, 1);
83}
84
85bool Adsdrivecommand50::drive_enable(const std::uint8_t* bytes,
86 int32_t length) const {
87 Byte t0(bytes + 0);
88 int32_t x = t0.get_byte(0, 1);
89
90 bool ret = x;
91 return ret;
92}
93
96 auto_shift_command_ = auto_shift_command;
97 return this;
98}
99
100// config detail: {'description': '0x0:N ;0x1:D ;0x2:R ;0x3:Reserved ', 'enum':
101// {0: 'AUTO_SHIFT_COMMAND_N', 1: 'AUTO_SHIFT_COMMAND_D', 2:
102// 'AUTO_SHIFT_COMMAND_R', 3: 'AUTO_SHIFT_COMMAND_RESERVED'}, 'precision': 1.0,
103// 'len': 2, 'name': 'AUTO_Shift_Command', 'is_signed_var': False, 'offset':
104// 0.0, 'physical_range': '[0|3]', 'bit': 9, 'type': 'enum', 'order':
105// 'motorola', 'physical_unit': ''}
106void Adsdrivecommand50::set_p_auto_shift_command(
107 uint8_t* data,
109 int x = auto_shift_command;
110
111 Byte to_set(data + 1);
112 to_set.set_value(x, 0, 2);
113}
114
116Adsdrivecommand50::auto_shift_command(const std::uint8_t* bytes,
117 int32_t length) const {
118 Byte t0(bytes + 1);
119 int32_t x = t0.get_byte(0, 2);
120
123 return ret;
124}
125
127 double auto_drive_torque) {
128 auto_drive_torque_ = auto_drive_torque;
129 return this;
130}
131
132// config detail: {'name': 'AUTO_Drive_Torque', 'offset': -665.0, 'precision':
133// 0.02, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|0]', 'bit':
134// 23, 'type': 'double', 'order': 'motorola', 'physical_unit': ''}
135void Adsdrivecommand50::set_p_auto_drive_torque(uint8_t* data,
136 double auto_drive_torque) {
137 auto_drive_torque = ProtocolData::BoundedValue(0.0, 50.0, auto_drive_torque);
138 int x = (auto_drive_torque - -665.000000) / 0.020000;
139 uint8_t t = 0;
140
141 t = x & 0xFF;
142 Byte to_set0(data + 3);
143 to_set0.set_value(t, 0, 8);
144 x >>= 8;
145
146 t = x & 0xFF;
147 Byte to_set1(data + 2);
148 to_set1.set_value(t, 0, 8);
149}
150
151double Adsdrivecommand50::auto_drive_torque(const std::uint8_t* bytes,
152 int32_t length) const {
153 Byte t0(bytes + 2);
154 int32_t x = t0.get_byte(0, 8);
155
156 Byte t1(bytes + 3);
157 int32_t t = t1.get_byte(0, 8);
158 x <<= 8;
159 x |= t;
160
161 double ret = (x * 0.020000) + -665.000000;
162 return ret;
163}
164
166 int auto_drivercmd_alivecounter) {
167 auto_drivercmd_alivecounter_ = auto_drivercmd_alivecounter;
168 return this;
169}
170
171// config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0,
172// 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range':
173// '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
174void Adsdrivecommand50::set_p_auto_drivercmd_alivecounter(
175 uint8_t* data, int auto_drivercmd_alivecounter) {
176 auto_drivercmd_alivecounter =
177 ProtocolData::BoundedValue(0, 15, auto_drivercmd_alivecounter);
178 int x = auto_drivercmd_alivecounter;
179
180 Byte to_set(data + 6);
181 to_set.set_value(x, 0, 4);
182}
183
185 int auto_drivercmd_checksum) {
186 auto_drivercmd_checksum_ = auto_drivercmd_checksum;
187 return this;
188}
189
190// config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0,
191// 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range':
192// '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
193void Adsdrivecommand50::set_p_auto_drivercmd_checksum(
194 uint8_t* data, int auto_drivercmd_checksum) {
195 auto_drivercmd_checksum =
196 ProtocolData::BoundedValue(0, 255, auto_drivercmd_checksum);
197 int x = auto_drivercmd_checksum;
198
199 Byte to_set(data + 7);
200 to_set.set_value(x, 0, 8);
201}
202
203} // namespace neolix_edu
204} // namespace canbus
205} // namespace apollo
Defines the Byte class.
Adsdrivecommand50 * set_auto_drive_torque(double auto_drive_torque)
Adsdrivecommand50 * set_auto_drivercmd_alivecounter(int auto_drivercmd_alivecounter)
Adsdrivecommand50 * set_auto_shift_command(Ads_drive_command_50::Auto_shift_commandType auto_shift_command)
void Parse(const std::uint8_t *bytes, int32_t length, Neolix_edu *chassis) const override
Adsdrivecommand50 * set_drive_enable(bool drive_enable)
Adsdrivecommand50 * set_auto_drivercmd_checksum(int auto_drivercmd_checksum)
class register implement
Definition arena_queue.h:37