Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
import pytest

import software.python_bindings as tbots_cpp
from software.py_constants import ENEMY_BALL_PLACEMENT_DISTANCE_METERS
from proto.play_pb2 import Play, PlayName
from software.simulated_tests.ball_enters_region import *
from software.simulated_tests.ball_stops_in_region import *
from software.simulated_tests.robot_enters_region import *

from proto.import_all_protos import *
from proto.ssl_gc_common_pb2 import Team
from proto.message_translation.tbots_protobuf import create_world_state
from software.simulated_tests.ball_enters_region import (
BallAlwaysStaysInRegion,
BallEventuallyEntersRegion,
)
from software.simulated_tests.robot_enters_region import RobotEventuallyExitsRegion
from software.simulated_tests.simulated_test_fixture import (
pytest_main,
)
from proto.message_translation.tbots_protobuf import create_world_state
from proto.ssl_gc_common_pb2 import Team


@pytest.mark.parametrize(
"ball_start_point, ball_placement_point",
[
# test normal ball placement (not edge case)
(tbots_cpp.Point(2, 2), tbots_cpp.Point(0, 1.5)),
# test when ball starting point is outside of the goal line
(tbots_cpp.Point(-4.7, 2.0), tbots_cpp.Point(0, 0.5)),
# test when ball starting point is outside of the side lines
(tbots_cpp.Point(-2.0, 3.2), tbots_cpp.Point(0, -0.5)),
# test when ball starting point is inside of enemy net
(tbots_cpp.Point(4.0, 0), tbots_cpp.Point(2.0, 2.0)),
# test when ball starting point is in friendly net
(tbots_cpp.Point(-4.0, 0), tbots_cpp.Point(-2.0, 2.0)),
],
)
def test_two_ai_ball_placement(
simulated_test_runner, ball_start_point, ball_placement_point
):
run_ball_placement_scenario(
simulated_test_runner, ball_start_point, ball_placement_point
)


@pytest.mark.parametrize(
"ball_start_point, ball_placement_point",
[
# TODO: Remove these ball placement tests until #3561 is resolved
Comment thread
nycrat marked this conversation as resolved.
# # 2023 RoboCup ball placement scenarios
# # Scenario 1
# (tbots_cpp.Point(-0.2, -2.8), tbots_cpp.Point(-0.2, 2.8)),
# # Scenario 2
# (tbots_cpp.Point(-3.5, -2.25), tbots_cpp.Point(0, 0)),
# # Scenario 3
# (tbots_cpp.Point(-1.5, -2.25), tbots_cpp.Point(-0.2, -2.8)),
# # Scenario 4
# (tbots_cpp.Point(-4.4, -2.9), tbots_cpp.Point(-0.2, 2.8)),
# # Scenario 5
# (tbots_cpp.Point(-0.5, -0), tbots_cpp.Point(-4.3, 2.8)),
# # Scenario 6
# (tbots_cpp.Point(-1, -3.15), tbots_cpp.Point(-3.5, -2.8)),
# # Scenario 7
# (tbots_cpp.Point(-1, 3.15), tbots_cpp.Point(-3.5, 2.8)),
# # Scenario 8
# (tbots_cpp.Point(-4.45, -0.1), tbots_cpp.Point(-0.5, 2.8)),
],
)
def test_robocup_technical_challenge_placement(
simulated_test_runner, ball_start_point, ball_placement_point
):
run_ball_placement_scenario(
simulated_test_runner, ball_start_point, ball_placement_point, blue_only=True
)


