Skip to content

Commit 5d87f4b

Browse files
authored
Port all simulated c++ tests to python (UBC-Thunderbots#3632)
* Port shoot or pass play test * Add todo list for tests to port * Add ball kicked in direction validation * Port chip tactic test * Port shoot or chip play test * Add delay validation * Port crease defense play test * Port stop play test * Port free kick play test * Port kickoff enemy play test * Port kickoff friendly play test * Fix kickoff enemy play test * Port additional crease defender tactic tests * Port penalty kick tactic test * Port move tactic test with lots of other changes * Add robot received ball validation * Port receiver tactic test * Port pivot kick tactic test * Port kick tactic test * Port halt tactic test * Port dribble tactic test * Port attacker tactic test * Fix example play test * Format * Remove todo * Update TODO issue tag * Fix typo * Fix shoot or pass play test * Skip flaky receiver tests, has TODO * Port ball occlusion test * Port penalty kick enemy play test * Small function refactor * Remove todo * Add duration validation * Use constant instead of 0.0166 * Make DurationValidation validate consecutive ticks * Add doc strings for delay and duration validations
1 parent 4b1b11c commit 5d87f4b

48 files changed

Lines changed: 3771 additions & 540 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/proto/message_translation/tbots_protobuf.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def create_world_state(
1111
blue_robot_locations: list[tbots_cpp.Point],
1212
ball_location: tbots_cpp.Point,
1313
ball_velocity: tbots_cpp.Vector,
14-
blue_robot_orientations: list[float] = [],
14+
blue_robot_orientations: list[tbots_cpp.Angle] = [],
15+
blue_robot_velocities: list[tbots_cpp.Vector] = [],
1516
) -> WorldState:
1617
"""Initializes the world from a list of robot locations and ball location/velocity.
1718
@@ -22,6 +23,7 @@ def create_world_state(
2223
:param ball_location: Location of the ball
2324
:param ball_velocity: Velocity of the ball
2425
:param blue_robot_orientations: A list of blue robots orientations
26+
:param blue_robot_velocities: A list of blue robots velocities
2527
"""
2628
world_state = WorldState()
2729

@@ -36,17 +38,26 @@ def create_world_state(
3638
)
3739

3840
for robot_id, robot_location in enumerate(blue_robot_locations):
39-
orientation = 0
41+
orientation = tbots_cpp.Angle.zero()
42+
velocity = tbots_cpp.Vector(0, 0)
43+
4044
try:
4145
orientation = blue_robot_orientations[robot_id]
4246
except IndexError:
4347
pass
48+
49+
try:
50+
velocity = blue_robot_velocities[robot_id]
51+
except IndexError:
52+
pass
53+
4454
world_state.blue_robots[robot_id].CopyFrom(
4555
RobotState(
4656
global_position=Point(
4757
x_meters=robot_location.x(), y_meters=robot_location.y()
4858
),
49-
global_orientation=Angle(radians=orientation),
59+
global_orientation=tbots_cpp.createAngleProto(orientation),
60+
global_velocity=tbots_cpp.createVectorProto(velocity),
5061
)
5162
)
5263

src/software/ai/hl/stp/play/crease_defense/crease_defense_play_test.py

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,75 @@
66
from software.simulated_tests.simulated_test_fixture import (
77
pytest_main,
88
)
9+
from software.simulated_tests.validation.robot_speed_threshold import (
10+
RobotSpeedEventuallyBelowThreshold,
11+
)
12+
from software.simulated_tests.validation.robot_enters_region import (
13+
NumberOfRobotsEventuallyEntersRegion,
14+
)
15+
from software.simulated_tests.validation.delay_validation import DelayValidation
916

1017

1118
def test_crease_defense_play(simulated_test_runner):
12-
def setup(*args):
13-
ball_initial_pos = tbots_cpp.Point(0.9, 2.85)
14-
15-
blue_bots = [
16-
tbots_cpp.Point(-4.5, 0),
17-
tbots_cpp.Point(-3, 1.5),
18-
tbots_cpp.Point(-3, 0.5),
19-
tbots_cpp.Point(-3, -0.5),
20-
tbots_cpp.Point(-3, -1.5),
21-
tbots_cpp.Point(-3, -3.0),
22-
]
23-
24-
yellow_bots = [
25-
tbots_cpp.Point(1, 3),
26-
tbots_cpp.Point(1, -0.25),
27-
tbots_cpp.Point(1, -1.25),
28-
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
29-
tbots_cpp.Field.createSSLDivisionBField()
30-
.enemyDefenseArea()
31-
.negXNegYCorner(),
32-
tbots_cpp.Field.createSSLDivisionBField()
33-
.enemyDefenseArea()
34-
.negXPosYCorner(),
35-
]
19+
field = tbots_cpp.Field.createSSLDivisionBField()
20+
goalie_position = tbots_cpp.Point(-4.5, 0)
3621

22+
def setup(*args):
3723
simulated_test_runner.set_world_state(
3824
create_world_state(
39-
yellow_robot_locations=yellow_bots,
40-
blue_robot_locations=blue_bots,
41-
ball_location=ball_initial_pos,
25+
blue_robot_locations=[
26+
goalie_position,
27+
tbots_cpp.Point(-3, 1.5),
28+
tbots_cpp.Point(-3, 0.5),
29+
tbots_cpp.Point(-3, -0.5),
30+
tbots_cpp.Point(-3, -1.5),
31+
tbots_cpp.Point(-3, -3.0),
32+
],
33+
yellow_robot_locations=[
34+
tbots_cpp.Point(1, 3),
35+
tbots_cpp.Point(1, -0.25),
36+
tbots_cpp.Point(1, -1.25),
37+
field.enemyGoalCenter(),
38+
field.enemyDefenseArea().negXNegYCorner(),
39+
field.enemyDefenseArea().negXPosYCorner(),
40+
],
41+
ball_location=tbots_cpp.Point(0.9, 2.85),
4242
ball_velocity=tbots_cpp.Vector(0, 0),
4343
),
4444
)
4545

46-
simulated_test_runner.send_gamecontroller_command(
47-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
48-
)
49-
simulated_test_runner.send_gamecontroller_command(
50-
gc_command=Command.Type.FORCE_START, team=Team.BLUE
51-
)
52-
5346
simulated_test_runner.set_plays(
5447
blue_play=PlayName.CreaseDefensePlay, yellow_play=PlayName.HaltPlay
5548
)
5649

57-
# TODO (#2778): actually add validations
58-
always_validation_sequence_set = [[]]
50+
simulated_test_runner.send_gamecontroller_command(
51+
gc_command=Command.Type.STOP, team=Team.UNKNOWN
52+
)
5953

60-
# TODO (#2778): actually add validations
61-
eventually_validation_sequence_set = [[]]
54+
eventually_validations = [
55+
[
56+
# Robots start moving and wait for all robots to come to a halt
57+
DelayValidation(
58+
delay_s=1, validation=RobotSpeedEventuallyBelowThreshold(0.001)
59+
),
60+
# Two friendly crease defenders should be close to the goalie
61+
NumberOfRobotsEventuallyEntersRegion(
62+
regions=[
63+
tbots_cpp.Rectangle(
64+
goalie_position + tbots_cpp.Vector(0, -1),
65+
goalie_position + tbots_cpp.Vector(1.5, 1),
66+
)
67+
],
68+
req_robot_cnt=3,
69+
),
70+
]
71+
]
6272

6373
simulated_test_runner.run_test(
6474
setup=setup,
65-
inv_eventually_validation_sequence_set=eventually_validation_sequence_set,
66-
inv_always_validation_sequence_set=always_validation_sequence_set,
67-
test_timeout_s=25,
75+
inv_eventually_validation_sequence_set=eventually_validations,
76+
ag_eventually_validation_sequence_set=eventually_validations,
77+
test_timeout_s=10,
6878
)
6979

7080

src/software/ai/hl/stp/play/example/BUILD

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cc_library(
2323
)
2424

2525
cc_test(
26-
name = "example_play_test",
26+
name = "example_play_cpp_test",
2727
srcs = ["example_play_test.cpp"],
2828
deps = [
2929
"//shared/test_util:tbots_gtest_main",
@@ -47,9 +47,8 @@ cc_test(
4747
)
4848

4949
py_test(
50-
name = "example_play_test_py",
50+
name = "example_play_test",
5151
srcs = ["example_play_test.py"],
52-
main = "example_play_test.py",
5352
# TODO (#2619) Remove tag to run in parallel
5453
tags = [
5554
"exclusive",

src/software/ai/hl/stp/play/example/example_play_test.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
NumberOfRobotsEventuallyExitsRegion,
44
NumberOfRobotsEventuallyEntersRegion,
55
)
6-
from software.simulated_tests.validation.robot_speed_threshold import *
76
from proto.message_translation.tbots_protobuf import create_world_state
87
from proto.ssl_gc_common_pb2 import Team
98
from proto.play_pb2 import PlayName
9+
from proto.import_all_protos import Command
1010
from software.simulated_tests.simulated_test_fixture import (
1111
pytest_main,
1212
)
@@ -47,10 +47,6 @@ def setup(*args):
4747
),
4848
)
4949

50-
simulated_test_runner.set_plays(
51-
blue_play=PlayName.ExamplePlay, yellow_play=PlayName.HaltPlay
52-
)
53-
5450
simulated_test_runner.send_gamecontroller_command(
5551
gc_command=Command.Type.STOP, team=Team.UNKNOWN
5652
)
@@ -61,23 +57,25 @@ def setup(*args):
6157
gc_command=Command.Type.DIRECT, team=Team.BLUE
6258
)
6359

64-
# params just have to be a list of length 1 to ensure the test runs at least once
60+
simulated_test_runner.set_plays(
61+
blue_play=PlayName.ExamplePlay, yellow_play=PlayName.HaltPlay
62+
)
63+
64+
eventually_validations = [
65+
[
66+
NumberOfRobotsEventuallyEntersRegion(
67+
regions=[tbots_cpp.Circle(ball_initial_pos, 1.15)], req_robot_cnt=6
68+
),
69+
NumberOfRobotsEventuallyExitsRegion(
70+
regions=[tbots_cpp.Circle(ball_initial_pos, 0.9)], req_robot_cnt=6
71+
),
72+
]
73+
]
74+
6575
simulated_test_runner.run_test(
6676
setup=setup,
67-
params=[0],
68-
inv_always_validation_sequence_set=[[]],
69-
inv_eventually_validation_sequence_set=[
70-
[
71-
NumberOfRobotsEventuallyEntersRegion(
72-
regions=[tbots_cpp.Circle(ball_initial_pos, 1.15)], req_robot_cnt=6
73-
),
74-
NumberOfRobotsEventuallyExitsRegion(
75-
regions=[tbots_cpp.Circle(ball_initial_pos, 0.9)], req_robot_cnt=6
76-
),
77-
]
78-
],
79-
ag_always_validation_sequence_set=[[]],
80-
ag_eventually_validation_sequence_set=[[]],
77+
inv_eventually_validation_sequence_set=eventually_validations,
78+
ag_eventually_validation_sequence_set=eventually_validations,
8179
test_timeout_s=10,
8280
)
8381

0 commit comments

Comments
 (0)