File locking + Tool to free robot body #218
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the workflow for dealing with the "a Stretch Body process is already running" error. In the past, trying to run Stretch Body while an instance of Stretch Body was already running would result in the following errors/warnings:
For novice Stretch users, this output is scary looking and doesn't clearly communicate how to check if another process is already running (since often, that process is running in the background). Additionally, the Dynamixel classes are not lock protected, so the background Stretch Body instance will start to have trouble pinging the Dxls:
To improve on this workflow, using the
Robot
class from Stretch Body will now acquire a lock from the filesystem and write its process ID using the lock. If another Stretch Body instance has already claimed the lock, the following error is printed out:The new
stretch_free_robot_process.py
tool reads the process ID of the Stretch Body instance holding the lock and terminates the process. This is more reliable than usingpkill -9 python
or similar because it actually knows the process ID and won't be fooled if the process running Stretch Body doesn't have "python" in the name. Additionally, other python processes (e.g. hello_robot_lrf_off.py) won't get killed unintentionally.At the moment, the lock is acquired in
Robot.__init__()
and released inRobot.stop()
, but after bug #217 is fixed, the lock acquiring logic can be moved toRobot.startup()
.Testing
Stretch 2 running Ubuntu 22.04. Tested with Stretch Body tools, iPython, ROS, ROS2, and more.