How to make a copy of all data contained within a ROS topic message?
Hello, I'm trying to write a node that subscribes to the kinect data from multiple turtlebots, then concatenates/averages the data, and republishes the resulting single data stream to rviz as part of a larger program intended to map a room cooperatively with multiple turtlebots at once.
I've already written a node that subscribes to kinect data from multiple turtlebots, but now am struggling with the republishing. I have several callback methods that are call every time a message is published on a certain topic, and within each of these callback methods, I would like to copy all the data contained within the message to a temporary global variable which can then be accessed in the main class. However, the only way I can think of to do this is to go through and manually copy each individual piece of data from the message to the global variable. Is there a simpler way to do this? For example, is there a command that I could use to create a copy of each message within each callback function, which I could call and then just modify whatever parts I wanted to modify, instead of having to manually copy each data piece?
Edit: Yes, I am using C++. Here is the odometry (location/heading) callback function. RIght now it just prints out the relevant data:
void OdomCallback(const nav_msgs::Odometry locator)
{
ROS_INFO("Position: %f,%f", locator.pose.pose.position.x,locator.pose.pose.position.y);
ROS_INFO("Heading: linear:%f,angular:%f", locator.twist.twist.linear.x,locator.twist.twist.angular.z);
}
So you're saying that in order to copy the message I would add in a line like this? nav_msgs::Odometry globalLocationVariable=locator;