Robotic Programming Environments Lab
Tasks
In the ROS workspace (replace angle brackets <> with correct ROS package name)
cd src
rosrun rtt_roscomm create_rtt_msgs <ros_package_name>
Let assume that in the workspace we have OROCOS oro_test package and ROS ros_test packages, and ros_test containing message MsgTest.msg in the msg folder. After
rosrun rtt_roscomm create_rtt_msgs ros_test
we get new package rtt_ros_test. Then we modify the oro_test component header file
#include <ros_test/MsgTest.h>
class Oro_test : public RTT::TaskContext{
private:
RTT::InputPort<ros_test::MsgTest> inport;
RTT::OutputPort<ros_test::MsgTest> outport;
...
}
We have defined input and output ports that can be connected to ROS topics, next we need to initialize these ports,
Oro_test::Oro_test(std::string const& name) :
TaskContext(name),
inport("MsgTest_in"),
outport("MsgTest_out")
{
this->addEventPort(inport).doc("Input port");
this->addPort(outport).doc("Sends out message.");
...
}
and handle message in updateHook
void Oro_test::updateHook()
{
ros_test::MsgTest msg;
if(RTT::NewData == inport.read(msg)){
//Process message
...
// Write message to output port
outport.write(msg);
}
}
The package.xml need to updated as well
<build_depend>rtt</build_depend>
<build_depend>orogen</build_depend>
<build_depend>rtt_ros</build_depend>
...
<run_depend>rtt</run_depend>
<run_depend>rtt_ros</run_depend>
...
<build_depend>rtt_ros_test</build_depend>
<run_depend>rtt_ros_test</run_depend>
...
<export>
<rtt_ros>
<plugin_depend>rtt_ros_test</plugin_depend>
</rtt_ros>
</export>
Finally in deployer (please launch roscore first)
import("rtt_ros")
import("rtt_roscomm")
ros.import("oro_test")
ros.import("rtt_ros_test")
# Load a oro_test component
loadComponent("Oro_test","Oro_test")
# Create connections
stream("Oro_test.MsgTest_out", ros.topic("oro_to_ros"))
stream("Oro_test.MsgTest_in", ros.topic("ros_to_oro"))
# Configure the component
Oro_test.configure()
# Start it
Oro_test.start()