Question: What is the efficient and equivalent implementation of OROCOS read in ROS, when subscribing to multiple (different rate) data sources?
Problem definition: Consider a case when we have two data sources: 1) publishing at higher rate (e.g 250Hz); 2) publishing at lower rate (e.g 10Hz). I have been trying to compare ros and orocos outputs by recording higher rate data at lower rate. When recorded in rosbag, there are instances when the data is not recorded at the correct sample time (or missed by one sample). I believe that the problem lies in my in-efficient implementation in ROS. I acknowledge that there may be a mistake in my implementation. Please see the explanation below.
Explanation: In orocos, assuming a sequential activity and the event port is set at the higher rate, the update is given by:
if (highRateInput.read(highRateData,false) == RTT::NewData) // If there is a new data @250Hz
{
if (lowRateInput.read(lowRateData,false) == RTT::NewData) // If there is a new data @10Hz
{
highRateOutput.write(highRateData); // write to the output port @10Hz
}
}
In ROS, the same can be achieved as follows:
void Node::HighRateCallback(const Node::HighRateConstPtr& highRateData) // Event at highRate callback
{
// copy high rate data
data::HighRate high;
high.timeStamp = highRateData->timeStamp;
high.x = highRateData->x;
high.y = highRateData->y;
high.z = highRateData->z;
data::LowRate low;
low = lastLowRateData; // copy low rate data
Update(high, low); // call update hook
}
void Node::LowRateCallback(const Node::LowRateConstPtr& lowRateData)
{
data::LowRate res;
res.timeStamp = lowRateData->timeStamp;
res.x = lowRateData->x;
res.y = lowRateData->y;
res.z = lowRateData->z;
lastLowRateData = res;
}
void Node::Update(data::HighRate& highD, data::LowRate& lowD)
{
currentTime = lowD.timeStamp;
if (currentTime > lastTime)
{
highRateOutput.publish(highD);
}
lastTime = currentTime;
}
Originally posted by Roboticist on ROS Answers with karma: 1 on 2015-07-23
Post score: 0