Skip to content

Commit cb85e2c

Browse files
committed
update tests
1 parent 741f502 commit cb85e2c

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed

robot_nav/sim.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def __init__(self, world_file="robot_world.yaml", disable_plotting=False):
2626
world_file (str): Path to the world configuration YAML file.
2727
disable_plotting (bool): If True, disables rendering and plotting.
2828
"""
29-
self.env = irsim.make(world_file, disable_all_plot=disable_plotting)
29+
display = False if disable_plotting else True
30+
self.env = irsim.make(world_file, disable_all_plot=disable_plotting, display=display)
3031
robot_info = self.env.get_robot_info(0)
3132
self.robot_goal = robot_info.goal
3233

@@ -84,7 +85,7 @@ def reset(
8485
and reward-related flags and values.
8586
"""
8687
if robot_state is None:
87-
robot_state = [[random.uniform(1, 9)], [random.uniform(1, 9)], [0], [0]]
88+
robot_state = [[random.uniform(1, 9)], [random.uniform(1, 9)], [0]]
8889

8990
self.env.robot.set_state(
9091
state=np.array(robot_state),

tests/test_sim.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from robot_nav.path_planners.probabilistic_road_map import PRMPlanner
24
from robot_nav.path_planners.rrt import RRT
35
from robot_nav.sim import SIM_ENV
@@ -29,27 +31,17 @@ def test_sincos():
2931
assert np.isclose(cos, 0)
3032
assert np.isclose(sin, 1)
3133

32-
33-
def test_astar_planner():
34-
sim = SIM_ENV("/tests/test_world.yaml")
35-
planner = AStarPlanner(env=sim, resolution=0.3)
36-
robot_info = sim.env.get_robot_info()
37-
robot_state = sim.env.get_robot_state()
38-
sim.env.get_robot_info()
39-
rx, ry = planner.planning(
40-
robot_state[0].item(),
41-
robot_state[1].item(),
42-
robot_info.goal[0].item(),
43-
robot_info.goal[1].item(),
44-
)
45-
plt.plot(rx, ry, "-r")
46-
plt.pause(0.001)
47-
plt.show()
48-
49-
50-
def test_prm_planner():
51-
sim = SIM_ENV("/tests/test_world.yaml")
52-
planner = PRMPlanner(env=sim, robot_radius=0.3)
34+
@pytest.mark.parametrize(
35+
"planner, radius",
36+
[
37+
(AStarPlanner, 0.3),
38+
(PRMPlanner, 0.3),
39+
(RRT, 0.3),
40+
],
41+
)
42+
def test_planners(planner, radius):
43+
sim = SIM_ENV("/tests/test_world.yaml", disable_plotting=True)
44+
planner = planner(sim, radius)
5345
robot_info = sim.env.get_robot_info()
5446
robot_state = sim.env.get_robot_state()
5547
sim.env.get_robot_info()
@@ -59,25 +51,6 @@ def test_prm_planner():
5951
robot_info.goal[0].item(),
6052
robot_info.goal[1].item(),
6153
)
62-
63-
plt.plot(rx, ry, "-r")
64-
plt.pause(0.001)
65-
plt.show()
66-
67-
68-
def test_rrt_planner():
69-
sim = SIM_ENV("/tests/test_world.yaml")
70-
planner = RRT(env=sim, robot_radius=0.3)
71-
robot_info = sim.env.get_robot_info()
72-
robot_state = sim.env.get_robot_state()
73-
sim.env.get_robot_info()
74-
rx, ry = planner.planning(
75-
robot_state[0].item(),
76-
robot_state[1].item(),
77-
robot_info.goal[0].item(),
78-
robot_info.goal[1].item(),
79-
)
80-
8154
plt.plot(rx, ry, "-r")
8255
plt.pause(0.001)
8356
plt.show()

0 commit comments

Comments
 (0)