Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

406 add back emergency stop button #425

Merged
merged 12 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/autoformat-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
ref: ${{ github.head_ref }}
token: ${{ secrets.WORKFLOW_COMMIT }}

- name: 🐍 Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: "pip"

- name: 📦 Install Hatch
uses: pypa/hatch@install

Expand All @@ -37,6 +43,6 @@ jobs:

- name: 🧶 Lint
run: hatch fmt --check
# - name: 🔍 Type Check
# run: hatch -e types run check

- name: 🔍 Type Check
run: hatch run check
11 changes: 5 additions & 6 deletions docs/development/socketio_api.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Socket.IO API

This section documents the Socket.IO API. The document is intended for developers building client applications
communicating with the server. If you are looking for information on how to set up and run the server, see the
[installation guide](../home/installation.md)!
This section documents the [Socket.IO](https://socket.io/) API. The document is intended for developers building client
applications communicating with the server. If you are looking for information on how to set up and run the server, see
the [installation guide](../home/installation.md)!

## Data Types

All messages on Socket.IO are passed as strings. Complex data structures are JSON encoded, converted to strings, and
then
sent. These structures have their JSON schemas documented
then sent. These structures have their JSON schemas documented
on [VBL Aquarium](https://github.com/VirtualBrainLab/vbl-aquarium/tree/main/models/schemas/ephys_link).

This documentation will reference the Pydantic versions of these models as they are extensively documented. For most
Expand All @@ -19,7 +18,7 @@ object to a string that can be sent over Socket.IO.
## Events

Client applications should send messages to these events to interact with the server. The server will respond using
Socket.IO acknowledgments.
[Socket.IO acknowledgments](https://socket.io/docs/v4/#acknowledgements).

### Get Ephys Link Version

Expand Down
7 changes: 2 additions & 5 deletions docs/home/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
cable and powered. A USB-to-ethernet adapter is acceptable. For New Scale manipulators,
the controller unit must be connected via USB and be powered by a 6V power
supply.
3. To use the emergency stop feature, ensure an Arduino with
the [StopSignal](https://github.com/VirtualBrainLab/StopSignal) sketch is
connected to the computer. Follow the instructions on that repo for how to
set up the Arduino.
3. To use the emergency stop feature, ensure a keyboard is attached.

## Pinpoint (Recommended Method)

Pinpoint comes bundled with the correct version of Ephys Link. If you are using Pinpoint on the same computer your
manipulators are connected to, you can launch the server from within Pinpoint. See the documentation
on [connecting from Pinpoint](../usage/connecting_to_pinpoint.md).
on [connecting from Pinpoint](../usage/using_ephys_link.md#connecting-to-pinpoint).

## Install as a Standalone Executable

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ to communicate with manipulators used in electrophysiology experiments.

Learn how to use Ephys Link to control your manipulators.

[:octicons-arrow-right-24: Usage](usage/index.md)
[:octicons-arrow-right-24: Usage](usage/starting_ephys_link.md)

- __:fontawesome-regular-square-plus: Add a Manipulator Platform__

Expand Down
8 changes: 0 additions & 8 deletions docs/usage/connecting_to_pinpoint.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/usage/starting_ephys_link.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Ephys Link is a server that runs in the background.
!!! info

Most people should use Ephys Link through Pinpoint. See documentation
on [connecting from Pinpoint](connecting_to_pinpoint.md) and using Ephys Link
for [experiment automation](experiment_automation.md).
on [connecting from Pinpoint](using_ephys_link.md#connecting-to-pinpoint) and using Ephys Link
for [experiment automation](using_ephys_link.md#experiment-automation).

If you are building a client application that will talk to Ephys Link, see
the [Socket.IO API reference](../development/socketio_api.md).
Expand Down
31 changes: 31 additions & 0 deletions docs/usage/using_ephys_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Using Ephys Link

Ephys Link is designed to interact with other software. Any [Socket.IO](https://socket.io/) client application can talk
to Ephys Link and access connected manipulators. [Pinpoint](https://github.com/VirtualBrainLab/Pinpoint) is a first-party application that does just that!

!!! info "Stop All Movement"

As you start using Ephys Link with other software you may want to stop all manipulators in case of an emergency.
<br/><br/>
Press the keyboard shortcut <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>alt</kbd> + <kbd>q</kbd> to "quit" all
movement.

## Connecting to Pinpoint

[Pinpoint](https://github.com/VirtualBrainLab/Pinpoint) is a tool for planning electrophysiology recordings and other
_in vivo_ insertions, as well as tracking the position of probes in real-time inside the brain.

Ephys Link was developed alongside Pinpoint to facilitate tracking and positioning of manipulators. Follow the
[instructions on Pinpoint's documentation](https://virtualbrainlab.org//pinpoint/tutorials/tutorial_ephys_link.html) to
use Ephys Link inside Pinpoint!

## Experiment Automation

Pinpoint and Ephys Link can work together to automate manual procedures in electrophysiology experiments. Follow the
[instructions on Pinpoint's documentation](https://virtualbrainlab.org//pinpoint/tutorials/tutorial_ephys_copilot.html)
to use automation in your next experiment!

!!! note

Automation is still in early development. We recommend [contacting](https://virtualbrainlab.org/about/overview.html)
Dan Birman and Kenneth Yang if you would like to try it out!
3 changes: 1 addition & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ nav:
- home/citing.md
- Usage:
- usage/starting_ephys_link.md
- usage/connecting_to_pinpoint.md
- usage/experiment_automation.md
- usage/using_ephys_link.md
- Development:
- development/index.md
- development/socketio_api.md
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ classifiers = [
dependencies = [
"aiohttp==3.11.11",
"colorama==0.4.6",
"keyboard==0.13.5",
"packaging==24.2",
"platformdirs==4.3.6",
"pyserial==3.5",
Expand Down Expand Up @@ -61,7 +62,7 @@ exclude = ["/.github", "/.idea"]
python = "3.13.1"
dependencies = [
"pyinstaller==6.11.1",
"basedpyright==1.23.1"
"basedpyright==1.23.1",
]
[tool.hatch.envs.default.scripts]
exe = "pyinstaller.exe ephys_link.spec -y -- -d && pyinstaller.exe ephys_link.spec -y"
Expand Down
6 changes: 5 additions & 1 deletion src/ephys_link/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
```
"""

from asyncio import run
from sys import argv

from keyboard import add_hotkey

from ephys_link.back_end.platform_handler import PlatformHandler
from ephys_link.back_end.server import Server
from ephys_link.front_end.cli import CLI
Expand Down Expand Up @@ -37,7 +40,8 @@ def main() -> None:
# 4. Instantiate the Platform Handler with the appropriate platform bindings.
platform_handler = PlatformHandler(options, console)

# 5. Instantiate the Emergency Stop service.
# 5. Add hotkeys for emergency stop.
_ = add_hotkey("ctrl+alt+shift+q", lambda: run(platform_handler.emergency_stop()))

# 6. Start the server.
Server(options, platform_handler, console).launch()
Expand Down
5 changes: 5 additions & 0 deletions src/ephys_link/back_end/platform_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,8 @@ async def stop_all(self) -> str:
return self._console.pretty_exception(e)
else:
return ""

async def emergency_stop(self) -> None:
"""Stops all manipulators with a message."""
self._console.critical_print("Emergency Stopping All Manipulators...")
_ = await self.stop_all()
4 changes: 2 additions & 2 deletions src/ephys_link/bindings/mpm_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, port: int = 8080) -> None:
self._movement_stopped = False

# Data cache.
self.cache = {}
self.cache: dict[str, Any] = {} # pyright: ignore [reportExplicitAny]
self.cache_time = 0

@staticmethod
Expand Down Expand Up @@ -286,7 +286,7 @@ async def _query_data(self) -> dict[str, Any]: # pyright: ignore [reportExplici
# Update cache if it's expired.
if get_running_loop().time() - self.cache_time > self.CACHE_LIFETIME:
# noinspection PyTypeChecker
self.cache = (await get_running_loop().run_in_executor(None, get, self._url)).json() # pyright: ignore [reportAny]
self.cache = (await get_running_loop().run_in_executor(None, get, self._url)).json()
self.cache_time = get_running_loop().time()
except ConnectionError as connectionError:
error_message = f"Unable to connect to MPM HTTP server: {connectionError}"
Expand Down
Loading