rtt_ros_service.cpp
Go to the documentation of this file.
00001 #include <rtt/RTT.hpp>
00002 #include <rtt/plugin/ServicePlugin.hpp>
00003 #include <rtt/internal/GlobalService.hpp>
00004 #include <RosLib.hpp> // todo: put RosLib.hpp in include dir of rtt_rosnode package
00005 
00006 using namespace RTT;
00007 using namespace std;
00008 
00012 class ROSService : public RTT::Service {
00013 public:
00014     int protocol_id;
00019     ROSService(TaskContext* owner) 
00020         : Service("ros", owner),
00021           protocol_id(ORO_ROS_PROTOCOL_ID)
00022     {
00023         this->doc("The main ROS helper service for RTT. See also the 'rosparam' service which can be added to a component and the 'rospack' global service for finding ros packages.");
00024         // stream("Simulation.ctrl", ros.topic("/cmd_vel") )
00025         this->addOperation("topic", &ROSService::topic, this).doc("Creates a ConnPolicy for subscribing to or publishing a topic. No buffering is done, only the last sample is kept.").arg("name", "The ros topic name");
00026         this->addOperation("topicBuffer", &ROSService::topicBuffer, this).doc("Creates a ConnPolicy for subscribing to or publishing a topic.").arg("name", "The ros topic name").arg("size","The size of the buffer.");
00027         this->addOperation("topicUnbuffered", &ROSService::topicUnbuffered, this).doc("Creates a ConnPolicy for unbuffered publishing a topic. This may not be real-time safe!").arg("name", "The ros topic name");
00028         this->addConstant("protocol_id", protocol_id );
00029     }
00030 
00035     ConnPolicy topic(const std::string& name) {
00036         ConnPolicy cp = ConnPolicy::data();
00037         cp.transport = ORO_ROS_PROTOCOL_ID;
00038         cp.name_id = name;
00039         return cp;
00040     }
00041 
00047     ConnPolicy topicBuffer(const std::string& name, int size) {
00048         ConnPolicy cp = ConnPolicy::buffer(size);
00049         cp.transport = ORO_ROS_PROTOCOL_ID;
00050         cp.name_id = name;
00051         return cp;
00052     }
00053 
00059     ConnPolicy topicUnbuffered(const std::string& name) {
00060         ConnPolicy cp = ConnPolicy();
00061         cp.type = ORO_ROS_CONNPOLICY_TYPE_UNBUFFERED;
00062         cp.transport = ORO_ROS_PROTOCOL_ID;
00063         cp.name_id = name;
00064         return cp;
00065     }
00066 };
00067 
00068 void loadROSService(){
00069   RTT::Service::shared_ptr rts(new ROSService(0));
00070   RTT::internal::GlobalService::Instance()->addService(rts);
00071 }


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