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

Revision history [back]

click to hide/show revision 1
initial version

The problem was that when running Gazebo (and it being VERY slow due to having walls -- I have a separate bug Trac on that that hasn't been answered), TF comes in much slower than the program executes, so wiatForTransform bombs out.

I got around this by using canTransform with Time::Now(). Still another corner case that the next (few) incoming messages can have times prior to the now() time that passes canTransform, sop that must be checked.

Example code in callback that works:

if (starting) {
  while (!tf_.canTransform(message.header.frame_id, "/base_footprint",ros::Time::now())) {
ROS_WARN("Waiting on transform from %s to %s to become available before running", message.header.frame_id.c_str(), "/base_footprint");
usleep(100000);
  }

  start_time = ros::Time::now();
  starting = false;
  ROS_INFO("Started");
  return;
}

// Needed for slow simulation laser scans.
  if (message.header.stamp < start_time) {
ROS_WARN("Got a stale pointcloud");
return;
  }

The problem was that when running Gazebo (and it being VERY slow due to having walls -- I have a separate bug Trac on that that hasn't been answered), TF comes in much slower than the program executes, so wiatForTransform waitForTransform bombs out.out (cannot catch exception because something catches it first and quits).

I got can get around this by using canTransform with Time::Now(). canTransform() and throwing out the scan is that fails, or catching the TransformException on the transformPoint() call directly. Still another corner case that the next (few) incoming messages can have times prior to the now() time that passes canTransform, sop that must be checked.That is easiest.

Example code in callback that works:

if (starting) {
  while (!tf_.canTransform(message.header.frame_id, "/base_footprint",ros::Time::now())) {
ROS_WARN("Waiting on transform from %s to %s to become available before running", message.header.frame_id.c_str(), "/base_footprint");
usleep(100000);
  }

  start_time = ros::Time::now();
  starting = false;
  ROS_INFO("Started");
  return;
}

// Needed for slow simulation laser scans.
  if (message.header.stamp < start_time) {
ROS_WARN("Got a stale pointcloud");
return;
  }