Apollo 10.0
自动驾驶开放平台
torque_control_a3.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 zhongyun {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Torquecontrola3::ID = 0xA3;
28
29// public
31
33 // TODO(ChaoM) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Torquecontrola3::UpdateData(uint8_t* data) {
39 set_p_driven_torque(data, driven_torque_);
40 set_p_driven_enable_control(data, driven_enable_control_);
41}
42
44 // TODO(ChaoM) : you should check this manually
45 driven_torque_ = 0.0;
46 driven_enable_control_ =
48}
49
51 driven_torque_ = driven_torque;
52 return this;
53}
54
55// config detail: {'name': 'driven_torque', 'offset': 0.0, 'precision': 0.05,
56// 'len': 16, 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 8,
57// 'type': 'double', 'order': 'intel', 'physical_unit': '%'}
58void Torquecontrola3::set_p_driven_torque(uint8_t* data, double driven_torque) {
59 driven_torque = ProtocolData::BoundedValue(0.0, 100.0, driven_torque);
60 int x = static_cast<int>(driven_torque / 0.050000);
61 uint8_t t = 0;
62
63 t = static_cast<uint8_t>(x & 0xFF);
64 Byte to_set0(data + 1);
65 to_set0.set_value(t, 0, 8);
66 x >>= 8;
67
68 t = static_cast<uint8_t>(x & 0xFF);
69 Byte to_set1(data + 2);
70 to_set1.set_value(t, 0, 8);
71}
72
75 driven_enable_control_ = driven_enable_control;
76 return this;
77}
78
79// config detail: {'name': 'Driven_Enable_control', 'enum': {0:
80// 'DRIVEN_ENABLE_CONTROL_DRIVE_MANUAL', 1: 'DRIVEN_ENABLE_CONTROL_DRIVE_AUTO'},
81// 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'offset': 0.0,
82// 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'intel',
83// 'physical_unit': ''}
84void Torquecontrola3::set_p_driven_enable_control(
85 uint8_t* data,
87 int x = driven_enable_control;
88
89 Byte to_set(data + 0);
90 to_set.set_value(static_cast<uint8_t>(x), 0, 8);
91}
92
93} // namespace zhongyun
94} // namespace canbus
95} // namespace apollo
Defines the Byte class.
Torquecontrola3 * set_driven_torque(double driven_torque)
Torquecontrola3 * set_driven_enable_control(Torque_control_a3::Driven_enable_controlType driven_enable_control)
class register implement
Definition arena_queue.h:37