Apollo 10.0
自动驾驶开放平台
ultrasonic_radar_message_manager.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
23
25
26namespace apollo {
27namespace drivers {
28namespace ultrasonic_radar {
29
31 const int entrance_num,
32 const std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>> &writer)
33 : entrance_num_(entrance_num), ultrasonic_radar_writer_(writer) {
34 sensor_data_.mutable_ranges()->Resize(entrance_num_, 0.0);
35}
36
38 std::shared_ptr<CanClient> can_client) {
39 can_client_ = can_client;
40}
41
42void UltrasonicRadarMessageManager::Parse(const uint32_t message_id,
43 const uint8_t *data, int32_t length) {
44 if (message_id == 0x301) {
45 sensor_data_.set_ranges(0, data[1]);
46 sensor_data_.set_ranges(1, data[2]);
47 sensor_data_.set_ranges(2, data[3]);
48 sensor_data_.set_ranges(3, data[4]);
49 } else if (message_id == 0x302) {
50 sensor_data_.set_ranges(4, data[1]);
51 sensor_data_.set_ranges(5, data[2]);
52 sensor_data_.set_ranges(6, data[3]);
53 sensor_data_.set_ranges(7, data[4]);
54 } else if (message_id == 0x303) {
55 sensor_data_.set_ranges(8, data[1]);
56 sensor_data_.set_ranges(9, data[2]);
57 } else if (message_id == 0x304) {
58 sensor_data_.set_ranges(10, data[1]);
59 sensor_data_.set_ranges(11, data[2]);
60 common::util::FillHeader("ultrasonic_radar", &sensor_data_);
61 ultrasonic_radar_writer_->Write(sensor_data_);
62 }
63
64 received_ids_.insert(message_id);
65 // check if need to check period
66 const auto it = check_ids_.find(message_id);
67 if (it != check_ids_.end()) {
68 const int64_t time = Time::Now().ToMicrosecond();
69 it->second.real_period = time - it->second.last_time;
70 // if period 1.5 large than base period, inc error_count
71 const double period_multiplier = 1.5;
72 if (it->second.real_period >
73 (static_cast<double>(it->second.period) * period_multiplier)) {
74 it->second.error_count += 1;
75 } else {
76 it->second.error_count = 0;
77 }
78 it->second.last_time = time;
79 }
80}
81
82} // namespace ultrasonic_radar
83} // namespace drivers
84} // namespace apollo
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
static Time Now()
get the current time.
Definition time.cc:57
UltrasonicRadarMessageManager(const int entrance_num, const std::shared_ptr<::apollo::cyber::Writer< Ultrasonic > > &writer)
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length)
Some string util functions.
class register implement
Definition arena_queue.h:37
The class of UltrasonicRadarMessageManager