Apollo 10.0
自动驾驶开放平台
accel_cmd_100.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 <algorithm>
20
22
23namespace apollo {
24namespace canbus {
25namespace lexus {
26
27using ::apollo::drivers::canbus::Byte;
28
29const int32_t Accelcmd100::ID = 0x100;
30
31// public
33
34uint32_t Accelcmd100::GetPeriod() const {
35 // TODO(QiL) modify every protocol's period manually
36 static const uint32_t PERIOD = 20 * 1000;
37 return PERIOD;
38}
39
40void Accelcmd100::UpdateData(uint8_t* data) {
41 set_p_ignore_overrides(data, ignore_overrides_);
42 set_p_enable(data, enable_);
43 set_p_clear_override(data, clear_override_);
44 set_p_clear_faults(data, clear_faults_);
45 set_p_accel_cmd(data, accel_cmd_);
46}
47
49 // TODO(QiL) you should check this manually
50 ignore_overrides_ = false;
51 enable_ = false;
52 clear_override_ = false;
53 clear_faults_ = false;
54 accel_cmd_ = 0.0;
55}
56
58 ignore_overrides_ = ignore_overrides;
59 return this;
60}
61
62// config detail: {'name': 'IGNORE_OVERRIDES', 'offset': 0.0, 'precision': 1.0,
63// 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 1,
64// 'type': 'bool', 'order': 'motorola', 'physical_unit': ''}
65void Accelcmd100::set_p_ignore_overrides(uint8_t* data, bool ignore_overrides) {
66 uint8_t x = ignore_overrides;
67
68 Byte to_set(data + 0);
69 to_set.set_value(static_cast<uint8_t>(x), 1, 1);
70}
71
73 enable_ = enable;
74 return this;
75}
76
77// config detail: {'name': 'ENABLE', 'offset': 0.0, 'precision': 1.0, 'len': 1,
78// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 0, 'type': 'bool',
79// 'order': 'motorola', 'physical_unit': ''}
80void Accelcmd100::set_p_enable(uint8_t* data, bool enable) {
81 uint8_t x = enable;
82
83 Byte to_set(data + 0);
84 to_set.set_value(static_cast<uint8_t>(x), 0, 1);
85}
86
88 clear_override_ = clear_override;
89 return this;
90}
91
92// config detail: {'name': 'CLEAR_OVERRIDE', 'offset': 0.0, 'precision': 1.0,
93// 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 2,
94// 'type': 'bool', 'order': 'motorola', 'physical_unit': ''}
95void Accelcmd100::set_p_clear_override(uint8_t* data, bool clear_override) {
96 uint8_t x = clear_override;
97
98 Byte to_set(data + 0);
99 to_set.set_value(static_cast<uint8_t>(x), 2, 1);
100}
101
103 clear_faults_ = clear_faults;
104 return this;
105}
106
107// config detail: {'name': 'CLEAR_FAULTS', 'offset': 0.0, 'precision': 1.0,
108// 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 3,
109// 'type': 'bool', 'order': 'motorola', 'physical_unit': ''}
110void Accelcmd100::set_p_clear_faults(uint8_t* data, bool clear_faults) {
111 uint8_t x = clear_faults;
112
113 Byte to_set(data + 0);
114 to_set.set_value(static_cast<uint8_t>(x), 3, 1);
115}
116
118 accel_cmd_ = accel_cmd;
119 return this;
120}
121
122// config detail: {'name': 'ACCEL_CMD', 'offset': 0.0, 'precision': 0.001,
123// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 15,
124// 'type': 'double', 'order': 'motorola', 'physical_unit': ''}
125void Accelcmd100::set_p_accel_cmd(uint8_t* data, double accel_cmd) {
126 const double scaling_bias = 0.0; // estimated from the garage test data
127 const double scaling_gain = 1.20; // estimated from the garage test data
128 accel_cmd = std::max(0.0, (accel_cmd - scaling_bias) / (scaling_gain * 100));
129 accel_cmd = ProtocolData::BoundedValue(0.0, 1.0, accel_cmd);
130 // TODO(AS): fix this scaling.
131 int x = static_cast<int>(accel_cmd / 0.001000);
132 uint8_t t = 0;
133
134 t = static_cast<uint8_t>(x & 0xFF);
135 Byte to_set0(data + 2);
136 to_set0.set_value(t, 0, 8);
137 x >>= 8;
138
139 t = static_cast<uint8_t>(x & 0xFF);
140 Byte to_set1(data + 1);
141 to_set1.set_value(t, 0, 8);
142}
143
144} // namespace lexus
145} // namespace canbus
146} // namespace apollo
Defines the Byte class.
Accelcmd100 * set_ignore_overrides(bool ignore_overrides)
Accelcmd100 * set_accel_cmd(double accel_cmd)
uint32_t GetPeriod() const override
Accelcmd100 * set_enable(bool enable)
Accelcmd100 * set_clear_override(bool clear_override)
void UpdateData(uint8_t *data) override
Accelcmd100 * set_clear_faults(bool clear_faults)
class register implement
Definition arena_queue.h:37