Skip to content

Commit

Permalink
fix launch delay issues
Browse files Browse the repository at this point in the history
  • Loading branch information
itsarune committed Nov 14, 2024
1 parent 49c106d commit 460986b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions environment_setup/setup_software.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ virtualenv_opt_args=""
if [[ $(lsb_release -rs) == "24.04" ]]; then
host_software_packages+=(python3-pyqt6)
host_software_packages+=(pyqt6-dev-tools)
host_software_packages+=(python3-pyqt6.qtsvg)

virtualenv_opt_args="--system-site-packages"
fi
Expand Down
1 change: 0 additions & 1 deletion environment_setup/ubuntu20_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ python-Levenshtein==0.25.1
psutil==5.9.0
PyOpenGL==3.1.6
ruff==0.5.5
evdev==1.7.0
1 change: 0 additions & 1 deletion environment_setup/ubuntu22_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ psutil==5.9.0
PyOpenGL==3.1.6
numpy==1.26.4
ruff==0.5.5
evdev==1.7.0
3 changes: 2 additions & 1 deletion src/software/thunderscope/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ py_library(
"//software/thunderscope/binary_context_managers:game_controller",
"//software/thunderscope/binary_context_managers:simulator",
"//software/thunderscope/binary_context_managers:tigers_autoref",
requirement("pyqtgraph"),
requirement("numpy"),
requirement("pyqtdarktheme-fork"),
requirement("pyqtgraph"),
],
)

Expand Down
2 changes: 2 additions & 0 deletions src/software/thunderscope/requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
evdev==1.7.0
numpy==1.26.4
protobuf==5.27.3
pyqtgraph==0.13.7
pyqtdarktheme-fork==2.3.2
PyQt6-Qt6==6.6.1
9 changes: 9 additions & 0 deletions src/software/thunderscope/requirements_lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ darkdetect==0.7.1 \
--hash=sha256:3efe69f8ecd5f1b7f4fbb0d1d93f656b0e493c45cc49222380ffe2a529cbc866 \
--hash=sha256:47be3cf5134432ddb616bbffc927237718407914993c82809983e7ccebf49013
# via pyqtdarktheme-fork
evdev==1.7.0 \
--hash=sha256:95bd2a1e0c6ce2cd7a2ecc6e6cd9736ff794b3ad5cb54d81d8cbc2e414d0b870
# via -r software/thunderscope/requirements.in
numpy==1.26.4 \
--hash=sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b \
--hash=sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818 \
Expand Down Expand Up @@ -61,6 +64,12 @@ protobuf==5.27.3 \
--hash=sha256:c84eee2c71ed83704f1afbf1a85c3171eab0fd1ade3b399b3fad0884cbcca8bf \
--hash=sha256:dcb307cd4ef8fec0cf52cb9105a03d06fbb5275ce6d84a6ae33bc6cf84e0a07b
# via -r software/thunderscope/requirements.in
pyqt6-qt6==6.6.1 \
--hash=sha256:0409aa09b8dae90d5f00ba2d9761e671dfbc54ab169cff8f4cdfecd7f664fd0f \
--hash=sha256:41f1ed3eadc00540c205a0e897ae0e0fffc21b896e575214f7c5b9c86d2037d1 \
--hash=sha256:8dcac0bd9df13d63deafb6a61969b832c34467da4a28d2b7abf78066bfce22e6 \
--hash=sha256:e7df8851c93886412d890d0ecc62b39f42521861ee7a80982136d65903e1f2c5
# via -r software/thunderscope/requirements.in
pyqtdarktheme-fork==2.3.2 \
--hash=sha256:3ea94fed5df262d960378409357c63032639f749794d766f41a45ad8558b2523 \
--hash=sha256:d96ee64f0884678fad9b6bc352d5e37d84ca786fa60ed32ffaa7e6c6bc67e964
Expand Down
1 change: 1 addition & 0 deletions src/software/thunderscope/robot_diagnostics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ py_library(
":handheld_controller",
"//software/thunderscope:constants",
requirement("pyqtgraph"),
requirement("evdev"),
],
)

Expand Down
4 changes: 2 additions & 2 deletions src/software/thunderscope/thunderscope_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def __ticker(tick_rate_ms: int) -> None:
"""
sync_simulation(
tscope.proto_unix_io_map[ProtoUnixIOTypes.SIM],
tscope,
0 if args.empty else DIV_B_NUM_ROBOTS,
)

Expand Down Expand Up @@ -494,7 +494,7 @@ def __ticker(tick_rate_ms: int) -> None:
autoref.setup_ssl_wrapper_packets(
autoref_proto_unix_io,
)

# Start the simulator
sim_ticker_thread = threading.Thread(
target=__ticker,
Expand Down
17 changes: 10 additions & 7 deletions src/software/thunderscope/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from proto.import_all_protos import *
from proto.message_translation import tbots_protobuf
from software.py_constants import SECONDS_PER_MILLISECOND
from software.thunderscope.constants import ProtoUnixIOTypes
from software.thunderscope.proto_unix_io import ProtoUnixIO
from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer
from software.thunderscope.thunderscope import Thunderscope
Expand Down Expand Up @@ -102,10 +103,6 @@ def realtime_sim_ticker(
sim_proto_unix_io.register_observer(SimulationState, simulation_state_buffer)
per_tick_delay_s = tick_rate_ms * SECONDS_PER_MILLISECOND

# Wait for Thunderscope to launch
while not tscope.is_open():
time.sleep(per_tick_delay_s)

# Tick simulation if Thundersocpe is open
while tscope.is_open():
simulation_state_message = simulation_state_buffer.get()
Expand All @@ -120,12 +117,14 @@ def realtime_sim_ticker(
)


def sync_simulation(sim_proto_unix_io: ProtoUnixIO, num_robots: int) -> None:
def sync_simulation(tscope: Thunderscope, num_robots: int, timeout_s: float = 0.1) -> None:
"""Ensure that simulator has synchronized with the default world state.
:param sim_proto_unix_io: ProtoUnixIO for the Simulation
:param tscope: Thunderscope instance that is tied to this instance of the simulation
:param num_robots: Number of robots to initialize the simulator with
:param timeout_s: How long to wait before we retry our attempt to synchronize with the simulator
"""
sim_proto_unix_io = tscope.proto_unix_io_map[ProtoUnixIOTypes.SIM]
world_state_received_buffer = ThreadSafeBuffer(1, WorldStateReceivedTrigger)
sim_proto_unix_io.register_observer(
WorldStateReceivedTrigger, world_state_received_buffer
Expand All @@ -137,11 +136,15 @@ def sync_simulation(sim_proto_unix_io: ProtoUnixIO, num_robots: int) -> None:

try:
world_state_received = world_state_received_buffer.get(
block=True, timeout=0.1
block=True, timeout=timeout_s
)
except queue.Empty:
# Did not receive a response within timeout period
continue
else:
# Received a response from the simulator
break

# Wait for Thunderscope to launch
while not tscope.is_open():
time.sleep(timeout_s)

0 comments on commit 460986b

Please sign in to comment.