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 #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)