def ball_placement_play_setup(
Expand Down Expand Up @@ -54,12 +110,22 @@ def ball_placement_play_setup(
.negXPosYCorner(),
]

# Create world state
simulated_test_runner.set_world_state(
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_start_point,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)

# Game Controller Setup
simulated_test_runner.gamecontroller.send_gc_command(
simulated_test_runner.send_gamecontroller_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)
# Pass in placement point here - not required for all play tests
simulated_test_runner.gamecontroller.send_gc_command(
simulated_test_runner.send_gamecontroller_command(
gc_command=Command.Type.BALL_PLACEMENT,
team=Team.BLUE,
final_ball_placement_point=ball_placement_point,
Expand All @@ -72,76 +138,9 @@ def ball_placement_play_setup(
yellow_play = Play()
yellow_play.name = PlayName.HaltPlay

simulated_test_runner.blue_full_system_proto_unix_io.send_proto(Play, blue_play)
simulated_test_runner.set_play(blue_play, is_friendly=True)
if not blue_only:
simulated_test_runner.yellow_full_system_proto_unix_io.send_proto(
Play, yellow_play
)

# Create world state
simulated_test_runner.simulator_proto_unix_io.send_proto(
WorldState,
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_start_point,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)


@pytest.mark.parametrize(
"ball_start_point, ball_placement_point",
[
# test normal ball placement (not edge case)
(tbots_cpp.Point(2, 2), tbots_cpp.Point(0, 1.5)),
# test when ball starting point is outside of the goal line
(tbots_cpp.Point(-4.7, 2.0), tbots_cpp.Point(0, 0.5)),
# test when ball starting point is outside of the side lines
(tbots_cpp.Point(-2.0, 3.2), tbots_cpp.Point(0, -0.5)),
# test when ball starting point is inside of enemy net
(tbots_cpp.Point(4.0, 0), tbots_cpp.Point(2.0, 2.0)),
# test when ball starting point is in friendly net
(tbots_cpp.Point(-4.0, 0), tbots_cpp.Point(-2.0, 2.0)),
],
)
def test_two_ai_ball_placement(
simulated_test_runner, ball_start_point, ball_placement_point
):
run_ball_placement_scenario(
simulated_test_runner, ball_start_point, ball_placement_point
)


@pytest.mark.parametrize(
"ball_start_point, ball_placement_point",
[
# TODO: Remove these ball placement tests until #3561 is resolved
# # 2023 RoboCup ball placement scenarios
# # Scenario 1
# (tbots_cpp.Point(-0.2, -2.8), tbots_cpp.Point(-0.2, 2.8)),
# # Scenario 2
# (tbots_cpp.Point(-3.5, -2.25), tbots_cpp.Point(0, 0)),
# # Scenario 3
# (tbots_cpp.Point(-1.5, -2.25), tbots_cpp.Point(-0.2, -2.8)),
# # Scenario 4
# (tbots_cpp.Point(-4.4, -2.9), tbots_cpp.Point(-0.2, 2.8)),
# # Scenario 5
# (tbots_cpp.Point(-0.5, -0), tbots_cpp.Point(-4.3, 2.8)),
# # Scenario 6
# (tbots_cpp.Point(-1, -3.15), tbots_cpp.Point(-3.5, -2.8)),
# # Scenario 7
# (tbots_cpp.Point(-1, 3.15), tbots_cpp.Point(-3.5, 2.8)),
# # Scenario 8
# (tbots_cpp.Point(-4.45, -0.1), tbots_cpp.Point(-0.5, 2.8)),
],
)
def test_robocup_technical_challenge_placement(
simulated_test_runner, ball_start_point, ball_placement_point
):
run_ball_placement_scenario(
simulated_test_runner, ball_start_point, ball_placement_point, blue_only=True
)
simulated_test_runner.set_play(yellow_play, is_friendly=False)


def run_ball_placement_scenario(
Expand All @@ -150,8 +149,8 @@ def run_ball_placement_scenario(
"""Runs a ball placement test scenario with the specified parameters.

:param simulated_test_runner: The test runner used to simulate robot and ball behavior.
:param ball_start_point: The initial position of the ball (provided by pytest parameterization).
:param ball_placement_point: The target position where the ball should be placed (provided by pytest parameterization).
:param ball_start_point: The initial position of the ball.
:param ball_placement_point: The target position where the ball should be placed.
:param blue_only: If True, only the blue team is active; the yellow team is ignored.
"""
# Placement Eventually Validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,64 @@


def test_crease_defense_play(simulated_test_runner):
# starting point must be Point
ball_initial_pos = tbots_cpp.Point(0.9, 2.85)
# placement point must be Vector2 to work with game controller
tbots_cpp.Point(-3, -2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did this go, what is this for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the line below ball_initial_pos literally did nothing

def setup(*args):
ball_initial_pos = tbots_cpp.Point(0.9, 2.85)

# Setup Bots
blue_bots = [
tbots_cpp.Point(-4.5, 0),
tbots_cpp.Point(-3, 1.5),
tbots_cpp.Point(-3, 0.5),
tbots_cpp.Point(-3, -0.5),
tbots_cpp.Point(-3, -1.5),
tbots_cpp.Point(-3, -3.0),
]
blue_bots = [
tbots_cpp.Point(-4.5, 0),
tbots_cpp.Point(-3, 1.5),
tbots_cpp.Point(-3, 0.5),
tbots_cpp.Point(-3, -0.5),
tbots_cpp.Point(-3, -1.5),
tbots_cpp.Point(-3, -3.0),
]

yellow_bots = [
tbots_cpp.Point(1, 3),
tbots_cpp.Point(1, -0.25),
tbots_cpp.Point(1, -1.25),
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
tbots_cpp.Field.createSSLDivisionBField().enemyDefenseArea().negXNegYCorner(),
tbots_cpp.Field.createSSLDivisionBField().enemyDefenseArea().negXPosYCorner(),
]
yellow_bots = [
tbots_cpp.Point(1, 3),
tbots_cpp.Point(1, -0.25),
tbots_cpp.Point(1, -1.25),
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXNegYCorner(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXPosYCorner(),
]

# Game Controller Setup
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.FORCE_START, team=Team.BLUE
)
simulated_test_runner.set_world_state(
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_initial_pos,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)

# Force play override here
blue_play = Play()
blue_play.name = PlayName.CreaseDefensePlay
simulated_test_runner.send_gamecontroller_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)
simulated_test_runner.send_gamecontroller_command(
gc_command=Command.Type.FORCE_START, team=Team.BLUE
)

yellow_play = Play()
yellow_play.name = PlayName.HaltPlay
blue_play = Play()
blue_play.name = PlayName.CreaseDefensePlay

simulated_test_runner.blue_full_system_proto_unix_io.send_proto(Play, blue_play)
simulated_test_runner.yellow_full_system_proto_unix_io.send_proto(Play, yellow_play)
yellow_play = Play()
yellow_play.name = PlayName.HaltPlay

# Create world state
simulated_test_runner.simulator_proto_unix_io.send_proto(
WorldState,
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_initial_pos,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)
simulated_test_runner.set_play(blue_play, is_friendly=True)
simulated_test_runner.set_play(yellow_play, is_friendly=False)

# Always Validation
# TODO- #2778 Validation
# TODO (#2778): actually add validations
always_validation_sequence_set = [[]]

# Eventually Validation
# TODO- #2778 Validation
# TODO (#2778): actually add validations
eventually_validation_sequence_set = [[]]

simulated_test_runner.run_test(
setup=setup,
inv_eventually_validation_sequence_set=eventually_validation_sequence_set,
inv_always_validation_sequence_set=always_validation_sequence_set,
test_timeout_s=25,
Expand Down
Loading