rosros 0.2.5
Simple unified interface to ROS1 / ROS2 Python API
Loading...
Searching...
No Matches
callback_groups.py
Go to the documentation of this file.
1"""
2Partial stand-in for `rclpy.callback_groups` in ROS1, providing `CallbackGroup` classes.
3
4------------------------------------------------------------------------------
5This file is part of rosros - simple unified interface to ROS1 / ROS2.
6Released under the BSD License.
7
8@author Erki Suurjaak
9@created 12.06.2022
10@modified 12.06.2022
11------------------------------------------------------------------------------
12"""
13## @namespace rosros.rclify.callback_groups
14import weakref
15
16
17class CallbackGroup:
18 """
19 The base class for a callback group.
20
21 A callback group controls when callbacks are allowed to be executed.
22
23 This class should not be instantiated.
24 Instead, classes should extend it and implement :meth:`can_execute`,
25 :meth:`beginning_execution`, and :meth:`ending_execution`.
26 """
27
28 def __init__(self):
29 self.entities = set()
30
31 def add_entity(self, entity):
32 """Adds an entity to this group."""
33 self.entities.add(weakref.ref(entity))
34
35 def has_entity(self, entity):
36 """Returns whether an entity has been added to this group."""
37 return weakref.ref(entity) in self.entities
38
39 def can_execute(self, entity):
40 """Returns True (ROS2 compatibility stand-in)."""
41 return True
42
43 def beginning_execution(self, entity):
44 """Returns True (ROS2 compatibility stand-in)."""
45 return True
46
47 def ending_execution(self, entity):
48 """Does nothing (ROS2 compatibility stand-in)."""
49
50
51class MutuallyExclusiveCallbackGroup(CallbackGroup):
52 """API stand-in for ROS2 compatibility."""
53
54class ReentrantCallbackGroup(CallbackGroup):
55 """API stand-in for ROS2 compatibility."""
56
57
58__all__ = ["CallbackGroup", "MutuallyExclusiveCallbackGroup", "ReentrantCallbackGroup"]
add_entity(self, entity)
Adds an entity to this group.
ending_execution(self, entity)
Does nothing (ROS2 compatibility stand-in).
has_entity(self, entity)
Returns whether an entity has been added to this group.
can_execute(self, entity)
Returns True (ROS2 compatibility stand-in).
beginning_execution(self, entity)
Returns True (ROS2 compatibility stand-in).