b1k / task01_picking_up_trash /code /tests /test_path_following.py
davidwdw's picture
Upload Task 00, Task 01 and Task 02 code, datasets and evaluation results (part 20)
9befad5 verified
Raw History Blame Contribute Delete
1.79 kB
import io
from types import SimpleNamespace
import numpy as np
from gpt6_b1k.path_following import follow_route, clear_line, lookahead
from gpt6_b1k.visual_navigation import VisualTrashPolicy, ObservedFloorGrid
from gpt6_b1k.sensors import planar
def test_continuous_route_goes_around_an_inflated_obstacle():
policy = VisualTrashPolicy(io.StringIO())
policy.grid = ObservedFloorGrid(size=100, resolution=.05)
policy.grid.seen_floor[:] = True
policy.grid.tall_obstacles[49:52, 45:56] = True
policy.grid.occupied[:] = policy.grid.tall_obstacles
policy.odom.pose = np.array([-1.2, 0., 0.])
cloud = np.tile([2., 0., 0.], (4, 4, 1))
policy.obs = SimpleNamespace(hold=lambda: np.zeros(23), cloud=lambda: cloud,
external=lambda points: np.ones(len(points), bool))
policy.observe = lambda: None
goal = np.array([1.2, 0., 0.])
for action in follow_route(policy, goal, lambda obs, direction: 2.):
previous = policy.odom.pose[:2].copy()
policy.steps += 1
policy.tracker.last_match = policy.steps
policy.odom.pose[:2] += planar(policy.odom.pose)[:2, :2]@action[:2]/30*.75
policy.odom.pose[2] += action[2]/30
assert clear_line(policy.grid, previous, policy.odom.pose[:2])
assert policy.steps < 700
assert np.linalg.norm(policy.odom.pose[:2]-goal[:2]) < .075
def test_lookahead_does_not_cut_an_unobserved_corner():
grid = ObservedFloorGrid(size=80, resolution=.05)
grid.seen_floor[20:25, 20:50] = True
grid.seen_floor[20:50, 45:50] = True
start, goal = grid.xy([22, 30]), grid.xy([40, 47])
route = grid.route(start, goal)
target = lookahead(grid, route, start, goal, distance=2.)
assert clear_line(grid, start, target)
assert not clear_line(grid, start, goal)