26namespace localization {
36 AERROR <<
"Init Config failed.";
41 AERROR <<
"Init IO failed.";
48bool MSFLocalizationComponent::InitConfig() {
49 lidar_topic_ = FLAGS_lidar_topic;
50 bestgnsspos_topic_ = FLAGS_gnss_best_pose_topic;
51 gnss_heading_topic_ = FLAGS_heading_topic;
53 if (!publisher_->InitConfig()) {
54 AERROR <<
"Init publisher config failed.";
58 if (!localization_.
Init().
ok()) {
59 AERROR <<
"Init class MSFLocalization failed.";
66bool MSFLocalizationComponent::InitIO() {
67 cyber::ReaderConfig reader_config;
68 reader_config.channel_name = lidar_topic_;
69 reader_config.pending_queue_size = 1;
71 std::function<void(
const std::shared_ptr<drivers::PointCloud>&)>
73 &localization_, std::placeholders::_1);
75 lidar_listener_ = this->
node_->CreateReader<drivers::PointCloud>(
76 reader_config, lidar_register_call);
78 std::function<void(
const std::shared_ptr<drivers::gnss::GnssBestPose>&)>
79 bestgnsspos_register_call =
81 std::placeholders::_1);
82 bestgnsspos_listener_ =
83 this->
node_->CreateReader<drivers::gnss::GnssBestPose>(
84 bestgnsspos_topic_, bestgnsspos_register_call);
86 std::function<void(
const std::shared_ptr<drivers::gnss::Heading>&)>
88 &localization_, std::placeholders::_1);
89 gnss_heading_listener_ = this->
node_->CreateReader<drivers::gnss::Heading>(
90 gnss_heading_topic_, gnss_heading_call);
93 if (!publisher_->InitIO()) {
94 AERROR <<
"Init publisher io failed.";
104 const std::shared_ptr<drivers::gnss::Imu>& imu_msg) {
110 const std::shared_ptr<cyber::Node>& node)
111 : node_(node), localization_gnss_compensator_(
113 tf2_broadcaster_(node) {}
116 localization_topic_ = FLAGS_localization_topic;
117 broadcast_tf_frame_id_ = FLAGS_broadcast_tf_frame_id;
118 broadcast_tf_child_frame_id_ = FLAGS_broadcast_tf_child_frame_id;
119 lidar_local_topic_ = FLAGS_localization_lidar_topic;
120 gnss_local_topic_ = FLAGS_localization_gnss_topic;
121 localization_status_topic_ = FLAGS_localization_msf_status;
127 localization_talker_ =
130 lidar_local_talker_ =
136 localization_status_talker_ =
147 uint64_t measurement_time =
150 auto mutable_head = tf2_msg.mutable_header();
152 localization_gnss_compensator_ = LocalizationGnssCompensator::Instance();
155 current_send_tf_time, &measurement_time);
157 mutable_head->set_timestamp_sec(
159 mutable_head->set_frame_id(broadcast_tf_frame_id_);
160 tf2_msg.set_child_frame_id(broadcast_tf_child_frame_id_);
162 auto mutable_translation = tf2_msg.mutable_transform()->mutable_translation();
163 mutable_translation->set_x(localization.
pose().
position().
x());
164 mutable_translation->set_y(localization.
pose().
position().
y());
165 mutable_translation->set_z(localization.
pose().
position().
z());
167 auto mutable_rotation = tf2_msg.mutable_transform()->mutable_rotation();
179 if (pre_system_time_ > 0.0 && cur_system_time - pre_system_time_ > 0.02) {
180 AERROR << std::setprecision(16)
181 <<
"the localization processing time enlonged more than 2 times "
182 "according to system time, "
183 <<
"the pre system time and current system time: "
184 << pre_system_time_ <<
" " << cur_system_time;
185 }
else if (pre_system_time_ > 0.0 &&
186 cur_system_time - pre_system_time_ < 0.0) {
187 AERROR << std::setprecision(16)
188 <<
"published localization message's time is eary than last imu "
190 "according to system time, "
191 <<
"the pre system time and current system time: "
192 << pre_system_time_ <<
" " << cur_system_time;
194 pre_system_time_ = cur_system_time;
195 localization_talker_->Write(localization);
200 gnss_local_talker_->Write(localization);
205 lidar_local_talker_->Write(localization);
210 localization_status_talker_->Write(localization_status);
bool ok() const
check whether the return status is OK.
a singleton clock that can be used to get the current timestamp.
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
std::shared_ptr< Node > node_
Cyber has builtin time type Time.
uint64_t ToNanosecond() const
convert time to nanosecond.
void ProcessCompensation(const uint64_t ¤t_send_tf_time, uint64_t *measurement_time)
compensate the time parsed from invalid GNSS data
void PublishLocalizationMsfGnss(const LocalizationEstimate &localization)
void PublishPoseBroadcastTopic(const LocalizationEstimate &localization)
void PublishLocalizationMsfLidar(const LocalizationEstimate &localization)
void PublishLocalizationStatus(const LocalizationStatus &localization_status)
LocalizationMsgPublisher(const std::shared_ptr< cyber::Node > &node)
void PublishPoseBroadcastTF(const LocalizationEstimate &localization)
MSFLocalizationComponent()
bool Proc(const std::shared_ptr< drivers::gnss::Imu > &imu_msg) override
void SetPublisher(const std::shared_ptr< LocalizationMsgPublisher > &publisher)
void OnPointCloud(const std::shared_ptr< drivers::PointCloud > &message)
void OnGnssBestPose(const std::shared_ptr< drivers::gnss::GnssBestPose > &bestgnsspos_msg)
apollo::common::Status Init()
void OnRawImuCache(const std::shared_ptr< drivers::gnss::Imu > &imu_msg)
void OnGnssHeading(const std::shared_ptr< drivers::gnss::Heading > &gnss_heading_msg)
The gflags used by localization module
Contains a number of helper functions related to quaternions.
optional apollo::localization::Pose pose
optional double measurement_time
optional apollo::common::Header header
optional apollo::common::Quaternion orientation
optional apollo::common::PointENU position