Skip to content

Commit 8b2433d

Browse files
authored
Merge pull request #3 from srobo/SR2025-fixes
Various minor fixes
2 parents 6325dfd + 549687e commit 8b2433d

File tree

6 files changed

+52
-38
lines changed

6 files changed

+52
-38
lines changed

requirements.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
sr-robot3==2025.0.1
22
april_vision==2.2.0
3-
opencv-python-headless >=4,<5
3+
opencv-python-headless >=4.8.0.76,<5
4+
5+
# Library versions are selected to provide support for Python 3.9-3.12
6+
7+
flask==2.3.3
8+
matplotlib==3.9.2
9+
networkx==3.1
10+
numpy==1.26.4
11+
pandas==2.2.3
12+
pillow==11.0.0
13+
scikit-learn==1.3.1
14+
scipy==1.11.2
15+
shapely==2.0.6

scripts/run_comp_match.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def execute_match(arena_root: Path) -> None:
175175
# Webots is only on the PATH on Linux so we have a helper function to find it
176176
try:
177177
webots, world_file = get_webots_parameters()
178-
except RuntimeError:
179-
raise FileNotFoundError("Webots executable not found.")
178+
except RuntimeError as e:
179+
raise FileNotFoundError(e)
180180

181181
sim_env = os.environ.copy()
182182
sim_env['ARENA_ROOT'] = str(arena_root)

scripts/run_simulator.py

+26-33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Largely just a shortcut to running the arena world in Webots.
66
"""
7+
# ruff: noqa: E501
78
from __future__ import annotations
89

910
import sys
@@ -18,11 +19,22 @@
1819

1920
if (Path(__file__).parent / 'simulator/VERSION').exists():
2021
print("Running in release mode")
21-
SIM_BASE = Path(__file__).parent
22+
SIM_BASE = Path(__file__).parent.resolve()
2223
else:
2324
print("Running in development mode")
2425
# Assume the script is in the scripts directory
25-
SIM_BASE = Path(__file__).parents[1]
26+
SIM_BASE = Path(__file__).parents[1].resolve()
27+
28+
POSSIBLE_WEBOTS_PATHS = [
29+
("darwin", "/Applications/Webots.app/Contents/MacOS/webots"),
30+
("win32", "C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"),
31+
("win32", expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe")),
32+
# Attempt to use the start menu shortcut
33+
("win32", expandvars("%ProgramData%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")),
34+
("win32", expandvars("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")),
35+
("linux", "/usr/local/bin/webots"),
36+
("linux", "/usr/bin/webots"),
37+
]
2638

2739

2840
def get_webots_parameters() -> tuple[Path, Path]:
@@ -36,45 +48,23 @@ def get_webots_parameters() -> tuple[Path, Path]:
3648
if not world_file.exists():
3749
raise RuntimeError("World file not found.")
3850

51+
if not (SIM_BASE / "venv").exists():
52+
raise RuntimeError("Please run the setup.py script before running the simulator.")
53+
3954
# Check if Webots is in the PATH
4055
webots = which("webots")
4156

4257
# Find the webots executable, if it is not in the PATH
4358
if webots is None:
44-
if sys.platform == "darwin":
45-
webots = "/Applications/Webots.app/Contents/MacOS/webots"
46-
elif sys.platform == "win32":
47-
possible_paths = [
48-
"C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe",
49-
expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"),
50-
]
51-
for path in possible_paths:
52-
if Path(path).exists():
53-
webots = path
54-
break
55-
else:
56-
print("Webots executable not found.")
57-
raise RuntimeError
58-
elif sys.platform.startswith("linux"):
59-
possible_paths = ["/usr/local/bin/webots", "/usr/bin/webots"]
60-
for path in possible_paths:
59+
for system_filter, path in POSSIBLE_WEBOTS_PATHS:
60+
if sys.platform.startswith(system_filter):
61+
print(f"Checking {path}")
6162
if Path(path).exists():
6263
webots = path
6364
break
64-
else:
65-
print("Webots executable not found.")
66-
raise RuntimeError
67-
else:
68-
print("Unsupported platform.")
69-
raise RuntimeError
7065

71-
if not Path(webots).exists():
72-
print("Webots executable not found.")
73-
raise RuntimeError
74-
75-
if not (SIM_BASE / "venv").exists():
76-
print("Please run the setup.py script before running the simulator.")
77-
raise RuntimeError
66+
if webots is None or not Path(webots).exists():
67+
raise RuntimeError("Webots executable not found.")
7868

7969
return Path(webots), world_file
8070

@@ -90,10 +80,13 @@ def main() -> None:
9080
Popen(
9181
[str(webots), str(world_file)],
9282
creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP,
83+
# shell=True is needed to run from shortcuts
84+
shell=(webots.suffix == ".lnk"),
9385
)
9486
else:
9587
Popen([str(webots), str(world_file)], start_new_session=True)
96-
except RuntimeError:
88+
except RuntimeError as e:
89+
print(f"An error occurred: {e}")
9790
input("Press enter to continue...")
9891
exit(1)
9992
except Exception as e:

scripts/setup.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import logging
1414
import platform
1515
import shutil
16+
import sys
1617
from pathlib import Path
1718
from subprocess import run
1819
from venv import create
@@ -62,13 +63,17 @@ def populate_python_config(runtime_ini: Path, venv_python: Path) -> None:
6263
try:
6364
if (Path(__file__).parent / 'simulator/VERSION').exists():
6465
# This is running from a release
66+
print("Running in release mode")
6567
project_root = Path(__file__).parent
6668
requirements = project_root / "simulator/requirements.txt"
6769
else:
6870
# This is running from the repository
71+
print("Running in development mode")
6972
project_root = Path(__file__).parents[1]
7073
requirements = project_root / "requirements.txt"
7174

75+
print(f"Python version: {sys.version} on {platform.platform()}")
76+
7277
venv_dir = project_root / "venv"
7378

7479
logger.info(f"Creating virtual environment in {venv_dir.absolute()}")

simulator/controllers/competition_supervisor/lighting_control.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def expand_lighting_fade(
178178
"""Expand a fade effect into a list of steps."""
179179
fades = []
180180

181-
assert isinstance(cue.start_time, float), \
181+
assert isinstance(cue.start_time, (float, int)), \
182182
"FromEnd times should be converted to absolute times"
183183
cue_start = int((cue.start_time * 1000) / self.timestep)
184184

simulator/modules/robot_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import json
5+
import platform
56
import subprocess
67
import sys
78
from pathlib import Path
@@ -87,7 +88,10 @@ def print_simulation_version() -> None:
8788
except subprocess.CalledProcessError:
8889
version = 'unknown'
8990

90-
print(f"Running simulator version: {version}")
91+
print(
92+
f"Running simulator version: {version} in Python {platform.python_version()} "
93+
f"({platform.system()}-{platform.machine()})"
94+
)
9195

9296

9397
def get_match_data() -> MatchData:

0 commit comments

Comments
 (0)