Apollo 10.0
自动驾驶开放平台
pc_vcu_205.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
19
20namespace apollo {
21namespace canbus {
22namespace ge3 {
23
24using ::apollo::drivers::canbus::Byte;
25
26const int32_t Pcvcu205::ID = 0x205;
27
28// public
30
31uint32_t Pcvcu205::GetPeriod() const {
32 // modify every protocol's period manually
33 static const uint32_t PERIOD = 20 * 1000;
34 return PERIOD;
35}
36
37void Pcvcu205::UpdateData(uint8_t* data) {
38 set_p_pc_accpedreq(data, pc_accpedreq_);
39 set_p_pc_accpedenable(data, pc_accpedenable_);
40 set_p_pc_torqreq(data, pc_torqreq_);
41 set_p_pc_torqenable(data, pc_torqenable_);
42 set_p_pc_gearreq(data, pc_gearreq_);
43 set_p_pc_gearenable(data, pc_gearenable_);
44}
45
47 // you should check this manually
48 pc_accpedreq_ = 0.0;
49 pc_accpedenable_ = Pc_vcu_205::PC_ACCPEDENABLE_DISABLE;
50 pc_torqreq_ = 0.0;
51 pc_torqenable_ = Pc_vcu_205::PC_TORQENABLE_DISABLE;
53 pc_gearenable_ = Pc_vcu_205::PC_GEARENABLE_DISABLE;
54}
55
56Pcvcu205* Pcvcu205::set_pc_accpedreq(double pc_accpedreq) {
57 pc_accpedreq_ = pc_accpedreq;
58 return this;
59}
60
61// config detail: {'description': 'Acceleration pedal request', 'offset': 0.0,
62// 'precision': 0.05, 'len': 12, 'name': 'PC_AccPedReq', 'is_signed_var': False,
63// 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order':
64// 'motorola', 'physical_unit': '%'}
65void Pcvcu205::set_p_pc_accpedreq(uint8_t* data, double pc_accpedreq) {
66 pc_accpedreq = ProtocolData::BoundedValue(0.0, 100.0, pc_accpedreq);
67 int x = static_cast<int>(pc_accpedreq / 0.050000);
68 uint8_t t = 0;
69
70 t = x & 0xF;
71 Byte to_set0(data + 2);
72 to_set0.set_value(t, 4, 4);
73 x >>= 4;
74
75 t = static_cast<uint8_t>(x & 0xFF);
76 Byte to_set1(data + 1);
77 to_set1.set_value(t, 0, 8);
78}
79
81 Pc_vcu_205::Pc_accpedenableType pc_accpedenable) {
82 pc_accpedenable_ = pc_accpedenable;
83 return this;
84}
85
86// config detail: {'description': 'Acceleration pedal control enable', 'enum':
87// {0: 'PC_ACCPEDENABLE_DISABLE', 1: 'PC_ACCPEDENABLE_ENABLE'},
88// 'precision': 1.0, 'len': 1, 'name': 'PC_AccPedEnable', 'is_signed_var':
89// False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum',
90// 'order': 'motorola', 'physical_unit': ''}
91void Pcvcu205::set_p_pc_accpedenable(
92 uint8_t* data, Pc_vcu_205::Pc_accpedenableType pc_accpedenable) {
93 int x = pc_accpedenable;
94
95 Byte to_set(data + 0);
96 to_set.set_value(static_cast<uint8_t>(x), 6, 1);
97}
98
100 pc_torqreq_ = pc_torqreq;
101 return this;
102}
103
104// config detail: {'description': 'Torque request', 'offset': -3000.0,
105// 'precision': 1.5, 'len': 12, 'name': 'PC_TorqReq', 'is_signed_var': False,
106// 'physical_range': '[-3000|3000]', 'bit': 19, 'type': 'double', 'order':
107// 'motorola', 'physical_unit': 'Nm'}
108void Pcvcu205::set_p_pc_torqreq(uint8_t* data, double pc_torqreq) {
109 pc_torqreq = ProtocolData::BoundedValue(-3000.0, 3000.0, pc_torqreq);
110 int x = static_cast<int>((pc_torqreq - -3000.000000) / 1.500000);
111 uint8_t t = 0;
112
113 t = static_cast<uint8_t>(x & 0xFF);
114 Byte to_set0(data + 3);
115 to_set0.set_value(t, 0, 8);
116 x >>= 8;
117
118 t = x & 0xF;
119 Byte to_set1(data + 2);
120 to_set1.set_value(t, 0, 4);
121}
122
124 Pc_vcu_205::Pc_torqenableType pc_torqenable) {
125 pc_torqenable_ = pc_torqenable;
126 return this;
127}
128
129// config detail: {'description': 'Torque control enable', 'enum': {0:
130// 'PC_TORQENABLE_DISABLE', 1: 'PC_TORQENABLE_ENABLE'}, 'precision': 1.0, 'len':
131// 1, 'name': 'PC_TorqEnable', 'is_signed_var': False, 'offset': 0.0,
132// 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola',
133// 'physical_unit': ''}
134void Pcvcu205::set_p_pc_torqenable(
135 uint8_t* data, Pc_vcu_205::Pc_torqenableType pc_torqenable) {
136 int x = pc_torqenable;
137
138 Byte to_set(data + 0);
139 to_set.set_value(static_cast<uint8_t>(x), 5, 1);
140}
141
143 pc_gearreq_ = pc_gearreq;
144 return this;
145}
146
147// config detail: {'description': 'Gear request', 'enum': {0:
148// 'PC_GEARREQ_INVALID', 1: 'PC_GEARREQ_DRIVE', 2: 'PC_GEARREQ_NEUTRAL', 3:
149// 'PC_GEARREQ_REVERSE', 4: 'PC_GEARREQ_PARK'}, 'precision': 1.0, 'len': 3,
150// 'name': 'PC_GearReq', 'is_signed_var': False, 'offset': 0.0,
151// 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', 'order': 'motorola',
152// 'physical_unit': ''}
153void Pcvcu205::set_p_pc_gearreq(uint8_t* data,
154 Pc_vcu_205::Pc_gearreqType pc_gearreq) {
155 int x = pc_gearreq;
156
157 Byte to_set(data + 0);
158 to_set.set_value(static_cast<uint8_t>(x), 0, 3);
159}
160
162 Pc_vcu_205::Pc_gearenableType pc_gearenable) {
163 pc_gearenable_ = pc_gearenable;
164 return this;
165}
166
167// config detail: {'description': 'Gear control enable', 'enum': {0:
168// 'PC_GEARENABLE_DISABLE', 1: 'PC_GEARENABLE_ENABLE'}, 'precision': 1.0, 'len':
169// 1, 'name': 'PC_GearEnable', 'is_signed_var': False, 'offset': 0.0,
170// 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola',
171// 'physical_unit': ''}
172void Pcvcu205::set_p_pc_gearenable(
173 uint8_t* data, Pc_vcu_205::Pc_gearenableType pc_gearenable) {
174 int x = pc_gearenable;
175
176 Byte to_set(data + 0);
177 to_set.set_value(static_cast<uint8_t>(x), 7, 1);
178}
179
180} // namespace ge3
181} // namespace canbus
182} // namespace apollo
Defines the Byte class.
Pcvcu205 * set_pc_gearenable(Pc_vcu_205::Pc_gearenableType pc_gearenable)
uint32_t GetPeriod() const override
Definition pc_vcu_205.cc:31
static const int32_t ID
Definition pc_vcu_205.h:29
Pcvcu205 * set_pc_torqreq(double pc_torqreq)
Definition pc_vcu_205.cc:99
Pcvcu205 * set_pc_gearreq(Pc_vcu_205::Pc_gearreqType pc_gearreq)
Pcvcu205 * set_pc_accpedenable(Pc_vcu_205::Pc_accpedenableType pc_accpedenable)
Definition pc_vcu_205.cc:80
Pcvcu205 * set_pc_accpedreq(double pc_accpedreq)
Definition pc_vcu_205.cc:56
Pcvcu205 * set_pc_torqenable(Pc_vcu_205::Pc_torqenableType pc_torqenable)
void UpdateData(uint8_t *data) override
Definition pc_vcu_205.cc:37
class register implement
Definition arena_queue.h:37