Skip to content

Commit 7a3ecdc

Browse files
committed
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software into sunghyuneun/robot_filter
2 parents e2c914d + 43493f2 commit 7a3ecdc

133 files changed

Lines changed: 1321 additions & 1171 deletions

File tree

Some content is hidden

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

scripts/lint_and_format.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ function run_ruff() {
7070
printf "\n***Failed to lint/format Python files!***\n\n"
7171
exit 1
7272
fi
73+
74+
# F403: https://docs.astral.sh/ruff/rules/undefined-local-with-import-star/
75+
# F405: https://docs.astral.sh/ruff/rules/undefined-local-with-import-star-usage/
76+
/opt/tbotspython/bin/python3 -m ruff check $BAZEL_ROOT_DIR --select F403,F405
77+
78+
if [[ "$?" != 0 ]]; then
79+
printf "\n***Wildcard imports should not be used (F403/F405)!***\n\n"
80+
exit 1
81+
fi
7382
}
7483

7584
function run_code_spell(){

src/proto/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ py_library(
251251
"import_all_protos.py",
252252
],
253253
deps = [
254+
":estop_state_py_proto",
254255
":software_py_proto",
255256
":tbots_py_proto",
257+
":validation_py_proto",
258+
":visualization_py_proto",
256259
],
257260
)

src/proto/import_all_protos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ def import_all_classes(package, input_globals):
4444
# Import all the protobuf classes that are generated into the proto library
4545
import_all_classes(proto, globals())
4646

47-
# Now add the following line to get access to all protobufs
48-
# from proto.import_all_protos import *
47+
# Now add the following line to get access to all protobufs through a single module
48+
# import proto.import_all_protos as protos

src/proto/message_translation/tbots_protobuf.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from proto.import_all_protos import *
3+
import proto.import_all_protos as protos
44
import software.python_bindings as tbots_cpp
55
import numpy
66
import math
@@ -13,7 +13,7 @@ def create_world_state(
1313
ball_velocity: tbots_cpp.Vector,
1414
blue_robot_orientations: list[tbots_cpp.Angle] = [],
1515
blue_robot_velocities: list[tbots_cpp.Vector] = [],
16-
) -> WorldState:
16+
) -> protos.WorldState:
1717
"""Initializes the world from a list of robot locations and ball location/velocity.
1818
1919
NOTE: (index is robot id)
@@ -25,17 +25,17 @@ def create_world_state(
2525
:param blue_robot_orientations: A list of blue robots orientations
2626
:param blue_robot_velocities: A list of blue robots velocities
2727
"""
28-
world_state = WorldState()
28+
world_state = protos.WorldState()
2929

