8#ifndef GRAPH_MANAGER_HPP
9#define GRAPH_MANAGER_HPP
17#include <gtsam/nonlinear/ExpressionFactorGraph.h>
18#include <gtsam/slam/expressions.h>
53 GraphManager(std::shared_ptr<GraphConfig> graphConfigPtr, std::string imuFrame, std::string worldFrame);
58 <<
" Additional slow batch smoother was built up. Next time the optimization of it can be called before shutting down (if "
68 const gtsam::Vector3& imuAngularVelocity);
72 std::shared_ptr<SafeNavStateWithCovarianceAndBias>& newOptimizedNavStatePtr,
73 const std::shared_ptr<ImuBuffer>& imuBufferPtr,
double imuTimeK,
bool createNewStateFlag);
83 typedef gtsam::Key (*
F)(std::uint64_t);
84 template <
class MEASUREMENT_TYPE,
int NOISE_DIM,
class FACTOR_TYPE,
F SYMBOL_SHORTHAND,
class... FACTOR_ARGS>
86 void addUnaryClassicFactor(
const MEASUREMENT_TYPE& unaryMeasurement,
const Eigen::Matrix<double, NOISE_DIM, 1>& unaryNoiseDensity,
87 double measurementTime,
const FACTOR_ARGS&... factorArgs);
90 template <
class GMSF_EXPRESSION_TYPE>
92 const bool addToOnlineSmootherFlag =
true);
95 gtsam::Key
addPoseBetweenFactor(
const gtsam::Pose3& deltaPose,
const Eigen::Matrix<double, 6, 1>& poseBetweenNoiseDensity,
96 double lidarTimeKm1,
double lidarTimeK,
double rate,
const RobustNormEnum& robustNormEnum,
97 const double robustNormConstant);
108 std::optional<BatchOptimizationResult>
optimizeSlowBatchSmoother(
int maxIterations,
const bool computePoseCovarianceFlag);
120 void saveOptimizedValuesToFile(
const gtsam::Values& optimizedValues,
const std::map<gtsam::Key, double>& keyTimestampMap,
121 const std::string& savePath,
const bool saveCovarianceFlag);
125 const std::string& saveFileName);
142 const gtsam::Key& generalKey,
const char* callingFunctionName);
146 std::shared_ptr<holistic_fusion::OptimizerBase> graphPtr,
const gtsam::Key& graphKey,
const char* callingFunctionName,
147 std::optional<const gtsam::NavState> optionalNavState = std::nullopt);
154 template <
class CHILDPTR>
156 template <
class CHILDPTR>
158 const std::string& measurementName,
const bool addToOnlineSmootherFlag =
true);
159 template <
class CHILDPTR>
167 const std::map<gtsam::Key, double>& newRtGraphKeysTimestampsMap,
168 const std::shared_ptr<GraphConfig>& graphConfigPtr,
const int additionalIterations);
171 const gtsam::Values& newBatchGraphValues,
172 const std::map<gtsam::Key, double>& newBatchGraphKeysTimestampsMap,
173 const std::shared_ptr<GraphConfig>& graphConfigPtr);
175 bool findGraphKeys_(gtsam::Key& closestKeyKm1, gtsam::Key& closestKeyK,
double& keyTimeStampDistance,
double maxTimestampDistance,
176 double timeKm1,
double timeK,
const std::string& name);
181 std::shared_ptr<std::map<gtsam::Key, double>> keyTimestampMapPtr);
184 std::shared_ptr<std::map<gtsam::Key, double>> keyTimestampMapPtr);
198 std::shared_ptr<gtsam::PreintegratedCombinedMeasurements::Params>
imuParamsPtr_;
204 Eigen::Isometry3d
T_W_O_ = Eigen::Isometry3d::Identity();
262#include "holistic_fusion/core/GraphManager.inl"
const uint64_t newPropagatedStateKey_()
Generate new key.
std::shared_ptr< TimeGraphKeyBuffer > timeToKeyBufferPtr_
gtsam::NavState O_imuPropagatedState_
std::shared_ptr< gtsam::PreintegratedCombinedMeasurements > imuStepPreintegratorPtr_
Step Preintegrator.
void saveOptimizedValuesToFile(const gtsam::Values &optimizedValues, const std::map< gtsam::Key, double > &keyTimestampMap, const std::string &savePath, const bool saveCovarianceFlag)
Eigen::Vector3d & getInitAccBiasReference()
Getters.
std::set< std::pair< std::string, std::string > > realTimeReferenceFrameNamePairs_
std::map< double, gtsam::Pose3 > realTimeOdomPoseContainer_
const GraphState & getOptimizedGraphState()
double lastOptimizedStateTime_
bool logLatencyAndUpdateDuration(const std::string &savePath, const std::string &timeString)
void addImuFactorAndGetState(SafeIntegratedNavState &returnPreIntegratedNavState, std::shared_ptr< SafeNavStateWithCovarianceAndBias > &newOptimizedNavStatePtr, const std::shared_ptr< ImuBuffer > &imuBufferPtr, double imuTimeK, bool createNewStateFlag)
bool setInitialWorldFrameToFixedFrameTransform(const Eigen::Isometry3d &T_W_F, const std::string &fixedFrame)
bool addFactorsToBatchSmootherAndOptimize(const gtsam::NonlinearFactorGraph &newBatchGraphFactors, const gtsam::Values &newBatchGraphValues, const std::map< gtsam::Key, double > &newBatchGraphKeysTimestampsMap, const std::shared_ptr< GraphConfig > &graphConfigPtr)
gtsam::Key(* F)(std::uint64_t)
bool runSlowBatchSmootherOptimization_(int maxIterations)
bool getUnaryFactorGeneralKey(gtsam::Key &returnedKey, double &returnedGraphTime, const UnaryMeasurement &unaryMeasurement)
bool hasReferenceFrameKeyframe(const std::string &worldFrame, const std::string &fixedFrame)
std::map< double, double > updateDurationContainer_
gtsam::NavState calculateStateAtGeneralKey(bool &computeSuccessfulFlag, const gtsam::Key &generalKey)
bool logRealTimeNavStates(const std::string &savePath, const std::string &timeString)
void addUnaryHolisticFactor(const std::shared_ptr< GMSF_EXPRESSION_TYPE > gmsfUnaryExpressionPtr, const bool addToOnlineSmootherFlag=true)
std::shared_ptr< holistic_fusion::GraphConfig > graphConfigPtr_
Config.
std::map< double, double > latencyContainer_
std::shared_ptr< gtsam::NonlinearFactorGraph > batchFactorGraphBufferPtr_
bool initImuIntegrators(double gravityValue)
gtsam::Vector3 latestGraphStateKeyAngularVelocity_
static gtsam::NavState calculateNavStateAtGeneralKey(bool &computeSuccessfulFlag, std::shared_ptr< holistic_fusion::OptimizerBase > graphPtr, const gtsam::Key &generalKey, const char *callingFunctionName)
std::shared_ptr< OptimizerBase > batchOptimizerPtr_
void writeValueKeysToKeyTimeStampMap_(const gtsam::Values &values, double measurementTime, std::shared_ptr< std::map< gtsam::Key, double > > keyTimestampMapPtr)
std::map< double, TransformsDictionary< Eigen::Isometry3d > > realTimeReferenceFrameContainer_
bool logRealTimeReferenceFrameStates(const std::string &savePath, const std::string &timeString)
void updateImuIntegrators_(const TimeToImuMap &imuMeas)
Update IMU integrators.
void addUnaryClassicFactor(const MEASUREMENT_TYPE &unaryMeasurement, const Eigen::Matrix< double, NOISE_DIM, 1 > &unaryNoiseDensity, double measurementTime, const FACTOR_ARGS &... factorArgs)
std::mutex optimizationRunningMutex_
BatchOptimizationResult extractBatchOptimizationResult_(const bool computePoseCovarianceFlag)
std::mutex operateOnGraphDataMutex_
Mutex.
std::chrono::time_point< std::chrono::high_resolution_clock > latencyEndTime_
GraphManager(std::shared_ptr< GraphConfig > graphConfigPtr, std::string imuFrame, std::string worldFrame)
std::chrono::time_point< std::chrono::high_resolution_clock > updateDurationEndTime_
Eigen::Vector3d & getInitGyrBiasReference()
bool initPoseVelocityBiasGraph(double timeStamp, const gtsam::Pose3 &T_W_I0, const gtsam::Pose3 &T_O_I0, const gtsam::Vector3 &imuAngularVelocity)
DynamicDictionaryContainer gtsamDynamicExpressionKeys_
std::shared_ptr< OptimizerBase > rtOptimizerPtr_
bool addFactorToRtAndBatchGraph_(const gtsam::NoiseModelFactor *noiseModelFactorPtr, const bool addToOnlineSmootherFlag=true)
std::chrono::time_point< std::chrono::high_resolution_clock > latencyStartTime_
bool findGraphKeys_(gtsam::Key &closestKeyKm1, gtsam::Key &closestKeyK, double &keyTimeStampDistance, double maxTimestampDistance, double timeKm1, double timeK, const std::string &name)
Find graph keys for timestamps.
std::map< double, gtsam::Pose3 > realTimeWorldPoseContainer_
holistic_fusion::GraphState optimizedGraphState_
gtsam::Key propagatedStateKey_
std::shared_ptr< gtsam::NonlinearFactorGraph > rtFactorGraphBufferPtr_
Data buffer.
std::shared_ptr< std::map< gtsam::Key, double > > rtGraphKeysTimestampsMapBufferPtr_
std::shared_ptr< gtsam::Values > batchGraphValuesBufferPtr_
bool addFactorsToRtSmootherAndOptimize(const gtsam::NonlinearFactorGraph &newRtGraphFactors, const gtsam::Values &newRtGraphValues, const std::map< gtsam::Key, double > &newRtGraphKeysTimestampsMap, const std::shared_ptr< GraphConfig > &graphConfigPtr, const int additionalIterations)
gtsam::NavState W_imuPropagatedState_
Propagated state (at IMU frequency).
bool addFactorToRtAndBatchGraph_(const gtsam::NoiseModelFactor *noiseModelFactorPtr, double measurementTimestamp, const std::string &measurementName, const bool addToOnlineSmootherFlag=true)
static Eigen::Matrix< double, 6, 6 > calculatePoseCovarianceAtKeyInWorldFrame(std::shared_ptr< holistic_fusion::OptimizerBase > graphPtr, const gtsam::Key &graphKey, const char *callingFunctionName, std::optional< const gtsam::NavState > optionalNavState=std::nullopt)
gtsam::Key addPoseBetweenFactor(const gtsam::Pose3 &deltaPose, const Eigen::Matrix< double, 6, 1 > &poseBetweenNoiseDensity, double lidarTimeKm1, double lidarTimeK, double rate, const RobustNormEnum &robustNormEnum, const double robustNormConstant)
std::shared_ptr< gtsam::imuBias::ConstantBias > imuBiasPriorPtr_
std::shared_ptr< std::map< gtsam::Key, double > > batchGraphKeysTimestampsMapBufferPtr_
gtsam::Vector6 lastImuVector_
IMU Buffer.
const gtsam::Key getPropagatedStateKey()
static void saveOptimizedGraphToG2o(const OptimizerBase &optimizedGraph, const gtsam::Values &optimizedValues, const std::string &saveFileName)
bool addFactorSafelyToRtAndBatchGraph_(const gtsam::NoiseModelFactor *noiseModelFactorPtr, double measurementTimestamp)
std::chrono::time_point< std::chrono::high_resolution_clock > updateDurationStartTime_
std::shared_ptr< gtsam::Values > rtGraphValuesBufferPtr_
double propagatedImuSampleTime_
std::shared_ptr< gtsam::PreintegratedCombinedMeasurements > imuBufferPreintegratorPtr_
Buffer Preintegrator.
void writeKeyToKeyTimeStampMap_(const gtsam::Key &key, double measurementTime, std::shared_ptr< std::map< gtsam::Key, double > > keyTimestampMapPtr)
Associate timestamp to each 'value key', e.g. for graph key 0, value keys (x0,v0,b0) need to be assoc...
std::shared_ptr< gtsam::PreintegratedCombinedMeasurements::Params > imuParamsPtr_
double latestGraphStateKeyTime_
bool optimizeSlowBatchSmoother(int maxIterations, const std::string &savePath, const bool saveCovarianceFlag)
Class to represent a unary measurement in the graph.
std::map< double, holistic_fusion::ImuMeasurement, std::less< double >, Eigen::aligned_allocator< std::pair< const double, holistic_fusion::ImuMeasurement > > > TimeToImuMap