Iain-S / sentry-bot

Autonomous Nerf turret
MIT License
3 stars 3 forks source link

sentry-bot

license platform python pre-commit

An autonomous Nerf turret

Optional Extras

This package has two optional extras. You must install at least one for camera-related features to work.

Deployment

To install on a Raspberry Pi, log in and then:

  1. Install the project with

    pip install "git+https://github.com/Iain-S/sentry-bot#egg=sentrybot[picamera]"`

    Note that we are installing the [picamera] extra and that the " quotes are required if using zsh.

  2. optional Manually compile and install OpenCV by following, for example, these instructions

  3. Proceed to Run the Server

User Setup

You can install this package on non-Pi hardware using pip. Some features of this package will be unavailable on non-Pi hardware but the web server will still run.

If your computer has a camera, you can install the [opencv] extra. You should not try to install the [picamera] extra on non-Pi hardware as installation will fail.

  1. Install the project with

    pip install "git+https://github.com/Iain-S/sentry-bot#egg=sentrybot[opencv]"`

    Note that we are installing the [opencv] extra and that the " quotes are required if using zsh.

  2. Proceed to Run the Server

Developer Setup

Obtain the Code

  1. Clone the repository with something like git clone path/to/sentry-bot-repo
  2. Change directory with cd sentry-bot/ (subsequent instructions assume you are in the repo root directory)

Layout

Pre-requisites

Python & Poetry

  1. Install Python >= 3.10
  2. Install Poetry
  3. Install the sentrybot package and [opencv] extra with poetry install -E opencv
  4. Active our new virtual environment with poetry shell (subsequent instructions assume this is still active)

Node

  1. Install Node and npm
  2. Install our frontend dependencies with npm --prefix ./frontend install ./frontend

Pre-commit

  1. Install pre-commit
  2. Install pre-commit hooks with pre-commit install

The formatters and linters specified in .pre-commit-config.yaml will run whenever you git commit.

Checks

  1. Check that pre-commit hooks pass when you run pre-commit run --all-files
  2. Check that Python pytest tests pass when you run ./test_backend.sh
  3. Check that TypeScript Jest tests pass when you run ./test_frontend.sh

Frontend

  1. Check that you can build the frontend with ./build_frontend.sh (you can build whenever a .ts file changes by adding a --watch argument)

Run the Server

On a Raspberry Pi

  1. Start the pigpio daemon with sudo pigpiod
  2. Set the CONTROL_TURRET environment variable to 1
  3. Set the CAMERA_LIBRARY environment variable to either "picamera" or "opencv"
  4. Run the webserver with python -m sentrybot.http_server but be aware that it will make the webserver accessible to all machines on the network
  5. Go to ip.of.the.pi:8000/ in your web browser, replacing ip.of.the.pi with your Pi's IP address

On Other Hardware

  1. Set the CONTROL_TURRET environment variable to 0
  2. Set the CAMERA_LIBRARY environment variable to either "picamera" or "opencv"
  3. Run the webserver with python -m sentrybot.http_server but be aware that it will make the webserver accessible to all machines on the network
  4. Go to localhost:8000/ in your web browser