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

Transform Listener Problem

asked 2016-11-27 15:27:59 -0500

MattMalt gravatar image

Hi I'm new to ROS and am trying to transform a point from the /odom frame to the /map frame. Every time I run the package I get the following error:

Invalid argument passed to lookupTransform argument source_frame in tf2 frame_ids cannot be empty

My code is detailed below:

geometry_msgs::PointStamped point1;
   geometry_msgs::PointStamped point2;
   std::string frame1 = "/odom"; 
   std::string frame2 = "/map";

void getPoseCallback(const geometry_msgs::Pose msg)

{
   point1.point.x = msg.position.x;
   point1.point.y = msg.position.y;
   point1.point.z = 0;
   point1.header.frame_id = frame1.c_str();
}

int main(int argc, char** argv)
{  
  ros::init(argc, argv, "tf_listener");

  ros::NodeHandle node;

  ros::Publisher pose = node.advertise<geometry_msgs::PointStamped>("odom_abs", 10);
  ros::Subscriber getPose = node.subscribe("/odom", 1000, getPoseCallback);
  tf::TransformListener listener;

      ros::Rate rate(10.0);

  point2.header.frame_id = frame2.c_str();

  while (node.ok())
  {
    try
    {
        listener.waitForTransform("/map","/odom",ros::Time::now(), ros::Duration(3.0));
        listener.transformPoint("/map", point1,point2);


       }
        catch (tf::TransformException &ex)
        {
      ROS_ERROR("%s",ex.what());
      ros::Duration(1.0).sleep();
      continue;
    }

    pose.publish(point2);



        ros::spin();
        rate.sleep();
      }

  return 0;
};

Checking with the class reference for the transform_listener, I can't find any error in the arguments.

edit retag flag offensive close merge delete

Comments

Just curious:

point1.header.frame_id = frame1.c_str();

why the detour via c_str()? Both header.frame_id and frame1 are std::strings.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-28 02:11:28 -0500 )edit

Ah I see, I saw an example online using c_str() and assumed that I had to use it. Thanks for pointing that out for future reference though!

MattMalt gravatar image MattMalt  ( 2016-11-28 12:16:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-29 01:21:41 -0500

NEngelhard gravatar image

updated 2016-11-29 01:23:14 -0500

The error message is quite accurate "Invalid argument passed to lookupTransform argument source_frame in tf2 frame_ids cannot be empty"

The target-frame of transformPoint is "/map", the source_frame is the frame_id of the second argument (namely point1). You create the subscriber that fills the frame, but you do not check if this callback was triggered. Just wait for getPoseCallback and you should be good to go. (You could put the whole transformation and publishing part into the callback)

point2.header.frame_id = frame2.c_str();

This is not needed. The frame_id of the output object is set automatically to the given target_frame.

edit flag offensive delete link more

Comments

Thanks for the reply! Yes, the error has stopped appearing.

MattMalt gravatar image MattMalt  ( 2016-11-30 04:53:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-27 15:27:59 -0500

Seen: 902 times

Last updated: Nov 29 '16