43 bool update(
const gtsam::NonlinearFactorGraph& newGraphFactors,
const gtsam::Values& newGraphValues,
44 const std::map<gtsam::Key, double>& newGraphKeysTimeStampMap,
const int depth = 0)
override {
48 }
catch (
const std::out_of_range& outOfRangeExeception) {
50 <<
" OutOfRange-Exception while optimizing graph: " << outOfRangeExeception.what() <<
COLOR_END << std::endl;
53 <<
" This usually happens if the measurement delay is larger than the graph-smootherLag, i.e. the optimized graph instances are "
54 "not connected. Increase the lag in this case."
58 }
catch (
const gtsam::ValuesKeyDoesNotExist& valuesKeyDoesNotExistException) {
60 std::cout <<
"----------------------------------------------------------" << std::endl;
62 <<
" Values Key Does Not Exist exeception while optimizing graph: " << valuesKeyDoesNotExistException.what() <<
COLOR_END
65 <<
" This happens if a factor is added to the graph that contains a non-existent state. The most common case is a factor "
66 "containing a graph state that was marginalized out before. To avoid this, increase the factor graph lag or reduce "
67 "the delay of your measurements."
70 gtsam::NonlinearFactorGraph newGraphFactorsFiltered;
71 gtsam::Key valuesKeyNotExistent = valuesKeyDoesNotExistException.key();
72 for (
auto factor : newGraphFactors) {
73 bool factorContainsExistentKeys =
true;
74 for (
auto key : factor->keys()) {
75 if (key == valuesKeyNotExistent) {
77 <<
" Factor contains non-existent key: " << gtsam::Symbol(key) <<
COLOR_END << std::endl;
78 factorContainsExistentKeys =
false;
82 if (factorContainsExistentKeys) {
83 newGraphFactorsFiltered.add(factor);
87 std::map<gtsam::Key, double> newGraphKeysTimeStampMapFiltered = newGraphKeysTimeStampMap;
88 newGraphKeysTimeStampMapFiltered.erase(valuesKeyNotExistent);
91 <<
" Filtered out the factor that caused the error. Trying to optimize again." <<
COLOR_END << std::endl;
92 std::cout <<
"----------------------------------------------------------" << std::endl;
93 return update(newGraphFactorsFiltered, newGraphValues, newGraphKeysTimeStampMapFiltered);
94 }
catch (
const std::runtime_error& runtimeError) {
95 std::cout <<
YELLOW_START <<
"GMsf-ISAM2" <<
RED_START <<
" Runtime error while optimizing graph: " << runtimeError.what()
97 throw std::runtime_error(runtimeError.what());
149 std::cout <<
"FixedLagSmoother: Marginal Covariance not implemented yet. Returning Identity of correct size for key type: "
150 << gtsam::symbolChr(key) << std::endl;
151 const unsigned char measurementType = gtsam::symbolChr(key);
153 switch (measurementType) {
155 return gtsam::Matrix::Identity(6, 6);
157 return gtsam::Matrix::Identity(3, 3);
159 return gtsam::Matrix::Identity(6, 6);
161 return gtsam::Matrix::Identity(6, 6);
163 return gtsam::Matrix::Identity(3, 3);
165 throw std::runtime_error(
"FixedLagSmoother: Marginal Covariance not implemented for this key type: " + gtsam::symbolChr(key));