Apollo 11.0
自动驾驶开放平台
conti_radar_message_manager.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
23
33
34namespace apollo {
35namespace drivers {
36namespace conti_radar {
37
39using micros = std::chrono::microseconds;
44
46 const std::shared_ptr<Writer<ContiRadar>> &writer)
47 : conti_radar_writer_(writer) {
48 AddRecvProtocolData<RadarState201, true>();
49 AddRecvProtocolData<ClusterListStatus600, true>();
50 AddRecvProtocolData<ClusterGeneralInfo701, true>();
51 AddRecvProtocolData<ClusterQualityInfo702, true>();
52 AddRecvProtocolData<ObjectExtendedInfo60D, true>();
53 AddRecvProtocolData<ObjectGeneralInfo60B, true>();
54 AddRecvProtocolData<ObjectListStatus60A, true>();
55 AddRecvProtocolData<ObjectQualityInfo60C, true>();
56}
57
59 radar_config_.set_radar_conf(radar_conf);
60}
61
63 std::shared_ptr<CanClient> can_client) {
64 can_client_ = can_client;
65}
66
68 const uint32_t message_id) {
69 uint32_t converted_message_id = message_id;
70 if (protocol_data_map_.find(converted_message_id) ==
71 protocol_data_map_.end()) {
72 ADEBUG << "Unable to get protocol data because of invalid message_id:"
73 << message_id;
74 return nullptr;
75 }
76 return protocol_data_map_[converted_message_id];
77}
78
79void ContiRadarMessageManager::Parse(const uint32_t message_id,
80 const uint8_t *data, int32_t length) {
81 ProtocolData<ContiRadar> *sensor_protocol_data =
83 if (sensor_protocol_data == nullptr) {
84 return;
85 }
86
87 std::lock_guard<std::mutex> lock(sensor_data_mutex_);
88 if (!is_configured_ && message_id != RadarState201::ID) {
89 // read radar state message first
90 return;
91 }
92
93 // trigger publishment
94 if (message_id == ClusterListStatus600::ID ||
95 message_id == ObjectListStatus60A::ID) {
96 ADEBUG << sensor_data_.ShortDebugString();
97
98 if (sensor_data_.contiobs_size() <=
100 // maybe lost an object_list_status msg
101 conti_radar_writer_->Write(sensor_data_);
102 }
103 sensor_data_.Clear();
104 // fill header when receive the general info message
105 common::util::FillHeader("conti_radar", &sensor_data_);
106 }
107
108 sensor_protocol_data->Parse(data, length, &sensor_data_);
109
110 if (message_id == RadarState201::ID) {
111 ADEBUG << sensor_data_.ShortDebugString();
113 radar_config_.radar_conf().send_quality() &&
115 radar_config_.radar_conf().send_ext_info() &&
117 radar_config_.radar_conf().max_distance() &&
119 radar_config_.radar_conf().output_type() &&
121 radar_config_.radar_conf().rcs_threshold() &&
123 radar_config_.radar_conf().radar_power()) {
124 is_configured_ = true;
125 } else {
126 AINFO << "configure radar again";
128 &radar_config_);
129 sender_message.Update();
130 can_client_->SendSingleFrame({sender_message.CanFrame()});
131 }
132 }
133
134 received_ids_.insert(message_id);
135 // check if need to check period
136 const auto it = check_ids_.find(message_id);
137 if (it != check_ids_.end()) {
138 const int64_t time = Time::Now().ToMicrosecond();
139 it->second.real_period = time - it->second.last_time;
140 // if period 1.5 large than base period, inc error_count
141 const double period_multiplier = 1.5;
142 if (it->second.real_period >
143 (static_cast<double>(it->second.period) * period_multiplier)) {
144 it->second.error_count += 1;
145 } else {
146 it->second.error_count = 0;
147 }
148 it->second.last_time = time;
149 }
150}
151
152} // namespace conti_radar
153} // namespace drivers
154} // namespace apollo
Cyber has builtin time type Time.
Definition time.h:31
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
static Time Now()
get the current time.
Definition time.cc:57
The class which defines the CAN client to send and receive message.
Definition can_client.h:92
std::unordered_map< uint32_t, ProtocolData< ContiRadar > * > protocol_data_map_
std::unordered_map< uint32_t, CheckIdArg > check_ids_
This is the base class of protocol data.
virtual void Parse(const uint8_t *bytes, int32_t length, SensorType *sensor_data) const
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
void set_can_client(std::shared_ptr< apollo::drivers::canbus::CanClient > can_client)
apollo::drivers::canbus::ProtocolData< ContiRadar > * GetMutableProtocolDataById(const uint32_t message_id)
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length)
parse data and store parsed info in receive protocol data
ContiRadarMessageManager(const std::shared_ptr< apollo::cyber::Writer< ContiRadar > > &writer)
RadarConfig200 * set_radar_conf(RadarConf radar_conf)
The class of ContiRadarMessageManager
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
Some string util functions.
class register implement
Definition arena_queue.h:37
optional RadarState_201 radar_state
optional ObjectListStatus_60A object_list_status
optional RcsThreshold rcs_threshold
optional RadarState_201::RcsThreshold rcs_threshold
optional RadarState_201::OutputType output_type