Prevent accidental queueing of jog commands
This commit is contained in:
parent
4d445396b2
commit
abda60adf6
1 changed files with 10 additions and 3 deletions
|
|
@ -333,7 +333,12 @@ class SangaboardThing(BaseStage):
|
||||||
:param timeout: how long to wait for the command to be completed, or `None`
|
:param timeout: how long to wait for the command to be completed, or `None`
|
||||||
to skip waiting.
|
to skip waiting.
|
||||||
"""
|
"""
|
||||||
with self._jog_lock:
|
if not self._jog_lock.acquire(timeout=0.1):
|
||||||
|
self.logger.warning(
|
||||||
|
"Could not send a jog message, this indicates a lock error."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
try:
|
||||||
# Make sure the queue exists.
|
# Make sure the queue exists.
|
||||||
# Check the background thread is running, and restart it if not.
|
# Check the background thread is running, and restart it if not.
|
||||||
if self._jog_thread is None or not self._jog_thread.is_alive():
|
if self._jog_thread is None or not self._jog_thread.is_alive():
|
||||||
|
|
@ -343,6 +348,8 @@ class SangaboardThing(BaseStage):
|
||||||
self._jog_thread.start()
|
self._jog_thread.start()
|
||||||
self._jog_queue.put(command)
|
self._jog_queue.put(command)
|
||||||
command.received.wait(1)
|
command.received.wait(1)
|
||||||
|
finally:
|
||||||
|
self._jog_lock.release()
|
||||||
# The final wait happens after releasing the lock: this allows jog moves to
|
# The final wait happens after releasing the lock: this allows jog moves to
|
||||||
# be interrupted.
|
# be interrupted.
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
|
|
@ -397,8 +404,8 @@ class SangaboardThing(BaseStage):
|
||||||
duration = 0.1 # Next iteration, we will probably time out.
|
duration = 0.1 # Next iteration, we will probably time out.
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"Unknown jog command: {command}")
|
raise RuntimeError(f"Unknown jog command: {command}")
|
||||||
self._update_position()
|
self.update_position()
|
||||||
if previous_command:
|
if previous_command:
|
||||||
# Notify the last command that it finished, because we stopped moving.
|
# Notify the last command that it finished, because we stopped moving.
|
||||||
previous_command.finished.set()
|
previous_command.finished.set()
|
||||||
self._update_position()
|
self.update_position()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue