Apollo 10.0
自动驾驶开放平台
throttle_62.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
28
29const int32_t Throttle62::ID = 0x62;
30
31uint32_t Throttle62::GetPeriod() const {
32 static const uint32_t PERIOD = 10 * 1000;
33 return PERIOD;
34}
35
36void Throttle62::UpdateData(uint8_t *data) {
37 set_pedal_p(data, pedal_cmd_);
38 set_enable_p(data, pedal_enable_);
39 set_clear_driver_override_flag_p(data, clear_driver_override_flag_);
40 set_ignore_driver_override_p(data, ignore_driver_override_);
41 set_watchdog_counter_p(data, watchdog_counter_);
42}
43
45 pedal_cmd_ = 0.0;
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 return this;
55}
56
58 pedal_enable_ = true;
59 return this;
60}
61
63 pedal_enable_ = false;
64 return this;
65}
66
67// private
68
69void Throttle62::set_pedal_p(uint8_t *data, double pedal) {
70 // change from [0-100] to [0.00-1.00]
71 // and a rough mapping
72 pedal /= 100.0;
73 pedal = ProtocolData::BoundedValue(0.0, 1.0, pedal);
74 int32_t x = static_cast<int32_t>(pedal / 1.52590218966964e-05);
75 std::uint8_t t = 0;
76
77 t = static_cast<uint8_t>(x & 0xFF);
78 Byte frame_low(data + 0);
79 frame_low.set_value(t, 0, 8);
80
81 x >>= 8;
82 t = static_cast<uint8_t>(x & 0xFF);
83 Byte frame_high(data + 1);
84 frame_high.set_value(t, 0, 8);
85}
86
87void Throttle62::set_enable_p(uint8_t *bytes, bool enable) {
88 Byte frame(bytes + 3);
89 if (enable) {
90 frame.set_bit_1(0);
91 } else {
92 frame.set_bit_0(0);
93 }
94}
95
96void Throttle62::set_clear_driver_override_flag_p(uint8_t *bytes, bool clear) {
97 Byte frame(bytes + 3);
98 if (clear) {
99 frame.set_bit_1(1);
100 } else {
101 frame.set_bit_0(1);
102 }
103}
104
105void Throttle62::set_ignore_driver_override_p(uint8_t *bytes, bool ignore) {
106 Byte frame(bytes + 3);
107 if (ignore) {
108 frame.set_bit_1(2);
109 } else {
110 frame.set_bit_0(2);
111 }
112}
113
114void Throttle62::set_watchdog_counter_p(uint8_t *data, int32_t count) {
115 count = ProtocolData::BoundedValue(0, 255, count);
116 Byte frame(data + 7);
117 frame.set_value(static_cast<uint8_t>(count), 0, 8);
118}
119
120} // namespace lincoln
121} // namespace canbus
122} // namespace apollo
Defines the Byte class.
one of the protocol data of lincoln vehicle
Definition throttle_62.h:41
Throttle62 * set_disable()
set disable
Throttle62 * set_pedal(double pcmd)
set pedal based on pedal command
Throttle62 * set_enable()
set enable
virtual uint32_t GetPeriod() const
get the data period
virtual void Reset()
reset the private variables
virtual void UpdateData(uint8_t *data)
update the data
class register implement
Definition arena_queue.h:37
the class of Throttle62 (for lincoln vehicle)