Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Tf tutorial Cpp Question

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...?

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);

  return 0;