Skip to content

Latest commit

 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🔭 PiTracker

A deep tracking rover.

License License License

Key Features • Usage • Setup • Credits • License

PiTracker leverages TensorFlow Lite and a lightweight neural network - Single Shot Detection - in order to deliver tracking at decent 3-4 FPS despite the RPi's weak CPU and GPU.

Key Features

  • Control the rover using your keyboard
  • Detect objects using TensorFlow Lite (tflite)
  • Track a specified object class (eg. person or bird) using a pan-tilt camera with Proportional Integral Derivative (PID) process control

Usage

usage: main.py

This produces a view from your RPi camera with bounding boxes of objects. Use "WASD" in the terminal to control the rover and the picamera should track any object you specify. Press "E" to exit.

Setup

There are two parts to the set-up: building the rover and setting up your Raspberry Pi.

Build Instructions

You need the following hardware:

The above schematic is how to connect all our components together. It might seem a little complicated, but don't worry, it's actually not that complex! There are two parts to the diagram: the motors (the batteries, L298N motor driver and the two DC motors) and the servos (the breadboard and two servos)

1. The motors

  1. Connect the two DC motors to the L298N motor driver
  2. Connect GPIO BOARD pin 13 to the L298N in1 pin (Brown) #B63802
  3. Connect GPIO BOARD pin 11 to the L298N in2 pin (Orange) #F6C02C
  4. Connect GPIO BOARD pin 15 to the L298N en1 pin (Green) #2FF32
  5. Connect GPIO BOARD pin 16 to the L298N in3 pin (Blue) #1261FF
  6. Connect GPIO BOARD pin 18 to the L298N in4 pin (Purple) #9012FF
  7. Connect GPIO BOARD pin 22 to the L298N en2 pin (White) #FFFFFF
  8. Connect the batteries to the L298N
  9. Connect the L298N to a GPIO GND pin

2. The servos

The servos are much simpler, so just follow that part of the schematic diagram

3. Pan-tilt camera

To build the pan-tilt camera, you just need two servos - one for panning and the other for tilting. You can either buy a Pimoroni one, or just tape together two servos like I did below.

Setting up RPi

1. Prepare Raspberry Pi OS

The supported software baseline is 64-bit Raspberry Pi OS Bookworm with Python 3.11. Configure and test the camera using the Raspberry Pi OS camera tools before starting PiTracker.

2. Clone this Github repository

$ git clone https://github.com/jwnicholas/PiTracker.git
$ cd PiTracker/

3. Create a new venv and install packages

Install the required system packages:

$ sudo apt update
$ sudo apt install -y python3-venv pigpio libgl1 libglib2.0-0
$ sudo systemctl enable --now pigpiod

Confirm that Python 3.11 is active:

$ python3 --version
Python 3.11.x

Create and activate a virtual environment:

$ python3 -m venv .venv
$ source .venv/bin/activate

Install the pinned runtime dependencies. The manifest includes current ARM wheels for OpenCV and TensorFlow Lite, so the old hand-installed wheels are no longer needed.

$ python -m pip install --upgrade pip
$ python -m pip install -r requirements-rpi.txt

4. Update main.py to use your own GPIO pins

It's likely that you will use different GPIO pins, so open up main.py and update the following lines:

# right motor
in1 = 13
in2 = 11
en1 = 15

# left motor
in3 = 16
in4 = 18
en2 = 22

# servos are using pigpio, which uses BCM numbering
# while the motors are using BOARD numbering
pan = 12
tilt = 13

Note that I am using two different modules for controlling GPIO pins: RPi.GPIO (for interfacing with the motor driver and the wheels) and pigpio (for controlling the servos). This is because pigpio is much more accurate than RPi.GPIO in maintaining pulse width modulation, hence preventing the servos from twitching too much.

Note that for the RPi.GPIO, I'm using BOARD numbering, while pigpio only allows me to use BCM numbering.

Credits

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Releases

Packages

Used by

Contributors

Languages