$search
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->addConstant("protocol_id", protocol_id ); 00028 } 00029 00034 ConnPolicy topic(const std::string& name) { 00035 ConnPolicy cp = ConnPolicy::data(); 00036 cp.transport = ORO_ROS_PROTOCOL_ID; 00037 cp.name_id = name; 00038 return cp; 00039 } 00040 00046 ConnPolicy topicBuffer(const std::string& name, int size) { 00047 ConnPolicy cp = ConnPolicy::buffer(size); 00048 cp.transport = ORO_ROS_PROTOCOL_ID; 00049 cp.name_id = name; 00050 return cp; 00051 } 00052 }; 00053 00054 void loadROSService(){ 00055 RTT::Service::shared_ptr rts(new ROSService(0)); 00056 RTT::internal::GlobalService::Instance()->addService(rts); 00057 }