Skip to content

Commit 318f6f8

Browse files
authored
Merge pull request #20 from ros-sports/feature/fast_tf_buffer
Use fast tf_buffer if available
2 parents fe34e20 + d11ba2f commit 318f6f8

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.github/workflows/build_and_test_humble.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ name: Build and Test (humble)
66
on:
77
# Triggers the workflow on push
88
push:
9-
branches: [ rolling ]
9+
branches: [ humble ]
1010

1111
# Triggers the workflow on pull requests
1212
pull_request:
13-
branches: [ rolling ]
13+
branches: [ humble ]
1414

1515
# Allows you to run this workflow manually from the Actions tab
1616
workflow_dispatch:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# RoboCup Soccer Inverse Perspective Mapping
22

3-
[![Build and Test (humble)](../../actions/workflows/build_and_test_humble.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_humble.yaml?query=branch:rolling)
3+
[![Build and Test (humble)](../../actions/workflows/build_and_test_humble.yaml/badge.svg?branch=humble)](../../actions/workflows/build_and_test_humble.yaml?query=branch:humble)
44
[![Build and Test (jazzy)](../../actions/workflows/build_and_test_jazzy.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_jazzy.yaml?query=branch:rolling)
55
[![Build and Test (rolling)](../../actions/workflows/build_and_test_rolling.yaml/badge.svg?branch=rolling)](../../actions/workflows/build_and_test_rolling.yaml?query=branch:rolling)
66

7-
This package is only available currently for ROS2 Rolling.
7+
8+
## Tip
9+
10+
Also install the [Bit-Bots TF Buffer](https:://github.com/bit-bots/bitbots_tf_buffer) to get a significant performance boost (up to a magnitude).

dependencies.repos

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ repositories:
33
type: git
44
url: https://github.com/ros-sports/ipm.git
55
version: rolling
6+
bitbots_tf_buffer:
7+
type: git
8+
url: https://github.com/bit-bots/bitbots_tf_buffer.git
9+
version: main
10+
ros2_python_extension:
11+
type: git
12+
url: https://github.com/bit-bots/ros2_python_extension.git
13+
version: main

soccer_ipm/soccer_ipm/soccer_ipm.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import rclpy
1717
from rclpy.duration import Duration
1818
from rclpy.executors import MultiThreadedExecutor
19+
from rclpy.experimental.events_executor import EventsExecutor
1920
from rclpy.node import Node
2021
from sensor_msgs.msg import CameraInfo
2122
from soccer_ipm.msgs.ball import map_ball_array
@@ -27,7 +28,13 @@
2728
from soccer_ipm.utils import catch_camera_info_not_set_error, catch_tf_timing_error
2829
import soccer_vision_2d_msgs.msg as sv2dm
2930
import soccer_vision_3d_msgs.msg as sv3dm
30-
import tf2_ros as tf2
31+
32+
try:
33+
from bitbots_tf_buffer import Buffer, TransformListener
34+
fast_tf_buffer_available = True
35+
except ImportError:
36+
from tf2_ros import Buffer, TransformListener
37+
fast_tf_buffer_available = False
3138

3239

3340
class SoccerIPM(Node):
@@ -52,8 +59,8 @@ def __init__(self) -> None:
5259
self.declare_parameter('use_distortion', False)
5360

5461
# We need to create a tf buffer
55-
self.tf_buffer = tf2.Buffer(cache_time=Duration(seconds=30.0))
56-
self.tf_listener = tf2.TransformListener(self.tf_buffer, self)
62+
self.tf_buffer = Buffer(cache_time=Duration(seconds=30.0))
63+
self.tf_listener = TransformListener(self.tf_buffer, self)
5764

5865
# Create an IPM instance
5966
self.ipm = IPM(self.tf_buffer, distortion=self.get_parameter('use_distortion').value)
@@ -218,7 +225,12 @@ def markings_sub(msg):
218225
def main(args=None):
219226
rclpy.init(args=args)
220227
node = SoccerIPM()
221-
ex = MultiThreadedExecutor(num_threads=4)
228+
# Due to the fact that the bitbots_tf_buffer handles all tf2 communication in another node
229+
# we can use the single threaded EventsExecutor without running into deadlocks.
230+
if fast_tf_buffer_available:
231+
ex = EventsExecutor()
232+
else:
233+
ex = MultiThreadedExecutor(num_threads=4)
222234
ex.add_node(node)
223235
try:
224236
ex.spin()

0 commit comments

Comments
 (0)