@@ -218,7 +218,7 @@ def pick_up_item(self, request, response):
218
218
response .message = f"Robot '{ request .robot_id } ' is already holding an item"
219
219
else :
220
220
for item_id , item in self .items .items ():
221
- self .get_logger ().info (f"Item '{ item_id } ': { item } " )
221
+ # self.get_logger().info(f"Item '{item_id}': {item}")
222
222
223
223
# Collects item if any is close enough.
224
224
if math .dist ((robot .x , robot .y ), (item .x , item .y )) < DISTANCE :
@@ -234,7 +234,7 @@ def pick_up_item(self, request, response):
234
234
235
235
return response
236
236
237
- def offload_item (self , request , response ):
237
+ async def offload_item (self , request , response ):
238
238
'''
239
239
Offloads an item held by the robot_id passed in the request message.
240
240
The 'success' field of response is set to True if offloading has succeeded, and otherwise
@@ -265,9 +265,8 @@ def offload_item(self, request, response):
265
265
pose .position .z = 0.0
266
266
267
267
# Use reference frame of the robot
268
- future = self .set_entity_state (robot .item_held , request .robot_id , pose )
269
- self .executor .spin_until_future_complete (future )
270
-
268
+ await self .set_entity_state (robot .item_held , request .robot_id , pose )
269
+
271
270
# We drop it on the floor if we are in a non-zone
272
271
response .success = True
273
272
response .message = f"Item '{ robot .item_held } ' held by robot '{ request .robot_id } ' has been offloaded in the arena."
@@ -288,8 +287,7 @@ def offload_item(self, request, response):
288
287
pose .position .y = self .items [robot .item_held ].y
289
288
pose .position .z = 0.0
290
289
291
- future = self .set_entity_state (robot .item_held , 'world' , pose )
292
- self .executor .spin_until_future_complete (future )
290
+ await self .set_entity_state (robot .item_held , 'world' , pose )
293
291
294
292
robot .item_held = None
295
293
robot .previous_item_held = None
@@ -394,7 +392,6 @@ def get_model_list(self):
394
392
request = GetModelList .Request ()
395
393
return self .get_model_list_client .call_async (request )
396
394
397
-
398
395
def get_entity_state (self , name ):
399
396
400
397
while not self .get_entity_state_client .wait_for_service ():
@@ -426,7 +423,7 @@ def initialize_arena(self):
426
423
427
424
return False
428
425
429
- def control_loop (self ):
426
+ async def control_loop (self ):
430
427
431
428
if self .first_run :
432
429
self .first_run = False
@@ -465,16 +462,11 @@ def control_loop(self):
465
462
466
463
self .get_logger ().info (f'Spawning { item_id } of { colour } at ({ x :.2f} , { y :.2f} )' )
467
464
468
- future = self .spawn_item (item_id , x , y , colour )
469
- self .executor .spin_until_future_complete (future )
465
+ await self .spawn_item (item_id , x , y , colour )
470
466
471
- future = self .spawn_item ("ready" , 0.0 , 0.0 , Colour .RED , z = - 0.5 )
472
- self .executor .spin_until_future_complete (future )
467
+ await self .spawn_item ("ready" , 0.0 , 0.0 , Colour .RED , z = - 0.5 )
473
468
474
- future = self .get_model_list ()
475
- self .executor .spin_until_future_complete (future )
476
-
477
- model_list_msg = future .result ()
469
+ model_list_msg = await self .get_model_list ()
478
470
479
471
# Update position of robots.
480
472
@@ -485,10 +477,7 @@ def control_loop(self):
485
477
486
478
for robot_id , robot in self .robots .items ():
487
479
488
- future = self .get_entity_state (robot_id )
489
- self .executor .spin_until_future_complete (future )
490
-
491
- entity_state_msg = future .result ()
480
+ entity_state_msg = await self .get_entity_state (robot_id )
492
481
robot_position = entity_state_msg .state .pose .position
493
482
494
483
robot .x = round (robot_position .x , 2 )
@@ -514,8 +503,7 @@ def control_loop(self):
514
503
pose .position .y = 0.0
515
504
pose .position .z = 0.15
516
505
517
- future = self .set_entity_state (robot .item_held , robot_id , pose )
518
- self .executor .spin_until_future_complete (future )
506
+ await self .set_entity_state (robot .item_held , robot_id , pose )
519
507
520
508
# Publish item holders
521
509
item_holders = ItemHolders ()
0 commit comments