Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
graph_slam_solver.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <gtsam/geometry/Pose2.h>
4#include <gtsam/inference/Symbol.h>
5#include <gtsam/nonlinear/NonlinearFactorGraph.h>
6#include <gtsam/nonlinear/Values.h>
7
8#include <queue>
9
22
34 public ImuIntegratorTrait,
37 std::shared_ptr<GraphSLAMInstance> _graph_slam_instance_; //< Instance of the graph SLAM solver
38 std::shared_ptr<PoseUpdater> _pose_updater_; //< Pose updater for the graph SLAM solver
39 std::shared_ptr<OdometryModel>
40 _odometry_model; //< Motion model for odometry integration TODO: improve, I dont like it
41 std::queue<MotionData>
42 _motion_data_queue_; //< Queue of velocities received while optimization ran
43 std::queue<ObservationData>
44 _observation_data_queue_; //< Queue of observations received while optimization ran
45 rclcpp::TimerBase::SharedPtr _optimization_timer_; //< Timer for asynchronous optimization
46 mutable std::shared_mutex
47 _mutex_; //< Mutex for the graph SLAM solver, locks access to the graph and other vars
48 bool _optimization_under_way_ = false; //< Flag to check if the optimization is under way
49 Eigen::VectorXi _associations_; //< Associations of the cones in the map
50 Eigen::VectorXd _observations_global_; //< Global observations of the cones
51 Eigen::VectorXd _map_coordinates_; //< Coordinates of the landmarks in the map
52
54
55 rclcpp::CallbackGroup::SharedPtr
56 _reentrant_group_; //< Reentrant callback group for the timer callback
57
65
76 bool _add_motion_data_to_graph(const std::shared_ptr<PoseUpdater> pose_updater,
77 const std::shared_ptr<GraphSLAMInstance> graph_slam_instance,
78 bool force_update = false);
79
81
82public:
91 GraphSLAMSolver(const SLAMParameters& params,
92 std::shared_ptr<DataAssociationModel> data_association,
93 std::shared_ptr<V2PMotionModel> motion_model,
94 std::shared_ptr<LandmarkFilter> landmark_filter,
95 std::shared_ptr<std::vector<double>> execution_times,
96 std::shared_ptr<LoopClosure> loop_closure);
97
98 ~GraphSLAMSolver() = default;
99
107 void init(std::weak_ptr<rclcpp::Node> node) override;
108
115 void add_velocities(const common_lib::structures::Velocities& velocities) override;
116
123 void add_odometry(const common_lib::structures::Pose& pose_difference) override;
124
130 void add_imu_data(const common_lib::sensor_data::ImuData& imu_data) override;
131
138 void add_observations(const std::vector<common_lib::structures::Cone>& cones,
139 rclcpp::Time cones_timestamp) override;
140
148 void load_initial_state(const Eigen::VectorXd& map, const Eigen::Vector3d& pose) override;
149
155 std::vector<common_lib::structures::Cone> get_map_estimate() override;
156
163
169 std::vector<common_lib::structures::Pose> get_trajectory_estimate() override;
170
176 Eigen::MatrixXd get_covariance() override;
177
183 int get_lap_counter() override { return lap_counter_; }
184
185 Eigen::VectorXi get_associations() const override;
186
187 Eigen::VectorXd get_observations_global() const override;
188
189 Eigen::VectorXd get_map_coordinates() const override;
190
208};
Graph SLAM solver class.
std::shared_mutex _mutex_
friend class GraphSlamSolverTest_MotionAndObservation_Test
Eigen::VectorXd get_observations_global() const override
~GraphSLAMSolver()=default
Eigen::VectorXd _observations_global_
std::shared_ptr< GraphSLAMInstance > _graph_slam_instance_
void add_odometry(const common_lib::structures::Pose &pose_difference) override
Add odometry data to the solver (for prediction step)
void add_imu_data(const common_lib::sensor_data::ImuData &imu_data) override
Add IMU data to the solver.
void _asynchronous_optimization_routine()
Asynchronous optimization routine.
bool _add_motion_data_to_graph(const std::shared_ptr< PoseUpdater > pose_updater, const std::shared_ptr< GraphSLAMInstance > graph_slam_instance, bool force_update=false)
Adds motion data to the graph if the pose updater is ready.
void add_velocities(const common_lib::structures::Velocities &velocities) override
Process new velocities data (prediction step)
std::shared_ptr< OdometryModel > _odometry_model
void init(std::weak_ptr< rclcpp::Node > node) override
Initialize the SLAM solver.
int get_lap_counter() override
Get the lap counter.
rclcpp::CallbackGroup::SharedPtr _reentrant_group_
void add_observations(const std::vector< common_lib::structures::Cone > &cones, rclcpp::Time cones_timestamp) override
Add observations to the solver (correction step)
rclcpp::TimerBase::SharedPtr _optimization_timer_
std::vector< common_lib::structures::Cone > get_map_estimate() override
Get the map estimate object.
void load_initial_state(const Eigen::VectorXd &map, const Eigen::Vector3d &pose) override
Initialize the graph SLAM solver with a previously saved map and pose.
common_lib::structures::Pose get_pose_estimate() override
Get the pose estimate object.
Eigen::VectorXi _associations_
Eigen::VectorXd get_map_coordinates() const override
std::queue< MotionData > _motion_data_queue_
std::shared_ptr< PoseUpdater > _pose_updater_
Eigen::MatrixXd get_covariance() override
Get the covariance matrix of the graph.
Eigen::VectorXd _map_coordinates_
std::queue< ObservationData > _observation_data_queue_
common_lib::sensor_data::ImuData _last_imu_data_
std::vector< common_lib::structures::Pose > get_trajectory_estimate() override
Get the trajectory estimate of the car (all poses)
Eigen::VectorXi get_associations() const override
Trait class for IMU integration in SLAM solvers.
Trait class for node control in SLAM solvers.
Trait class for odometry integration in SLAM solvers.
Interface for SLAM solvers.
Trait class for trajectory calculation in SLAM solvers.
Trait class for velocities integration in SLAM solvers.
Parameters for the SLAM node.
Struct for pose representation.
Definition pose.hpp:13