Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamecontroller can Bind to a Different Port Based on Command Line Argument #3207

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bacfacf
chnage port depending on argument
Mr-Anyone May 20, 2024
d620120
added docs
Mr-Anyone May 20, 2024
1557448
remove stuff
Mr-Anyone May 20, 2024
5478f15
updated entry points
Mr-Anyone May 20, 2024
8d394cd
fixed stuff
Mr-Anyone May 21, 2024
0b5d2a6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 21, 2024
5d5e130
copied code from nima
Mr-Anyone May 22, 2024
53b3120
added some new port to fix
Mr-Anyone May 22, 2024
c052a97
change bind address and stuff like that
Mr-Anyone May 23, 2024
ace67d6
added new stuff to robot communication
Mr-Anyone May 23, 2024
730753a
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 23, 2024
9b8d59d
added new stuff for robot communication
Mr-Anyone May 23, 2024
9453411
Merge branch 'gamecontroller_port' of github.com:Mr-Anyone/Thunderbot…
Mr-Anyone May 23, 2024
ebcc8d6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 23, 2024
6ad2b47
merged arune's changes
Mr-Anyone May 31, 2024
e730860
added new feature that arune requested
Mr-Anyone Jun 11, 2024
60dad81
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 11, 2024
b44cdcf
added requested feature
Mr-Anyone Jun 26, 2024
0c984eb
added comments and remove necessary print statements
Mr-Anyone Jun 26, 2024
749fb3f
remove code that are non necessary
Mr-Anyone Jun 26, 2024
f3a42e7
removed one line of legacy code
Mr-Anyone Jun 26, 2024
bed3109
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 26, 2024
51f42e2
Merge branch 'gamecontroller_port' of github.com:Mr-Anyone/Thunderbot…
Mr-Anyone Jun 26, 2024
1e8fcba
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 26, 2024
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
163 changes: 94 additions & 69 deletions src/software/field_tests/field_test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
:param test_name: The name of the test to run
:param blue_full_system_proto_unix_io: The blue full system proto unix io to use
:param yellow_full_system_proto_unix_io: The yellow full system proto unix io to use
:param gamecontroller: The gamecontroller context managed instance
:param gamecontroller: The gamecontroller context managed instance
:param publish_validation_protos: whether to publish validation protos
:param: is_yellow_friendly: if yellow is the friendly team
"""
Expand Down Expand Up @@ -320,6 +320,27 @@ def load_command_line_arguments():
help="Run the test with friendly robots in yellow mode",
)

parser.add_argument(
"--sslvision_multicast_address",
type=str,
default=SSL_VISION_ADDRESS,
help="the multicast address for ssl vision",
)

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need this arg, we can default to SSL_VISION_ADDRESS and just change the port

parser.add_argument(
"--use_unconventional_port",
action="store_true",
default=False,
help="setting this option would cause gamecontroller to bind on an unconventional port, likely 12393",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need this as @nimazareian suggested. If we run --launch_gc, then we can set the appropriate port in RobotCommunication


parser.add_argument(
"--not_launch_gc",
action="store_true",
default=False,
help="whether we are launching gamecontroller or not",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's do the inverse --launch_gc


estop_group = parser.add_mutually_exclusive_group()
estop_group.add_argument(
"--keyboard_estop",
Expand Down Expand Up @@ -373,84 +394,88 @@ def field_test_runner():
debug_full_system=debug_full_sys,
friendly_colour_yellow=args.run_yellow,
should_restart_on_crash=False,
) as friendly_fs, RobotCommunication(
) as friendly_fs, Gamecontroller(
use_unconventional_port=args.use_unconventional_port,
not_launch_gc=args.not_launch_gc,
supress_logs=(not args.show_gamecontroller_logs),
) as gamecontroller, RobotCommunication(
current_proto_unix_io=friendly_proto_unix_io,
multicast_channel=getRobotMulticastChannel(args.channel),
interface=args.interface,
estop_mode=estop_mode,
estop_path=estop_path,
enable_radio=args.enable_radio,
sslvision_address=args.sslvision_multicast_address,
referee_port=gamecontroller.get_referee_port(),
Copy link
Contributor

Choose a reason for hiding this comment

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

yup this is exactly right, but we don't need sslvision_address

) as rc_friendly:
with Gamecontroller(
supress_logs=(not args.show_gamecontroller_logs)
) as gamecontroller:
friendly_fs.setup_proto_unix_io(friendly_proto_unix_io)
rc_friendly.setup_for_fullsystem()

gamecontroller.setup_proto_unix_io(
blue_full_system_proto_unix_io, yellow_full_system_proto_unix_io,
)
# Inject the proto unix ios into thunderscope and start the test
tscope = Thunderscope(
configure_field_test_view(
simulator_proto_unix_io=simulator_proto_unix_io,
blue_full_system_proto_unix_io=blue_full_system_proto_unix_io,
yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io,
yellow_is_friendly=args.run_yellow,
),
layout_path=None,
)

# connect the keyboard estop toggle to the key event if needed
if estop_mode == EstopMode.KEYBOARD_ESTOP:
tscope.keyboard_estop_shortcut.activated.connect(
rc_friendly.toggle_keyboard_estop
)
# we call this method to enable estop automatically when a field test starts
rc_friendly.toggle_keyboard_estop()
logger.warning(
"\x1b[31;20m"
+ "Keyboard Estop Enabled, robots will start moving automatically when test starts!"
+ "\x1b[0m"
)
friendly_fs.setup_proto_unix_io(friendly_proto_unix_io)
rc_friendly.setup_for_fullsystem()

time.sleep(LAUNCH_DELAY_S)
runner = FieldTestRunner(
test_name=current_test,
gamecontroller.setup_proto_unix_io(
blue_full_system_proto_unix_io, yellow_full_system_proto_unix_io,
)
# Inject the proto unix ios into thunderscope and start the test
tscope = Thunderscope(
configure_field_test_view(
simulator_proto_unix_io=simulator_proto_unix_io,
blue_full_system_proto_unix_io=blue_full_system_proto_unix_io,
yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io,
gamecontroller=gamecontroller,
thunderscope=tscope,
is_yellow_friendly=args.run_yellow,
yellow_is_friendly=args.run_yellow,
),
layout_path=None,
)

# connect the keyboard estop toggle to the key event if needed
if estop_mode == EstopMode.KEYBOARD_ESTOP:
tscope.keyboard_estop_shortcut.activated.connect(
rc_friendly.toggle_keyboard_estop
)
# we call this method to enable estop automatically when a field test starts
rc_friendly.toggle_keyboard_estop()
logger.warning(
"\x1b[31;20m"
+ "Keyboard Estop Enabled, robots will start moving automatically when test starts!"
+ "\x1b[0m"
)

friendly_proto_unix_io.register_observer(World, runner.world_buffer)

# Setup proto loggers.
#
# NOTE: Its important we use the test runners time provider because
# test will run as fast as possible with a varying tick rate. The
# SimulatorTestRunner time provider is tied to the simulators
# t_capture coming out of the wrapper packet (rather than time.time).
with ProtoLogger(
f"{args.blue_full_system_runtime_dir}/logs/{current_test}",
time_provider=runner.time_provider,
) as blue_logger, ProtoLogger(
f"{args.yellow_full_system_runtime_dir}/logs/{current_test}",
time_provider=runner.time_provider,
) as yellow_logger:
blue_full_system_proto_unix_io.register_to_observe_everything(
blue_logger.buffer
)
yellow_full_system_proto_unix_io.register_to_observe_everything(
yellow_logger.buffer
)
yield runner
print(
f"\n\nTo replay this test for the blue team, go to the `src` folder and run \n./tbots.py run thunderscope --blue_log {blue_logger.log_folder}",
flush=True,
)
print(
f"\n\nTo replay this test for the yellow team, go to the `src` folder and run \n./tbots.py run thunderscope --yellow_log {yellow_logger.log_folder}",
flush=True,
)
time.sleep(LAUNCH_DELAY_S)
runner = FieldTestRunner(
test_name=current_test,
blue_full_system_proto_unix_io=blue_full_system_proto_unix_io,
yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io,
gamecontroller=gamecontroller,
thunderscope=tscope,
is_yellow_friendly=args.run_yellow,
)

friendly_proto_unix_io.register_observer(World, runner.world_buffer)

# Setup proto loggers.
#
# NOTE: Its important we use the test runners time provider because
# test will run as fast as possible with a varying tick rate. The
# SimulatorTestRunner time provider is tied to the simulators
# t_capture coming out of the wrapper packet (rather than time.time).
with ProtoLogger(
f"{args.blue_full_system_runtime_dir}/logs/{current_test}",
time_provider=runner.time_provider,
) as blue_logger, ProtoLogger(
f"{args.yellow_full_system_runtime_dir}/logs/{current_test}",
time_provider=runner.time_provider,
) as yellow_logger:
blue_full_system_proto_unix_io.register_to_observe_everything(
blue_logger.buffer
)
yellow_full_system_proto_unix_io.register_to_observe_everything(
yellow_logger.buffer
)
yield runner
print(
f"\n\nTo replay this test for the blue team, go to the `src` folder and run \n./tbots.py run thunderscope --blue_log {blue_logger.log_folder}",
flush=True,
)
print(
f"\n\nTo replay this test for the yellow team, go to the `src` folder and run \n./tbots.py run thunderscope --yellow_log {yellow_logger.log_folder}",
flush=True,
)
11 changes: 8 additions & 3 deletions src/software/networking/ssl_proto_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ def __init__(self, port: int) -> None:

:param port the port to bind to
"""
# bind to all local interfaces, TCP
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(("", port))
try:
# bind to all local interfaces, TCP
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(("", port))
except ConnectionRefusedError:
raise ConnectionRefusedError(
f"SSL Socket connection refused on port {port}. Is binary already running in a separate process?"
)

def send(self, proto: protobuf_message.Message) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/software/simulated_tests/simulated_test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def load_command_line_arguments():
default=False,
help="Use realism in the simulator",
)

return parser.parse_args()


Expand Down Expand Up @@ -542,7 +543,7 @@ def simulated_test_runner():
should_restart_on_crash=False,
) as yellow_fs:
with Gamecontroller(
supress_logs=(not args.show_gamecontroller_logs)
supress_logs=(not args.show_gamecontroller_logs),
) as gamecontroller:

blue_fs.setup_proto_unix_io(blue_full_system_proto_unix_io)
Expand Down
Loading
Loading