Skip to content

Commit 5c1ed9a

Browse files
committed
Move topic advertising to initialization phase
1 parent 9968bab commit 5c1ed9a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/compas_fab/backends/ros/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ def __init__(self, host='localhost', port=9090, is_secure=False, planner_backend
8181
planner_backend_type = PLANNER_BACKENDS[planner_backend]
8282
self.__class__ = type('RosClient_' + planner_backend_type.__name__, (planner_backend_type, RosClient), {})
8383

84+
8485
def __enter__(self):
8586
self.run()
8687
self.connect()
88+
89+
# Planners usually need to initialize/advertise topics and/or services
90+
self.init_planner()
91+
8792
return self
8893

8994
def __exit__(self, *args):
95+
self.dispose_planner()
96+
9097
self.close()
9198

9299
def inverse_kinematics(self, frame, base_link, group,

src/compas_fab/backends/ros/planner_backend_moveit.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ class MoveItPlanner(PlannerBackend):
9292
GetPlanningSceneRequest,
9393
GetPlanningSceneResponse)
9494

95+
def init_planner(self):
96+
self.collision_object_topic = Topic(self, '/collision_object',
97+
'moveit_msgs/CollisionObject', queue_size=None)
98+
self.collision_object_topic.advertise()
99+
100+
self.attached_collision_object_topic = Topic(
101+
self, '/attached_collision_object',
102+
'moveit_msgs/AttachedCollisionObject', queue_size=None)
103+
self.attached_collision_object_topic.advertise()
104+
105+
def dispose_planner(self):
106+
self.collision_object_topic.unadvertise()
107+
self.attached_collision_object_topic.unadvertise()
108+
95109
# ==========================================================================
96110
# planning services
97111
# ==========================================================================
@@ -286,8 +300,7 @@ def append_collision_mesh(self, collision_mesh):
286300

287301
def _collision_object(self, collision_object, operation=CollisionObject.ADD):
288302
collision_object.operation = operation
289-
topic = Topic(self, '/collision_object', 'moveit_msgs/CollisionObject')
290-
topic.publish(collision_object.msg)
303+
self.collision_object_topic.publish(collision_object.msg)
291304

292305
def add_attached_collision_mesh(self, attached_collision_mesh):
293306
"""Add a collision mesh attached to the robot."""
@@ -303,6 +316,4 @@ def remove_attached_collision_mesh(self, id):
303316

304317
def _attached_collision_object(self, attached_collision_object, operation=CollisionObject.ADD):
305318
attached_collision_object.object.operation = operation
306-
topic = Topic(self, '/attached_collision_object',
307-
'moveit_msgs/AttachedCollisionObject')
308-
topic.publish(attached_collision_object.msg)
319+
self.attached_collision_object_topic.publish(attached_collision_object.msg)

0 commit comments

Comments
 (0)