Skip to content

Commit 81ec083

Browse files
Thunderscope Hotfix (#3407)
* Wait for Thunderscope to launch before sending simulation ticks * fix launch delay issues * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 78556e6 commit 81ec083

File tree

9 files changed

+30
-11
lines changed

9 files changed

+30
-11
lines changed

environment_setup/setup_software.sh

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ virtualenv_opt_args=""
108108
if [[ $(lsb_release -rs) == "24.04" ]]; then
109109
host_software_packages+=(python3-pyqt6)
110110
host_software_packages+=(pyqt6-dev-tools)
111+
host_software_packages+=(python3-pyqt6.qtsvg)
111112

112113
virtualenv_opt_args="--system-site-packages"
113114
fi

environment_setup/ubuntu20_requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ python-Levenshtein==0.25.1
77
psutil==5.9.0
88
PyOpenGL==3.1.6
99
ruff==0.5.5
10-
evdev==1.7.0

environment_setup/ubuntu22_requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ psutil==5.9.0
88
PyOpenGL==3.1.6
99
numpy==1.26.4
1010
ruff==0.5.5
11-
evdev==1.7.0

src/software/thunderscope/BUILD

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ py_library(
4747
"//software/thunderscope/binary_context_managers:game_controller",
4848
"//software/thunderscope/binary_context_managers:simulator",
4949
"//software/thunderscope/binary_context_managers:tigers_autoref",
50-
requirement("pyqtgraph"),
5150
requirement("numpy"),
51+
requirement("pyqtdarktheme-fork"),
52+
requirement("pyqtgraph"),
5253
],
5354
)
5455

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
evdev==1.7.0
12
numpy==1.26.4
23
protobuf==5.27.3
34
pyqtgraph==0.13.7
45
pyqtdarktheme-fork==2.3.2
6+
PyQt6-Qt6==6.6.1

src/software/thunderscope/requirements_lock.txt

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ darkdetect==0.7.1 \
88
--hash=sha256:3efe69f8ecd5f1b7f4fbb0d1d93f656b0e493c45cc49222380ffe2a529cbc866 \
99
--hash=sha256:47be3cf5134432ddb616bbffc927237718407914993c82809983e7ccebf49013
1010
# via pyqtdarktheme-fork
11+
evdev==1.7.0 \
12+
--hash=sha256:95bd2a1e0c6ce2cd7a2ecc6e6cd9736ff794b3ad5cb54d81d8cbc2e414d0b870
13+
# via -r software/thunderscope/requirements.in
1114
numpy==1.26.4 \
1215
--hash=sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b \
1316
--hash=sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818 \
@@ -61,6 +64,12 @@ protobuf==5.27.3 \
6164
--hash=sha256:c84eee2c71ed83704f1afbf1a85c3171eab0fd1ade3b399b3fad0884cbcca8bf \
6265
--hash=sha256:dcb307cd4ef8fec0cf52cb9105a03d06fbb5275ce6d84a6ae33bc6cf84e0a07b
6366
# via -r software/thunderscope/requirements.in
67+
pyqt6-qt6==6.6.1 \
68+
--hash=sha256:0409aa09b8dae90d5f00ba2d9761e671dfbc54ab169cff8f4cdfecd7f664fd0f \
69+
--hash=sha256:41f1ed3eadc00540c205a0e897ae0e0fffc21b896e575214f7c5b9c86d2037d1 \
70+
--hash=sha256:8dcac0bd9df13d63deafb6a61969b832c34467da4a28d2b7abf78066bfce22e6 \
71+
--hash=sha256:e7df8851c93886412d890d0ecc62b39f42521861ee7a80982136d65903e1f2c5
72+
# via -r software/thunderscope/requirements.in
6473
pyqtdarktheme-fork==2.3.2 \
6574
--hash=sha256:3ea94fed5df262d960378409357c63032639f749794d766f41a45ad8558b2523 \
6675
--hash=sha256:d96ee64f0884678fad9b6bc352d5e37d84ca786fa60ed32ffaa7e6c6bc67e964

src/software/thunderscope/robot_diagnostics/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ py_library(
3535
":handheld_controller",
3636
"//software/thunderscope:constants",
3737
requirement("pyqtgraph"),
38+
requirement("evdev"),
3839
],
3940
)
4041

src/software/thunderscope/thunderscope_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def __ticker(tick_rate_ms: int) -> None:
421421
422422
"""
423423
sync_simulation(
424-
tscope.proto_unix_io_map[ProtoUnixIOTypes.SIM],
424+
tscope,
425425
0 if args.empty else DIV_B_NUM_ROBOTS,
426426
)
427427

src/software/thunderscope/util.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from proto.import_all_protos import *
44
from proto.message_translation import tbots_protobuf
55
from software.py_constants import SECONDS_PER_MILLISECOND
6+
from software.thunderscope.constants import ProtoUnixIOTypes
67
from software.thunderscope.proto_unix_io import ProtoUnixIO
78
from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer
89
from software.thunderscope.thunderscope import Thunderscope
@@ -100,6 +101,7 @@ def realtime_sim_ticker(
100101
"""
101102
simulation_state_buffer = ThreadSafeBuffer(5, SimulationState)
102103
sim_proto_unix_io.register_observer(SimulationState, simulation_state_buffer)
104+
per_tick_delay_s = tick_rate_ms * SECONDS_PER_MILLISECOND
103105

104106
# Tick simulation if Thundersocpe is open
105107
while tscope.is_open():
@@ -109,18 +111,19 @@ def realtime_sim_ticker(
109111
tick = SimulatorTick(milliseconds=tick_rate_ms)
110112
sim_proto_unix_io.send_proto(SimulatorTick, tick)
111113

112-
time.sleep(
113-
(tick_rate_ms * SECONDS_PER_MILLISECOND)
114-
/ simulation_state_message.simulation_speed
115-
)
114+
time.sleep(per_tick_delay_s / simulation_state_message.simulation_speed)
116115

117116

118-
def sync_simulation(sim_proto_unix_io: ProtoUnixIO, num_robots: int) -> None:
117+
def sync_simulation(
118+
tscope: Thunderscope, num_robots: int, timeout_s: float = 0.1
119+
) -> None:
119120
"""Ensure that simulator has synchronized with the default world state.
120121
121-
:param sim_proto_unix_io: ProtoUnixIO for the Simulation
122+
:param tscope: Thunderscope instance that is tied to this instance of the simulation
122123
:param num_robots: Number of robots to initialize the simulator with
124+
:param timeout_s: How long to wait before we retry our attempt to synchronize with the simulator
123125
"""
126+
sim_proto_unix_io = tscope.proto_unix_io_map[ProtoUnixIOTypes.SIM]
124127
world_state_received_buffer = ThreadSafeBuffer(1, WorldStateReceivedTrigger)
125128
sim_proto_unix_io.register_observer(
126129
WorldStateReceivedTrigger, world_state_received_buffer
@@ -132,11 +135,15 @@ def sync_simulation(sim_proto_unix_io: ProtoUnixIO, num_robots: int) -> None:
132135

133136
try:
134137
world_state_received = world_state_received_buffer.get(
135-
block=True, timeout=0.1
138+
block=True, timeout=timeout_s
136139
)
137140
except queue.Empty:
138141
# Did not receive a response within timeout period
139142
continue
140143
else:
141144
# Received a response from the simulator
142145
break
146+
147+
# Wait for Thunderscope to launch
148+
while not tscope.is_open():
149+
time.sleep(timeout_s)

0 commit comments

Comments
 (0)