Docsity

controle ball and table, Manuais, Projetos, Pesquisas de Sistemas de Controle Lineares

Toggle sidebar
bg1
instructables
Ball Balancing PID System
by Johan Link
This system holds a ball in balance on a plate. A
webcam films the system and a python program
analyzes the images to find the position of the ball.
The python program calculates the tilting of the tray to
prevent the ball from falling.
A proportional-integral-derivative (PID) regulator is
used to compensate the movements of the ball. The
position and speed of the ball are measured by the
camera and these measurements are used by the
PID regulator in the python program.
Sorry about the English faults, it’s not my mother
tongue.
Ball Balancing PID System: Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
Discount

Em oferta

Pré-visualização parcial do texto

Baixe controle ball and table e outras Manuais, Projetos, Pesquisas em PDF para Sistemas de Controle Lineares, somente na Docsity!

instructables

Ball Balancing PID System

by Johan Link This system holds a ball in balance on a plate. A webcam films the system and a python program analyzes the images to find the position of the ball. The python program calculates the tilting of the tray to prevent the ball from falling. A proportional-integral-derivative (PID) regulator is used to compensate the movements of the ball. The position and speed of the ball are measured by the camera and these measurements are used by the PID regulator in the python program. Sorry about the English faults, it’s not my mother tongue.

https://www.youtube.com/watch?v=57DbEEBF7sE

https://www.instructables.com/ORIG/FPU/YODV/JQ2O7V56/FPUYODVJQ2O7V56.zip… Download

Step 2: 3D Printing

Warning : inferieur.stl, superieur.stl and plateau.stl files are not 3D printable. inferieur.stl and superieur.stl are made of acrylic. You can use a CNC to make these parts, but you can also cut them yourself in an acrylic sheet because these parts don't have a very complicated design. plateau.stl can be cut in cardboard.

https://www.instructables.com/ORIG/F8M/1X6E/JQ2O70M0/F8M1X6EJQ2O70M0.stl… View in 3D Download https://www.instructables.com/ORIG/FN9/SJ1N/JQ2O70OT/FN9SJ1NJQ2O70OT.stl… View in 3D Download https://www.instructables.com/ORIG/FRT/9R7Q/JQ2O70P8/FRT9R7QJQ2O70P8.stl… View in 3D Download https://www.instructables.com/ORIG/FLF/UI7T/JQ2O70P7/FLFUI7TJQ2O70P7.stl… View in 3D Download https://www.instructables.com/ORIG/FCX/WFJ8/JQ2O70OS/FCXWFJ8JQ2O70OS.stl… View in 3D Download https://www.instructables.com/ORIG/FK5/4UOY/JQ2O70OR/FK54UOYJQ2O70OR.stl… View in 3D Download https://www.instructables.com/ORIG/FG6/UDDE/JQ2O70OP/FG6UDDEJQ2O70OP.stl… View in 3D Download https://www.instructables.com/ORIG/FGD/ZYON/JQ2O70ME/FGDZYONJQ2O70ME.stl… View in 3D Download https://www.instructables.com/ORIG/FCT/TZ8X/JQ2O70MG/FCTTZ8XJQ2O70MG.stl… View in 3D Download https://www.instructables.com/ORIG/F7Z/TVZL/JQ2O70MI/F7ZTVZLJQ2O70MI.stl… View in 3D Download

Step 3: Parts Assembly

Mechanical parts : Futaba servo s Magnets and balls https://fr.aliexpress.com/item/2017-One-Set-Diago... 13X M4 * 10mm bolt https://www.amazon.fr/Boulon-hexagonal-acier-inox... 10X M4 nut https://www.amazon.fr/Boulon-hexagonal-acier-inox... 15X https://www.amazon.fr/Boulon-hexagonal-acier-inox... 3X M4 * 10mm bolt https://www.amazon.fr/Boulon-hexagonal-acier-inox... 3X M4 nut https://www.amazon.fr/Boulon-hexagonal-acier-inox... USB Webcam https://www.amazon.fr/Boulon-hexagonal-acier-inox... Aluminum tube : length 474mm ,diameter 8mm

  1. acrylic
  2. acrylic
  3. cardboard

