Skip to content

Commit 3c8ee82

Browse files
authored
Fix robot control mode not being initialized properly on startup (UBC-Thunderbots#3461)
* Fix robot control mode not being initialized properly on startup * Fix broken field test fixture * Refactorings * Address comments
1 parent e0e8ed8 commit 3c8ee82

9 files changed

Lines changed: 138 additions & 165 deletions

File tree

src/software/field_tests/field_test_fixture.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
from proto.import_all_protos import *
99

1010
from software.simulated_tests import validation
11-
from software.thunderscope.constants import EstopMode
11+
from software.thunderscope.constants import EstopMode, IndividualRobotMode
1212
from software.thunderscope.thunderscope import Thunderscope
1313
from software.thunderscope.proto_unix_io import ProtoUnixIO
1414
from software.thunderscope.binary_context_managers.full_system import FullSystem
1515
from software.thunderscope.binary_context_managers.game_controller import Gamecontroller
16+
from software.thunderscope.wifi_communication_manager import WifiCommunicationManager
1617
from software.logger.logger import create_logger
1718

1819

@@ -360,27 +361,29 @@ def field_test_runner():
360361

361362
# Launch all binaries
362363
with FullSystem(
363-
runtime_dir,
364+
full_system_runtime_dir=runtime_dir,
364365
debug_full_system=debug_full_sys,
365366
friendly_colour_yellow=args.run_yellow,
366367
should_restart_on_crash=False,
367368
) as friendly_fs, Gamecontroller(
368369
# we would be using conventional port if and only if we are playing in robocup.
369370
suppress_logs=(not args.show_gamecontroller_logs),
370371
use_conventional_port=False,
371-
) as gamecontroller, RobotCommunication(
372+
) as gamecontroller, WifiCommunicationManager(
372373
current_proto_unix_io=friendly_proto_unix_io,
373374
multicast_channel=getRobotMulticastChannel(args.channel),
375+
should_setup_full_system=True,
374376
interface=args.interface,
375-
estop_mode=estop_mode,
376-
estop_path=estop_path,
377-
enable_radio=args.enable_radio,
378377
referee_port=gamecontroller.get_referee_port()
379378
if gamecontroller
380379
else SSL_REFEREE_PORT,
380+
) as wifi_communication_manager, RobotCommunication(
381+
current_proto_unix_io=friendly_proto_unix_io,
382+
communication_manager=wifi_communication_manager,
383+
estop_mode=estop_mode,
384+
estop_path=estop_path,
381385
) as rc_friendly:
382386
friendly_fs.setup_proto_unix_io(friendly_proto_unix_io)
383-
rc_friendly.setup_for_fullsystem()
384387

385388
gamecontroller.setup_proto_unix_io(
386389
blue_full_system_proto_unix_io=blue_full_system_proto_unix_io,
@@ -398,6 +401,13 @@ def field_test_runner():
398401
layout_path=None,
399402
)
400403

404+
# Set control mode for all robots to AI so that packets are sent to the robots
405+
for robot_id in range(MAX_ROBOT_IDS_PER_SIDE):
406+
rc_friendly.toggle_individual_robot_control_mode(
407+
robot_id,
408+
IndividualRobotMode.AI,
409+
)
410+
401411
# connect the keyboard estop toggle to the key event if needed
402412
if estop_mode == EstopMode.KEYBOARD_ESTOP:
403413
tscope.keyboard_estop_shortcut.activated.connect(

src/software/simulated_tests/simulated_test_fixture.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,13 @@ def run_test(
384384
assert failed_tests == 0
385385

386386

387-
def load_command_line_arguments():
387+
def load_command_line_arguments(allow_unrecognized: bool = False):
388388
"""Load in command-line arguments using argparse
389389
390390
NOTE: Pytest has its own built in argument parser (conftest.py, pytest_addoption)
391391
but it doesn't seem to play nicely with bazel. We just use argparse instead.
392+
393+
:param allow_unrecognized: if true, does not raise an error for unrecognized arguments
392394
"""
393395
parser = argparse.ArgumentParser(description="Run simulated pytests")
394396
parser.add_argument(
@@ -464,15 +466,16 @@ def load_command_line_arguments():
464466
default=False,
465467
help="Use realism in the simulator",
466468
)
467-
return parser.parse_args()
469+
return parser.parse_known_args()[0] if allow_unrecognized else parser.parse_args()
468470

469471

470472
def pytest_main(file):
471473
"""Runs the pytest file
472474
473475
:param file: The test file to run
474476
"""
475-
args = load_command_line_arguments()
477+
args = load_command_line_arguments(allow_unrecognized=True)
478+
476479
# Run the test, -s disables all capturing at -vv increases verbosity
477480
# -W ignore::DeprecationWarning ignores deprecation warnings that spam the output
478481
sys.exit(

src/software/thunderscope/robot_diagnostics/robot_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ def create_control_mode_menu(
225225
)
226226

227227
control_mode_menu.currentIndexChanged.connect(
228-
lambda mode,
229-
robot_id=self.robot_id: self.individual_robot_control_mode_signal.emit(
230-
robot_id, IndividualRobotMode(mode)
228+
lambda mode: self.individual_robot_control_mode_signal.emit(
229+
self.robot_id, IndividualRobotMode(mode)
231230
)
232231
)
233232

src/software/thunderscope/robot_diagnostics/robot_view.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ def __init__(self, available_control_modes: list[IndividualRobotMode]) -> None:
101101

102102
self.layout = QVBoxLayout()
103103

104-
self.robot_view_widgets = []
104+
self.components = []
105105

106106
for id in range(MAX_ROBOT_IDS_PER_SIDE):
107-
robot_view_widget = RobotViewComponent(
107+
component = RobotViewComponent(
108108
id, available_control_modes, self.individual_robot_control_mode_signal
109109
)
110-
self.robot_view_widgets.append(robot_view_widget)
111-
self.layout.addWidget(robot_view_widget)
110+
self.components.append(component)
111+
self.layout.addWidget(component)
112112

113113
# for a QScrollArea, widgets cannot be added to it directly
114114
# doing so causes no scrolling to happen, and all the components get smaller
@@ -134,16 +134,16 @@ def refresh(self) -> None:
134134
and robot_statistic is not None
135135
and robot_status.robot_id == robot_statistic.robot_id
136136
): # if both pieces of data are available
137-
self.robot_view_widgets[robot_status.robot_id].update(
137+
self.components[robot_status.robot_id].update(
138138
robot_status=robot_status, robot_statistic=robot_statistic
139139
)
140140
else:
141141
if robot_status is not None:
142-
self.robot_view_widgets[robot_status.robot_id].update(
142+
self.components[robot_status.robot_id].update(
143143
robot_status,
144144
robot_statistic=None,
145145
)
146146
if robot_statistic is not None:
147-
self.robot_view_widgets[robot_statistic.robot_id].update(
147+
self.components[robot_statistic.robot_id].update(
148148
robot_status=None, robot_statistic=robot_statistic
149149
)

src/software/thunderscope/thunderscope.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def __init__(
4040
The interval in milliseconds to refresh all the widgets.
4141
"""
4242
self.refresh_interval_ms = refresh_interval_ms
43-
self.widgets = {}
4443
self.refresh_timers = []
4544

4645
self.tabs = QTabWidget()

0 commit comments

Comments
 (0)