3030
if yellow_robot_locations:
31-
yellow_robot_states = RobotStates()
31+
yellow_robot_states = protos.RobotStates()
3232
for robot_id, robot_location in enumerate(yellow_robot_locations):
3333
yellow_robot_states.robot_states[robot_id].CopyFrom(
34-
RobotState(
35-
global_position=Point(
34+
protos.RobotState(
35+
global_position=protos.Point(
3636
x_meters=robot_location.x(), y_meters=robot_location.y()
3737
),
38-
global_orientation=Angle(radians=math.pi),
38+
global_orientation=protos.Angle(radians=math.pi),
3939
)
4040
)
4141
world_state.yellow_robots.CopyFrom(yellow_robot_states)
@@ -44,7 +44,7 @@ def create_world_state(
4444
orientation = tbots_cpp.Angle.zero()
4545
velocity = tbots_cpp.Vector(0, 0)
4646

47-
blue_robot_states = RobotStates()
47+
blue_robot_states = protos.RobotStates()
4848
for robot_id, robot_location in enumerate(blue_robot_locations):
4949
try:
5050
orientation = blue_robot_orientations[robot_id]
@@ -57,8 +57,8 @@ def create_world_state(
5757
pass
5858

5959
blue_robot_states.robot_states[robot_id].CopyFrom(
60-
RobotState(
61-
global_position=Point(
60+
protos.RobotState(
61+
global_position=protos.Point(
6262
x_meters=robot_location.x(), y_meters=robot_location.y()
6363
),
6464
global_orientation=tbots_cpp.createAngleProto(orientation),
@@ -68,11 +68,11 @@ def create_world_state(
6868
world_state.blue_robots.CopyFrom(blue_robot_states)
6969

7070
world_state.ball_state.CopyFrom(
71-
BallState(
72-
global_position=Point(
71+
protos.BallState(
72+
global_position=protos.Point(
7373
x_meters=ball_location.x(), y_meters=ball_location.y()
7474
),
75-
global_velocity=Vector(
75+
global_velocity=protos.Vector(
7676
x_component_meters=ball_velocity.x(),
7777
y_component_meters=ball_velocity.y(),
7878
),
@@ -82,7 +82,7 @@ def create_world_state(
8282
return world_state
8383

8484

85-
def create_default_world_state(num_robots: int) -> WorldState:
85+
def create_default_world_state(num_robots: int) -> protos.WorldState:
8686
"""Create a WorldState proto with num_robots yellow and blue robots evenly spaced in two parallel lines on the field.
8787
8888
:param num_robots: Number of robots for the yellow and blue teams

src/software/ai/hl/stp/play/ball_placement/ball_placement_play_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import software.python_bindings as tbots_cpp
33
from software.py_constants import ENEMY_BALL_PLACEMENT_DISTANCE_METERS
44

5-
from proto.import_all_protos import *
6-
from proto.ssl_gc_common_pb2 import Team
5+
import proto.import_all_protos as protos
6+
from proto.ssl_gc_common_pb2 import Team as SslTeam
77
from proto.message_translation.tbots_protobuf import create_world_state
88
from software.gameplay_tests.validation.ball_enters_region import (
99
BallAlwaysStaysInRegion,
@@ -124,18 +124,19 @@ def ball_placement_play_setup(
124124

125125
# Game Controller Setup
126126
simulated_test_runner.send_gamecontroller_command(
127-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
127+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
128128
)
129129
# Pass in placement point here - not required for all play tests
130130
simulated_test_runner.send_gamecontroller_command(
131-
gc_command=Command.Type.BALL_PLACEMENT,
132-
team=Team.BLUE,
131+
gc_command=protos.Command.Type.BALL_PLACEMENT,
132+
team=SslTeam.BLUE,
133133
final_ball_placement_point=ball_placement_point,
134134
)
135135

136136
# Force play override here
137137
simulated_test_runner.set_plays(
138-
blue_play=PlayName.BallPlacementPlay, yellow_play=PlayName.HaltPlay
138+
blue_play=protos.PlayName.BallPlacementPlay,
139+
yellow_play=protos.PlayName.HaltPlay,
139140
)
140141

141142

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import software.python_bindings as tbots_cpp
2-
from proto.play_pb2 import PlayName
3-
from proto.import_all_protos import *
2+
import proto.import_all_protos as protos
43
from proto.message_translation.tbots_protobuf import create_world_state
5-
from proto.ssl_gc_common_pb2 import Team
4+
from proto.ssl_gc_common_pb2 import Team as SslTeam
65
from software.gameplay_tests.simulated_test_fixture import (
76
pytest_main,
87
)
@@ -44,11 +43,12 @@ def setup(*args):
4443
)
4544

4645
simulated_test_runner.set_plays(
47-
blue_play=PlayName.CreaseDefensePlay, yellow_play=PlayName.HaltPlay
46+
blue_play=protos.PlayName.CreaseDefensePlay,
47+
yellow_play=protos.PlayName.HaltPlay,
4848
)
4949

5050
simulated_test_runner.send_gamecontroller_command(
51-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
51+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
5252
)
5353

5454
eventually_validations = [

src/software/ai/hl/stp/play/defense/defense_play_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import pytest
22

33
import software.python_bindings as tbots_cpp
4-
from proto.play_pb2 import PlayName
5-
from software.gameplay_tests.validation.ball_enters_region import *
4+
import proto.import_all_protos as protos
5+
from software.gameplay_tests.validation.ball_enters_region import (
6+
BallNeverEntersRegion,
7+
)
68
from software.gameplay_tests.validation.friendly_has_ball_possession import (
79
FriendlyEventuallyHasBallPossession,
810
)
911
from proto.message_translation.tbots_protobuf import create_world_state
10-
from proto.ssl_gc_common_pb2 import Team
12+
from proto.ssl_gc_common_pb2 import Team as SslTeam
1113
from software.gameplay_tests.simulated_test_fixture import (
1214
pytest_main,
1315
)
@@ -49,14 +51,14 @@ def setup(*args):
4951
)
5052

5153
simulated_test_runner.send_gamecontroller_command(
52-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
54+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
5355
)
5456
simulated_test_runner.send_gamecontroller_command(
55-
gc_command=Command.Type.FORCE_START, team=Team.BLUE
57+
gc_command=protos.Command.Type.FORCE_START, team=SslTeam.BLUE
5658
)
5759

5860
simulated_test_runner.set_plays(
59-
blue_play=PlayName.DefensePlay, yellow_play=PlayName.HaltPlay
61+
blue_play=protos.PlayName.DefensePlay, yellow_play=protos.PlayName.HaltPlay
6062
)
6163

6264
simulated_test_runner.run_test(
@@ -114,14 +116,15 @@ def setup(*args):
114116
)
115117

116118
simulated_test_runner.send_gamecontroller_command(
117-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
119+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
118120
)
119121
simulated_test_runner.send_gamecontroller_command(
120-
gc_command=Command.Type.FORCE_START, team=Team.BLUE
122+
gc_command=protos.Command.Type.FORCE_START, team=SslTeam.BLUE
121123
)
122124

123125
simulated_test_runner.set_plays(
124-
blue_play=PlayName.DefensePlay, yellow_play=PlayName.ShootOrPassPlay
126+
blue_play=protos.PlayName.DefensePlay,
127+
yellow_play=protos.PlayName.ShootOrPassPlay,
125128
)
126129

127130
simulated_test_runner.run_test(

src/software/ai/hl/stp/play/enemy_ball_placement/enemy_ball_placement_play_test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import pytest
22

33
import software.python_bindings as tbots_cpp
4-
from proto.play_pb2 import PlayName
5-
from software.gameplay_tests.validation.robot_enters_placement_region import *
4+
import proto.import_all_protos as protos
5+
from software.gameplay_tests.validation.robot_enters_placement_region import (
6+
RobotNeverEntersPlacementRegion,
7+
)
68
from software.gameplay_tests.simulated_test_fixture import (
79
pytest_main,
810
)
911
from proto.message_translation.tbots_protobuf import create_world_state
10-
from proto.ssl_gc_common_pb2 import Team
12+
from proto.ssl_gc_common_pb2 import Team as SslTeam
1113

1214

1315
@pytest.mark.parametrize(
@@ -55,17 +57,17 @@ def setup(*args):
5557
)
5658

5759
simulated_test_runner.send_gamecontroller_command(
58-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
60+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
5961
)
6062
simulated_test_runner.send_gamecontroller_command(
61-
gc_command=Command.Type.BALL_PLACEMENT,
62-
team=Team.YELLOW,
63+
gc_command=protos.Command.Type.BALL_PLACEMENT,
64+
team=SslTeam.YELLOW,
6365
final_ball_placement_point=ball_placement_point,
6466
)
6567

6668
simulated_test_runner.set_plays(
67-
blue_play=PlayName.EnemyBallPlacementPlay,
68-
yellow_play=PlayName.BallPlacementPlay,
69+
blue_play=protos.PlayName.EnemyBallPlacementPlay,
70+
yellow_play=protos.PlayName.BallPlacementPlay,
6971
)
7072

7173
always_validation_sequence_set = [

src/software/ai/hl/stp/play/enemy_free_kick/enemy_free_kick_play_test.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import pytest
22

33
import software.python_bindings as tbots_cpp
4-
from proto.play_pb2 import PlayName
4+
import proto.import_all_protos as protos
55

66
from software.gameplay_tests.validation.or_validation import OrValidation
77

8-
from software.gameplay_tests.validation.friendly_team_scored import *
9-
from software.gameplay_tests.validation.ball_enters_region import *
8+
from software.gameplay_tests.validation.ball_enters_region import (
9+
BallNeverEntersRegion,
10+
)
1011
from software.gameplay_tests.validation.robot_enters_region import (
1112
RobotEventuallyEntersRegion,
1213
RobotNeverEntersRegion,
1314
)
1415
from proto.message_translation.tbots_protobuf import create_world_state
15-
from proto.ssl_gc_common_pb2 import Team
16+
from proto.ssl_gc_common_pb2 import Team as SslTeam
1617
from software.gameplay_tests.simulated_test_fixture import (
1718
pytest_main,
1819
)
@@ -106,14 +107,15 @@ def setup(*args):
106107
)
107108

108109
simulated_test_runner.send_gamecontroller_command(
109-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
110+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
110111
)
111112
simulated_test_runner.send_gamecontroller_command(
112-
gc_command=Command.Type.DIRECT, team=Team.YELLOW
113+
gc_command=protos.Command.Type.DIRECT, team=SslTeam.YELLOW
113114
)
114115

115116
simulated_test_runner.set_plays(
116-
blue_play=PlayName.EnemyFreeKickPlay, yellow_play=PlayName.FreeKickPlay
117+
blue_play=protos.PlayName.EnemyFreeKickPlay,
118+
yellow_play=protos.PlayName.FreeKickPlay,
117119
)
118120

119121
# Validation RoboCup SSL rules: can't be within 0.5m of ball before its kicked

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
NumberOfRobotsEventuallyEntersRegion,
55
)
66
from proto.message_translation.tbots_protobuf import create_world_state
7-
from proto.ssl_gc_common_pb2 import Team
8-
from proto.play_pb2 import PlayName
9-
from proto.import_all_protos import Command
7+
from proto.ssl_gc_common_pb2 import Team as SslTeam
8+
import proto.import_all_protos as protos
109
from software.gameplay_tests.simulated_test_fixture import (
1110
pytest_main,
1211
)
@@ -48,17 +47,17 @@ def setup(*args):
4847
)
4948

5049
simulated_test_runner.send_gamecontroller_command(
51-
gc_command=Command.Type.STOP, team=Team.UNKNOWN
50+
gc_command=protos.Command.Type.STOP, team=SslTeam.UNKNOWN
5251
)
5352
simulated_test_runner.send_gamecontroller_command(
54-
gc_command=Command.Type.NORMAL_START, team=Team.BLUE
53+
gc_command=protos.Command.Type.NORMAL_START, team=SslTeam.BLUE
5554
)
5655
simulated_test_runner.send_gamecontroller_command(
57-
gc_command=Command.Type.DIRECT, team=Team.BLUE
56+
gc_command=protos.Command.Type.DIRECT, team=SslTeam.BLUE
5857
)
5958

6059
simulated_test_runner.set_plays(
61-
blue_play=PlayName.ExamplePlay, yellow_play=PlayName.HaltPlay
60+
blue_play=protos.PlayName.ExamplePlay, yellow_play=protos.PlayName.HaltPlay
6261
)
6362

6463
eventually_validations = [

0 commit comments

Comments
 (0)