ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This could be a way around? Example code

#include ros/ros.h>
#include boost/thread.hpp>
#include tf/transform_broadcaster.h>
#include turtlesim/Pose.h>

tf::Transform tfA;
tf::Transform tfB;
static boost::mutex mutex;

void topicACallback(const turtlesim::PoseConstPtr& msg){
  tf::Transform transform;
  transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) );
  tf::Quaternion q;
  q.setRPY(0, 0, msg->theta);
  transform.setRotation(q);
  mutex.lock();
  tfA = transform;
  mutex.unlock();
}

void topicBCallback(const turtlesim::PoseConstPtr& msg){
  tf::Transform transform;
  transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) );
  tf::Quaternion q;
  q.setRPY(0, 0, msg->theta);
  transform.setRotation(q);
  mutex.lock();
  tfB = transform;
  mutex.unlock();
}

void timerCallback(const ros::TimerEvent& event){
  tf::Transform tfA_local,tfB_local;
  mutex.lock();
  tfA_local = tfA;
  tfB_local = tfB;
  mutex.unlock();
  ROS_INFO("doing the rest of computation");
}

int main(int argc, char** argv){
  ros::init(argc, argv, "test");
  ros::NodeHandle node;
  ros::Subscriber sub1 = node.subscribe("/turtle1/pose", 10, &topicACallback);
  ros::Subscriber sub2 = node.subscribe("/turtle2/pose", 10, &topicBCallback);
  ros::Timer timer = node.createTimer(ros::Duration(0.1),timerCallback);
  ros::spin();
  return 0;
};