15
15
from std_srvs .srv import SetBool
16
16
17
17
# Local imports
18
+ from ada_feeding_msgs .srv import ModifyCollisionObject
18
19
from ada_feeding .behaviors .moveit2 import (
19
- ModifyCollisionObject ,
20
- ModifyCollisionObjectOperation ,
21
20
ToggleCollisionObject ,
22
21
)
23
22
from .retry_call_ros_service import retry_call_ros_service
@@ -127,9 +126,49 @@ def get_toggle_watchdog_listener_behavior(
127
126
return toggle_watchdog_listener
128
127
129
128
130
- def get_add_in_front_of_wheelchair_wall_behavior (
129
+ def get_modify_collision_object_behavior (
130
+ name : str ,
131
+ object_id : str ,
132
+ add : bool ,
133
+ ) -> py_trees .behaviour .Behaviour :
134
+ """
135
+ Creates a behaviour that adds or removes a collision object.
136
+
137
+ Parameters
138
+ ----------
139
+ name: The name of the behaviour.
140
+ object_id: The ID of the collision object to add or remove.
141
+ add: Whether to add or remove the collision object.
142
+
143
+ Returns
144
+ -------
145
+ behavior: The behaviour that adds or removes the collision object.
146
+ """
147
+ modify_collision_object_key_response = Blackboard .separator .join ([name , "response" ])
148
+ return retry_call_ros_service (
149
+ name = name ,
150
+ service_type = ModifyCollisionObject ,
151
+ service_name = "~/modify_collision_object" ,
152
+ key_request = None ,
153
+ request = ModifyCollisionObject .Request (
154
+ operation = ModifyCollisionObject .Request .ADD
155
+ if add
156
+ else ModifyCollisionObject .Request .REMOVE ,
157
+ object_id = object_id ,
158
+ ),
159
+ key_response = modify_collision_object_key_response ,
160
+ response_checks = [
161
+ py_trees .common .ComparisonExpression (
162
+ variable = modify_collision_object_key_response + ".success" ,
163
+ value = True ,
164
+ operator = operator .eq ,
165
+ )
166
+ ],
167
+ )
168
+
169
+
170
+ def get_add_in_front_of_face_wall_behavior (
131
171
name : str ,
132
- collision_object_id : str ,
133
172
):
134
173
"""
135
174
Creates a behavior that adds a collision wall between the staging pose and the user,
@@ -138,35 +177,20 @@ def get_add_in_front_of_wheelchair_wall_behavior(
138
177
Parameters
139
178
----------
140
179
name: The name of the behaviour.
141
- collision_object_id: The ID of the collision object to add.
142
180
143
181
Returns
144
182
-------
145
183
behavior: The behaviour that adds the collision wall.
146
184
"""
147
- # Create the behavior to add a collision wall between the staging pose and the user,
148
- # to prevent the robot from moving closer to the user.
149
- return ModifyCollisionObject (
185
+ return get_modify_collision_object_behavior (
150
186
name = name ,
151
- inputs = {
152
- "operation" : ModifyCollisionObjectOperation .ADD ,
153
- "collision_object_id" : collision_object_id ,
154
- "collision_object_position" : (0.37 , 0.17 , 0.85 ),
155
- "collision_object_orientation" : (0.0 , 0.0 , 0.0 , 1.0 ),
156
- "prim_type" : 1 , # Box=1. See shape_msgs/SolidPrimitive.msg
157
- "dims" : [
158
- 0.65 ,
159
- 0.01 ,
160
- 0.4 ,
161
- ], # Box has 3 dims: [x, y, z]
162
- "frame_id" : "root" ,
163
- },
187
+ object_id = "in_front_of_face_wall" ,
188
+ add = True ,
164
189
)
165
190
166
191
167
- def get_remove_in_front_of_wheelchair_wall_behavior (
192
+ def get_remove_in_front_of_face_wall_behavior (
168
193
name : str ,
169
- collision_object_id : str ,
170
194
):
171
195
"""
172
196
Creates a behavior that removes the collision wall between the staging pose and the user.
@@ -179,13 +203,8 @@ def get_remove_in_front_of_wheelchair_wall_behavior(
179
203
-------
180
204
behavior: The behaviour that removes the collision wall.
181
205
"""
182
- # Create the behavior to remove the collision wall between the staging pose and the user.
183
- remove_in_front_of_wheelchair_wall = ModifyCollisionObject (
206
+ return get_modify_collision_object_behavior (
184
207
name = name ,
185
- inputs = {
186
- "operation" : ModifyCollisionObjectOperation .REMOVE ,
187
- "collision_object_id" : collision_object_id ,
188
- },
208
+ object_id = "in_front_of_face_wall" ,
209
+ add = False ,
189
210
)
190
-
191
- return remove_in_front_of_wheelchair_wall
0 commit comments