Skip to content

Fix/e stop - #10

Merged
ratheron merged 7 commits into
mainfrom
fix/e-stop
Jul 9, 2026
Merged

Fix/e stop#10
ratheron merged 7 commits into
mainfrom
fix/e-stop

Conversation

@yiyixuu

@yiyixuu yiyixuu commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

now drones will immediately drop when pressing ctrl + c or pressing the e-stop button on the front end

@yiyixuu
yiyixuu requested a review from ratheron June 23, 2026 16:51

@ratheron ratheron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR can be made significantly cleaner by removing all the extra checks.

Comment thread swarm_gpt/core/backend.py Outdated
self._preset: None | str = None
self._strict_processing = strict_processing
self._strict_drone_match = strict_drone_match
self._active_swarm: Any | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._active_swarm: Any | None = None
self._active_swarm: DroneSwarm | None = None

Comment thread swarm_gpt/core/backend.py Outdated
self.music_manager.stop()
swarm.goto(final_pos_dict, duration=2.0) # Transition from ideal point to hover pos
if self.settings["land_on_docks"]: # Commented out for demo
if self.settings["land_on_docks"]: # Commented out for demo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space from linting. The comment should be removed though

Comment thread swarm_gpt/launch.py Outdated
Comment on lines +56 to +60
server = uvicorn.Server(uvicorn.Config(app, host=host, port=port))
# uvicorn captures SIGINT/SIGTERM itself (Server.capture_signals installs self.handle_exit)
# and only starts a graceful shutdown, which waits on the open events WebSocket while the
# deploy thread keeps flying. Wrap handle_exit so the first Ctrl+C cuts the motors before
# uvicorn begins draining. capture_signals installs whatever self.handle_exit is at call time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only have the button. This CTRL+C handling seems like unnecessary overhead, since we are inside the frontend only anyway

Comment thread swarm_gpt/core/drone_swarm.py Outdated
Comment on lines +287 to +296
# In-flight loop coroutines self-cut on the latch; this also sends the packet directly
# to cover idle windows. Bounded so the caller never blocks on a loop that has stopped.
coro = self._parallel_by_uri("Emergency stop", uris, self._emergency_stop, timeout=0.5)
try:
if self._loop_thread is not None or self._loop.is_running():
asyncio.run_coroutine_threadsafe(coro, self._loop).result(timeout=1.0)
else:
self._loop.run_until_complete(coro)
except Exception as exc:
logger.error(f"Emergency stop encountered errors: {exc}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this essentially the same as just doing run?

Comment thread swarm_gpt/core/drone_swarm.py Outdated
Sets a latch that halts the choreography stream and blocks further motion
commands so fresh setpoints cannot override the motor cut.
"""
self._estop.set()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't really matter what other threads do. Not sure if we need this

Comment thread swarm_gpt/core/backend.py
Comment thread swarm_gpt/core/drone_swarm.py Outdated
Comment on lines +40 to +43
class EmergencyStopActive(RuntimeError):
"""Raised when a motion command is issued after the emergency-stop latch is set."""


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Comment thread swarm_gpt/core/drone_swarm.py Outdated
Comment on lines +152 to +153
if await self._estop_guarded_sleep(uri, duration):
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no continuous commands here -> we should be able to do a regular sleep in this thread. This is also true for all other sleeps

Comment thread swarm_gpt/core/drone_swarm.py Outdated
Comment on lines +657 to +659
if self._estop.is_set():
await self._emergency_stop(uri)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only point where checking for the estop makes sense, since the commands might overwrite the estop. However, emergency stop sets the estop, so calling emergency stop when estop is set doesn't make sense? Further, I think sending a command won't overwrite an estop, so we should be able to remove this.

@ratheron
ratheron merged commit 369206c into main Jul 9, 2026
5 checks passed
@ratheron
ratheron deleted the fix/e-stop branch July 9, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants