Apollo 10.0
自动驾驶开放平台
brake_cmd_6b.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 Brakecmd6b::ID = 0x6B;
28
29// public
31
32uint32_t Brakecmd6b::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 Brakecmd6b::UpdateData(uint8_t* data) {
39 set_p_brake_cmd(data, brake_cmd_);
40}
41
43 // TODO(QiL) :you should check this manually
44 brake_cmd_ = 0.0;
45}
46
48 brake_cmd_ = brake_cmd;
49 return this;
50}
51
52// config detail: {'name': 'BRAKE_CMD', 'offset': 0.0, 'precision': 0.001,
53// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 7,
54// 'type': 'double', 'order': 'motorola', 'physical_unit': '%'}
55void Brakecmd6b::set_p_brake_cmd(uint8_t* data, double brake_cmd) {
56 brake_cmd = ProtocolData::BoundedValue(0.0, 1.0, brake_cmd);
57 int x = static_cast<int>(brake_cmd / 0.001000);
58 uint8_t t = 0;
59
60 t = static_cast<uint8_t>(x & 0xFF);
61 Byte to_set0(data + 1);
62 to_set0.set_value(t, 0, 8);
63 x >>= 8;
64
65 t = static_cast<uint8_t>(x & 0xFF);
66 Byte to_set1(data + 0);
67 to_set1.set_value(t, 0, 8);
68}
69
70} // namespace gem
71} // namespace canbus
72} // namespace apollo
Defines the Byte class.
Brakecmd6b * set_brake_cmd(double brake_cmd)
uint32_t GetPeriod() const override
void UpdateData(uint8_t *data) override
class register implement
Definition arena_queue.h:37