From a49149ab91fced0990d70b1267d4539eb6c838f5 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 19 Oct 2024 20:39:07 +0100 Subject: [PATCH 1/7] Fix lighting controller crash --- .../controllers/competition_supervisor/lighting_control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulator/controllers/competition_supervisor/lighting_control.py b/simulator/controllers/competition_supervisor/lighting_control.py index 2485073..30a508c 100644 --- a/simulator/controllers/competition_supervisor/lighting_control.py +++ b/simulator/controllers/competition_supervisor/lighting_control.py @@ -178,7 +178,7 @@ def expand_lighting_fade( """Expand a fade effect into a list of steps.""" fades = [] - assert isinstance(cue.start_time, float), \ + assert isinstance(cue.start_time, (float, int)), \ "FromEnd times should be converted to absolute times" cue_start = int((cue.start_time * 1000) / self.timestep) From 80f048e1ad4cf56729e884362322f3185a674fc9 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 19 Oct 2024 20:39:58 +0100 Subject: [PATCH 2/7] Rework run_simulator to use a unified list of search paths Expand locations searched on Windows --- scripts/run_simulator.py | 48 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/scripts/run_simulator.py b/scripts/run_simulator.py index 8b9f301..9c94e4b 100755 --- a/scripts/run_simulator.py +++ b/scripts/run_simulator.py @@ -4,6 +4,7 @@ Largely just a shortcut to running the arena world in Webots. """ +# ruff: noqa: E501 from __future__ import annotations import sys @@ -24,6 +25,17 @@ # Assume the script is in the scripts directory SIM_BASE = Path(__file__).parents[1] +POSSIBLE_WEBOTS_PATHS = [ + ("darwin", "/Applications/Webots.app/Contents/MacOS/webots"), + ("win32", "C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"), + ("win32", expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe")), + # Attempt to use the start menu shortcut + ("win32", expandvars("%ProgramData%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")), + ("win32", expandvars("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")), + ("linux", "/usr/local/bin/webots"), + ("linux", "/usr/bin/webots"), +] + def get_webots_parameters() -> tuple[Path, Path]: """ @@ -36,46 +48,26 @@ def get_webots_parameters() -> tuple[Path, Path]: if not world_file.exists(): raise RuntimeError("World file not found.") + if not (SIM_BASE / "venv").exists(): + print("Please run the setup.py script before running the simulator.") + raise RuntimeError + # Check if Webots is in the PATH webots = which("webots") # Find the webots executable, if it is not in the PATH if webots is None: - if sys.platform == "darwin": - webots = "/Applications/Webots.app/Contents/MacOS/webots" - elif sys.platform == "win32": - possible_paths = [ - "C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe", - expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"), - ] - for path in possible_paths: + for system_filter, path in POSSIBLE_WEBOTS_PATHS: + if sys.platform.startswith(system_filter): + print(f"Checking {path}") if Path(path).exists(): webots = path break - else: - print("Webots executable not found.") - raise RuntimeError - elif sys.platform.startswith("linux"): - possible_paths = ["/usr/local/bin/webots", "/usr/bin/webots"] - for path in possible_paths: - if Path(path).exists(): - webots = path - break - else: - print("Webots executable not found.") - raise RuntimeError - else: - print("Unsupported platform.") - raise RuntimeError - if not Path(webots).exists(): + if webots is None or not Path(webots).exists(): print("Webots executable not found.") raise RuntimeError - if not (SIM_BASE / "venv").exists(): - print("Please run the setup.py script before running the simulator.") - raise RuntimeError - return Path(webots), world_file From 386eb95816cd6a085098848484f6be82c7990d83 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 19 Oct 2024 21:15:41 +0100 Subject: [PATCH 3/7] Fix support for windows shortcuts --- scripts/run_simulator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/run_simulator.py b/scripts/run_simulator.py index 9c94e4b..5f800db 100755 --- a/scripts/run_simulator.py +++ b/scripts/run_simulator.py @@ -19,11 +19,11 @@ if (Path(__file__).parent / 'simulator/VERSION').exists(): print("Running in release mode") - SIM_BASE = Path(__file__).parent + SIM_BASE = Path(__file__).parent.resolve() else: print("Running in development mode") # Assume the script is in the scripts directory - SIM_BASE = Path(__file__).parents[1] + SIM_BASE = Path(__file__).parents[1].resolve() POSSIBLE_WEBOTS_PATHS = [ ("darwin", "/Applications/Webots.app/Contents/MacOS/webots"), @@ -82,6 +82,8 @@ def main() -> None: Popen( [str(webots), str(world_file)], creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, + # shell=True is needed to run from shortcuts + shell=(webots.suffix == ".lnk"), ) else: Popen([str(webots), str(world_file)], start_new_session=True) From 3ab0aefc7512c086cf1f5c2cee44a2c43bc9df3e Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 26 Oct 2024 11:08:25 +0100 Subject: [PATCH 4/7] Log python version --- scripts/setup.py | 5 +++++ simulator/modules/robot_utils.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/setup.py b/scripts/setup.py index 4b1557e..bbf1d30 100755 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -13,6 +13,7 @@ import logging import platform import shutil +import sys from pathlib import Path from subprocess import run from venv import create @@ -62,13 +63,17 @@ def populate_python_config(runtime_ini: Path, venv_python: Path) -> None: try: if (Path(__file__).parent / 'simulator/VERSION').exists(): # This is running from a release + print("Running in release mode") project_root = Path(__file__).parent requirements = project_root / "simulator/requirements.txt" else: # This is running from the repository + print("Running in development mode") project_root = Path(__file__).parents[1] requirements = project_root / "requirements.txt" + print(f"Python version: {sys.version} on {platform.platform()}") + venv_dir = project_root / "venv" logger.info(f"Creating virtual environment in {venv_dir.absolute()}") diff --git a/simulator/modules/robot_utils.py b/simulator/modules/robot_utils.py index 04b2833..4cb02f5 100644 --- a/simulator/modules/robot_utils.py +++ b/simulator/modules/robot_utils.py @@ -2,6 +2,7 @@ from __future__ import annotations import json +import platform import subprocess import sys from pathlib import Path @@ -87,7 +88,10 @@ def print_simulation_version() -> None: except subprocess.CalledProcessError: version = 'unknown' - print(f"Running simulator version: {version}") + print( + f"Running simulator version: {version} in Python {platform.python_version()} " + f"({platform.system()}-{platform.machine()})" + ) def get_match_data() -> MatchData: From e79035d85c802a30fde521148a63b939981661a3 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Tue, 29 Oct 2024 21:43:24 +0000 Subject: [PATCH 5/7] Update requirements to include additional libraries --- requirements.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fdb4017..560f1cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,15 @@ sr-robot3==2025.0.1 april_vision==2.2.0 -opencv-python-headless >=4,<5 +opencv-python-headless >=4.8.0.76,<5 + +# Library versions are selected to provide support for Python 3.9-3.12 + +flask==2.3.3 +matplotlib==3.9.2 +networkx==3.1 +numpy==1.26.4 +pandas==2.2.3 +pillow==11.0.0 +scikit-learn==1.3.0 +scipy==1.11.2 +shapely==2.0.6 From 9d37f8f5e2f281dcc79ca136e7fc1b0e651e0986 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 9 Nov 2024 18:54:06 +0000 Subject: [PATCH 6/7] Bump scikit-learn to support 3.12 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 560f1cb..ff61e2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,6 @@ networkx==3.1 numpy==1.26.4 pandas==2.2.3 pillow==11.0.0 -scikit-learn==1.3.0 +scikit-learn==1.3.1 scipy==1.11.2 shapely==2.0.6 From 549687e6443dc598a0bbcef01924efc521f32580 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Mon, 11 Nov 2024 21:00:02 +0000 Subject: [PATCH 7/7] Move error messages into runtime errors --- scripts/run_comp_match.py | 4 ++-- scripts/run_simulator.py | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/run_comp_match.py b/scripts/run_comp_match.py index 655cc73..9754fd2 100755 --- a/scripts/run_comp_match.py +++ b/scripts/run_comp_match.py @@ -175,8 +175,8 @@ def execute_match(arena_root: Path) -> None: # Webots is only on the PATH on Linux so we have a helper function to find it try: webots, world_file = get_webots_parameters() - except RuntimeError: - raise FileNotFoundError("Webots executable not found.") + except RuntimeError as e: + raise FileNotFoundError(e) sim_env = os.environ.copy() sim_env['ARENA_ROOT'] = str(arena_root) diff --git a/scripts/run_simulator.py b/scripts/run_simulator.py index 5f800db..e4a6a7d 100755 --- a/scripts/run_simulator.py +++ b/scripts/run_simulator.py @@ -49,8 +49,7 @@ def get_webots_parameters() -> tuple[Path, Path]: raise RuntimeError("World file not found.") if not (SIM_BASE / "venv").exists(): - print("Please run the setup.py script before running the simulator.") - raise RuntimeError + raise RuntimeError("Please run the setup.py script before running the simulator.") # Check if Webots is in the PATH webots = which("webots") @@ -65,8 +64,7 @@ def get_webots_parameters() -> tuple[Path, Path]: break if webots is None or not Path(webots).exists(): - print("Webots executable not found.") - raise RuntimeError + raise RuntimeError("Webots executable not found.") return Path(webots), world_file @@ -87,7 +85,8 @@ def main() -> None: ) else: Popen([str(webots), str(world_file)], start_new_session=True) - except RuntimeError: + except RuntimeError as e: + print(f"An error occurred: {e}") input("Press enter to continue...") exit(1) except Exception as e: