Update warehouse digital twin and robot fleet optimization
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""Unit tests for multi-robot collision avoidance, footprint clearance, and headway enforcement."""
|
||||
|
||||
import pytest
|
||||
from warehouse_twin.domain.warehouse import Position3D
|
||||
from warehouse_twin.routing.reservations import TimeSpaceReservationGrid
|
||||
|
||||
|
||||
def test_footprint_aware_spatial_clearance_conflict():
|
||||
"""Verify two robots attempting to reserve nearby nodes within footprint distance trigger conflict."""
|
||||
# Define node positions with wp_1 at (10.0, 10.0) and wp_2 at (10.5, 10.0) -> distance 0.5m
|
||||
node_positions = {
|
||||
"wp_1": Position3D(10.0, 10.0, 0.0),
|
||||
"wp_2": Position3D(10.5, 10.0, 0.0),
|
||||
"wp_far": Position3D(15.0, 10.0, 0.0),
|
||||
}
|
||||
|
||||
grid = TimeSpaceReservationGrid(
|
||||
safety_buffer_seconds=1.0,
|
||||
node_positions=node_positions,
|
||||
robot_footprint_radius=0.5, # 2 * 0.5 = 1.0m min safe distance
|
||||
)
|
||||
|
||||
# Robot 1 reserves wp_1 from t=10.0 to t=15.0
|
||||
r1 = grid.reserve_node("wp_1", t_start=10.0, t_end=15.0, robot_id="amr_01")
|
||||
assert r1 is True
|
||||
|
||||
# Robot 2 attempts to reserve wp_2 (0.5m away, < 1.0m safe distance) at overlapping time [11.0, 14.0]
|
||||
is_free_nearby, conflict_id = grid.is_node_free("wp_2", t_start=11.0, t_end=14.0, ignore_robot_id="amr_02")
|
||||
assert is_free_nearby is False
|
||||
assert conflict_id == "amr_01"
|
||||
|
||||
# Robot 2 attempts to reserve wp_far (5.0m away, > 1.0m) at overlapping time -> Free!
|
||||
is_free_far, _ = grid.is_node_free("wp_far", t_start=11.0, t_end=14.0, ignore_robot_id="amr_02")
|
||||
assert is_free_far is True
|
||||
|
||||
|
||||
def test_exclusive_berth_occupancy():
|
||||
"""Verify only one robot can reserve a charging berth or picking point at a time."""
|
||||
grid = TimeSpaceReservationGrid(safety_buffer_seconds=1.0)
|
||||
|
||||
# Robot 1 reserves charge bay 1
|
||||
assert grid.reserve_node("charge_bay_1", 20.0, 50.0, robot_id="amr_01") is True
|
||||
|
||||
# Robot 2 requests same berth during charging window -> Rejected
|
||||
is_free, conflict_id = grid.is_node_free("charge_bay_1", 30.0, 60.0, ignore_robot_id="amr_02")
|
||||
assert is_free is False
|
||||
assert conflict_id == "amr_01"
|
||||
|
||||
# Robot 2 requests berth after Robot 1 completes + safety buffer [52.0, 80.0] -> Approved
|
||||
is_free_after, _ = grid.is_node_free("charge_bay_1", 52.0, 80.0, ignore_robot_id="amr_02")
|
||||
assert is_free_after is True
|
||||
|
||||
|
||||
def test_reservation_release_on_task_finish_or_reassignment():
|
||||
"""Verify releasing reservations for a robot immediately frees the slot for other fleet members."""
|
||||
grid = TimeSpaceReservationGrid(safety_buffer_seconds=1.0)
|
||||
|
||||
# Robot 1 reserves nodes wp_a, wp_b, wp_c
|
||||
grid.reserve_node("wp_a", 10.0, 15.0, robot_id="amr_01")
|
||||
grid.reserve_node("wp_b", 15.0, 20.0, robot_id="amr_01")
|
||||
|
||||
# Robot 2 is blocked at wp_a
|
||||
assert grid.is_node_free("wp_a", 11.0, 14.0, ignore_robot_id="amr_02")[0] is False
|
||||
|
||||
# Robot 1 cancels task / aborts: release reservations
|
||||
released = grid.release_reservations_for_robot("amr_01")
|
||||
assert released == 2
|
||||
|
||||
# Now wp_a is immediately available for Robot 2
|
||||
assert grid.is_node_free("wp_a", 11.0, 14.0, ignore_robot_id="amr_02")[0] is True
|
||||
Reference in New Issue
Block a user