00001 /* +---------------------------------------------------------------------------+ 00002 | Mobile Robot Programming Toolkit (MRPT) | 00003 | http://www.mrpt.org/ | 00004 | | 00005 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file | 00006 | See: http://www.mrpt.org/Authors - All rights reserved. | 00007 | Released under BSD License. See details in http://www.mrpt.org/License | 00008 +---------------------------------------------------------------------------+ */ 00009 00010 #pragma once 00011 00012 // ROS 00013 #include <ros/ros.h> 00014 #include <mrpt_bridge/mrpt_bridge.h> 00015 #include <mrpt_msgs/GraphSlamStats.h> 00016 #include <geometry_msgs/PoseStamped.h> 00017 #include <geometry_msgs/PoseArray.h> 00018 #include <geometry_msgs/TransformStamped.h> 00019 #include <sensor_msgs/LaserScan.h> 00020 #include <nav_msgs/Path.h> 00021 #include <nav_msgs/Odometry.h> 00022 #include <nav_msgs/OccupancyGrid.h> 00023 #include <std_msgs/Header.h> 00024 00025 #include <tf/transform_datatypes.h> 00026 #include <tf2_ros/buffer.h> 00027 #include <tf2_ros/transform_broadcaster.h> 00028 #include <tf2_ros/transform_listener.h> 00029 #include <tf2/LinearMath/Quaternion.h> 00030 #include <tf2/LinearMath/Vector3.h> 00031 00032 // MRPT 00033 #include <mrpt/graphs/CNetworkOfPoses.h> 00034 #include <mrpt/maps/COccupancyGridMap2D.h> 00035 #include <mrpt/obs/CObservationOdometry.h> 00036 #include <mrpt/obs/CObservation2DRangeScan.h> 00037 00038 #include <mrpt/system/string_utils.h> 00039 #include <mrpt/system/filesystem.h> 00040 #include <mrpt/system/os.h> 00041 #include <mrpt/utils/COutputLogger.h> 00042 #include <mrpt/graphslam/apps_related/CGraphSlamHandler.h> 00043 00044 #include "mrpt_graphslam_2d/CGraphSlamEngine_ROS.h" 00045 #include "mrpt_graphslam_2d/CGraphSlamEngine_MR.h" 00046 #include "mrpt_graphslam_2d/TUserOptionsChecker_ROS.h" 00047 00048 00049 // cpp headers 00050 #include <string> 00051 #include <sstream> 00052 #include <vector> 00053 00054 namespace mrpt { namespace graphslam { namespace apps { 00055 00059 template<class GRAPH_T=mrpt::graphs::CNetworkOfPoses2DInf> 00060 class CGraphSlamHandler_ROS : 00061 public CGraphSlamHandler<GRAPH_T> 00062 { 00063 public: 00065 typedef typename GRAPH_T::constraint_t constraint_t; 00067 typedef typename GRAPH_T::constraint_t::type_value pose_t; 00068 00070 typedef CGraphSlamHandler_ROS<GRAPH_T> self_t; 00072 typedef CGraphSlamHandler<GRAPH_T> parent_t; 00073 00074 CGraphSlamHandler_ROS( 00075 mrpt::utils::COutputLogger* logger, 00076 TUserOptionsChecker<GRAPH_T>* options_checker, 00077 ros::NodeHandle* nh_in); 00078 ~CGraphSlamHandler_ROS(); 00079 00080 00081 void getParamsAsString(std::string* str_out); 00082 std::string getParamsAsString(); 00083 00088 void readParams(); 00092 void printParams(); 00093 00102 void sniffOdom(const nav_msgs::Odometry::ConstPtr& ros_odom); 00106 void sniffLaserScan(const sensor_msgs::LaserScan::ConstPtr& ros_laser_scan); 00107 void sniffCameraImage(); 00109 void sniff3DPointCloud(); 00114 bool continueExec(); 00118 void generateReport(); 00129 bool usePublishersBroadcasters(); 00138 void setupComm(); 00139 00147 void initEngine_ROS(); 00148 void initEngine_MR(); 00151 static const std::string sep_header; 00152 static const std::string sep_subheader; 00153 00154 private: 00164 void processObservation(mrpt::obs::CObservation::Ptr& observ); 00170 void _process(mrpt::obs::CObservation::Ptr& observ); 00175 void readROSParameters(); 00176 void readStaticTFs(); 00182 void getROSParameters(std::string* str_out); 00186 void verifyUserInput(); 00187 00191 void resetReceivedFlags(); 00199 void setupSubs(); 00200 void setupPubs(); 00201 void setupSrvs(); 00204 ros::NodeHandle* m_nh; 00205 00206 // ROS server parameters 00209 std::string m_node_reg; 00210 std::string m_edge_reg; 00211 std::string m_optimizer; 00221 VerbosityLevel m_min_logging_level; 00222 00229 bool m_received_odom; 00230 bool m_received_laser_scan; 00231 bool m_received_camera; 00232 bool m_received_point_cloud; 00242 mrpt::obs::CObservationOdometry::Ptr m_mrpt_odom; 00243 mrpt::obs::CObservation2DRangeScan::Ptr m_mrpt_laser_scan; 00251 ros::Subscriber m_odom_sub; 00252 ros::Subscriber m_laser_scan_sub; 00253 ros::Subscriber m_camera_scan_sub; 00254 ros::Subscriber m_point_cloud_scan_sub; 00255 00256 ros::Publisher m_curr_robot_pos_pub; 00257 ros::Publisher m_robot_trajectory_pub; 00258 ros::Publisher m_robot_tr_poses_pub; 00259 ros::Publisher m_gt_trajectory_pub; // TODO 00260 ros::Publisher m_SLAM_eval_metric_pub; // TODO 00261 ros::Publisher m_odom_trajectory_pub; 00262 ros::Publisher m_gridmap_pub; 00263 ros::Publisher m_stats_pub; 00271 std::string m_odom_topic; 00272 std::string m_laser_scan_topic; 00273 std::string m_camera_topic; 00274 std::string m_point_cloud_topic; 00275 00276 std::string m_curr_robot_pos_topic; 00277 std::string m_robot_trajectory_topic; 00278 std::string m_robot_tr_poses_topic; 00279 std::string m_odom_trajectory_topic; 00280 std::string m_gridmap_topic; 00281 std::string m_stats_topic; 00287 tf2_ros::Buffer m_buffer; 00288 tf2_ros::TransformBroadcaster m_broadcaster; 00298 std::string m_anchor_frame_id; 00299 std::string m_base_link_frame_id; 00300 std::string m_odom_frame_id; 00308 geometry_msgs::TransformStamped m_anchor_odom_transform; 00314 nav_msgs::Path m_odom_path; 00315 00318 int m_pub_seq; 00319 int m_stats_pub_seq; 00320 00323 size_t m_measurement_cnt; 00324 00326 int m_queue_size; 00327 00328 size_t m_graph_nodes_last_size; 00329 00334 bool m_first_time_in_sniff_odom; 00335 pose_t m_input_odometry_offset; 00336 }; 00337 00338 } } } // end of namespaces 00339 00340 #include "mrpt_graphslam_2d/CGraphSlamHandler_ROS_impl.h" 00341