Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <ros/ros.h>
00035 #include <nodelet/nodelet.h>
00036 #include <pluginlib/class_list_macros.h>
00037 #include <std_msgs/String.h>
00038
00039 namespace some_namespace
00040 {
00041
00042 using std::string;
00043
00044 class MyNodelet : public nodelet::Nodelet
00045 {
00046 private:
00047 ros::NodeHandle nh_priv;
00048 ros::NodeHandle nh;
00049
00050 bool enable_awesomeness;
00051 double awesome_factor;
00052
00053 ros::Publisher awesome_pub;
00054
00055 ros::Subscriber chatter_sub;
00056
00057 ros::Timer output_timer;
00058
00059 string latest_chatter;
00060
00061 public:
00062 MyNodelet() :
00063 enable_awesomeness(true), awesome_factor(1.57)
00064 {
00065 }
00066 private:
00067 void onInit()
00068 {
00069 nh = getMTNodeHandle();
00070 nh_priv = getMTPrivateNodeHandle();
00071
00072 NODELET_INFO("onInit()");
00073
00074
00075 nh_priv.param("enable_awesomeness", enable_awesomeness, enable_awesomeness);
00076 nh_priv.param("awesome_factor", awesome_factor, awesome_factor);
00077
00078 awesome_pub = nh_priv.advertise<std_msgs::String> ("awesome", 10);
00079
00080 chatter_sub = nh.subscribe("chatter", 10, &MyNodelet::chatterCb, this);
00081
00082 output_timer = nh.createTimer(ros::Duration(0.1), &MyNodelet::outputTimerCb, this);
00083 }
00084
00085 void outputTimerCb(const ros::TimerEvent& e)
00086 {
00087 std_msgs::String output;
00088 std::ostringstream s;
00089 s << "foo bar baz " << awesome_factor;
00090 output.data = s.str();
00091 awesome_pub.publish(output);
00092 }
00093
00094 void chatterCb(const std_msgs::StringConstPtr& chatter)
00095 {
00096 NODELET_INFO_STREAM("Heard chatter: " << chatter->data);
00097 }
00098
00099 };
00100 PLUGINLIB_DECLARE_CLASS(some_namespace, MyNodelet, some_namespace::MyNodelet, nodelet::Nodelet)
00101 ;
00102 }