1 #ifndef _CSLAM_LOGGER_H_
2 #define _CSLAM_LOGGER_H_
8 #include <rclcpp/rclcpp.hpp>
10 #include <gtsam/geometry/Pose3.h>
11 #include <gtsam/inference/Key.h>
12 #include <gtsam/inference/LabeledSymbol.h>
13 #include <gtsam/linear/NoiseModel.h>
14 #include <gtsam/nonlinear/GncOptimizer.h>
15 #include <gtsam/nonlinear/NonlinearFactorGraph.h>
16 #include <gtsam/nonlinear/Values.h>
17 #include <gtsam/slam/BetweenFactor.h>
18 #include <gtsam/slam/dataset.h>
24 #include <sensor_msgs/msg/nav_sat_fix.hpp>
25 #include <diagnostic_msgs/msg/key_value.hpp>
27 #include <cslam_common_interfaces/msg/pose_graph.hpp>
28 #include <cslam_common_interfaces/msg/inter_robot_matches.hpp>
40 Logger(std::shared_ptr<rclcpp::Node> &
node,
const unsigned int &robot_id,
const unsigned int &max_nb_robots,
const std::string &log_folder);
45 const gtsam::Values::shared_ptr &initial);
48 const gtsam::Values &result,
49 const unsigned int &origin_robot_id);
62 void log_callback(
const diagnostic_msgs::msg::KeyValue::ConstSharedPtr msg);
69 void log_matches_callback(
const cslam_common_interfaces::msg::InterRobotMatches::ConstSharedPtr msg);
71 void fill_msg(cslam_common_interfaces::msg::PoseGraph & msg);
73 void log_pose_timestamp(
const gtsam::LabeledSymbol & symbol,
const int& sec,
const int& nanosec);
77 double compute_error(
const gtsam::NonlinearFactorGraph::shared_ptr &graph,
78 const gtsam::Values::shared_ptr &result);
80 std::vector<std::pair<std::pair<gtsam::LabeledSymbol, gtsam::LabeledSymbol>,
double>> compute_inter_robot_loop_closure_errors(
const gtsam::NonlinearFactorGraph::shared_ptr &graph,
81 const gtsam::Values::shared_ptr &result);
83 std::shared_ptr<rclcpp::Node> node_;
85 std::string log_folder_;
86 unsigned int robot_id_, origin_robot_id_, max_nb_robots_;
87 std::chrono::steady_clock::time_point start_time_;
88 uint64_t elapsed_time_, total_pgo_time_;
90 std::map<unsigned int, std::map<unsigned int, sensor_msgs::msg::NavSatFix>> gps_values_;
91 std::pair<gtsam::NonlinearFactorGraph::shared_ptr, gtsam::Values::shared_ptr> initial_global_pose_graph_;
92 std::pair<gtsam::NonlinearFactorGraph::shared_ptr, gtsam::Values::shared_ptr> optimized_global_pose_graph_;
93 std::vector<cslam_common_interfaces::msg::PoseGraph> pose_graphs_log_info_;
95 rclcpp::Subscription<diagnostic_msgs::msg::KeyValue>::SharedPtr
98 rclcpp::Subscription<cslam_common_interfaces::msg::InterRobotMatches>::SharedPtr
99 inter_robot_matches_subscriber_;
101 cslam_common_interfaces::msg::InterRobotMatches spectral_matches_;
103 unsigned int log_nb_matches_, log_nb_failed_matches_, log_nb_vertices_transmitted_, log_nb_matches_selected_, log_detection_cumulative_communication_, log_local_descriptors_cumulative_communication_;
104 float log_sparsification_cumulative_computation_time_;
106 std::map<gtsam::LabeledSymbol, std::pair<int, int>> pose_time_map_;
void log_initial_global_pose_graph(const gtsam::NonlinearFactorGraph::shared_ptr &graph, const gtsam::Values::shared_ptr &initial)
void add_pose_graph_log_info(const cslam_common_interfaces::msg::PoseGraph &msg)
void log_matches_callback(const cslam_common_interfaces::msg::InterRobotMatches::ConstSharedPtr msg)
Receive log messages.
void fill_msg(cslam_common_interfaces::msg::PoseGraph &msg)
void log_optimized_global_pose_graph(const gtsam::NonlinearFactorGraph::shared_ptr &graph, const gtsam::Values &result, const unsigned int &origin_robot_id)
void log_pose_timestamp(const gtsam::LabeledSymbol &symbol, const int &sec, const int &nanosec)
Logger(std::shared_ptr< rclcpp::Node > &node, const unsigned int &robot_id, const unsigned int &max_nb_robots, const std::string &log_folder)
Logger class to log various metrics.
void log_callback(const diagnostic_msgs::msg::KeyValue::ConstSharedPtr msg)
Receive log messages.