pathplan.cpp
Go to the documentation of this file.
00001 /*************************************************************************
00002         > File Name: pathplan.cpp
00003         > Author: Minglong Li
00004         > Mail: minglong_l@163.com
00005         > Created on: July 18th, 2016
00006  ************************************************************************/
00007 
00008 #include<iostream>
00009 #include<ros/ros.h>
00010 #include<nodelet/nodelet.h>
00011 #include<std_msgs/Bool.h>
00012 #include<micros_mars_task_alloc/Heading.h>
00013 #include<micros_mars_task_alloc/Path.h>
00014 #include<pluginlib/class_list_macros.h>
00015 
00016 namespace micros_mars_task_alloc{
00017     using namespace std;
00018     class Pathplan : public nodelet::Nodelet
00019     {
00020     public:
00021         Pathplan() : start_pathplan_(false){}
00022         ~Pathplan(){}
00023 
00024         virtual void onInit();
00025         void callback_0(const micros_mars_task_alloc::PathConstPtr & msg);
00026         void callback_1(const std_msgs::BoolConstPtr & msg);
00027 
00028     private:    
00029         ros::NodeHandle nh_;
00030         ros::Subscriber sub_0_; 
00031         ros::Subscriber sub_1_;
00032         ros::Publisher pub_;
00033         bool start_pathplan_;
00034     };
00035 
00036     void Pathplan::onInit()
00037     {
00038         nh_ = getPrivateNodeHandle();
00039         sub_0_ = nh_.subscribe("/look/path", 10, &Pathplan::callback_0, this);//This is an absolute topic.
00040         sub_1_ = nh_.subscribe("/whenlook/startlook", 10, &Pathplan::callback_1, this);//This is an absolute topic.
00041         pub_ = nh_.advertise<micros_mars_task_alloc::Heading>("suppressor", 10);//This is a relative topic, the prefix pathplan will be added automaically.
00042     }
00043 
00044     void Pathplan::callback_0(const micros_mars_task_alloc::PathConstPtr & msg)
00045     {
00046         if (start_pathplan_)
00047         {
00048             micros_mars_task_alloc::HeadingPtr heading_ptr(new micros_mars_task_alloc::Heading);
00049             heading_ptr -> angle = msg -> path_angle;
00050             heading_ptr -> distance = msg -> path_distance;
00051             pub_.publish(heading_ptr);
00052         }
00053         start_pathplan_ = false;
00054     }
00055 
00056     void Pathplan::callback_1(const std_msgs::BoolConstPtr & msg)
00057     {
00058         start_pathplan_ = msg -> data;
00059         /*
00060         if(start_pathplan_)
00061         {
00062             ros::Duration(0.5).sleep();
00063             start_pathplan_ = false;
00064         }
00065         */
00066         
00067     }
00068 }//namespace micros_mars_task_alloc
00069 PLUGINLIB_EXPORT_CLASS(micros_mars_task_alloc::Pathplan, nodelet::Nodelet)


micros_mars_task_alloc
Author(s): Minglong Li , Xiaodong Yi , Yanzhen Wang , Zhongxuan Cai
autogenerated on Mon Jul 1 2019 19:55:03