19#include "yaml-cpp/yaml.h"
27namespace localization {
35 gnss_antenna_extrinsic_(
TransformD::Identity()),
42 measure_data_queue_size_(150),
43 delay_output_counter_(0) {}
65 gnss_antenna_extrinsic_ = TransformD::Identity();
67 AINFO <<
"gnss and imu lever arm: "
68 << gnss_antenna_extrinsic_.translation()(0) <<
" "
69 << gnss_antenna_extrinsic_.translation()(1) <<
" "
70 << gnss_antenna_extrinsic_.translation()(2);
72 sins_->SetImuAntennaLeverArm(gnss_antenna_extrinsic_.translation()(0),
73 gnss_antenna_extrinsic_.translation()(1),
74 gnss_antenna_extrinsic_.translation()(2));
85 double cur_imu_time = imu_msg.measurement_time;
87 if (cur_imu_time < 3000) {
88 AERROR <<
"the imu time is error: " << cur_imu_time;
92 static double pre_imu_time = cur_imu_time;
93 double delta_time = cur_imu_time - pre_imu_time;
94 if (delta_time > 0.1) {
95 AERROR << std::setprecision(16) <<
"the imu message loss more than 10, "
96 <<
"the pre time and current time: " << pre_imu_time <<
" "
98 }
else if (delta_time < 0.0) {
99 AERROR << std::setprecision(16)
100 <<
"received imu message's time is eary than last imu message, "
101 <<
"the pre time and current time: " << pre_imu_time <<
" "
106 static double pre_system_time = cur_system_time;
108 double delta_system_time = cur_system_time - pre_system_time;
109 if (delta_system_time > 0.1) {
110 AERROR << std::setprecision(16)
111 <<
"the imu message loss more than 10 according to system time, "
112 <<
"the pre system time and current system time: " << pre_system_time
113 <<
" " << cur_system_time;
114 }
else if (delta_system_time < 0.0) {
115 AERROR << std::setprecision(16)
116 <<
"received imu message's time is eary than last imu message "
117 "according to system time, "
118 <<
"the pre system time and current system time: " << pre_system_time
119 <<
" " << cur_system_time;
123 sins_->AddImu(imu_msg);
124 sins_->GetPose(&ins_pva_, pva_covariance_);
125 sins_->GetRemoveBiasImu(&corrected_imu_);
126 sins_->GetEarthParameter(&earth_param_);
128 if (sins_->IsSinsAligned()) {
130 if (delay_output_counter_ < 3000) {
131 ++delay_output_counter_;
137 if (cur_imu_time - 0.5 > pre_imu_time) {
138 AINFO <<
"SINS has completed alignment!" << std::endl;
139 pre_imu_time = cur_imu_time;
142 delay_output_counter_ = 0;
143 if (cur_imu_time - 0.5 > pre_imu_time) {
144 AINFO <<
"SINS is aligning!" << std::endl;
145 pre_imu_time = cur_imu_time;
149 pre_imu_time = cur_imu_time;
150 pre_system_time = cur_system_time;
153void LocalizationIntegProcess::GetValidFromOK() {
160 if (pva_covariance_[0][0] < 0.3 * 0.3 && pva_covariance_[1][1] < 0.3 * 0.3 &&
161 pva_covariance_[2][2] < 0.3 * 0.3 && pva_covariance_[8][8] < 0.1 * 0.1) {
167 CHECK_NOTNULL(state);
169 *state = integ_state_;
174 CHECK_NOTNULL(state);
175 CHECK_NOTNULL(localization);
178 *state = integ_state_;
181 ADEBUG << std::setprecision(16)
182 <<
"IntegratedLocalization Debug Log: integ_pose msg: "
183 <<
"[time:" << ins_pva_.time <<
"]"
184 <<
"[x:" << ins_pva_.pos.longitude * 57.295779513082323 <<
"]"
185 <<
"[y:" << ins_pva_.pos.latitude * 57.295779513082323 <<
"]"
186 <<
"[z:" << ins_pva_.pos.height <<
"]"
187 <<
"[ve:" << ins_pva_.vel.ve <<
"]"
188 <<
"[vn:" << ins_pva_.vel.vn <<
"]"
189 <<
"[vu:" << ins_pva_.vel.vu <<
"]"
190 <<
"[pitch: " << ins_pva_.att.pitch * 57.295779513082323 <<
"]"
191 <<
"[roll:" << ins_pva_.att.roll * 57.295779513082323 <<
"]"
192 <<
"[yaw:" << ins_pva_.att.yaw * 57.295779513082323 <<
"]";
199 localization->set_measurement_time(ins_pva_.time);
207 position_loc->set_x(utm_xy.
x);
208 position_loc->set_y(utm_xy.
y);
209 position_loc->set_z(ins_pva_.pos.height);
211 quaternion->set_qx(ins_pva_.qbn[1]);
212 quaternion->set_qy(ins_pva_.qbn[2]);
213 quaternion->set_qz(ins_pva_.qbn[3]);
214 quaternion->set_qw(ins_pva_.qbn[0]);
217 posepb_loc->mutable_linear_velocity();
218 velocitylinear->set_x(ins_pva_.vel.ve);
219 velocitylinear->set_y(ins_pva_.vel.vn);
220 velocitylinear->set_z(ins_pva_.vel.vu);
223 eulerangles->set_x(ins_pva_.att.pitch);
224 eulerangles->set_y(ins_pva_.att.roll);
225 eulerangles->set_z(ins_pva_.att.yaw);
227 posepb_loc->set_heading(ins_pva_.att.yaw);
230 localization->mutable_uncertainty();
232 uncertainty->mutable_position_std_dev();
233 position_std_dev->set_x(std::sqrt(pva_covariance_[0][0]));
234 position_std_dev->set_y(std::sqrt(pva_covariance_[1][1]));
235 position_std_dev->set_z(std::sqrt(pva_covariance_[2][2]));
238 uncertainty->mutable_linear_velocity_std_dev();
239 linear_velocity_std_dev->set_x(std::sqrt(pva_covariance_[3][3]));
240 linear_velocity_std_dev->set_y(std::sqrt(pva_covariance_[4][4]));
241 linear_velocity_std_dev->set_z(std::sqrt(pva_covariance_[5][5]));
244 uncertainty->mutable_orientation_std_dev();
245 orientation_std_dev->set_x(std::sqrt(pva_covariance_[6][6]));
246 orientation_std_dev->set_y(std::sqrt(pva_covariance_[7][7]));
247 orientation_std_dev->set_z(std::sqrt(pva_covariance_[8][8]));
251 double pva_covariance[9][9]) {
252 CHECK_NOTNULL(state);
253 CHECK_NOTNULL(sins_pva);
254 CHECK_NOTNULL(pva_covariance);
256 *state = integ_state_;
257 *sins_pva = ins_pva_;
258 memcpy(pva_covariance, pva_covariance_,
sizeof(
double) * 9 * 9);
262 CHECK_NOTNULL(imu_data);
264 *imu_data = corrected_imu_;
268 InertialParameter *earth_param) {
269 CHECK_NOTNULL(earth_param);
271 *earth_param = earth_param_;
275 const MeasureData &measure_msg) {
276 measure_data_queue_mutex_.lock();
277 measure_data_queue_.push(measure_msg);
278 measure_data_queue_mutex_.unlock();
281void LocalizationIntegProcess::StartThreadLoop() {
282 keep_running_ =
true;
283 measure_data_queue_size_ = 150;
284 cyber::Async(&LocalizationIntegProcess::MeasureDataThreadLoop,
this);
287void LocalizationIntegProcess::StopThreadLoop() {
288 if (keep_running_.load()) {
289 keep_running_ =
false;
293void LocalizationIntegProcess::MeasureDataThreadLoop() {
294 AINFO <<
"Started measure data process thread";
295 while (keep_running_.load()) {
297 std::unique_lock<std::mutex> lock(measure_data_queue_mutex_);
298 int size =
static_cast<int>(measure_data_queue_.size());
299 while (size > measure_data_queue_size_) {
300 measure_data_queue_.pop();
303 if (measure_data_queue_.empty()) {
313 std::unique_lock<std::mutex> lock(measure_data_queue_mutex_);
314 measure = measure_data_queue_.front();
315 measure_data_queue_.pop();
316 waiting_num =
static_cast<int>(measure_data_queue_.size());
319 if (waiting_num > measure_data_queue_size_ / 4) {
320 AWARN << waiting_num <<
" measure are waiting to process.";
323 MeasureDataProcessImpl(measure);
325 AINFO <<
"Exited measure data process thread";
328void LocalizationIntegProcess::MeasureDataProcessImpl(
329 const MeasureData &measure_msg) {
330 common::util::Timer timer;
333 if (!CheckIntegMeasureData(measure_msg)) {
337 sins_->AddMeasurement(measure_msg);
339 timer.End(
"time of integrated navigation measure update");
342bool LocalizationIntegProcess::CheckIntegMeasureData(
343 const MeasureData &measure_data) {
344 if (measure_data.measure_type == MeasureType::ODOMETER_VEL_ONLY) {
345 AERROR <<
"receive a new odometry measurement!!!\n";
348 ADEBUG << std::setprecision(16)
349 <<
"IntegratedLocalization Debug Log: measure data: "
350 <<
"[time:" << measure_data.time <<
"]"
351 <<
"[x:" << measure_data.gnss_pos.longitude * 57.295779513082323 <<
"]"
352 <<
"[y:" << measure_data.gnss_pos.latitude * 57.295779513082323 <<
"]"
353 <<
"[z:" << measure_data.gnss_pos.height <<
"]"
354 <<
"[ve:" << measure_data.gnss_vel.ve <<
"]"
355 <<
"[vn:" << measure_data.gnss_vel.vn <<
"]"
356 <<
"[vu:" << measure_data.gnss_vel.vu <<
"]"
357 <<
"[pitch:" << measure_data.gnss_att.pitch * 57.295779513082323 <<
"]"
358 <<
"[roll:" << measure_data.gnss_att.roll * 57.295779513082323 <<
"]"
359 <<
"[yaw:" << measure_data.gnss_att.yaw * 57.295779513082323 <<
"]"
360 <<
"[measure type:" << int(measure_data.measure_type) <<
"]";
365bool LocalizationIntegProcess::LoadGnssAntennaExtrinsic(
366 const std::string &file_path, TransformD *extrinsic)
const {
367 CHECK_NOTNULL(extrinsic);
369 YAML::Node confige = YAML::LoadFile(file_path);
370 if (confige[
"leverarm"]) {
371 if (confige[
"leverarm"][
"primary"][
"offset"]) {
372 extrinsic->translation()(0) =
373 confige[
"leverarm"][
"primary"][
"offset"][
"x"].as<double>();
374 extrinsic->translation()(1) =
375 confige[
"leverarm"][
"primary"][
"offset"][
"y"].as<double>();
376 extrinsic->translation()(2) =
377 confige[
"leverarm"][
"primary"][
"offset"][
"z"].as<double>();
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
void GetEarthParameter(InertialParameter *earth_param)
void MeasureDataProcess(const MeasureData &measure_msg)
Eigen::Affine3d TransformD
void RawImuProcess(const ImuData &imu_msg)
apollo::common::Status Init(const LocalizationIntegParam ¶ms)
LocalizationIntegProcess()
void GetState(IntegState *state)
void GetCorrectedImu(ImuData *imu_data)
void GetResult(IntegState *state, LocalizationEstimate *localization)
~LocalizationIntegProcess()
double sins_state_pos_std
bool is_sins_align_with_vel
double vel_threshold_get_yaw
bool is_ins_can_self_align
double sins_state_span_time
bool is_using_raw_gnsspos
ImuToAntOffset imu_to_ant_offset
the UTM coordinate struct including x and y.