Apollo 10.0
自动驾驶开放平台
steering_control_a2.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 zhongyun {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Steeringcontrola2::ID = 0xA2;
28
29// public
31
33 // TODO(ChaoM) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Steeringcontrola2::UpdateData(uint8_t* data) {
39 set_p_steering_target(data, steering_target_);
40 set_p_steering_enable_control(data, steering_enable_control_);
41}
42
44 // TODO(ChaoM) : you should check this manually
45 steering_target_ = 0.0;
46 steering_enable_control_ =
48}
49
51 double steering_target) {
52 steering_target_ = steering_target;
53 return this;
54}
55
56// config detail: {'name': 'Steering_target', 'offset': -1638.35, 'precision':
57// 0.05, 'len': 16, 'is_signed_var': False, 'physical_range': '[-32|32]', 'bit':
58// 8, 'type': 'double', 'order': 'intel', 'physical_unit': 'deg'}
59void Steeringcontrola2::set_p_steering_target(uint8_t* data,
60 double steering_target) {
61 steering_target = ProtocolData::BoundedValue(-32.0, 32.0, steering_target);
62 int x = static_cast<int>((steering_target - -1638.350000) / 0.050000);
63 uint8_t t = 0;
64
65 t = static_cast<uint8_t>(x & 0xFF);
66 Byte to_set0(data + 1);
67 to_set0.set_value(t, 0, 8);
68 x >>= 8;
69
70 t = static_cast<uint8_t>(x & 0xFF);
71 Byte to_set1(data + 2);
72 to_set1.set_value(t, 0, 8);
73}
74
77 steering_enable_control_ = steering_enable_control;
78 return this;
79}
80
81// config detail: {'name': 'Steering_Enable_control', 'enum': {0:
82// 'STEERING_ENABLE_CONTROL_STEERING_MANUALCONTROL', 1:
83// 'STEERING_ENABLE_CONTROL_STEERING_AUTOCONTROL'}, 'precision': 1.0, 'len': 8,
84// 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0,
85// 'type': 'enum', 'order': 'intel', 'physical_unit': ''}
86void Steeringcontrola2::set_p_steering_enable_control(
87 uint8_t* data,
89 int x = steering_enable_control;
90
91 Byte to_set(data + 0);
92 to_set.set_value(static_cast<uint8_t>(x), 0, 8);
93}
94
95} // namespace zhongyun
96} // namespace canbus
97} // namespace apollo
Defines the Byte class.
Steeringcontrola2 * set_steering_target(double steering_target)
Steeringcontrola2 * set_steering_enable_control(Steering_control_a2::Steering_enable_controlType steering_enable_control)
class register implement
Definition arena_queue.h:37