|
6 | 6 | from proto.import_all_protos import * |
7 | 7 | from proto.message_translation.tbots_protobuf import create_world_state |
8 | 8 | from software.gameplay_tests.util import pytest_main |
| 9 | +from software.gameplay_tests.validation.robot_enters_region import ( |
| 10 | + RobotEventuallyEntersRegion, |
| 11 | +) |
| 12 | +from software.gameplay_tests.validation.delay_validation import DelayValidation |
9 | 13 | from software.logger.logger import create_logger |
10 | 14 |
|
11 | 15 | logger = create_logger(__name__) |
|
148 | 152 | ], |
149 | 153 | ) |
150 | 154 | def test_one_robots_square(start_position, end_position, gameplay_test_runner): |
151 | | - gameplay_test_runner.set_world_state( |
152 | | - create_world_state( |
153 | | - blue_robot_locations=[ |
154 | | - start_position, |
155 | | - ], |
156 | | - yellow_robot_locations=[], |
157 | | - ball_location=tbots_cpp.Point(0, 0), |
158 | | - ball_velocity=tbots_cpp.Vector(0, 0), |
159 | | - ), |
160 | | - ) |
161 | | - world = gameplay_test_runner.world_buffer.get(block=True, timeout=5.0) |
162 | | - while len(world.friendly_team.team_robots) == 0: |
163 | | - tick = SimulatorTick(milliseconds=1000 / 60) |
164 | | - gameplay_test_runner.simulator_proto_unix_io.send_proto(SimulatorTick, tick) |
165 | | - |
166 | | - world = gameplay_test_runner.world_buffer.get(block=True, timeout=5.0) |
167 | | - print("The first world received had no robots in it!") |
168 | | - # raise Exception("The first world received had no robots in it!") |
169 | | - |
170 | | - print("Here are the robots:") |
171 | | - print( |
172 | | - [ |
173 | | - robot.current_state.global_position |
174 | | - for robot in world.friendly_team.team_robots |
175 | | - ] |
176 | | - ) |
177 | | - |
178 | | - id = world.friendly_team.team_robots[0].id |
179 | | - print(f"Running test on robot {id}") |
180 | | - |
181 | | - tactic = MoveTactic( |
182 | | - destination=tbots_cpp.createPointProto(end_position), |
183 | | - dribbler_mode=DribblerMode.OFF, |
184 | | - final_orientation=Angle(radians=-math.pi / 2), |
185 | | - ball_collision_type=BallCollisionType.AVOID, |
186 | | - auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), |
187 | | - max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, |
188 | | - obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, |
189 | | - ) |
190 | | - |
191 | | - print(f"Going to {tactic.destination}") |
192 | | - |
193 | | - gameplay_test_runner.set_tactics( |
194 | | - blue_tactics={ |
195 | | - id: tactic, |
196 | | - }, |
197 | | - ) |
| 155 | + def setup(): |
| 156 | + gameplay_test_runner.set_world_state( |
| 157 | + create_world_state( |
| 158 | + blue_robot_locations=[ |
| 159 | + start_position, |
| 160 | + ], |
| 161 | + yellow_robot_locations=[], |
| 162 | + ball_location=tbots_cpp.Point(0, 0), |
| 163 | + ball_velocity=tbots_cpp.Vector(0, 0), |
| 164 | + ), |
| 165 | + ) |
| 166 | + |
| 167 | + tactic = MoveTactic( |
| 168 | + destination=tbots_cpp.createPointProto(end_position), |
| 169 | + dribbler_mode=DribblerMode.OFF, |
| 170 | + final_orientation=Angle(radians=-math.pi / 2), |
| 171 | + ball_collision_type=BallCollisionType.AVOID, |
| 172 | + auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), |
| 173 | + max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, |
| 174 | + obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, |
| 175 | + ) |
| 176 | + |
| 177 | + gameplay_test_runner.set_tactics( |
| 178 | + blue_tactics={ |
| 179 | + 0: tactic, |
| 180 | + }, |
| 181 | + ) |
198 | 182 |
|
199 | 183 | gameplay_test_runner.run_test( |
| 184 | + setup=setup, |
200 | 185 | test_timeout_s=4, |
| 186 | + eventually_validation_sequence_set=[ |
| 187 | + [ |
| 188 | + RobotEventuallyEntersRegion( |
| 189 | + regions=[tbots_cpp.Circle(end_position, 0.05)] |
| 190 | + ), |
| 191 | + DelayValidation( |
| 192 | + delay_s=1, |
| 193 | + validation=RobotEventuallyEntersRegion( |
| 194 | + regions=[tbots_cpp.Circle(end_position, 0.05)] |
| 195 | + ), |
| 196 | + ), |
| 197 | + ] |
| 198 | + ], |
201 | 199 | ) |
202 | 200 |
|
203 | 201 |
|
|
0 commit comments