Apollo 10.0
自动驾驶开放平台
racobit_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
24#include <utility>
25
35
36namespace apollo {
37namespace drivers {
38namespace racobit_radar {
39
41 std::shared_ptr<cyber::Writer<RacobitRadar>> writer)
42 : writer_(std::move(writer)) {
43 AddRecvProtocolData<RadarState201, true>();
44 AddRecvProtocolData<ClusterListStatus600, true>();
45 AddRecvProtocolData<ClusterGeneralInfo701, true>();
46 AddRecvProtocolData<ClusterQualityInfo702, true>();
47 AddRecvProtocolData<ObjectExtendedInfo60D, true>();
48 AddRecvProtocolData<ObjectGeneralInfo60B, true>();
49 AddRecvProtocolData<ObjectListStatus60A, true>();
50 AddRecvProtocolData<ObjectQualityInfo60C, true>();
51}
52
54 radar_config_.set_radar_conf(radar_conf);
55}
56
58 std::shared_ptr<CanClient> can_client) {
59 can_client_ = can_client;
60}
61
62ProtocolData<RacobitRadar>
64 const uint32_t message_id) {
65 uint32_t converted_message_id = message_id;
66 if (protocol_data_map_.find(converted_message_id) ==
67 protocol_data_map_.end()) {
68 ADEBUG << "Unable to get protocol data because of invalid message_id:"
69 << message_id;
70 return nullptr;
71 }
72 return protocol_data_map_[converted_message_id];
73}
74
75void RacobitRadarMessageManager::Parse(const uint32_t message_id,
76 const uint8_t *data, int32_t length) {
77 ProtocolData<RacobitRadar> *sensor_protocol_data =
79 if (sensor_protocol_data == nullptr) {
80 return;
81 }
82
83 std::lock_guard<std::mutex> lock(sensor_data_mutex_);
84 if (!is_configured_ && message_id != RadarState201::ID) {
85 // read radar state message first
86 return;
87 }
88
89 common::util::FillHeader(FLAGS_sensor_node_name, &sensor_data_);
90
91 // trigger publishment
92 if (message_id == ClusterListStatus600::ID ||
93 message_id == ObjectListStatus60A::ID) {
94 ADEBUG << sensor_data_.ShortDebugString();
95
96 if (sensor_data_.contiobs_size() <=
97 sensor_data_.object_list_status().nof_objects()) {
98 // maybe lost an object_list_status msg
99 common::util::FillHeader("racobit_radar", &sensor_data_);
100 writer_->Write(sensor_data_);
101 }
102 sensor_data_.Clear();
103 // fill header when receive the general info message
104 }
105
106 sensor_protocol_data->Parse(data, length, &sensor_data_);
107
108 if (message_id == RadarState201::ID) {
109 ADEBUG << sensor_data_.ShortDebugString();
110 if (sensor_data_.radar_state().send_quality() ==
111 radar_config_.radar_conf().send_quality() &&
112 sensor_data_.radar_state().send_ext_info() ==
113 radar_config_.radar_conf().send_ext_info() &&
114 sensor_data_.radar_state().max_distance() ==
115 radar_config_.radar_conf().max_distance() &&
116 sensor_data_.radar_state().output_type() ==
117 radar_config_.radar_conf().output_type() &&
118 sensor_data_.radar_state().rcs_threshold() ==
119 radar_config_.radar_conf().rcs_threshold() &&
120 sensor_data_.radar_state().radar_power() ==
121 radar_config_.radar_conf().radar_power()) {
122 is_configured_ = true;
123 } else {
124 AINFO << "configure radar again";
126 &radar_config_);
127 sender_message.Update();
128 can_client_->SendSingleFrame({sender_message.CanFrame()});
129 }
130 }
131
132 received_ids_.insert(message_id);
133 // check if need to check period
134 const auto it = check_ids_.find(message_id);
135 if (it != check_ids_.end()) {
136 const int64_t time = Time::Now().ToMicrosecond();
137 it->second.real_period = time - it->second.last_time;
138 // if period 1.5 large than base period, inc error_count
139 const double period_multiplier = 1.5;
140 if (it->second.real_period >
141 (static_cast<double>(it->second.period) * period_multiplier)) {
142 it->second.error_count += 1;
143 } else {
144 it->second.error_count = 0;
145 }
146 it->second.last_time = time;
147 }
148}
149
150} // namespace racobit_radar
151} // namespace drivers
152} // 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
This class defines the message to send.
Definition can_sender.h:56
struct CanFrame CanFrame()
Get the CAN frame to send.
Definition can_sender.h:293
void Update()
Update the protocol data.
Definition can_sender.h:264
RacobitRadarMessageManager(std::shared_ptr< cyber::Writer< RacobitRadar > > writer)
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length)
ProtocolData< RacobitRadar > * GetMutableProtocolDataById(const uint32_t message_id)
RadarConfig200 * set_radar_conf(RadarConf radar_conf)
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
Some string util functions.
class register implement
Definition arena_queue.h:37
Definition future.h:29
The class of RacobitRadarMessageManager
optional RacobitRadarState_201::RcsThreshold rcs_threshold
optional RacobitRadarState_201::OutputType output_type