Apollo 10.0
自动驾驶开放平台
pc_eps_204.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 Pceps204::ID = 0x204;
27
28// public
30
31uint32_t Pceps204::GetPeriod() const {
32 // modify every protocol's period manually
33 static const uint32_t PERIOD = 20 * 1000;
34 return PERIOD;
35}
36
37void Pceps204::UpdateData(uint8_t* data) {
38 set_p_pc_steerspdreq(data, pc_steerspdreq_);
39 set_p_pc_steerenable(data, pc_steerenable_);
40 set_p_pc_steerangreq(data, pc_steerangreq_);
41}
42
44 // you should check this manually
45 pc_steerspdreq_ = 0;
46 pc_steerenable_ = Pc_eps_204::PC_STEERENABLE_DISABLE;
47 pc_steerangreq_ = 0.0;
48}
49
51 pc_steerspdreq_ = pc_steerspdreq;
52 return this;
53}
54
55// config detail: {'description': 'Steer speed request', 'offset': 0.0,
56// 'precision': 1.0, 'len': 16, 'name': 'PC_SteerSpdReq', 'is_signed_var':
57// False, 'physical_range': '[0|500]', 'bit': 31, 'type': 'int', 'order':
58// 'motorola', 'physical_unit': 'deg/s'}
59void Pceps204::set_p_pc_steerspdreq(uint8_t* data, int pc_steerspdreq) {
60 pc_steerspdreq = ProtocolData::BoundedValue(0, 500, pc_steerspdreq);
61 int x = pc_steerspdreq;
62 uint8_t t = 0;
63
64 t = static_cast<uint8_t>(x & 0xFF);
65 Byte to_set0(data + 4);
66 to_set0.set_value(t, 0, 8);
67 x >>= 8;
68
69 t = static_cast<uint8_t>(x & 0xFF);
70 Byte to_set1(data + 3);
71 to_set1.set_value(t, 0, 8);
72}
73
75 Pc_eps_204::Pc_steerenableType pc_steerenable) {
76 pc_steerenable_ = pc_steerenable;
77 return this;
78}
79
80// config detail: {'description': 'Steer control enable', 'enum': {0:
81// 'PC_STEERENABLE_DISABLE', 1: 'PC_STEERENABLE_ENABLE'}, 'precision': 1.0,
82// 'len': 1, 'name': 'PC_SteerEnable', 'is_signed_var': False, 'offset': 0.0,
83// 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola',
84// 'physical_unit': ''}
85void Pceps204::set_p_pc_steerenable(
86 uint8_t* data, Pc_eps_204::Pc_steerenableType pc_steerenable) {
87 int x = pc_steerenable;
88
89 Byte to_set(data + 0);
90 to_set.set_value(static_cast<uint8_t>(x), 7, 1);
91}
92
93Pceps204* Pceps204::set_pc_steerangreq(double pc_steerangreq) {
94 pc_steerangreq_ = pc_steerangreq;
95 return this;
96}
97
98// config detail: {'description': 'Steer angle request', 'offset': -500.0,
99// 'precision': 0.1, 'len': 16, 'name': 'PC_SteerAngReq', 'is_signed_var':
100// False, 'physical_range': '[-500|500]', 'bit': 15, 'type': 'double', 'order':
101// 'motorola', 'physical_unit': 'deg'}
102void Pceps204::set_p_pc_steerangreq(uint8_t* data, double pc_steerangreq) {
103 pc_steerangreq = ProtocolData::BoundedValue(-500.0, 500.0, pc_steerangreq);
104 int x = static_cast<int>((pc_steerangreq - -500.000000) / 0.100000);
105 uint8_t t = 0;
106
107 t = static_cast<uint8_t>(x & 0xFF);
108 Byte to_set0(data + 2);
109 to_set0.set_value(t, 0, 8);
110 x >>= 8;
111
112 t = static_cast<uint8_t>(x & 0xFF);
113 Byte to_set1(data + 1);
114 to_set1.set_value(t, 0, 8);
115}
116
117} // namespace ge3
118} // namespace canbus
119} // namespace apollo
Defines the Byte class.
static const int32_t ID
Definition pc_eps_204.h:29
uint32_t GetPeriod() const override
Definition pc_eps_204.cc:31
Pceps204 * set_pc_steerangreq(double pc_steerangreq)
Definition pc_eps_204.cc:93
Pceps204 * set_pc_steerenable(Pc_eps_204::Pc_steerenableType pc_steerenable)
Definition pc_eps_204.cc:74
Pceps204 * set_pc_steerspdreq(int pc_steerspdreq)
Definition pc_eps_204.cc:50
void UpdateData(uint8_t *data) override
Definition pc_eps_204.cc:37
class register implement
Definition arena_queue.h:37