Apollo 10.0
自动驾驶开放平台
steering_cmd_12c.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
20
21namespace apollo {
22namespace canbus {
23namespace lexus {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Steeringcmd12c::ID = 0x12C;
28
29// public
31
32uint32_t Steeringcmd12c::GetPeriod() const {
33 // TODO(QiL) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Steeringcmd12c::UpdateData(uint8_t* data) {
39 set_p_ignore_overrides(data, ignore_overrides_);
40 set_p_enable(data, enable_);
41 set_p_clear_override(data, clear_override_);
42 set_p_clear_faults(data, clear_faults_);
43 set_p_position(data, position_);
44 set_p_rotation_rate(data, rotation_rate_);
45}
46
48 // TODO(QiL) : you should check this manually
49 ignore_overrides_ = false;
50 enable_ = false;
51 clear_override_ = false;
52 clear_faults_ = false;
53 position_ = 0.0;
54 rotation_rate_ = 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 Steeringcmd12c::set_p_ignore_overrides(uint8_t* data,
66 bool ignore_overrides) {
67 uint8_t x = ignore_overrides;
68
69 Byte to_set(data + 0);
70 to_set.set_value(static_cast<uint8_t>(x), 1, 1);
71}
72
74 enable_ = enable;
75 return this;
76}
77
78// config detail: {'name': 'ENABLE', 'offset': 0.0, 'precision': 1.0, 'len': 1,
79// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 0, 'type': 'bool',
80// 'order': 'motorola', 'physical_unit': ''}
81void Steeringcmd12c::set_p_enable(uint8_t* data, bool enable) {
82 uint8_t x = enable;
83
84 Byte to_set(data + 0);
85 to_set.set_value(static_cast<uint8_t>(x), 0, 1);
86}
87
89 clear_override_ = clear_override;
90 return this;
91}
92
93// config detail: {'name': 'CLEAR_OVERRIDE', 'offset': 0.0, 'precision': 1.0,
94// 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 2,
95// 'type': 'bool', 'order': 'motorola', 'physical_unit': ''}
96void Steeringcmd12c::set_p_clear_override(uint8_t* data, bool clear_override) {
97 uint8_t x = clear_override;
98
99 Byte to_set(data + 0);
100 to_set.set_value(static_cast<uint8_t>(x), 2, 1);
101}
102
104 clear_faults_ = clear_faults;
105 return this;
106}
107
108// config detail: {'name': 'CLEAR_FAULTS', 'offset': 0.0, 'precision': 1.0,
109// 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 3,
110// 'type': 'bool', 'order': 'motorola', 'physical_unit': ''}
111void Steeringcmd12c::set_p_clear_faults(uint8_t* data, bool clear_faults) {
112 uint8_t x = clear_faults;
113
114 Byte to_set(data + 0);
115 to_set.set_value(static_cast<uint8_t>(x), 3, 1);
116}
117
119 // TODO(AS): fix this direction and scaling.
120 position_ = position;
121 return this;
122}
123
124// config detail: {'name': 'POSITION', 'offset': 0.0, 'precision': 0.001, 'len':
125// 16, 'is_signed_var': True, 'physical_range': '[-32.768|32.767]', 'bit': 15,
126// 'type': 'double', 'order': 'motorola', 'physical_unit': 'rad'}
127void Steeringcmd12c::set_p_position(uint8_t* data, double position) {
128 position = ProtocolData::BoundedValue(-32.768, 32.767, position);
129 int x = static_cast<int>(position / -0.001000);
130 uint8_t t = 0;
131
132 t = static_cast<uint8_t>(x & 0xFF);
133 Byte to_set0(data + 2);
134 to_set0.set_value(t, 0, 8);
135 x >>= 8;
136
137 t = static_cast<uint8_t>(x & 0xFF);
138 Byte to_set1(data + 1);
139 to_set1.set_value(t, 0, 8);
140}
141
143 rotation_rate_ = rotation_rate;
144 return this;
145}
146
147// config detail: {'name': 'ROTATION_RATE', 'offset': 0.0, 'precision': 0.001,
148// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65.535]', 'bit': 31,
149// 'type': 'double', 'order': 'motorola', 'physical_unit': 'rad/s'}
150void Steeringcmd12c::set_p_rotation_rate(uint8_t* data, double rotation_rate) {
151 rotation_rate = ProtocolData::BoundedValue(0.0, 65.535, rotation_rate);
152 int x = static_cast<int>(rotation_rate / 0.001000);
153 uint8_t t = 0;
154
155 t = static_cast<uint8_t>(x & 0xFF);
156 Byte to_set0(data + 4);
157 to_set0.set_value(t, 0, 8);
158 x >>= 8;
159
160 t = static_cast<uint8_t>(x & 0xFF);
161 Byte to_set1(data + 3);
162 to_set1.set_value(t, 0, 8);
163}
164
165} // namespace lexus
166} // namespace canbus
167} // namespace apollo
Defines the Byte class.
void UpdateData(uint8_t *data) override
Steeringcmd12c * set_clear_override(bool clear_override)
Steeringcmd12c * set_ignore_overrides(bool ignore_overrides)
Steeringcmd12c * set_enable(bool enable)
Steeringcmd12c * set_position(double position)
Steeringcmd12c * set_clear_faults(bool clear_faults)
Steeringcmd12c * set_rotation_rate(double rotation_rate)
class register implement
Definition arena_queue.h:37