HelloRobot.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Ruben Smits  Tue Nov 16 09:21:07 CET 2010  HelloRobot.cpp
00003 
00004                         HelloRobot.cpp -  description
00005                            -------------------
00006     begin                : Tue November 16 2010
00007     copyright            : (C) 2010 Ruben Smits
00008     email                : first.last@mech.kuleuven.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 
00029 #include <rtt/TaskContext.hpp>
00030 #include <rtt/Port.hpp>
00031 #include <std_msgs/Float64.h>
00032 #include <std_msgs/String.h>
00033 #include <rtt/Component.hpp>
00034 
00035 using namespace RTT;
00036 
00037 class HelloRobot : public RTT::TaskContext{
00038 private:  
00039   InputPort<std_msgs::Float64> inport;
00040   OutputPort<std_msgs::Float64> outport;
00041 
00042   InputPort<std_msgs::String> sinport;
00043   OutputPort<std_msgs::String> soutport;
00044   
00045   std::string prop_answer;
00046   double prop_counter_step;
00047 
00048   double counter;
00049   
00050 public:
00051   HelloRobot(const std::string& name):
00052     TaskContext(name),
00053     inport("float_in"),outport("float_out"),
00054     sinport("string_in"),soutport("string_out","Hello Robot"),
00055     prop_answer("Hello Robot"),prop_counter_step(0.01)
00056   {
00057     this->addEventPort(inport).doc("Receiving a message here will wake up this component.");
00058     this->addPort(outport).doc("Sends out 'answer'.");
00059     this->addEventPort(sinport).doc("Receiving a message here will wake up this component.");
00060     this->addPort(soutport).doc("Sends out a counter value based on 'counter_step'.");
00061     
00062     this->addProperty("answer",prop_answer).doc("The text being sent out on 'string_out'.");
00063     this->addProperty("counter_step",prop_counter_step).doc("The increment for each new sample on 'float_out'");
00064     
00065     counter=0.0;
00066   }
00067   ~HelloRobot(){}
00068 private:
00069   void updateHook(){
00070     std_msgs::Float64 fdata;
00071     std_msgs::String sdata;
00072     if(NewData==inport.read(fdata)){
00073       log(Info)<<"Float in: "<<fdata<<endlog();
00074       counter=fdata.data;
00075     }
00076     if(NewData==sinport.read(sdata))
00077       log(Info)<<"String in: "<<sdata<<endlog();
00078     counter+=prop_counter_step;
00079     fdata.data=counter;
00080     outport.write(fdata);
00081     sdata.data=prop_answer;
00082     soutport.write(sdata);
00083   }
00084 };
00085 ORO_CREATE_COMPONENT(HelloRobot)


rtt_ros_integration_example
Author(s): Ruben Smits, ruben.smits@mech.kuleuven.be
autogenerated on Mon Oct 6 2014 07:24:33