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

Tf tutorial Cpp Question

asked 2013-03-10 03:15:57 -0500

Sentinal_Bias gravatar image

The following is code from the TF cpp broadcaster tutorial. As i understand you are subscribing to a turtlesim topic/pose

In the callback function you are meant to give a pointer to the message

void poseCallback(const turtlesim::PoseConstPtr& msg){

I am wondering how do we find the name of such pointers? i checked the code api namespace and the pointer isn't listed...? http://ros.org/doc/groovy/api/turtlesim/html/namespaceturtlesim.html

I also checked the header file turtlesim.h

I prefer to know how to find these things independently using the Code API or wiki documentation, but I am kind of new to ROS

#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <turtlesim/Pose.h>

std::string turtle_name;
void poseCallback(const turtlesim::PoseConstPtr& msg){
  static tf::TransformBroadcaster br;
  tf::Transform transform;
  transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0) );
  transform.setRotation( tf::Quaternion(msg->theta, 0, 0) );
  br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", turtle_name));
}

int main(int argc, char** argv){
  ros::init(argc, argv, "my_tf_broadcaster");
  if (argc != 2){ROS_ERROR("need turtle name as argument"); return -1;};
  turtle_name = argv[1];

  ros::NodeHandle node;
  ros::Subscriber sub = node.subscribe(turtle_name+"/pose", 10, &poseCallback);

  ros::spin();
  return 0;
};
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-03-10 03:22:24 -0500

dornhege gravatar image

This is not specific to the turtlesim messages. You can this for any ROS message.

Usually for message type MSG you have a MSG, MSGPtr, MSGConstPtr. You are free to use whatever fits your needs.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-10 03:15:57 -0500

Seen: 577 times

Last updated: Mar 10 '13