Step 4: PCB Programming

The PCB contains the same microcontroller as the arduino leonardo. Therefore it can be programmed with Arduino software. The code can be downloaded here. Before programming the PCB, you have to burn the bootloader: Arduino as ISP and Arduino Bootloaders Burning the Bootloader

  1. You need an Arduino
  2. Upload the ArduinoISP sketch (arduino software / Examples / ArduinoISP) onto your Arduino board
  3. Make the connections as in the picture
  4. Select "Arduino Leonardo" from the Tools > Board menu.
  5. Select "Arduino as ISP" from Tools > Programmer
  6. Run Tools > Burn Bootloader
  7. The process can take several minutes.
  8. Disconnect all cables. After this step you have to connect the pcb to the computer with a USB cable and upload this code.

Step 5: Python Program

The most important code is in the computer that controls the system. You can find the code here. How does it work. The first step is to find the position of the ball. The camera sends the computer live video. The python program receives the video and has to process it. I use the OpenCV library to do the image processing. The program detects the ball thanks to its color. Here the ball is orange, the program will then average the position of all the orange pixels of the image to find the position of the ball. With OpenCV all this is quite simple. I recommend this tutorial for color recognition with OpenCV: href="https://www.pyimagesearch.com/2015/09/14/ba ll-tracking-with- opencv/">https://www.pyimagesearch.com/2015/09/ 4/ball-tracking-with-opencv/ Now that we have the ball position we can calculate the inclination of the board with PID (proportional, integral, and derivative) control. The regulation is done in three stages. The first step is the simplest. Imagine that we want to stabilize the ball in the center of the board. The further away the ball is from the center, the more it will be necessary to tilt the board. Then you have to measure the speed of the ball: the faster the ball moves away from the center, the more

  1. 5-6v 2A 1. Connect the PCB
    1. Start/Stop
    2. Webcam video

Hi Johan, I constructed your Ball Balancer, but I am getting the following error code thrown up every time, can you help? cv2.error: OpenCV(4.0.0) /Users/travis/build/skvark/opencv- python/opencv/modules/imgproc/src/shapedescr.cpp:272: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'contourArea' Hello, I noticed that you have to replace line 421 ("cnts = cnts [0] if imutils.is_cv2 () else cnts [1]") by "cnts = imutils.grab_contours (cnts)" when using OpenCV 4. This solution works for me, I hope it will work for you too. Hi Johan, I have a question regarding the camera. I've included a image so that you can tell me if the frame width is OK. Seems a bit wide to me but I may be wrong. I installed everything on a Raspberry pie thanks to Adrian @pyimagesearch. Hi, Does the system work? Is there latency with the Raspberry pie? It looks nice!

  1. Go to the folder where the interface.py file is located 1. Run the program

Step 6: Conclusion

Thanks for reading! If you have any questions, do not hesitate to write a comment. You can also vote for me in the PCB contest.

Hi Johan, I haven't completed my tests yet, but it looks promising. I can see some latency, so that can be an issue I guess. FPS is 24. What do you think? I think it should work. Hi Johan, Is the default ball color supposed to be orange? I find that the color is blue on my RPi, which is kind of the complementary color. Is this normal? Hi, There is no default color. You have to right click on a color to select it. Hi Johan, OK for the right mouse click to store the color but what are the HSV sliders for on the interface program? Hi Johan, please forget that question, I simply forgot to consider that the 'plateau' will raise to a position that centers it. Great work!! Best example to demonstrate the effectiveness of the PID control algorithm. John, again great work, very impressive. I had to make some modifications to get the python code to work my Windows 10 system.

  1. Line 527: Removed background=black so the button will show. BConnect = tk.Button(controllerWindow, text ="Connect", command = connectArduino)
  2. I’m using an Arduino Nano for servo control. My system does not return “Arduino” in the port description. I printed the port and it returns “CH340”. I modified line 273 in the connectArduino() module to account for it: if "CH340" in p.description: Hope this will help anyone else using Windows. Thank you for those modifications that will help many people! Hello! Beautiful design, congratulations! I'm reproducing. I'm using an Arduino Uno with Ubuntu Linux system. I can already do the mapping of the ball, but I can not establish the connection with the arduino. I made the impression of the port "ttyACM0" and replaced in line 273 of the code "Arduino", but it did not work. Any tips to help? Hi, Did you write "print(p.description)" to print the port? In progress...

