Skip to content

Commit e0abe02

Browse files
committed
Share TF listener across ED
1 parent 0905671 commit e0abe02

File tree

7 files changed

+61
-28
lines changed

7 files changed

+61
-28
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ find_package(catkin REQUIRED COMPONENTS
1919
rgbd_msgs
2020
rosconsole_bridge
2121
roscpp
22+
tf2_ros
2223
tue_config
2324
tue_filesystem
2425
tue_serialization
@@ -35,7 +36,7 @@ find_package(TinyXML2 REQUIRED)
3536
catkin_package(
3637
INCLUDE_DIRS include
3738
LIBRARIES ${PROJECT_NAME}_core ${PROJECT_NAME}_io ${PROJECT_NAME}_server ${PROJECT_NAME}_hello_world_plugin ${PROJECT_NAME}_custom_properties_plugin
38-
CATKIN_DEPENDS code_profiler ${PROJECT_NAME}_msgs geolib2 pluginlib rgbd rgbd_msgs roscpp tue_config tue_filesystem tue_serialization
39+
CATKIN_DEPENDS code_profiler ${PROJECT_NAME}_msgs geolib2 pluginlib rgbd rgbd_msgs roscpp tf2_ros tue_config tue_filesystem tue_serialization
3940
DEPENDS OpenCV PCL
4041
)
4142

@@ -129,10 +130,9 @@ target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_core ${PROJECT_NAME}_io ${
129130

130131
find_package(tf2 REQUIRED)
131132
find_package(tf2_geometry_msgs REQUIRED)
132-
find_package(tf2_ros REQUIRED)
133133
add_library(${PROJECT_NAME}_tf_publisher_plugin plugins/tf_publisher_plugin.cpp)
134-
target_include_directories(${PROJECT_NAME}_tf_publisher_plugin BEFORE PRIVATE SYSTEM ${tf2_geometry_msgs_INCLUDE_DIRS} ${tf2_INCLUDE_DIRS} ${tf2_ros_INCLUDE_DIRS})
135-
target_link_libraries(${PROJECT_NAME}_tf_publisher_plugin ${tf2_geometry_msgs_LIBRARIES} ${tf2_LIBRARIES} ${tf2_ros_LIBRARIES} ${catkin_LIBRARIES})
134+
target_include_directories(${PROJECT_NAME}_tf_publisher_plugin BEFORE PRIVATE SYSTEM ${tf2_geometry_msgs_INCLUDE_DIRS} ${tf2_INCLUDE_DIRS})
135+
target_link_libraries(${PROJECT_NAME}_tf_publisher_plugin ${tf2_geometry_msgs_LIBRARIES} ${tf2_LIBRARIES} ${catkin_LIBRARIES})
136136

137137
find_package(kdl_parser REQUIRED)
138138
add_library(${PROJECT_NAME}_robot_plugin plugins/robot_plugin.cpp)

include/ed/plugin.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
#include <tue/config/configuration.h>
88

9+
#include "ed/types.h"
910
#include "ed/init_data.h"
1011

12+
#include <tf2_ros/buffer.h>
13+
1114
#include <vector>
1215

13-
namespace ed {
1416

15-
class WorldModel;
16-
class UpdateRequest;
17+
namespace ed {
1718

1819
struct PluginInput
1920
{
@@ -44,6 +45,10 @@ class Plugin
4445

4546
const std::string& name() const { return name_; }
4647

48+
protected:
49+
50+
TFBufferConstPtr tf_buffer_;
51+
4752
private:
4853

4954
std::string name_;

include/ed/plugin_container.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PluginContainer
2727

2828
public:
2929

30-
PluginContainer();
30+
PluginContainer(const ed::TFBufferConstPtr& tf_buffer_);
3131

3232
virtual ~PluginContainer();
3333

@@ -111,6 +111,8 @@ class PluginContainer
111111

112112
WorldModelConstPtr world_current_;
113113

114+
TFBufferConstPtr tf_buffer_;
115+
114116
std::unique_ptr<ed::LoopUsageStatus> loop_usage_status_;
115117

116118
bool step();

include/ed/server.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@
33

44
#include "ed/types.h"
55

6-
#include <diagnostic_updater/diagnostic_updater.h>
6+
#include "ed/property_key_db.h"
7+
#include <ed/models/model_loader.h>
78

8-
#include <tf/transform_listener.h>
99

10-
#include <ros/publisher.h>
10+
#include <diagnostic_updater/diagnostic_updater.h>
1111

12-
#include <ed/models/model_loader.h>
12+
#include <ros/publisher.h>
1313

14-
#include "ed/property_key_db.h"
14+
#include <tf2_ros/buffer.h>
1515

1616
#include "tue/config/configuration.h"
1717

1818
#include <map>
1919
#include <queue>
2020
#include <vector>
2121

22+
namespace tf2_ros
23+
{
24+
25+
class TransformListener;
26+
27+
}
28+
2229
namespace ed
2330
{
2431

@@ -89,6 +96,10 @@ class Server
8996
//! Profiling
9097
diagnostic_updater::Updater updater_;
9198
ros::Publisher pub_stats_;
99+
100+
TFBufferPtr tf_buffer_;
101+
TFBufferConstPtr tf_buffer_const_;
102+
ed::shared_ptr<tf2_ros::TransformListener> tf_listener_;
92103
};
93104

94105
}

include/ed/types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include <limits>
1010
#include <stdint.h>
1111

12+
namespace tf2_ros {
13+
14+
class Buffer;
15+
16+
}
17+
1218
namespace ed
1319
{
1420

@@ -73,6 +79,10 @@ class UUID;
7379

7480
typedef std::string TYPE;
7581

82+
// tf2_ros::Buffer
83+
typedef shared_ptr<tf2_ros::Buffer> TFBufferPtr;
84+
typedef shared_ptr<const tf2_ros::Buffer> TFBufferConstPtr;
85+
7686
}
7787

7888
#endif

src/plugin_container.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "ed/plugin_container.h"
22

33
#include <ed/error_context.h>
4-
#include <ed/plugin.h>
4+
#include "ed/init_data.h"
5+
#include "ed/plugin.h"
56

67
#include <pluginlib/class_loader.h>
78

@@ -12,8 +13,9 @@ namespace ed
1213

1314
// --------------------------------------------------------------------------------
1415

15-
PluginContainer::PluginContainer()
16-
: class_loader_(nullptr), request_stop_(false), is_running_(false), cycle_duration_(0.1), loop_frequency_(10), loop_frequency_max_(11), loop_frequency_min_(9), step_finished_(true), t_last_update_(0),
16+
PluginContainer::PluginContainer(const TFBufferConstPtr& tf_buffer)
17+
: class_loader_(nullptr), request_stop_(false), is_running_(false), cycle_duration_(0.1), loop_frequency_(10),
18+
loop_frequency_max_(11), loop_frequency_min_(9), step_finished_(true), t_last_update_(0), tf_buffer_(tf_buffer),
1719
loop_usage_status_(nullptr)
1820
{
1921
}
@@ -51,6 +53,7 @@ PluginPtr PluginContainer::loadPlugin(const std::string& plugin_name, const std:
5153
{
5254
name_ = plugin_name;
5355
plugin_->name_ = plugin_name;
56+
plugin_->tf_buffer_ = tf_buffer_;
5457

5558
configure(init, false);
5659

src/server.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
#include "ed/server.h"
22

33
#include "ed/entity.h"
4+
#include "ed/error_context.h"
45
#include "ed/measurement.h"
5-
6-
#include <geolib/Box.h>
6+
#include "ed/plugin.h"
7+
#include "ed/plugin_container.h"
8+
#include "ed/types.h"
9+
#include "ed/world_model.h"
710

811
// Storing measurements to disk
912
#include "ed/io/filesystem/write.h"
1013

11-
#include <tue/filesystem/path.h>
12-
13-
#include "ed/plugin.h"
14-
#include "ed/plugin_container.h"
15-
#include "ed/world_model.h"
14+
#include "ed/serialization/serialization.h"
1615

16+
#include <tue/config/writer.h>
1717
#include <tue/config/loaders/yaml.h>
1818

19-
#include <boost/make_shared.hpp>
19+
#include <tue/filesystem/path.h>
2020

2121
#include <std_msgs/String.h>
2222

23-
#include "ed/serialization/serialization.h"
24-
#include <tue/config/writer.h>
25-
26-
#include "ed/error_context.h"
23+
#include <tf2_ros/buffer.h>
24+
#include <tf2_ros/transform_listener.h>
2725

2826
namespace ed
2927
{
@@ -33,6 +31,10 @@ namespace ed
3331
Server::Server() : world_model_(new WorldModel(&property_key_db_))
3432
{
3533
updater_.setHardwareID("none");
34+
35+
tf_buffer_ = ed::make_shared<tf2_ros::Buffer>();
36+
tf_buffer_const_ = ed::const_pointer_cast<const tf2_ros::Buffer>(tf_buffer_);
37+
tf_listener_ = ed::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
3638
}
3739

3840
// ----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)