Skip to content

Commit 5b2d347

Browse files
(laser) reduce tf log/migrate to tf2 (#59)
2 parents b490827 + 98ed9aa commit 5b2d347

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

ed_sensor_integration/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ find_package(catkin REQUIRED COMPONENTS
77
geolib2
88
image_geometry
99
sensor_msgs
10+
tf2
11+
tf2_ros
1012
tue_config
1113
tue_filesystem
1214
visualization_msgs

ed_sensor_integration/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<depend>geolib2</depend>
1919
<depend>image_geometry</depend>
2020
<depend>sensor_msgs</depend>
21+
<depend>tf2</depend>
22+
<depend>tf2_ros</depend>
2123
<depend>tue_config</depend>
2224
<depend>tue_filesystem</depend>
2325
<depend>visualization_msgs</depend>

ed_sensor_integration/src/laser/laser_plugin.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include <ed/update_request.h>
1010
#include <ed/world_model.h>
1111

12-
#include <geolib/ros/tf_conversions.h>
12+
#include <geolib/ros/msg_conversions.h>
1313
#include <geolib/Shape.h>
1414

15-
#include <tue/profiling/timer.h>
16-
1715
#include <opencv2/imgproc/imgproc.hpp>
1816

1917
#include <ros/console.h>
2018
#include <ros/node_handle.h>
2119

20+
#include "tf2/transform_datatypes.h"
21+
2222
#include <iostream>
2323

2424

@@ -45,13 +45,12 @@ void lasermsgToSensorRanges(const sensor_msgs::LaserScan::ConstPtr& scan, std::v
4545
}
4646
}
4747

48-
LaserPlugin::LaserPlugin() : tf_listener_(0)
48+
LaserPlugin::LaserPlugin() : tf_buffer_(), tf_listener_(nullptr)
4949
{
5050
}
5151

5252
LaserPlugin::~LaserPlugin()
5353
{
54-
delete tf_listener_;
5554
}
5655

5756
void LaserPlugin::initialize(ed::InitData& init)
@@ -71,7 +70,8 @@ void LaserPlugin::initialize(ed::InitData& init)
7170
// Communication
7271
sub_scan_ = nh.subscribe<sensor_msgs::LaserScan>(laser_topic, 3, &LaserPlugin::scanCallback, this);
7372

74-
tf_listener_ = new tf::TransformListener;
73+
if (!tf_listener_)
74+
tf_listener_ = std::make_unique<tf2_ros::TransformListener>(tf_buffer_);
7575

7676
//pose_cache.clear();
7777
}
@@ -89,24 +89,25 @@ void LaserPlugin::process(const ed::WorldModel& world, ed::UpdateRequest& req)
8989

9090
try
9191
{
92-
tf::StampedTransform t_sensor_pose;
93-
tf_listener_->lookupTransform("map", scan->header.frame_id, scan->header.stamp, t_sensor_pose);
92+
geometry_msgs::TransformStamped gm_sensor_pose;
93+
gm_sensor_pose = tf_buffer_.lookupTransform("map", scan->header.frame_id, scan->header.stamp);
9494
scan_buffer_.pop();
9595
geo::Pose3D sensor_pose;
96-
geo::convert(t_sensor_pose, sensor_pose);
96+
geo::convert(gm_sensor_pose.transform, sensor_pose);
9797
update(world, scan, sensor_pose, req);
9898
}
99-
catch(tf::ExtrapolationException& ex)
99+
catch(tf2::ExtrapolationException& ex)
100100
{
101-
ROS_WARN_STREAM_DELAYED_THROTTLE(10, "ED Laserplugin: " << ex.what());
101+
ROS_WARN_STREAM_DELAYED_THROTTLE(60, "ED Laserplugin: " << ex.what());
102+
ROS_DEBUG_STREAM("ED Laserplugin: " << ex.what());
102103
try
103104
{
104105
// Now we have to check if the error was an interpolation or extrapolation error
105106
// (i.e., the scan is too old or too new, respectively)
106-
tf::StampedTransform latest_transform;
107-
tf_listener_->lookupTransform("map", scan->header.frame_id, ros::Time(0), latest_transform);
107+
geometry_msgs::TransformStamped latest_transform;
108+
latest_transform = tf_buffer_.lookupTransform("map", scan->header.frame_id, ros::Time(0));
108109

109-
if (scan_buffer_.front()->header.stamp > latest_transform.stamp_)
110+
if (scan_buffer_.front()->header.stamp > latest_transform.header.stamp)
110111
{
111112
// Scan is too new
112113
break;
@@ -117,12 +118,12 @@ void LaserPlugin::process(const ed::WorldModel& world, ed::UpdateRequest& req)
117118
scan_buffer_.pop();
118119
}
119120
}
120-
catch(tf::TransformException& exc)
121+
catch(tf2::TransformException& exc)
121122
{
122123
scan_buffer_.pop();
123124
}
124125
}
125-
catch(tf::TransformException& exc)
126+
catch(tf2::TransformException& exc)
126127
{
127128
ROS_ERROR_STREAM_DELAYED_THROTTLE(10, "ED Laserplugin: " << exc.what());
128129
scan_buffer_.pop();
@@ -133,9 +134,6 @@ void LaserPlugin::process(const ed::WorldModel& world, ed::UpdateRequest& req)
133134
void LaserPlugin::update(const ed::WorldModel& world, const sensor_msgs::LaserScan::ConstPtr& scan,
134135
const geo::Pose3D& sensor_pose, ed::UpdateRequest& req)
135136
{
136-
tue::Timer t_total;
137-
t_total.start();
138-
139137
// - - - - - - - - - - - - - - - - - -
140138
// Update laser model
141139

ed_sensor_integration/src/laser/laser_plugin.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
#include <ros/subscriber.h>
1212
#include <ros/callback_queue.h>
13-
#include <tf/transform_listener.h>
13+
#include <tf2_ros/buffer.h>
14+
#include <tf2_ros/transform_listener.h>
1415
#include <sensor_msgs/LaserScan.h>
1516

1617
#include <queue>
1718
#include <map>
19+
#include <memory>
1820

1921
class LaserPlugin : public ed::Plugin
2022
{
@@ -38,14 +40,15 @@ class LaserPlugin : public ed::Plugin
3840

3941
std::queue<sensor_msgs::LaserScan::ConstPtr> scan_buffer_;
4042

41-
tf::TransformListener* tf_listener_;
43+
tf2_ros::Buffer tf_buffer_;
44+
std::unique_ptr<tf2_ros::TransformListener> tf_listener_;
4245

4346
LaserUpdater updater_;
4447

4548
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg);
4649

4750
/**
48-
* @brief update update the worldmodel based on a novel laserscan message.
51+
* @brief Update the worldmodel based on a novel laserscan message.
4952
*
5053
* @param[in] world worldmodel to be updated
5154
* @param[in] scan laserscan message

0 commit comments

Comments
 (0)