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

TF frame error

asked 2014-05-28 07:43:42 -0600

dreamcase gravatar image

hi, all,

I am trying to set up a simple TF tree to convert incoming odometer data. however, the listener doesn't seem picking up anything at all. the tf_monitor shows no frame either.

~$ rosrun tf tf_monitor
RESULTS: for all Frames

Frames:

All Broadcasters:

how do I make it work? here's the broadcaster code.

void OdoCallback(const nav_msgs::Odometry::ConstPtr& odom_in)
{
    ros::Time current_time = ros::Time::now();
    tf::TransformBroadcaster odom_broadcaster;
    tf::Stamped<tf::Pose> transform;
    transform.setOrigin( tf::Vector3(odom_in->pose.pose.position.x, odom_in->pose.pose.position.y, 0.0) );
    tf::Quaternion q;
    q.setRPY(odom_in->pose.pose.orientation.z, 0, 0);
    transform.setRotation(q);

    odom_broadcaster.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "/odom_frame", "/base_link"));
}
int main(int argc, char** argv)
{

  ros::init(argc, argv, "sensor_convert_node");
  ros::NodeHandle n;

  ros::Subscriber odo_sub = n.subscribe("odom", 100, OdoCallback);

  printf("setting up laser filter\r\n");
  ros::Rate loop_rate(100);

  while (ros::ok())
  {
    ros::Time start = ros::Time::now();
    ros::spinOnce();
    loop_rate.sleep();
  }

  return 0;
}

and here's the listener code

int main(int argc, char** argv){
  ros::init(argc, argv, "robot_tf_listener");
  ros::NodeHandle n;
  tf::TransformListener listener;
  ros::Rate r(50);
  while(n.ok()){
      tf::Stamped<tf::Pose> ident (tf::Transform(tf::createIdentityQuaternion(),
              tf::Vector3(0,0,0)), ros::Time(0), "/odom_frame");
      tf::Stamped<tf::Pose> odom_pose;
      try{
            listener.transformPose("/odom_frame",ident, odom_pose);
      }
      catch (tf::TransformException &ex) {
          ROS_ERROR("%s",ex.what());
          ros::Duration(1.0).sleep();
      }
      ros::spinOnce();
      r.sleep();
  }
  return 0;
}

your help is appreciated.

Ray

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-05-28 07:57:30 -0600

tfoote gravatar image

You need to make sure that your broadcaster has time to publish the transform before destructing. In general you should not construct it inside you callback. If you construct and destruct it immediately it will not have time to initialize it's connections and send the information before destructing.

edit flag offensive delete link more

Comments

you are absolutely right! thanks.

dreamcase gravatar image dreamcase  ( 2014-05-28 19:55:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-05-28 07:43:42 -0600

Seen: 594 times

Last updated: May 28 '14