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 #include "template_node.h"
00022
00023 int main(int argc, char **argv) {
00024
00025 ros::init(argc, argv, "Scan2Line");
00026 ros::NodeHandle n;
00027 Scan2LineNode my_node(n);
00028 my_node.init();
00029 my_node.loop();
00030 return 0;
00031 }
00032
00033 Scan2LineNode::~Scan2LineNode() {
00034 }
00035
00036 Scan2LineNode::Scan2LineNode(ros::NodeHandle &n) :
00037 Scan2Line(new Scan2LineNode::ParametersNode()), n_(n), loop_count_(0) {
00038
00039 }
00040
00041 Scan2LineNode::ParametersNode *Scan2LineNode::param() {
00042 return (Scan2LineNode::ParametersNode*) param_;
00043 }
00044
00045 void Scan2LineNode::init() {
00046 if (param()->publish) {
00047 pubString_ = n_.advertise<std_msgs::String>("chatter", 1);
00048 } else {
00049 subString_ = n_.subscribe("chatter", 1000, &Scan2LineNode::callbackString, this);
00050 }
00051
00052 }
00053
00054 void Scan2LineNode::loop() {
00055 for (ros::Rate rate(param()->rate); ros::ok(); loop_count_++) {
00056 param()->update(loop_count_);
00057 if (param()->publish) {
00058 std_msgs::String str;
00059 char text[0xFF];
00060 sprintf(text, "%4lu Hallo World!", loop_count_);
00061 str.data = text;
00062 pubString_.publish(str);
00063 }
00064 ros::spinOnce();
00065 rate.sleep();
00066 }
00067 }
00068
00069 void Scan2LineNode::callbackString(const std_msgs::String::ConstPtr& msg) {
00070 ROS_INFO("callbackString: %s", msg->data.c_str());
00071 }