0
$\begingroup$

Rosanswers logo

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

Originally posted by Sentinal_Bias on ROS Answers with karma: 418 on 2013-03-10

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2013-03-10

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.