Apollo 10.0
自动驾驶开放平台
steering_cmd_6d.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 gem {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Steeringcmd6d::ID = 0x6D;
28
29// public
31
32uint32_t Steeringcmd6d::GetPeriod() const {
33 // TODO(QiL) :modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Steeringcmd6d::UpdateData(uint8_t* data) {
39 set_p_position_value(data, position_value_);
40 set_p_speed_limit(data, speed_limit_);
41}
42
44 // TODO(QiL) :you should check this manually
45 position_value_ = 0.0;
46 speed_limit_ = 0.0;
47}
48
50 position_value_ = position_value;
51 return this;
52}
53
54// config detail: {'name': 'POSITION_VALUE', 'offset': 0.0, 'precision': 0.001,
55// 'len': 32, 'is_signed_var': True, 'physical_range':
56// '[-2147483.648|2147483.647]', 'bit': 7, 'type': 'double', 'order':
57// 'motorola', 'physical_unit': 'radians'}
58void Steeringcmd6d::set_p_position_value(uint8_t* data, double position_value) {
59 position_value =
60 ProtocolData::BoundedValue(-2147483.648, 2147483.647, position_value);
61 int x = static_cast<int>(position_value / 0.001000);
62 uint8_t t = 0;
63
64 t = static_cast<uint8_t>(x & 0xFF);
65 Byte to_set0(data + 3);
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 + 2);
71 to_set1.set_value(t, 0, 8);
72 x >>= 8;
73
74 t = static_cast<uint8_t>(x & 0xFF);
75 Byte to_set2(data + 1);
76 to_set2.set_value(t, 0, 8);
77 x >>= 8;
78
79 t = static_cast<uint8_t>(x & 0xFF);
80 Byte to_set3(data + 0);
81 to_set3.set_value(t, 0, 8);
82}
83
85 speed_limit_ = speed_limit;
86 return this;
87}
88
89// config detail: {'name': 'SPEED_LIMIT', 'offset': 0.0, 'precision': 0.001,
90// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65.535]', 'bit': 39,
91// 'type': 'double', 'order': 'motorola', 'physical_unit': 'rad/s'}
92void Steeringcmd6d::set_p_speed_limit(uint8_t* data, double speed_limit) {
93 speed_limit = ProtocolData::BoundedValue(0.0, 65.535, speed_limit);
94 int x = static_cast<int>(speed_limit / 0.001000);
95 uint8_t t = 0;
96
97 t = static_cast<uint8_t>(x & 0xFF);
98 Byte to_set0(data + 7);
99 to_set0.set_value(t, 0, 8);
100 x >>= 8;
101
102 t = static_cast<uint8_t>(x & 0xFF);
103 Byte to_set1(data + 6);
104 to_set1.set_value(t, 0, 8);
105 x >>= 8;
106
107 t = static_cast<uint8_t>(x & 0xFF);
108 Byte to_set2(data + 5);
109 to_set2.set_value(t, 0, 8);
110 x >>= 8;
111
112 t = static_cast<uint8_t>(x & 0xFF);
113 Byte to_set3(data + 4);
114 to_set3.set_value(t, 0, 8);
115}
116
117} // namespace gem
118} // namespace canbus
119} // namespace apollo
Defines the Byte class.
uint32_t GetPeriod() const override
void UpdateData(uint8_t *data) override
Steeringcmd6d * set_position_value(double position_value)
Steeringcmd6d * set_speed_limit(double speed_limit)
class register implement
Definition arena_queue.h:37