21#include "Eigen/Geometry"
26#include "modules/drivers/canbus/proto/sensor_canbus_conf.pb.h"
27#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
37namespace conti_radar {
46 : monitor_logger_buffer_(
52 return OnError(
"Unable to load canbus conf file: " +
ConfigFilePath());
56 ADEBUG <<
"Canbus_conf:" << conti_radar_conf_.ShortDebugString();
59 auto can_factory = CanClientFactory::Instance();
60 can_factory->RegisterCanClients();
61 can_client_ = can_factory->CreateCANClient(
64 return OnError(
"Failed to create can client.");
66 AINFO <<
"Can client is successfully created.";
70 FLAGS_localization_topic,
71 [&](
const std::shared_ptr<LocalizationEstimate>& pose) {
75 sensor_message_manager_ = std::unique_ptr<ContiRadarMessageManager>(
77 if (sensor_message_manager_ ==
nullptr) {
78 return OnError(
"Failed to create message manager.");
80 sensor_message_manager_->set_radar_conf(conti_radar_conf_.
radar_conf());
81 sensor_message_manager_->set_can_client(can_client_);
82 AINFO <<
"Sensor message manager is successfully created.";
84 if (can_receiver_.Init(can_client_.get(), sensor_message_manager_.get(),
87 return OnError(
"Failed to init can receiver.");
89 AINFO <<
"The can receiver is successfully initialized.";
91 start_success_ = Start();
92 return start_success_;
99 sender_message.Update();
100 return can_client_->SendSingleFrame({sender_message.CanFrame()});
103bool ContiRadarCanbusComponent::Start() {
105 if (can_client_->Start() != ErrorCode::OK) {
106 return OnError(
"Failed to start can client");
108 AINFO <<
"Can client is started.";
109 if (ConfigureRadar() != ErrorCode::OK) {
110 return OnError(
"Failed to configure radar.");
112 AINFO <<
"The radar is successfully configured.";
114 if (can_receiver_.Start() != ErrorCode::OK) {
115 return OnError(
"Failed to start can receiver.");
117 AINFO <<
"Can receiver is started.";
120 monitor_logger_buffer_.INFO(
"Canbus is started.");
125void ContiRadarCanbusComponent::Stop() {
126 if (start_success_) {
127 can_receiver_.Stop();
133bool ContiRadarCanbusComponent::OnError(
const std::string& error_msg) {
134 monitor_logger_buffer_.ERROR(error_msg);
139void ContiRadarCanbusComponent::PoseCallback(
140 const std::shared_ptr<LocalizationEstimate>& pose_msg) {
142 uint64_t now_nsec = cyber::Time().Now().ToNanosecond();
143 if (last_nsec_ != 0 && (now_nsec - last_nsec_) < send_interval) {
146 last_nsec_ = now_nsec;
147 Eigen::Quaterniond orientation_vehicle_world(
148 pose_msg->pose().orientation().qw(), pose_msg->pose().orientation().qx(),
149 pose_msg->pose().orientation().qy(), pose_msg->pose().orientation().qz());
150 Eigen::Matrix3d rotation_matrix =
151 orientation_vehicle_world.toRotationMatrix().inverse();
152 Eigen::Vector3d speed_v(pose_msg->pose().linear_velocity().x(),
153 pose_msg->pose().linear_velocity().y(),
154 pose_msg->pose().linear_velocity().z());
155 float speed =
static_cast<float>((rotation_matrix * speed_v).y());
156 float yaw_rate =
static_cast<float>(pose_msg->pose().angular_velocity().z() *
159 AINFO <<
"radar speed:" << speed <<
";yaw rate:" << yaw_rate;
160 MotionInputSpeed300 input_speed;
161 input_speed.SetSpeed(speed);
164 sender_message_speed.Update();
165 can_client_->SendSingleFrame({sender_message_speed.CanFrame()});
167 MotionInputYawRate301 input_yawrate;
168 input_yawrate.SetYawRate(yaw_rate);
171 sender_message_yawrate.Update();
172 can_client_->SendSingleFrame({sender_message_yawrate.CanFrame()});
Defines the CanClientFactory class.
Defines SenderMessage class and CanSender class.
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
CanClientFactory inherites apollo::common::util::Factory.
This class defines the message to send.
~ContiRadarCanbusComponent()
ContiRadarCanbusComponent()
RadarConfig200 * set_radar_conf(RadarConf radar_conf)
The class of ContiRadarMessageManager
optional apollo::drivers::canbus::CANCardParameter can_card_parameter
optional bool enable_receiver_log
optional string radar_channel
optional RadarConf radar_conf
optional CanConf can_conf
optional uint64 input_send_interval