Apollo 10.0
自动驾驶开放平台
throttle_63.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
27const int32_t Throttle63::ID = 0x63;
28
29void Throttle63::Parse(const std::uint8_t *bytes, int32_t length,
30 Lincoln *chassis_detail) const {
31 chassis_detail->mutable_gas()->set_throttle_input(pedal_input(bytes, length));
32 chassis_detail->mutable_gas()->set_throttle_cmd(pedal_cmd(bytes, length));
33 chassis_detail->mutable_gas()->set_throttle_output(
34 pedal_output(bytes, length));
35 chassis_detail->mutable_gas()->set_watchdog_source(
36 watchdog_counter_source(bytes, length));
37 chassis_detail->mutable_gas()->set_throttle_enabled(
38 is_enabled(bytes, length));
39 chassis_detail->mutable_gas()->set_driver_override(
40 is_driver_override(bytes, length));
41 chassis_detail->mutable_gas()->set_driver_activity(
42 is_driver_activity(bytes, length));
43 chassis_detail->mutable_gas()->set_watchdog_fault(
44 is_watchdog_counter_fault(bytes, length));
45 chassis_detail->mutable_gas()->set_channel_1_fault(
46 is_channel_1_fault(bytes, length));
47 chassis_detail->mutable_gas()->set_channel_2_fault(
48 is_channel_2_fault(bytes, length));
49 chassis_detail->mutable_gas()->set_connector_fault(
50 is_connector_fault(bytes, length));
51 chassis_detail->mutable_check_response()->set_is_vcu_online(
52 !is_driver_override(bytes, length));
53}
54
55double Throttle63::pedal_input(const std::uint8_t *bytes,
56 int32_t length) const {
57 // Pedal Input from the physical pedal
58 Byte frame_high(bytes + 1);
59 int32_t high = frame_high.get_byte(0, 8);
60 Byte frame_low(bytes + 0);
61 int32_t low = frame_low.get_byte(0, 8);
62 int32_t value = (high << 8) | low;
63 // control needs a value in range [0, 100] %
64 double output = 100.0 * value * 1.52590218966964e-05;
65 output = ProtocolData::BoundedValue(0.0, 100.0, output);
66 return output;
67}
68
69double Throttle63::pedal_cmd(const std::uint8_t *bytes, int32_t length) const {
70 // Pedal Command from the command message
71 Byte frame_high(bytes + 3);
72 int32_t high = frame_high.get_byte(0, 8);
73 Byte frame_low(bytes + 2);
74 int32_t low = frame_low.get_byte(0, 8);
75 int32_t value = (high << 8) | low;
76 // control needs a value in range [0, 100] %
77 double output = 100.0 * value * 1.52590218966964e-05;
78 output = ProtocolData::BoundedValue(0.0, 100.0, output);
79 return output;
80}
81
82double Throttle63::pedal_output(const std::uint8_t *bytes,
83 int32_t length) const {
84 // Pedal Output is the maximum of PI and PC
85 Byte frame_high(bytes + 5);
86 int32_t high = frame_high.get_byte(0, 8);
87 Byte frame_low(bytes + 4);
88 int32_t low = frame_low.get_byte(0, 8);
89 int32_t value = (high << 8) | low;
90 // control needs a value in range [0, 100] %
91 double output = 100.0 * value * 1.52590218966964e-05;
92 output = ProtocolData::BoundedValue(0.0, 100.0, output);
93 return output;
94}
95
96int32_t Throttle63::watchdog_counter_source(const std::uint8_t *bytes,
97 int32_t length) const {
98 Byte frame(bytes + 6);
99 int32_t x = frame.get_byte(4, 4);
100 return x;
101}
102
103bool Throttle63::is_enabled(const std::uint8_t *bytes, int32_t length) const {
104 Byte frame(bytes + 7);
105 return frame.is_bit_1(0);
106}
107
108bool Throttle63::is_driver_override(const std::uint8_t *bytes,
109 int32_t length) const {
110 Byte frame(bytes + 7);
111 return frame.is_bit_1(1);
112}
113
114bool Throttle63::is_driver_activity(const std::uint8_t *bytes,
115 int32_t length) const {
116 Byte frame(bytes + 7);
117 return frame.is_bit_1(2);
118}
119
120bool Throttle63::is_watchdog_counter_fault(const std::uint8_t *bytes,
121 int32_t length) const {
122 Byte frame(bytes + 7);
123 return frame.is_bit_1(3);
124}
125
126bool Throttle63::is_channel_1_fault(const std::uint8_t *bytes,
127 int32_t length) const {
128 Byte frame(bytes + 7);
129 return frame.is_bit_1(4);
130}
131
132bool Throttle63::is_channel_2_fault(const std::uint8_t *bytes,
133 int32_t length) const {
134 Byte frame(bytes + 7);
135 return frame.is_bit_1(5);
136}
137
138bool Throttle63::is_connector_fault(const std::uint8_t *bytes,
139 int32_t length) const {
140 Byte frame(bytes + 7);
141 return frame.is_bit_1(7);
142}
143
144} // namespace lincoln
145} // namespace canbus
146} // namespace apollo
Defines the Byte class.
bool is_driver_override(const std::uint8_t *bytes, int32_t length) const
check driver override bit based on byte array.
double pedal_cmd(const std::uint8_t *bytes, int32_t length) const
calculate pedal command based on byte array.
double pedal_output(const std::uint8_t *bytes, int32_t length) const
calculate pedal output based on byte array.
bool is_connector_fault(const std::uint8_t *bytes, int32_t length) const
check connector fault bit based on byte array.
double pedal_input(const std::uint8_t *bytes, int32_t length) const
calculate pedal input based on byte array.
bool is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const
check channel 2 fault bit based on byte array.
bool is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const
check watchdog counter fault bit based on byte array.
bool is_enabled(const std::uint8_t *bytes, int32_t length) const
check enabled bit based on byte array.
virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const
bool is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const
check channel 1 fault bit based on byte array.
bool is_driver_activity(const std::uint8_t *bytes, int32_t length) const
check driver activity bit based on byte array.
int32_t watchdog_counter_source(const std::uint8_t *bytes, int32_t length) const
calculate watchdog counter source based on byte array.
class register implement
Definition arena_queue.h:37
the class of Throttle63 (for lincoln vehicle)