/sentry-bot

Autonomous Nerf turret

Primary LanguagePythonMIT LicenseMIT

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.

  • [picamera] can only be installed on Raspberry Pi hardware
  • [opencv] is used for object recognition. It can be installed on Pi and non-Pi hardware but is extremely slow to compile on a Pi.

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

  • assets/ contains images, etc. for the README
  • frontend/ contains the frontend code and tests, which are written in TypeScript
  • sentrybot/ contains the backend code, which is a Python Flask webserver
  • stubs/ contains type stubs for Mypy
  • tests/ contains the backend tests

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

  1. Make a config.toml file in the directory you will run the app from

  2. optional Add an environment variable to config.toml with the path to a .mp4 video

    VIDEO_PATH='/path/to/any/video.mp4'
  3. optional Build webGL project with Unity and copy the Build/, StreamingAssets/ and TemplateData/ directories to sentrybot/static/. This game can be accessed via the /game URL.

  4. If you are running on a Pi:

    1. Start the pigpio daemon with sudo pigpiod
    2. Run the webserver with flask --app sentrybot --debug run --host 0.0.0.0 but be aware that it will make the webserver accessible to all machines on the network
  5. Else, if you are running on other hardware:

    1. Run the webserver with flask --app sentrybot --debug run
    2. Go to localhost:5000/ in your web browser