dancj / pid_distance_control

RPi Demo that shows a sensor sensing and a motor moving using a Proportional-Integral-Derivative (PID) controller.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PID Distance Control

RPi Demo using Python3 that shows a sensor sensing and a motor moving using a Proportional-Integral-Derivative (PID) controller.

Getting Started

  1. Flash Raspbian lite to SD card, current version is Raspbian Buster
  2. Add empty file named "ssh" to root directory of SD card, to enable ssh
  3. Insert card into RPi and boot up for the first time
  4. Use another computer to SSH into RPi, ssh pi@192.168.1.[rpi_ip]. Default password is raspberry and it's always a good idea to change that right away with passwd command
  5. Update things with *sudo apt update && sudo apt upgrade
  6. sudo apt install git
  7. git clone https://github.com/dancj/pid_distance_control.git
  8. Now this project is on the RPi, just need to set up virtual environment and download dependencies
    1. cd pid_distance_control/
    2. sudo apt install python3-venv
    3. python3 -m venv venv
    4. source venv/bin/activate
    5. pip install -r requirements.txt
  9. Uses pigpiod library to communicate with distance sensor, which needs to be installed:
    1. sudo apt install pigpiod

Getting Started - Docker Edition

  1. Flash Raspbian lite to SD card, current version is Raspbian Buster
  2. Add empty file named "ssh" to root directory of SD card, to enable ssh
  3. Insert card into RPi and boot up for the first time
  4. Use another computer to SSH into RPi, ssh pi@192.168.1.[rpi_ip]. Default password is raspberry and it's always a good idea to change that right away with passwd command
  5. Update things with *sudo apt update && sudo apt upgrade
  6. Install Docker: curl -sSL https://get.docker.com | sh
  7. Update user permissions: sudo usermod -aG docker pi
  8. Run this project's container (TBD): docker run armhf/hello-world

Running

Just need to run the main python routine

  1. cd pid_distance_control/
  2. source venv/bin/activate
  3. sudo pigpiod
  4. python src/run.py

Hardware

  1. Raspberry Pi (RPi) 1 model B (could use any model, this is just the one I had available)
    1. Use cat /proc/cpuinfo | grep model to show processor version. This indicates which Docker base image is needed
  2. Ultrasonic distance sensor (HC-SR04)
    1. This sense transmits a sound wave out of its transitter, then receives the reflected wave in its receiver
  3. Servo motor
  4. Cobbler Pi breakout board
  5. Half size breadboard
  6. Jumper wires
  7. Resistors: 330 and 470 Ohm

Software

Wiring

Testing

References

  1. Using a Raspberry Pi distance sensor
  2. Raspberry Pi Servo Motor control
  3. Ultrasonic sensor tutorial
  4. Sonar Ranger pigpio example

License

This is for a class extra credit project, but mostly just for fun.

Put out there to the world "as is" with MIT license.

About

RPi Demo that shows a sensor sensing and a motor moving using a Proportional-Integral-Derivative (PID) controller.

License:MIT License


Languages

Language:Python 91.4%Language:Dockerfile 8.6%