Apollo 10.0
自动驾驶开放平台
brake_60.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 lincoln {
24
25using ::apollo::drivers::canbus::Byte;
26
27// public
28const int32_t Brake60::ID = 0x60;
29
30uint32_t Brake60::GetPeriod() const {
31 static const uint32_t PERIOD = 10 * 1000;
32 return PERIOD;
33}
34
35void Brake60::UpdateData(uint8_t *data) {
36 set_pedal_p(data, pedal_cmd_);
37 set_boo_cmd_p(data, boo_cmd_);
38 set_enable_p(data, pedal_enable_);
39 set_clear_driver_override_flag_p(data, clear_driver_override_flag_);
40 set_watchdog_counter_p(data, watchdog_counter_);
41}
42
44 pedal_cmd_ = 0.0;
45 boo_cmd_ = false;
46 pedal_enable_ = false;
47 clear_driver_override_flag_ = false;
48 ignore_driver_override_ = false;
49 watchdog_counter_ = 0;
50}
51
53 pedal_cmd_ = pedal;
54 if (pedal_cmd_ < 1e-3) {
55 disable_boo_cmd();
56 } else {
57 enable_boo_cmd();
58 }
59 return this;
60}
61
62Brake60 *Brake60::enable_boo_cmd() {
63 boo_cmd_ = true;
64 return this;
65}
66
67Brake60 *Brake60::disable_boo_cmd() {
68 boo_cmd_ = false;
69 return this;
70}
71
73 pedal_enable_ = true;
74 return this;
75}
76
78 pedal_enable_ = false;
79 return this;
80}
81
82void Brake60::set_pedal_p(uint8_t *data, double pedal) {
83 // change from [0-100] to [0.00-1.00]
84 // and a rough mapping
85 pedal /= 100.;
86 pedal = ProtocolData::BoundedValue(0.0, 1.0, pedal);
87 int32_t x = static_cast<int32_t>(pedal / 1.52590218966964e-05);
88 std::uint8_t t = 0;
89
90 t = static_cast<uint8_t>(x & 0xFF);
91 Byte frame_low(data + 0);
92 frame_low.set_value(t, 0, 8);
93
94 x >>= 8;
95 t = static_cast<uint8_t>(x & 0xFF);
96 Byte frame_high(data + 1);
97 frame_high.set_value(t, 0, 8);
98}
99
100void Brake60::set_boo_cmd_p(uint8_t *bytes, bool boo_cmd) {
101 Byte frame(bytes + 2);
102 if (boo_cmd) {
103 frame.set_bit_1(0);
104 } else {
105 frame.set_bit_0(0);
106 }
107}
108
109void Brake60::set_enable_p(uint8_t *bytes, bool enable) {
110 Byte frame(bytes + 3);
111 if (enable) {
112 frame.set_bit_1(0);
113 } else {
114 frame.set_bit_0(0);
115 }
116}
117
118void Brake60::set_clear_driver_override_flag_p(uint8_t *bytes, bool clear) {
119 Byte frame(bytes + 3);
120 if (clear) {
121 frame.set_bit_1(1);
122 } else {
123 frame.set_bit_0(1);
124 }
125}
126
127void Brake60::set_watchdog_counter_p(uint8_t *data, int32_t count) {
128 count = ProtocolData::BoundedValue(0, 255, count);
129 Byte frame(data + 7);
130 frame.set_value(static_cast<uint8_t>(count), 0, 8);
131}
132
133} // namespace lincoln
134} // namespace canbus
135} // namespace apollo
the class of Brake60 (for lincoln vehicle)
Defines the Byte class.
one of the protocol data of lincoln vehicle
Definition brake_60.h:41
Brake60 * set_pedal(double pcmd)
set pedal based on pedal command
Definition brake_60.cc:52
uint32_t GetPeriod() const override
get the data period
Definition brake_60.cc:30
Brake60 * set_enable()
set pedal_enable_ to true
Definition brake_60.cc:72
void Reset() override
reset the private variables
Definition brake_60.cc:43
Brake60 * set_disable()
set pedal_enable_ to false
Definition brake_60.cc:77
static const int32_t ID
Definition brake_60.h:43
void UpdateData(uint8_t *data) override
update the data
Definition brake_60.cc:35
class register implement
Definition arena_queue.h:37