pose_labeler_node.cpp
Go to the documentation of this file.
00001 
00027 #include <string>
00028 
00029 #include <boost/shared_ptr.hpp>
00030 
00031 #include <ros/ros.h>
00032 #include <nav_msgs/MapMetaData.h>
00033 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00034 
00035 #include <topological_tools/pose_labeler.h>
00036 #include <topological_tools/PoseLabel.h>
00037 
00038 #include <stdlib.h>
00039 
00040 #include <SDL/SDL_image.h>
00041 
00042 
00043 
00044 namespace topological_tools
00045 {
00046 class PoseLabelerWrapper : public PoseLabeler
00047 {
00048 public:
00049     PoseLabelerWrapper ( const std::string& label_map_filename,
00050                          const std::string& pose_topic ) :
00051         PoseLabeler ( label_map_filename ),
00052         map_meta_sub_ ( nh_.subscribe ( "/map_metadata", 1, &PoseLabelerWrapper::mapMetadataCallback, this ) ),
00053         pose_sub_ ( nh_.subscribe ( pose_topic, 1, &PoseLabelerWrapper::poseCallback, this ) ),
00054         label_pub_ ( nh_.advertise<PoseLabel> ( "pose_label", 1, true ) ),
00055         last_label_ (),
00056         started_ ( false ) {}
00057 
00058     void mapMetadataCallback ( const nav_msgs::MapMetaDataConstPtr& msg )
00059     {
00060         setMapMetaData ( msg );
00061     }
00062 
00063     void poseCallback ( const geometry_msgs::PoseWithCovarianceStampedConstPtr& msg )
00064     {
00065         PoseLabel currentLabel = getPoseLabel ( *msg );
00066         if ( !started_ || ( currentLabel.label != last_label_.label ) )
00067         {
00068             label_pub_.publish ( currentLabel );
00069             started_ = true;
00070             last_label_.label = currentLabel.label;
00071         }
00072     }
00073 
00074 private:
00075     ros::NodeHandle nh_;
00076 
00077     ros::Subscriber map_meta_sub_;
00078     ros::Subscriber pose_sub_;
00079 
00080     ros::Publisher label_pub_;
00081     PoseLabel last_label_;
00082     bool started_;
00083 };
00084 }
00085 
00086 
00087 
00088 int main ( int argc, char** argv )
00089 {
00090     ros::init ( argc, argv, "pose_labeler_node" );
00091 
00092     if ( argc < 3 )
00093     {
00094         ROS_ERROR ( "\nUSAGE: pose_labeler_node <path to label map> <pose topic>\n" );
00095     }
00096     else
00097     {
00098         topological_tools::PoseLabelerWrapper plw ( argv[1], argv[2] );
00099         ros::spin();
00100     }
00101 
00102     return 0;
00103 }


topological_tools
Author(s): Joao Messias
autogenerated on Wed Aug 26 2015 12:28:47