Apollo 10.0
自动驾驶开放平台
brake_61.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
19#include "glog/logging.h"
20
23
24namespace apollo {
25namespace canbus {
26namespace lincoln {
27
28using ::apollo::drivers::canbus::Byte;
29
30const int32_t Brake61::ID = 0x61;
31
32void Brake61::Parse(const std::uint8_t *bytes, int32_t length,
33 Lincoln *chassis_detail) const {
34 chassis_detail->mutable_brake()->set_brake_input(pedal_input(bytes, length));
35 chassis_detail->mutable_brake()->set_brake_cmd(pedal_cmd(bytes, length));
36 chassis_detail->mutable_brake()->set_brake_output(
37 pedal_output(bytes, length));
38 chassis_detail->mutable_brake()->set_boo_input(boo_input(bytes, length));
39 chassis_detail->mutable_brake()->set_boo_cmd(boo_cmd(bytes, length));
40 chassis_detail->mutable_brake()->set_boo_output(boo_output(bytes, length));
41 chassis_detail->mutable_brake()->set_watchdog_applying_brakes(
42 is_watchdog_counter_applying_brakes(bytes, length));
43 chassis_detail->mutable_brake()->set_watchdog_source(
44 watchdog_counter_source(bytes, length));
45 chassis_detail->mutable_brake()->set_brake_enabled(is_enabled(bytes, length));
46 chassis_detail->mutable_brake()->set_driver_override(
47 is_driver_override(bytes, length));
48 chassis_detail->mutable_brake()->set_driver_activity(
49 is_driver_activity(bytes, length));
50 chassis_detail->mutable_brake()->set_watchdog_fault(
51 is_watchdog_counter_fault(bytes, length));
52 chassis_detail->mutable_brake()->set_channel_1_fault(
53 is_channel_1_fault(bytes, length));
54 chassis_detail->mutable_brake()->set_channel_2_fault(
55 is_channel_2_fault(bytes, length));
56 chassis_detail->mutable_brake()->set_boo_fault(
57 is_boo_switch_fault(bytes, length));
58 chassis_detail->mutable_brake()->set_connector_fault(
59 is_connector_fault(bytes, length));
60 chassis_detail->mutable_check_response()->set_is_esp_online(
61 !is_driver_override(bytes, length));
62}
63
64double Brake61::pedal_input(const std::uint8_t *bytes, int32_t length) const {
65 DCHECK_GE(length, 2);
66 // Pedal Input from the physical pedal
67 return parse_two_frames(bytes[0], bytes[1]);
68}
69
70double Brake61::pedal_cmd(const std::uint8_t *bytes, int32_t length) const {
71 DCHECK_GE(length, 4);
72 // Pedal Command from the command message
73 return parse_two_frames(bytes[2], bytes[3]);
74}
75
76double Brake61::pedal_output(const std::uint8_t *bytes, int32_t length) const {
77 DCHECK_GE(length, 6);
78 // Pedal Output is the maximum of PI and PC
79 return parse_two_frames(bytes[4], bytes[5]);
80}
81
82double Brake61::parse_two_frames(const std::uint8_t low_byte,
83 const std::uint8_t high_byte) const {
84 Byte frame_high(&high_byte);
85 int32_t high = frame_high.get_byte(0, 8);
86 Byte frame_low(&low_byte);
87 int32_t low = frame_low.get_byte(0, 8);
88 int32_t value = (high << 8) | low;
89 // control needs a value in range [0, 100] %
90 double output = 100.0 * value * 1.52590218966964e-05;
91 output = ProtocolData::BoundedValue(0.0, 100.0, output);
92 return output;
93}
94
95bool Brake61::boo_input(const std::uint8_t *bytes, int32_t length) const {
96 Byte frame(bytes + 6);
97 // seems typo here
98 return frame.is_bit_1(0);
99}
100
101bool Brake61::boo_cmd(const std::uint8_t *bytes, int32_t length) const {
102 Byte frame(bytes + 6);
103 return frame.is_bit_1(1);
104}
105
106bool Brake61::boo_output(const std::uint8_t *bytes, int32_t length) const {
107 Byte frame(bytes + 6);
108 // seems typo here
109 return frame.is_bit_1(2);
110}
111
112bool Brake61::is_watchdog_counter_applying_brakes(const std::uint8_t *bytes,
113 int32_t length) const {
114 Byte frame(bytes + 6);
115 return frame.is_bit_1(3);
116}
117
118int32_t Brake61::watchdog_counter_source(const std::uint8_t *bytes,
119 int32_t length) const {
120 // see table for status code
121 Byte frame(bytes + 6);
122 int32_t x = frame.get_byte(4, 4);
123 return x;
124}
125
126bool Brake61::is_enabled(const std::uint8_t *bytes, int32_t length) const {
127 Byte frame(bytes + 7);
128 return frame.is_bit_1(0);
129}
130
131bool Brake61::is_driver_override(const std::uint8_t *bytes,
132 int32_t length) const {
133 Byte frame(bytes + 7);
134 return frame.is_bit_1(1);
135}
136
137bool Brake61::is_driver_activity(const std::uint8_t *bytes,
138 int32_t length) const {
139 Byte frame(bytes + 7);
140 return frame.is_bit_1(2);
141}
142
143bool Brake61::is_watchdog_counter_fault(const std::uint8_t *bytes,
144 int32_t length) const {
145 Byte frame(bytes + 7);
146 return frame.is_bit_1(3);
147}
148
149bool Brake61::is_channel_1_fault(const std::uint8_t *bytes,
150 int32_t length) const {
151 Byte frame(bytes + 7);
152 return frame.is_bit_1(4);
153}
154
155bool Brake61::is_channel_2_fault(const std::uint8_t *bytes,
156 int32_t length) const {
157 Byte frame(bytes + 7);
158 return frame.is_bit_1(5);
159}
160
161bool Brake61::is_boo_switch_fault(const std::uint8_t *bytes,
162 int32_t length) const {
163 Byte frame(bytes + 7);
164 return frame.is_bit_1(6);
165}
166
167bool Brake61::is_connector_fault(const std::uint8_t *bytes,
168 int32_t length) const {
169 Byte frame(bytes + 7);
170 return frame.is_bit_1(7);
171}
172
173} // namespace lincoln
174} // namespace canbus
175} // namespace apollo
the class of Brake61 (for lincoln vehicle)
Defines the Byte class.
static const int32_t ID
Definition brake_61.h:43
virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const
Definition brake_61.cc:32
class register implement
Definition arena_queue.h:37