Apollo 10.0
自动驾驶开放平台
ads1_111.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
18
20
21namespace apollo {
22namespace canbus {
23namespace wey {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Ads1111::ID = 0x111;
28
29// public
31
32uint32_t Ads1111::GetPeriod() const {
33 // TODO(ChaoMa) :modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Ads1111::UpdateData(uint8_t* data) {
39 set_p_ads_dectostop(data, ads_dectostop_);
40 set_p_ads_mode(data, ads_mode_);
41 set_p_ads_taracce(data, ads_taracce_);
42 set_p_ads_driveoff_req(data, ads_driveoff_req_);
43 set_p_ads_aeb_taracce(data, ads_aeb_taracce_);
44 set_p_ads_aeb_tgtdecel_req(data, ads_aeb_tgtdecel_req_);
45}
46
48 // TODO(ChaoMa) :you should check this manually
49 ads_dectostop_ = Ads1_111::ADS_DECTOSTOP_NO_DEMAND;
51 ads_taracce_ = 0.0;
52 ads_driveoff_req_ = Ads1_111::ADS_DRIVEOFF_REQ_NO_DEMAND;
53 ads_aeb_taracce_ = 0.0;
54 ads_aeb_tgtdecel_req_ = Ads1_111::ADS_AEB_TGTDECEL_REQ_NO_DEMAND;
55}
56
58 ads_dectostop_ = ads_dectostop;
59 return this;
60}
61
62// config detail: {'description': 'ADS request ESP/VLC to decelerate until
63// standstill.', 'enum': {0: 'ADS_DECTOSTOP_NO_DEMAND', 1:
64// 'ADS_DECTOSTOP_DEMAND'}, 'precision': 1.0, 'len': 1, 'name': 'ADS_DecToStop',
65// 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 17,
66// 'type': 'enum', 'order': 'motorola', 'physical_unit': ''}
67void Ads1111::set_p_ads_dectostop(uint8_t* data,
68 Ads1_111::Ads_dectostopType ads_dectostop) {
69 int x = ads_dectostop;
70
71 Byte to_set(data + 2);
72 to_set.set_value(static_cast<uint8_t>(x), 1, 1);
73}
74
76 ads_mode_ = ads_mode;
77 return this;
78}
79
80// config detail: {'description': 'The status of the ADS control unit.
81// The ADS mode should be contained in every message sent by ADS', 'enum':
82// {0: 'ADS_MODE_OFF_MODE', 3: 'ADS_MODE_ACTIVE_MODE'}, 'precision': 1.0,
83// 'len': 5, 'name': 'ADS_Mode', 'is_signed_var': False, 'offset': 0.0,
84// 'physical_range': '[0|31]', 'bit': 7, 'type': 'enum', 'order': 'motorola',
85// 'physical_unit': ''}
86void Ads1111::set_p_ads_mode(uint8_t* data, Ads1_111::Ads_modeType ads_mode) {
87 int x = ads_mode;
88
89 Byte to_set(data + 0);
90 to_set.set_value(static_cast<uint8_t>(x), 3, 5);
91}
92
93Ads1111* Ads1111::set_ads_taracce(double ads_taracce) {
94 ads_taracce_ = ads_taracce;
95 return this;
96}
97
98// config detail: {'description': 'ADS target acceleration for transmission',
99// 'offset': -7.0, 'precision': 0.05, 'len': 8, 'name': 'ADS_TarAcce',
100// 'is_signed_var': False, 'physical_range': '[-7|5.75]', 'bit': 15, 'type':
101// 'double', 'order': 'motorola', 'physical_unit': 'm/s2'}
102void Ads1111::set_p_ads_taracce(uint8_t* data, double ads_taracce) {
103 ads_taracce = ProtocolData::BoundedValue(-7.0, 5.75, ads_taracce);
104 int x = static_cast<int>((ads_taracce - -7.000000) / 0.050000);
105
106 Byte to_set(data + 1);
107 to_set.set_value(static_cast<uint8_t>(x), 0, 8);
108}
109
111 Ads1_111::Ads_driveoff_reqType ads_driveoff_req) {
112 ads_driveoff_req_ = ads_driveoff_req;
113 return this;
114}
115
116// config detail: {'description': 'ACC request ESP drive off', 'enum': {0:
117// 'ADS_DRIVEOFF_REQ_NO_DEMAND', 1: 'ADS_DRIVEOFF_REQ_DEMAND'}, 'precision':1.0,
118// 'len': 1, 'name': 'ADS_Driveoff_Req', 'is_signed_var': False, 'offset': 0.0,
119// 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': 'motorola',
120// 'physical_unit': ''}
121void Ads1111::set_p_ads_driveoff_req(
122 uint8_t* data, Ads1_111::Ads_driveoff_reqType ads_driveoff_req) {
123 int x = ads_driveoff_req;
124
125 Byte to_set(data + 0);
126 to_set.set_value(static_cast<uint8_t>(x), 1, 1);
127}
128
129Ads1111* Ads1111::set_ads_aeb_taracce(double ads_aeb_taracce) {
130 ads_aeb_taracce_ = ads_aeb_taracce;
131 return this;
132}
133
134// config detail: {'description': 'target deceleration value from AEB',
135// 'offset': -16.0, 'precision': 0.000488, 'len': 16, 'name': 'ADS_AEB_TarAcce',
136// 'is_signed_var': False, 'physical_range': '[-16|16]', 'bit': 39, 'type':
137// 'double', 'order': 'motorola', 'physical_unit': 'm/s2'}
138void Ads1111::set_p_ads_aeb_taracce(uint8_t* data, double ads_aeb_taracce) {
139 ads_aeb_taracce = ProtocolData::BoundedValue(-16.0, 16.0, ads_aeb_taracce);
140 int x = static_cast<int>((ads_aeb_taracce - -16.000000) / 0.000488);
141 uint8_t t = 0;
142
143 t = static_cast<uint8_t>(x & 0xFF);
144 Byte to_set0(data + 5);
145 to_set0.set_value(t, 0, 8);
146 x >>= 8;
147
148 t = static_cast<uint8_t>(x & 0xFF);
149 Byte to_set1(data + 4);
150 to_set1.set_value(t, 0, 8);
151}
152
154 Ads1_111::Ads_aeb_tgtdecel_reqType ads_aeb_tgtdecel_req) {
155 ads_aeb_tgtdecel_req_ = ads_aeb_tgtdecel_req;
156 return this;
157}
158
159// config detail: {'description': 'Request of the AEB deceleration control.',
160// 'enum': {0: 'ADS_AEB_TGTDECEL_REQ_NO_DEMAND', 1:
161// 'ADS_AEB_TGTDECEL_REQ_DEMAND'}, 'precision': 1.0, 'len': 1,
162// 'name': 'ADS_AEB_TgtDecel_Req', 'is_signed_var': False, 'offset': 0.0,
163// 'physical_range': '[0|1]', 'bit': 31, 'type': 'enum', 'order':'motorola',
164// 'physical_unit': ''}
165void Ads1111::set_p_ads_aeb_tgtdecel_req(
166 uint8_t* data, Ads1_111::Ads_aeb_tgtdecel_reqType ads_aeb_tgtdecel_req) {
167 int x = ads_aeb_tgtdecel_req;
168
169 Byte to_set(data + 3);
170 to_set.set_value(static_cast<uint8_t>(x), 7, 1);
171}
172
173} // namespace wey
174} // namespace canbus
175} // namespace apollo
Defines the Byte class.
Ads1111 * set_ads_aeb_taracce(double ads_aeb_taracce)
Definition ads1_111.cc:129
Ads1111 * set_ads_taracce(double ads_taracce)
Definition ads1_111.cc:93
Ads1111 * set_ads_dectostop(Ads1_111::Ads_dectostopType ads_dectostop)
Definition ads1_111.cc:57
Ads1111 * set_ads_driveoff_req(Ads1_111::Ads_driveoff_reqType ads_driveoff_req)
Definition ads1_111.cc:110
void UpdateData(uint8_t *data) override
Definition ads1_111.cc:38
static const int32_t ID
Definition ads1_111.h:29
Ads1111 * set_ads_mode(Ads1_111::Ads_modeType ads_mode)
Definition ads1_111.cc:75
Ads1111 * set_ads_aeb_tgtdecel_req(Ads1_111::Ads_aeb_tgtdecel_reqType ads_aeb_tgtdecel_req)
Definition ads1_111.cc:153
uint32_t GetPeriod() const override
Definition ads1_111.cc:32
class register implement
Definition arena_queue.h:37