Skip to content

Commit

Permalink
Add documentation and script for detector setup
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranbarr committed Jul 3, 2024
1 parent 1493c5a commit a9ac0d2
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 3 deletions.
11 changes: 8 additions & 3 deletions doc/setup.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Setup
# Repo Setup

Please see the section that pertains to your operating system below.

## Windows
### Windows

Please install a recent version of Visual Studio Build Tools: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022

Expand All @@ -16,7 +16,7 @@ cd ../..
pip install -r requirements.txt
```

## Linux
### Linux

Install python3.11. If you are on a Debian-based distribution and you cannot find that version of Python, you can try the deadsnakes ppa: https://askubuntu.com/questions/1398568/installing-python-who-is-deadsnakes-and-why-should-i-trust-them

Expand All @@ -35,3 +35,8 @@ pip install -r requirements.txt

wxPython wheel failure, try: https://wxpython.org/blog/2017-08-17-builds-for-linux-with-pip/index.html

# Detector Setup

This system is intended to be used over a LAN connecting Raspberry Pi -based detector(s) and a main computer. The Raspberry Pi's run the src.main_detector, while the main computer runs the src.main_pose_solver and optionally the src.gui.gui module.

To setup the Raspberry Pi -based detectors, run the setup/create_image.sh script on a compatible linux system. Flash the resulting image to a microSD card (or multiple) for use.
116 changes: 116 additions & 0 deletions setup/create_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

# Setup script for custom Raspbian Lite image for Pi detectors

# If this is your first time running this script and it does not work, try to download these dependencies
#apt-get install coreutils quilt parted qemu-user-static debootstrap zerofree zip \
#dosfstools libarchive-tools libcap2-bin grep rsync xz-utils file git curl bc \
#gpg pigz xxd arch-test

# If it not your first time and it still doesn't work, try deleting the pi-gen directory first
# The below version clones the arm64 branch specfically because I have been building this on a Raspberry Pi 5
# You might need to change this depending on your build system
git clone --branch arm64 https://github.com/RPI-Distro/pi-gen.git
pushd pi-gen
chmod +x build.sh

# Start build process
SECONDS=0
clean=false

# NOTE: This config currently configures the detectors to have default user/pass and ssh open at first boot
# This is obviously a security risk on certain networks, be careful
cat > config <<EOL
export IMG_NAME=detector-raspbian
export RELEASE=bookworm
export DEPLOY_ZIP=1
export LOCALE_DEFAULT=en_US.UTF-8
export TARGET_HOSTNAME=detector-pi
export KEYBOARD_KEYMAP=us
export KEYBOARD_LAYOUT="English (US)"
export TIMEZONE_DEFAULT=America/Toronto
export TARGET_HOSTNAME=pi
export DISABLE_FIRST_BOOT_USER_RENAME=1
export FIRST_USER_NAME=pi
export FIRST_USER_PASS="password"
export ENABLE_SSH=1
EOL

# Skip stages 3-5, only want Raspbian lite
touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES

pushd stage2

# don't need NOOBS
rm -f EXPORT_NOOBS || true

# Add stage to the end of build process that performs the necessary detector setup
step="04-detector-setup"
if [ -d "$step" ]; then rm -Rf $step; fi
mkdir $step && pushd $step
cat > 00-run.sh <<RUN
#!/bin/bash
on_chroot << CHROOT
# Update package list and upgrade packages
apt-get update
apt-get upgrade -y
apt-get install -y python3-venv python3-pip build-essential libgtk-3-dev libglib2.0-dev libgl1-mesa-dev libglu1-mesa-dev python3-picamera2 ufw
# Download and set up the MCSTrack repository
cd /home/pi
wget --no-check-certificate -O MCSTrack.zip https://github.com/PerkLab/MCSTrack/archive/refs/heads/main.zip
unzip MCSTrack.zip
mv MCSTrack-main MCSTrack
chmod 777 MCSTrack
# Set up Python virtual environment and install dependencies
pushd MCSTrack
python3 -m venv .venv --system-site-packages
source .venv/bin/activate
# Exclude the following packages from this install, because the detector doesn't need it
grep -ivE "wxasync|wxpython|PyOpenGL==3.1.7|PyOpenGL-accelerate==3.1.7" requirements.txt> edited_requirements.txt
pip3 install --break-system-packages -r edited_requirements.txt
popd
# Create startup script
cat > /usr/local/bin/startup << EOF
#!/bin/bash
sudo ufw allow 8001
cd /home/pi/MCSTrack
source .venv/bin/activate
python -m src.main_detector
EOF
chmod +x /usr/local/bin/startup
# Schedule the script to run at boot
echo '@reboot root /usr/local/bin/startup >> startup_log.log' > /etc/cron.d/startup
CHROOT
RUN

chmod +x 00-run.sh

popd
popd # stage 02

# run build
if [ "$clean" = true ] ; then
echo "Running build with clean to rebuild last stage"
CLEAN=1 ./build.sh
else
echo "Running build"
./build.sh
fi

exitCode=$?

duration=$SECONDS
echo "Build process completed in $(($duration / 60)) minutes"

if [ $exitCode -ne 0 ]; then
echo "Custom Raspbian lite build failed with exit code ${exitCode}" ; exit -1
fi

ls ./deploy

0 comments on commit a9ac0d2

Please sign in to comment.