Skip to content

A simple-ish project using a Raspberry Pi and three servos.

Notifications You must be signed in to change notification settings

nicohmje/PID-ballonplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using a PID algo and Computer Vision to stabilize a ping-pong ball on a moving plane

the complete assembly

A relatively straightforward project using a Raspberry Pi, three servos and a 3D printed structure.

SEE IT IN ACTION!

Principle behind the project:

  1. A Pi camera tracks the position of the ball, using OpenCV. A mask is first applied separating the orange color of the ball from the rest. The mask is then eroded twice, blurred, and finally a 'smallest enclosing circle' command returns the radius and the center position.

  2. This information is then filtered by radius. If it is part of the range of radii that the ball is expected to have, the program calculates the error between the position of the ball and the center of the plate. Three errors total are calculated, one for each servos' line of action.

  3. These three errors are then input in the three PID Controllers, including past errors and past derivatives. The PID Controllers then output a change of angle for each servo, which is first normalized against computing time to account for small variations, and then sent using AdaFruit's servo library to the motors.

Improvements / Failures

My current platform is unstable at best, and requires constant recalibration (Done through the GUI); a more stable platform could be obtained with a better interface between the arms. Ball bearings could be used to further smoothen the motion of the platform, and more drastically three more servos could be added for a full on Stewart platform. At this scale however with this level of precision, the current platform is suitable enough.

One could also use Dynamixel Servos for a more accurate position control, although this would significantly increase the price of the whole assembly.

Parts list :

  • Raspberry Pi 4b 8 gb
  • Pi Camera V2
  • Adafruit Camera cable extension
  • Three DIYMORE Full metal servos
  • Waveshare Servo HAT
  • Pimoroni Fan Shim
  • Three Dexter Cardan Joints (Universal joints)

The rest of the parts are 3D printed.

Part selection really doesn't matter that much apart from the RPi and the PiCamera. Use what is available to you for a fair price, and adapt the parts to your needs.

Want to replicate this project yourself ?

Great idea! If you need any help, feel free to shoot me a message on reddit (/u/parisiancyclist) or Instagram (@nicohmje). You can also directly contact me through GitHub.

The STL Files folder includes the necessary parts for this project. These should be adapted to your parts and specific setup, and should only serve as a reference. The 3MF Files folder includes the prototypes too, if you want a deeper, in-depth look at the projects evolution.

Happy building!

About

A simple-ish project using a Raspberry Pi and three servos.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages