Apollo 10.0
自动驾驶开放平台
racobit_radar_canbus_component.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
22
23#include "cyber/common/file.h"
25#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
27
32namespace apollo {
33namespace drivers {
34namespace racobit_radar {
35
37 : monitor_logger_buffer_(
38 common::monitor::MonitorMessageItem::RACOBIT_RADAR) {}
39
41 if (!GetProtoConfig(&racobit_radar_conf_)) {
42 return OnError("Unable to load canbus conf file: " + ConfigFilePath()).ok();
43 }
44
45 AINFO << "The canbus conf file is loaded: " << ConfigFilePath();
46 ADEBUG << "Canbus_conf:" << racobit_radar_conf_.ShortDebugString();
47 racobit_radar_writer_ =
48 node_->CreateWriter<RacobitRadar>(FLAGS_racobit_radar_topic);
50 &racobit_radar_conf_)) {
51 return OnError("Unable to load canbus conf file: " + ConfigFilePath()).ok();
52 }
53
54 AINFO << "The canbus conf file is loaded: " << ConfigFilePath();
55 ADEBUG << "Canbus_conf:" << racobit_radar_conf_.ShortDebugString();
56
57 auto can_factory = CanClientFactory::Instance();
58 can_factory->RegisterCanClients();
59 can_client_ = can_factory->CreateCANClient(
60 racobit_radar_conf_.can_conf().can_card_parameter());
61 if (!can_client_) {
62 return OnError("Failed to create can client.").ok();
63 }
64 AINFO << "Can client is successfully created.";
65
66 sensor_message_manager_ = std::unique_ptr<RacobitRadarMessageManager>(
67 new RacobitRadarMessageManager(racobit_radar_writer_));
68 if (sensor_message_manager_ == nullptr) {
69 return OnError("Failed to create message manager.").ok();
70 }
71 sensor_message_manager_->set_radar_conf(racobit_radar_conf_.radar_conf());
72 sensor_message_manager_->set_can_client(can_client_);
73 AINFO << "Sensor message manager is successfully created.";
74
75 if (can_receiver_.Init(
76 can_client_.get(), sensor_message_manager_.get(),
77 racobit_radar_conf_.can_conf().enable_receiver_log()) !=
78 ErrorCode::OK) {
79 return OnError("Failed to init can receiver.").ok();
80 }
81 AINFO << "The can receiver is successfully initialized.";
82
83 if (can_client_->Start() != ErrorCode::OK) {
84 return OnError("Failed to start can client").ok();
85 }
86
87 AINFO << "Can client is started.";
88 if (ConfigureRadar() != ErrorCode::OK) {
89 return OnError("Failed to configure radar.").ok();
90 }
91 AINFO << "The radar is successfully configured.";
92
93 if (can_receiver_.Start() != ErrorCode::OK) {
94 return OnError("Failed to start can receiver.").ok();
95 }
96 AINFO << "Can receiver is started.";
97 monitor_logger_buffer_.INFO("Canbus is started.");
98
99 return true;
100}
101
102apollo::common::ErrorCode RacobitRadarCanbusComponent::ConfigureRadar() {
103 RadarConfig200 radar_config;
104 radar_config.set_radar_conf(racobit_radar_conf_.radar_conf());
105 SenderMessage<RacobitRadar> sender_message(RadarConfig200::ID, &radar_config);
106 sender_message.Update();
107 return can_client_->SendSingleFrame({sender_message.CanFrame()});
108}
109
111 if (start_success_) {
112 can_receiver_.Stop();
113 can_client_->Stop();
114 }
115}
116
117Status RacobitRadarCanbusComponent::OnError(const std::string &error_msg) {
118 monitor_logger_buffer_.ERROR(error_msg);
119 return Status(ErrorCode::CANBUS_ERROR, error_msg);
120}
121
122} // namespace racobit_radar
123} // namespace drivers
124} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
bool ok() const
check whether the return status is OK.
Definition status.h:67
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
This class defines the message to send.
Definition can_sender.h:56
RadarConfig200 * set_radar_conf(RadarConf radar_conf)
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37
The class of RacobitRadarMessageManager
optional apollo::drivers::canbus::CANCardParameter can_card_parameter