@@ -533,7 +533,7 @@ void GraphManager::updateGraph() {
533
533
gtsam::Matrix33 resultVelocityCovariance =
534
534
rtOptimizerPtr_->calculateMarginalCovarianceMatrixAtKey (gtsam::symbol_shorthand::V (currentPropagatedKey));
535
535
536
- // D. FixedFrame Transformations ------------------------------
536
+ // D. Reference Frame Transformations ------------------------------
537
537
// Containers
538
538
TransformsDictionary<Eigen::Isometry3d> resultReferenceFrameTransformations (Eigen::Isometry3d::Identity ());
539
539
TransformsDictionary<Eigen::Matrix<double , 6 , 6 >> resultReferenceFrameTransformationsCovariance (gtsam::Z_6x6);
@@ -547,6 +547,9 @@ void GraphManager::updateGraph() {
547
547
548
548
// Iterate through all dynamically allocated variables (holistic, calibration, landmarks) --------------------------------
549
549
for (auto & framePairKeyMapIterator : gtsamDynamicExpressionKeys_.get <gtsam::Pose3>().getTransformsMap ()) {
550
+ // Frame Pair
551
+ const std::pair<std::string, std::string>& framePair = framePairKeyMapIterator.first ; // alias
552
+
550
553
// Get Variable Key
551
554
const gtsam::Key& gtsamKey = framePairKeyMapIterator.second .key (); // alias
552
555
@@ -606,17 +609,30 @@ void GraphManager::updateGraph() {
606
609
T_frame2_frame1_corrected.translation () + framePairKeyMapIterator.second .getReferenceFrameKeyframePosition ());
607
610
gtsam::Pose3 T_frame1_frame2_corrected = T_frame2_frame1_corrected.inverse ();
608
611
// Write to container
612
+ // 1: For Landmark States
609
613
if (isLandmarkState) {
614
+ // Write to landmark container
610
615
resultLandmarkTransformations.set_T_frame1_frame2 (framePairKeyMapIterator.first .first , framePairKeyMapIterator.first .second ,
611
616
Eigen::Isometry3d (T_frame1_frame2_corrected.matrix ()));
612
617
resultLandmarkTransformationsCovariance.set_T_frame1_frame2 (framePairKeyMapIterator.first .first ,
613
618
framePairKeyMapIterator.first .second , T_frame1_frame2_covariance);
614
- } else {
619
+ }
620
+ // 2: For Reference Frame States
621
+ else {
622
+ // Write to reference frame container
615
623
resultReferenceFrameTransformations.set_T_frame1_frame2 (framePairKeyMapIterator.first .first ,
616
624
framePairKeyMapIterator.first .second ,
617
625
Eigen::Isometry3d (T_frame1_frame2_corrected.matrix ()));
618
626
resultReferenceFrameTransformationsCovariance.set_T_frame1_frame2 (
619
627
framePairKeyMapIterator.first .first , framePairKeyMapIterator.first .second , T_frame1_frame2_covariance);
628
+ // Potentially fill in existing pairs for logging
629
+ if (graphConfigPtr_->logRealTimeStateToMemoryFlag_ ) {
630
+ if (realTimeReferenceFrameNamePairs_.find (framePair) == realTimeReferenceFrameNamePairs_.end ()) {
631
+ realTimeReferenceFrameNamePairs_.insert (framePair);
632
+ REGULAR_COUT << " Added frame pair: " << framePair.first << " to " << framePair.second << " to real-time logging."
633
+ << std::endl;
634
+ }
635
+ }
620
636
}
621
637
622
638
// Mark that this key has at least been optimized once
@@ -697,8 +713,8 @@ void GraphManager::updateGraph() {
697
713
}
698
714
}
699
715
} // catch statement
700
- } // end: if active statement
701
- } // for loop over all transforms
716
+ } // end: if active statement
717
+ } // for loop over all transforms
702
718
}
703
719
704
720
// Mutex block 2 ------------------
@@ -740,6 +756,11 @@ void GraphManager::updateGraph() {
740
756
// Update the time of the last optimized state
741
757
lastOptimizedStateTime_ = currentPropagatedTime;
742
758
} // end of locking
759
+
760
+ // Potentially log real-time state to container
761
+ if (graphConfigPtr_->logRealTimeStateToMemoryFlag_ ) {
762
+ realTimeReferenceFrameContainer_.emplace (currentPropagatedTime, resultReferenceFrameTransformations);
763
+ }
743
764
}
744
765
745
766
bool GraphManager::optimizeSlowBatchSmoother (int maxIterations, const std::string& savePath, const bool saveCovarianceFlag) {
@@ -768,16 +789,16 @@ bool GraphManager::optimizeSlowBatchSmoother(int maxIterations, const std::strin
768
789
}
769
790
}
770
791
771
- // Logging of the real-time states
772
- bool GraphManager::logRealTimeStates (const std::string& savePath, const std::string& timeString) {
792
+ // Logging of the real-time navigation states
793
+ bool GraphManager::logRealTimeNavStates (const std::string& savePath, const std::string& timeString) {
773
794
// Note enabled
774
795
if (!graphConfigPtr_->logRealTimeStateToMemoryFlag_ ) {
775
796
REGULAR_COUT << RED_START << " Logging of real-time states is disabled. " << COLOR_END << std::endl;
776
797
return false ;
777
798
}
778
799
// Enabled
779
800
else {
780
- // Main container: map, although only one element
801
+ // Main container: map
781
802
std::map<std::string, std::ofstream> fileStreams;
782
803
783
804
// Create directory if it does not exist
@@ -814,6 +835,62 @@ bool GraphManager::logRealTimeStates(const std::string& savePath, const std::str
814
835
}
815
836
}
816
837
838
+ // Logging of real-time reference frame states
839
+ bool GraphManager::logRealTimeReferenceFrameStates (const std::string& savePath, const std::string& timeString) {
840
+ // Note enabled
841
+ if (!graphConfigPtr_->logRealTimeStateToMemoryFlag_ ) {
842
+ REGULAR_COUT << RED_START << " Logging of real-time states is disabled. " << COLOR_END << std::endl;
843
+ return false ;
844
+ }
845
+ // Enabled
846
+ else {
847
+ // Main container: map
848
+ std::map<std::string, std::ofstream> fileStreams;
849
+
850
+ // Create directory if it does not exist
851
+ if (!std::filesystem::exists (savePath + timeString)) {
852
+ std::filesystem::create_directories (savePath + timeString);
853
+ }
854
+
855
+ // State Category String
856
+ std::string stateCategoryString = " rt_R_6D_transform" ;
857
+
858
+ // Go through all reference frame states that have been logged
859
+ for (const std::pair<std::string, std::string>& framePair : realTimeReferenceFrameNamePairs_) {
860
+ // Frame Information
861
+ std::string frameInformation = " _" + framePair.first + " _to_" + framePair.second ;
862
+ // Create File Streams
863
+ // CSV
864
+ FileLogger::createPose3CsvFileStream (fileStreams, savePath, stateCategoryString + frameInformation, timeString, false );
865
+ // TUM
866
+ FileLogger::createPose3TumFileStream (fileStreams, savePath, stateCategoryString + frameInformation + " _tum" , timeString);
867
+ }
868
+
869
+ // Iterate through all timestamps and corresponding transform maps
870
+ for (const auto & mapPair : realTimeReferenceFrameContainer_) {
871
+ const double & timeStamp = mapPair.first ; // alias
872
+ const TransformsDictionary<Eigen::Isometry3d>& referenceFrameTransforms = mapPair.second ;
873
+ // Iterate through all transforms for this time stamp
874
+ for (const auto & framePairTransform : referenceFrameTransforms.getTransformsMap ()) {
875
+ // Frame Pair
876
+ const std::pair<std::string, std::string>& framePair = framePairTransform.first ; // alias
877
+ // Transform
878
+ const Eigen::Isometry3d& transform = framePairTransform.second ; // alias
879
+ // Frame Information
880
+ std::string frameInformation = " _" + framePair.first + " _to_" + framePair.second ;
881
+ // Write to files
882
+ // CSV
883
+ FileLogger::writePose3ToCsvFile (fileStreams, gtsam::Pose3 (transform.matrix ()), stateCategoryString + frameInformation, timeStamp,
884
+ false );
885
+ // TUM
886
+ FileLogger::writePose3ToTumFile (fileStreams, gtsam::Pose3 (transform.matrix ()), stateCategoryString + frameInformation + " _tum" ,
887
+ timeStamp);
888
+ }
889
+ }
890
+ return true ;
891
+ }
892
+ }
893
+
817
894
// Save optimized values to file
818
895
void GraphManager::saveOptimizedValuesToFile (const gtsam::Values& optimizedValues, const std::map<gtsam::Key, double >& keyTimestampMap,
819
896
const std::string& savePath, const bool saveCovarianceFlag) {
@@ -846,7 +923,10 @@ void GraphManager::saveOptimizedValuesToFile(const gtsam::Values& optimizedValue
846
923
847
924
// Save real-time states
848
925
if (graphConfigPtr_->logRealTimeStateToMemoryFlag_ ) {
849
- std::ignore = logRealTimeStates (savePath, timeString);
926
+ // Real-time states
927
+ std::ignore = logRealTimeNavStates (savePath, timeString);
928
+ // Real-time Reference Frame States
929
+ std::ignore = logRealTimeReferenceFrameStates (savePath, timeString);
850
930
}
851
931
852
932
// Save optimized states
0 commit comments