Apollo 10.0
自动驾驶开放平台
accel_6b.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
19#include "glog/logging.h"
20
23
24namespace apollo {
25namespace canbus {
26namespace lincoln {
27
28using ::apollo::drivers::canbus::Byte;
29
30const int32_t Accel6b::ID = 0x6B;
31
32void Accel6b::Parse(const std::uint8_t *bytes, int32_t length,
33 Lincoln *chassis_detail) const {
34 chassis_detail->mutable_vehicle_spd()->set_lat_acc(
35 lateral_acceleration(bytes, length));
36 chassis_detail->mutable_vehicle_spd()->set_long_acc(
37 longitudinal_acceleration(bytes, length));
38 chassis_detail->mutable_vehicle_spd()->set_vert_acc(
39 vertical_acceleration(bytes, length));
40}
41
42double Accel6b::lateral_acceleration(const std::uint8_t *bytes,
43 const int32_t length) const {
44 DCHECK_GE(length, 2);
45 return parse_two_frames(bytes[0], bytes[1]);
46}
47
48double Accel6b::longitudinal_acceleration(const std::uint8_t *bytes,
49 const int32_t length) const {
50 DCHECK_GE(length, 4);
51 return parse_two_frames(bytes[2], bytes[3]);
52}
53
54double Accel6b::vertical_acceleration(const std::uint8_t *bytes,
55 const int32_t length) const {
56 DCHECK_GE(length, 6);
57 return parse_two_frames(bytes[4], bytes[5]);
58}
59
60double Accel6b::parse_two_frames(const std::uint8_t low_byte,
61 const std::uint8_t high_byte) const {
62 Byte high_frame(&high_byte);
63 int32_t high = high_frame.get_byte(0, 8);
64 Byte low_frame(&low_byte);
65 int32_t low = low_frame.get_byte(0, 8);
66 int32_t value = (high << 8) | low;
67 if (value > 0x7FFF) {
68 value -= 0x10000;
69 }
70 return value * 0.010000;
71}
72
73} // namespace lincoln
74} // namespace canbus
75} // namespace apollo
the class of Accel6b (for lincoln vehicle)
Defines the Byte class.
static const int32_t ID
Definition accel_6b.h:43
virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const
Definition accel_6b.cc:32
class register implement
Definition arena_queue.h:37