template_node.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2014 by Markus Bader                                    *
00003  *   markus.bader@tuwien.ac.at                                             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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 }


template
Author(s):
autogenerated on Wed Aug 26 2015 16:42:05