CGraphSlamHandler_ROS.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+
9  */
10 
11 #pragma once
12 
13 // ROS
14 #include <ros/ros.h>
15 #include <mrpt_msgs/GraphSlamStats.h>
16 #include <geometry_msgs/PoseStamped.h>
17 #include <geometry_msgs/PoseArray.h>
18 #include <geometry_msgs/TransformStamped.h>
19 #include <sensor_msgs/LaserScan.h>
20 #include <nav_msgs/Path.h>
21 #include <nav_msgs/Odometry.h>
22 #include <nav_msgs/OccupancyGrid.h>
23 #include <std_msgs/Header.h>
24 
27 #include <geometry_msgs/TransformStamped.h>
28 #include <tf2_ros/buffer.h>
32 #include <tf2/LinearMath/Vector3.h>
33 
34 // MRPT
35 #include <mrpt/graphs/CNetworkOfPoses.h>
36 #include <mrpt/maps/COccupancyGridMap2D.h>
37 #include <mrpt/obs/CObservationOdometry.h>
38 #include <mrpt/obs/CObservation2DRangeScan.h>
39 
40 #include <mrpt/system/string_utils.h>
41 #include <mrpt/system/filesystem.h>
42 #include <mrpt/system/os.h>
43 #include <mrpt/system/COutputLogger.h>
44 #include <mrpt/graphslam/apps_related/CGraphSlamHandler.h>
45 
49 
50 // cpp headers
51 #include <string>
52 #include <sstream>
53 #include <vector>
54 
55 namespace mrpt
56 {
57 namespace graphslam
58 {
59 namespace apps
60 {
64 template <class GRAPH_T = mrpt::graphs::CNetworkOfPoses2DInf>
65 class CGraphSlamHandler_ROS : public CGraphSlamHandler<GRAPH_T>
66 {
67  public:
69  typedef typename GRAPH_T::constraint_t constraint_t;
71  typedef typename GRAPH_T::constraint_t::type_value pose_t;
72 
76  typedef CGraphSlamHandler<GRAPH_T> parent_t;
77 
79  mrpt::system::COutputLogger* logger,
80  TUserOptionsChecker<GRAPH_T>* options_checker, ros::NodeHandle* nh_in);
82 
83  void getParamsAsString(std::string* str_out);
84  std::string getParamsAsString();
85 
90  void readParams();
94  void printParams();
95 
104  void sniffOdom(const nav_msgs::Odometry::ConstPtr& ros_odom);
108  void sniffLaserScan(const sensor_msgs::LaserScan::ConstPtr& ros_laser_scan);
109  void sniffCameraImage();
111  void sniff3DPointCloud();
117  bool continueExec();
121  void generateReport();
141  void setupComm();
142 
150  void initEngine_ROS();
151  void initEngine_MR();
154  static const std::string sep_header;
155  static const std::string sep_subheader;
156 
157  private:
167  void processObservation(mrpt::obs::CObservation::Ptr& observ);
173  void _process(mrpt::obs::CObservation::Ptr& observ);
178  void readROSParameters();
179  void readStaticTFs();
185  void getROSParameters(std::string* str_out);
189  void verifyUserInput();
190 
194  void resetReceivedFlags();
202  void setupSubs();
203  void setupPubs();
204  void setupSrvs();
208 
209  // ROS server parameters
212  std::string m_node_reg;
213  std::string m_edge_reg;
214  std::string m_optimizer;
224  VerbosityLevel m_min_logging_level;
225 
245  mrpt::obs::CObservationOdometry::Ptr m_mrpt_odom;
246  mrpt::obs::CObservation2DRangeScan::Ptr m_mrpt_laser_scan;
258 
274  std::string m_odom_topic;
275  std::string m_laser_scan_topic;
276  std::string m_camera_topic;
277  std::string m_point_cloud_topic;
278 
283  std::string m_gridmap_topic;
284  std::string m_stats_topic;
301  std::string m_anchor_frame_id;
302  std::string m_base_link_frame_id;
303  std::string m_odom_frame_id;
311  geometry_msgs::TransformStamped m_anchor_odom_transform;
317  nav_msgs::Path m_odom_path;
318 
324 
328 
331 
333 
340 };
341 
342 } // namespace apps
343 } // namespace graphslam
344 } // namespace mrpt
345 
void readROSParameters()
read configuration parameters from the ROS parameter server.
void readParams()
Read the problem configuration parameters.
void verifyUserInput()
Verify that the parameters read are valid and can be used with the CGraphSlamEngine_ROS instance...
bool usePublishersBroadcasters()
Provide feedback about the SLAM operation using ROS publilshers, update the registered frames using t...
void generateReport()
Generate the relevant report directory/files after the graphSLAM execution.
void initEngine_ROS()
Initialize the CGraphslamEngine_* object.
bool m_first_time_in_sniff_odom
Initial offset of the received odometry.
size_t m_measurement_cnt
Total counter of the processed measurements.
mrpt::obs::CObservation2DRangeScan::Ptr m_mrpt_laser_scan
GRAPH_T::constraint_t::type_value pose_t
type of underlying poses (2D/3D).
GRAPH_T::constraint_t constraint_t
type of graph constraints
CGraphSlamHandler_ROS< GRAPH_T > self_t
Handy self type.
VerbosityLevel m_min_logging_level
Minimum logging level for the current class instance.
bool continueExec()
Indicate whether graphslam execution can proceed normally.
geometry_msgs::TransformStamped m_anchor_odom_transform
ros::NodeHandle * m_nh
Pointer to the Ros NodeHanle instance.
void sniffOdom(const nav_msgs::Odometry::ConstPtr &ros_odom)
Callback method for handling incoming odometry measurements in a ROS topic.
CGraphSlamHandler< GRAPH_T > parent_t
Handy parent type.
void _process(mrpt::obs::CObservation::Ptr &observ)
Low level wrapper for executing the CGraphSlamEngine_ROS::execGraphSlamStep method.
void sniffLaserScan(const sensor_msgs::LaserScan::ConstPtr &ros_laser_scan)
Callback method for handling incoming LaserScans objects in a ROS topic.
void setupComm()
Wrapper method around the protected setup* class methods.
void getROSParameters(std::string *str_out)
Fill in the given string with the parameters that have been read from the ROS parameter server...
nav_msgs::Path m_odom_path
Odometry path of the robot. Handy mostly for visualization reasons.
std::string m_anchor_frame_id
Frame that the robot starts from. In a single-robot SLAM setup this can be set to the world frame...
void printParams()
Print in a compact manner the overall problem configuration parameters.
int m_pub_seq
Times a messge has been published => usePublishersBroadcasters method is called.
void resetReceivedFlags()
Reset the flags indicating whether we have received new data (odometry, laser scans etc...
Manage variables, ROS parameters and everything else related to the graphslam-engine ROS wrapper...
mrpt::obs::CObservationOdometry::Ptr m_mrpt_odom
Received laser scan - converted into MRPT CObservation* format.
void processObservation(mrpt::obs::CObservation::Ptr &observ)
Process an incoming measurement.
int m_queue_size
ROS topic publisher standard queue size.
CGraphSlamHandler_ROS(mrpt::system::COutputLogger *logger, TUserOptionsChecker< GRAPH_T > *options_checker, ros::NodeHandle *nh_in)


mrpt_graphslam_2d
Author(s): Nikos Koukis
autogenerated on Sun Jun 26 2022 02:12:26