Skip to content

Commit e0bc6fd

Browse files
authored
Merge pull request #7 from UoY-RoboStar/assessment-fix-1
Assessment fix 1
2 parents 8075a07 + 2114812 commit e0bc6fd

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

assessment/assessment/item_manager.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def pick_up_item(self, request, response):
218218
response.message = f"Robot '{request.robot_id}' is already holding an item"
219219
else:
220220
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}")
222222

223223
# Collects item if any is close enough.
224224
if math.dist((robot.x, robot.y), (item.x, item.y)) < DISTANCE:
@@ -234,7 +234,7 @@ def pick_up_item(self, request, response):
234234

235235
return response
236236

237-
def offload_item(self, request, response):
237+
async def offload_item(self, request, response):
238238
'''
239239
Offloads an item held by the robot_id passed in the request message.
240240
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):
265265
pose.position.z = 0.0
266266

267267
# 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+
271270
# We drop it on the floor if we are in a non-zone
272271
response.success = True
273272
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):
288287
pose.position.y = self.items[robot.item_held].y
289288
pose.position.z = 0.0
290289

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)
293291

294292
robot.item_held = None
295293
robot.previous_item_held = None
@@ -394,7 +392,6 @@ def get_model_list(self):
394392
request = GetModelList.Request()
395393
return self.get_model_list_client.call_async(request)
396394

397-
398395
def get_entity_state(self, name):
399396

400397
while not self.get_entity_state_client.wait_for_service():
@@ -426,7 +423,7 @@ def initialize_arena(self):
426423

427424
return False
428425

429-
def control_loop(self):
426+
async def control_loop(self):
430427

431428
if self.first_run:
432429
self.first_run = False
@@ -465,16 +462,11 @@ def control_loop(self):
465462

466463
self.get_logger().info(f'Spawning {item_id} of {colour} at ({x:.2f}, {y:.2f})')
467464

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)
470466

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)
473468

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()
478470

479471
# Update position of robots.
480472

@@ -485,10 +477,7 @@ def control_loop(self):
485477

486478
for robot_id, robot in self.robots.items():
487479

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)
492481
robot_position = entity_state_msg.state.pose.position
493482

494483
robot.x = round(robot_position.x, 2)
@@ -514,8 +503,7 @@ def control_loop(self):
514503
pose.position.y = 0.0
515504
pose.position.z = 0.15
516505

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)
519507

520508
# Publish item holders
521509
item_holders = ItemHolders()

assessment/assessment/zone_sensor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def image_callback(self, data):
9090

9191
# For image segmentation, sets up masks in HSV colour space.
9292
cyan_mask = cv2.inRange(hsv, np.array([self.cyan[0][0][0], 100, 20]), np.array([self.cyan[0][0][0], 255,255]))
93-
purple_mask = cv2.inRange(hsv, np.array([self.purple[0][0][0], 100, 20]), np.array([self.purple[0][0][0], 255,255]))
93+
purple_mask = cv2.inRange(hsv, np.array([self.purple[0][0][0], 100, 20]), np.array([self.purple[0][0][0]+1, 255,255]))
9494
green_mask = cv2.inRange(hsv, np.array([self.green[0][0][0], 100, 20]), np.array([self.green[0][0][0], 255,255]))
9595
pink_mask = cv2.inRange(hsv, np.array([self.pink[0][0][0]-3, 100, 20]), np.array([self.pink[0][0][0], 255,255]))
9696

@@ -185,4 +185,4 @@ def main(args=None):
185185

186186

187187
if __name__ == '__main__':
188-
main()
188+
main()

0 commit comments

Comments
 (0)