@@ -34,7 +34,8 @@ FactorManager::FactorManager(const Parameters& params)
3434 // set noise model
3535 gps_noise_ = gtsam::noiseModel::Isotropic::Sigma (3 , params.gps_noise );
3636 orient_noise_ = gtsam::noiseModel::Diagonal::Sigmas (gtsam::Vector3 (params.roll_pitch_cov , params.roll_pitch_cov , params.heading_cov ));
37-
37+ dgpsfm_noise_ = gtsam::noiseModel::Diagonal::Sigmas (gtsam::Vector3 (M_PI/2 , M_PI/2 , params.dgpsfm_cov ));
38+
3839 // set key index
3940 key_index_ = 0 ;
4041
@@ -153,14 +154,78 @@ void FactorManager::addGpsFactor(int64_t timestamp, const Eigen::Vector3d& gps)
153154 gtsam::Point3 meas (gps (0 ), gps (1 ), gps (2 ));
154155 gtsam::Rot3 rot = gtsam::Rot3::Quaternion (orient_ (0 ), orient_ (1 ), orient_ (2 ), orient_ (3 ));
155156
156- // add measurements to factor graph
157+ // add gps measurement to factor graph as gtsam object
157158 graph_.add (gtsam::GPSFactor (X (key_index_), gps, gps_noise_));
158159 graph_.addExpressionFactor (gtsam::rotation (X (key_index_)), rot, orient_noise_);
160+
161+ // increment key index
162+ key_index_++;
163+ }
164+
165+ void FactorManager::addGpsFactor (int64_t timestamp, const Eigen::Vector3d& gps, const double & heading, const bool fuse)
166+ {
167+ // wait until the imu is initialized
168+ if (!imu_initialized_) return ;
169+
170+ double time = nanosecIntToDouble (timestamp);
171+
172+ if (key_index_ == 0 )
173+ {
174+ // set the initial NavState
175+ // The initial orientation is the the initial orientation from the imu initialization
176+ // The initial position is from the gps
177+ // Initial velocity is set to zero
178+ gtsam::Pose3 initial_pose = gtsam::Pose3 (initial_orientation_, gtsam::Point3 (gps (0 ), gps (1 ), gps (2 )));
179+ gtsam::NavState initial_navstate (initial_pose, gtsam::Point3 (0.0 , 0.0 , 0.0 )); // TODO why do I need this??
180+
181+ // save the initial values
182+ initials_.insert (X (key_index_), initial_pose);
183+ initials_.insert (V (key_index_), gtsam::Point3 (0.0 , 0.0 , 0.0 ));
184+ initials_.insert (B (key_index_), bias_);
185+
186+ // save the timestamps for the smoother
187+ smoother_timestamps_[X (key_index_)] = time;
188+ smoother_timestamps_[V (key_index_)] = time;
189+ smoother_timestamps_[B (key_index_)] = time;
190+
191+ // add prior factors to the graph
192+ graph_.add (gtsam::PriorFactor<gtsam::Pose3>(X (key_index_), initial_pose, gtsam::noiseModel::Isotropic::Sigma (6 , 0.001 )));
193+ graph_.add (gtsam::PriorFactor<gtsam::Point3>(V (key_index_), gtsam::Point3 (0.0 , 0.0 , 0.0 ), gtsam::noiseModel::Isotropic::Sigma (3 , 0.001 )));
194+ graph_.add (gtsam::PriorFactor<gtsam::imuBias::ConstantBias>(B (key_index_), bias_, gtsam::noiseModel::Isotropic::Sigma (6 , 0.001 )));
195+
196+ key_index_++;
197+ gps_initialized_ = true ;
198+ LOG (INFO) << " [GLIDER] GPS Initialized" ;
199+ return ;
200+ }
201+
202+ // add the pim to the graph under a mutex
203+ std::unique_lock<std::mutex> lock (mutex_);
204+ graph_.add (gtsam::CombinedImuFactor (X (key_index_-1 ), V (key_index_-1 ), X (key_index_), V (key_index_), B (key_index_-1 ), B (key_index_), *pim_));
205+ lock.unlock ();
206+
207+ // insert new initial values
208+ initials_.insert (X (key_index_), current_state_.getPose <gtsam::Pose3>());
209+ initials_.insert (V (key_index_), current_state_.getVelocity <gtsam::Vector3>());
210+ initials_.insert (B (key_index_), bias_);
211+
212+ // save the time for the smoother
213+ smoother_timestamps_[X (key_index_)] = time;
214+ smoother_timestamps_[V (key_index_)] = time;
215+ smoother_timestamps_[B (key_index_)] = time;
216+
217+ // add gps measurement to factor graph as gtsam object
218+ gtsam::Point3 meas (gps (0 ), gps (1 ), gps (2 ));
219+ gtsam::Rot3 rot = gtsam::Rot3::Ypr (heading, 0.0 , 0.0 );
220+
221+ graph_.add (gtsam::GPSFactor (X (key_index_), gps, gps_noise_));
222+ if (fuse) graph_.addExpressionFactor (gtsam::rotation (X (key_index_)), rot, dgpsfm_noise_);
159223
160224 // increment key index
161225 key_index_++;
162226}
163227
228+
164229void FactorManager::addImuFactor (int64_t timestamp, const Eigen::Vector3d& accel, const Eigen::Vector3d& gyro, const Eigen::Vector4d& orient)
165230{
166231 // if the imu is not initialized, pass the meaurements to initialize it
0 commit comments