Merci de me lire. En complément, voici l'erreur une fois que j'ai autorisé la camera dans 'Privacy Settings':

Traceback (most recent call last): File "C:\Users\Rolland Jones\Desktop\3D Prints\Ball_Balancing_PID_System\Ball-Balancing-PID- System-master\pythonCodes\interface.py", line 551, in main() File "C:\Users\Rolland Jones\Desktop\3D Prints\Ball_Balancing_PID_System\Ball-Balancing-PID- System-master\pythonCodes\interface.py", line 432, in main c = max(cnts, key=cv2.contourArea) cv2.error: OpenCV(4.0.0) C:\projects\opencv- python\opencv\modules\imgproc\src\shapedescr.cpp:272: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'

Hello, J'ai remarqué qu'il faut remplacer la ligne 421 ("cnts = cnts[0] if imutils.is_cv2() else cnts[1]") par "cnts = imutils.grab_contours(cnts)" lorsqu'on utilise OpenCV 4. Cette solution fonctionne pour moi, j'espère que ça fonctionnera aussi pour toi. Hi Johan, Thanks for taking the time to share you project with everyone. I notice your plans contain a joystick connection. Is this to manually to control the balance table? Did you manage to complete the design of the Joystick connection? Un énorme bravo! Your project is simply great. JP (France) Hi Johan, what is the "layer" or "Calque" function used for? I assume it is to line up the servo arms with the camera. Is that correct? Yes it's correct. Thanks for your response. I'll give that a try. I loved it I Loved It I loved it I play table tennis at local level and also software engineer with python developing experience. I want this in my bedroom, will make this Hi, here is a picture of my implementation of the design. I was able to print all the parts on my CR10. I used an Arduino Nano for the servo control and had to provide a separate power supply for the servos to keep them from resetting the Arduino. I’ve been trying to get the PID working off and on for a couple of weeks, but haven’t been able to make it work. I assume the problem is the mapping of the camera to the angles controlled by the servos. Hi, Thank you very much for the picture. I may know where your problems come from.

  • Is there 18cm between the end of each arm. (see picture)
  • If you press the "Ranger les bras" button, all arms should be lowered as much as possible. (see

picture) Thanks Johan, the ends of my arms are 18 cm apart from center to center. Should they be 18cm between the outsides of the magnet holders? I found I have a loose servo arm and and need to disassemble the project to tighten it. I am kind of speechless at the beauty and ingenuity of this project. Congratulations on winning the competition and I look forward to your next instructable. Amazing! I wonder if a RPi w/ camera would be able to handle the speed for balancing the ball Such a great project..you deserved to win first prize :) Amazing! :D Hy John. We have almost done your project but we have a problem. The program doesn't recognize the ball. We have tried with diferent colours but we haven't been able to. Could you help us? Hi, You have to right click with the mouse on the ball so that the program detects the color of the ball. Did you do this right click? I hope it helps Feel free to send me a picture of the project, I'm interested :) You need to put the ball in front of the camera and select it to start. If you are on windows, it will be the middle button. Thanks a lot, Johan, for uploading the step files. I'll be up and running pretty soon. THis is wonderfull!!!!!! Well done mate ,it is really nice very quick response ,just great!! I was sure from the first video that i am going to made it , but those magnets and camera is really expensive. But it is great Very impressive work! Hi Johan, it seems the camera orientation to the table is important. Which two angles if the camera base set between? From the pictures it looks like the camera is aligned opposite of angel B is that correct? Hi Johan, I have mine assembled and working. I’m using Windows 10 and an Arduino Nano. I found that I need to use the middle mouse button on Windows to set the color target for the ball. I'm having trouble with it keeping the ball on the table. Do you have recommendations on the startup sequence and PID parameters? Thanks for any help you can give me. Hi, At the beginning you have to put each coefficients (pid) to 0. Then you can slightly increase the