@@ -38,6 +38,7 @@ FactorManager::FactorManager(const Parameters& params)
3838 last_optimize_time_ = 0.0 ;
3939 last_imu_time_ = 0.0 ;
4040 imu_params_ = defaultImuParams (params.gravity );
41+ gravity_vec_ = Eigen::Vector3d (0.0 , 0.0 , params.gravity );
4142
4243 prior_noise_ = gtsam::noiseModel::Isotropic::Sigma (6 , params.gps_noise ); // maybe this can be odom noise??
4344 gps_noise_ = gtsam::noiseModel::Isotropic::Sigma (3 , params.gps_noise );
@@ -148,8 +149,9 @@ void FactorManager::addGpsFactor(int64_t timestamp, const Eigen::Vector3d& gps)
148149 }
149150
150151 if (key_index_ > 0 )
151- {
152- std::lock_guard<std::mutex> lock (std::mutex);
152+ {
153+ static std::mutex imu_mutex;
154+ std::unique_lock<std::mutex> lock (imu_mutex);
153155
154156 graph_.add (gtsam::CombinedImuFactor (X (key_index_),
155157 V (key_index_),
@@ -167,6 +169,8 @@ void FactorManager::addGpsFactor(int64_t timestamp, const Eigen::Vector3d& gps)
167169 smoother_timestamps_[X (key_index_)] = timestamp_f;
168170 smoother_timestamps_[V (key_index_)] = timestamp_f;
169171 smoother_timestamps_[B (key_index_)] = timestamp_f;
172+
173+ lock.unlock ();
170174 }
171175
172176 gtsam::Rot3 imu_rot = gtsam::Rot3 (orient_ (0 ), orient_ (1 ), orient_ (2 ), orient_ (3 ));
@@ -246,7 +250,8 @@ void FactorManager::addImuFactor(int64_t timestamp, const Eigen::Vector3d& accel
246250 double timestamp_f = nanosecInt2Float (timestamp);
247251 gtsam::Quaternion q (orient (0 ), orient (1 ), orient (2 ), orient (3 ));
248252
249- std::lock_guard<std::mutex> lock (std::mutex);
253+ static std::mutex imu_mutex;
254+ std::lock_guard<std::mutex> lock (imu_mutex);
250255 // imu_buffer_.add(timestamp_f, accel, gyro, orient);
251256
252257 // Eigen::Vector3d accel_meas = accel;
0 commit comments