Raspberry Pi Motion Following Network Camera Project
This is the project page for raspberrypi-motion, a Raspberry Pi based motion tracking network camera. It's a Buildroot (bsquask) based project that incorporates the software and hardware necessary to create a prototype motion tracking pan and tilt network camera. You can jump right to the github page or continue reading.
The center of the motion tracking is a modified version of motion. It's a very naive and simplistic approach, but it's also lightweight and easy to setup and customize. As always, it would not be to hard to take this project and switch to OpenCV and do full face tracking or obstacle avoidance.
Here are some shots of the setup. I'll post more with a video later.
- Automatic motion detection and adjusting the motion to the camera's center field of view
- 180 degree pan and tilt motion
- Network interface for viewing the live stream
Raspberry Pi Model B 756-8308 Motherboard (RASPBRRYPCBA512)
RioRand 2 Pcs TowerPro SG90 9G micro servo motor
Raspberry PI 5MP Camera Board Module
ZITRADES Aircraft FPV dedicated nylon Pan/Tilt
The Raspberry Pi and camera mount are mounted to the top of a plastic project box. The Raspberry Pi is attached with a couple of offsets. I also made some plastic spacers to mount the camera to the camera mount with some bolts. The camera boards is actually much smaller than what the camera mount supports so it will not hold it out of the box and due to the configuration of the camera board itself, it can't be mounted to a flat surface nicely.
There's not much of a schematic, but here it is. If you were to improve on this, put some isolation between the servos and the Raspberry Pi, but I have not had any problems yet.
There are two main hardware interfaces: driving the 2 micro servos and handling the camera. It turns out, the camera is well supported as a v4l2 device out of the box with the latest official Raspberry Pi kernel, so the more interesting thing is driving the servos. Driving a standard RC servo is really simple. It's just a simple PWM (Pulse Width Modulation) where the duty cycle controls the position of the servo. The problem is the Raspberry Pi only has a single hardware PWM. Trying to bitbang a PWM in software is out of the question on Linux. It turns out, needing more than one PWM is a common pitfall and many others have already taken to implementing PWM's using DMA to drive many gpio pins. This works really well and I've taken advantage of one of those projects: raspberrypi-pwm.
For building, see the README.
- Add a complete web interface where the camera can be configured and allow the pan and tilt to be manually controlled.
- Record sound.
- When in idle (no motion detected for some length of time), listen for sound to find motion.
- While this does work, the Raspberry Pi is definitely strained on CPU. I've played around with both the motion and Raspberry Pi CPU settings and have definitely found some major improvements, but it's still not where I'd like it before pushing an update.