Apollo 10.0
自动驾驶开放平台
brake_control_a4.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 Brakecontrola4::ID = 0xA4;
28
29// public
31
32uint32_t Brakecontrola4::GetPeriod() const {
33 // TODO(ChaoM) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Brakecontrola4::UpdateData(uint8_t* data) {
39 set_p_brake_torque(data, brake_torque_);
40 set_p_brake_enable_control(data, brake_enable_control_);
41}
42
44 // TODO(ChaoM) : you should check this manually
45 brake_torque_ = 0.0;
47}
48
50 brake_torque_ = brake_torque;
51 return this;
52}
53
54// config detail: {'name': 'brake_torque', 'offset': 0.0, 'precision': 0.05,
55// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 8,
56// 'type': 'double', 'order': 'intel', 'physical_unit': '%'}
57void Brakecontrola4::set_p_brake_torque(uint8_t* data, double brake_torque) {
58 brake_torque = ProtocolData::BoundedValue(0.0, 100.0, brake_torque);
59 int x = static_cast<int>(brake_torque / 0.050000);
60 uint8_t t = 0;
61
62 t = static_cast<uint8_t>(x & 0xFF);
63 Byte to_set0(data + 1);
64 to_set0.set_value(t, 0, 8);
65 x >>= 8;
66
67 t = static_cast<uint8_t>(x & 0xFF);
68 Byte to_set1(data + 2);
69 to_set1.set_value(t, 0, 8);
70}
71
73 Brake_control_a4::Brake_enable_controlType brake_enable_control) {
74 brake_enable_control_ = brake_enable_control;
75 return this;
76}
77
78// config detail: {'name': 'Brake_Enable_control', 'enum':
79// {0: 'BRAKE_ENABLE_CONTROL_BRAKE_MANUAL',
80// 1: 'BRAKE_ENABLE_CONTROL_BRAKE_AUTO'}, 'precision': 1.0, 'len': 8,
81// 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0,
82// 'type': 'enum', 'order': 'intel', 'physical_unit': ''}
83void Brakecontrola4::set_p_brake_enable_control(
84 uint8_t* data,
85 Brake_control_a4::Brake_enable_controlType brake_enable_control) {
86 int x = brake_enable_control;
87
88 Byte to_set(data + 0);
89 to_set.set_value(static_cast<uint8_t>(x), 0, 8);
90}
91
92} // namespace zhongyun
93} // namespace canbus
94} // namespace apollo
Defines the Byte class.
Brakecontrola4 * set_brake_enable_control(Brake_control_a4::Brake_enable_controlType brake_enable_control)
void UpdateData(uint8_t *data) override
Brakecontrola4 * set_brake_torque(double brake_torque)
class register implement
Definition arena_queue.h:37