Apollo 10.0
自动驾驶开放平台
motion_input_speed_300.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 drivers {
23namespace conti_radar {
24
27
28const uint32_t MotionInputSpeed300::ID = 0x300;
29
32
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
43 if (std::isnan(speed_)) {
44 AWARN << "speed is nan";
45 return;
46 }
47 uint32_t speed_direction = 0;
48 if (fabs(speed_) < 0.02) {
49 speed_direction = 0;
50 } else if (speed_ < 0) {
51 speed_direction = 2;
52 } else {
53 speed_direction = 1;
54 }
55 uint32_t speed_value = static_cast<uint32_t>(fabs(speed_) / 0.02);
56 Byte frame_speed_direction(data);
57 frame_speed_direction.set_value(
58 static_cast<unsigned char>((speed_direction << 6) & 0x00C0) |
59 static_cast<unsigned char>((speed_value & 0x1F00) >> 8),
60 0, 8);
61 Byte frame_speed(data + 1);
62 frame_speed.set_value(static_cast<unsigned char>(speed_value & 0x00FF), 0, 8);
63}
64
68void MotionInputSpeed300::Reset() { speed_ = NAN; }
69
70void MotionInputSpeed300::SetSpeed(const float& speed) { speed_ = speed; }
71
72} // namespace conti_radar
73} // namespace drivers
74} // namespace apollo
Defines the Byte class.
The class of one byte, which is 8 bits.
Definition byte.h:39
void set_value(const uint8_t value)
Reset this Byte by a specified one-byte unsigned integer.
Definition byte.cc:90
void Reset() override
reset the private variables
void UpdateData(uint8_t *data) override
update the data
uint32_t GetPeriod() const override
get the data period
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37