lunes, 3 de febrero de 2014

New Project: Air Hockey Robot (a 3D printer hack)

[Version en español aqui]
After the last B-ROBOT project, this is what I've been doing the last months...really fun...



  Everything started when I built my 3D printer. First, the posibility to design and build my own parts and second, how could I hack the components of a 3D printer to make something different? 
  I have seen several interesting projects of robots that paint or manufacture PCBs, etc ... but I was looking for something different... 
  My daughter loves the Air Hockey game and I love robotics so one day an idea born in my mind... can I construct...??... Mmmmm .... it seemed very complicated and with many unresolved questions (puck detection??, robot speed??), but that is also part of the fun...


  Based on the idea of use standard RepRap 3D printer parts : NEMA17 stepper motors, drivers, Arduino Mega, RAMPS, belts , bearings, rods, printed pieces ... I started to develop the project. The main advantage of use these parts is that they are cheap and easily available. First I started with the construction of the air hockey table. I choose a medium size (my house is small, ;-)) I wanted something easily transportable but comfortable to play. The final dimensions are 100x60cm. 
  I Bought some wood boards and wood slats and began to mount the table. First I started to build and airless version but it really lacks the feeling so I decided to make a table with air. I tried different possibilities until I test a very simple combination with 2 old PC fans that works very well. I made the table holes (it seemed a hard work but it was not so hard) and I now I had a fully playable Air Hockey table! Time to enjoy it an play!! 



  Meanwhile I was designing the robot parts. I think two defferent designs, one H-Bot and another with 3 motors. Finally I decided to use the 3 motor design (2 for the Y axis and one for the X axis). After several design iterations of the pieces, and some material changes to minimize the weight and inertia (and thus increase the accelerations of the robot) I got a fairly operational design. One of the most important change is the replace of the X axis rods with carbon tubes ones (from kites) that works very well on PLA printed bushings and save a lot of weight.



  The code: I started studying the code of Marlin ( typical RepRap firmware) software but I decided to start from scratch, first because I don´t need a gcode interpreter and second because the software of a 3D printer have a motion planning algorithm and this is not the way the Air Hockey robot must work. 3D printers plans movements for smooth paths through all the points. The Air Hockey Robot should move inmediately with every new command canceling the previous one, because what we need is that the robot moves as quickly as possible to the new position. 
  I began developing the driver for Steppers motors using Arduino interruptions and making the code as efficient as possible. I implemented position, velocity and acceleration control, using an acceleration ramp with a simplified S-profile. The interrupts can generate pulses up to 25Khz which is the maximum speed that I can achieve with the steppers. The position control works at 1 kHz.



  For the puck detection problem I decided to use a computer vision system. Initially I planned to use the CMUCAM5 (Pixy) sensor that fits very well in this project (and in near future I will prepare a version for this sensor), but the camera is not available yet, so I started a new route: Use the PS3 EYE camera with a PC to develop the vision system. I developed the vision system in C lenguaje using OpenCV libraries for capturing, thresholding, filtering and segmentation. 
  The system detects the puck (must have a special color) and the result is sent to the Arduino by serial port.   The vision system sends information packets containing the position of the puck and the robot in pixels within the image. The camera is running at 60Hz at a resolution of 320x240. Fortunately the camera has very little distortion and I don´t need to implement a lens distortion correction. The software records a video on the PC which is very useful for debugging.



  One of the main problems I've had is that the power of the NEMA17 motors are pretty fair for this project and the disadvantage of using stepper motors is that if we lose steps (which can easily happen, for example when the robot hits the puck against the wall) and we do not take into account the missing steps we lose the position of the robot. To fix this, what I've done is to use the vision system to detect also the robot (with a different color) so we can detect when the robot has lost steps and fix it. 
  What remained was the implementation (in the Arduino) of the trajectory prediction system and the strategy of the robot. Once we have detected the puck in two consecutive frames we can calculate the trajectory (equation of the line through two points, this is college math!). The trajectory prediction takes into acount that the puck could bounce in a side wall. All these calculations are accesible to the strategy subsystem that decides what the robot will do: defense, defense+attack of prepare a new attack



  A nice part of this project is that the Strategy subsystem is fully insulated and is very easy for everyone to modify this part and program their own strategy algorithms isolated from the complexities of motor control, vision system and prediction code. The strategy is what makes the robot wins or lose! so in the future we could see Air Hockey robot competitions?

Although it can seems a complex project, it´s an affordable and doable project.

  • Code repository, 3D designs, documentation link: GitHub
  • Detailed build Instructions link: Build manual
(*) The build manual contains high detailed photos of the project

Some other considerations that have been taken during into account in this projectt (and the future):

  • The project is reproducible: Easy to get materials, documentation, open source code and open hardware ... 
  • The robot is removed completely from table with only 6 screws. So it can be removed for play or transport 
  • It's very easy to adjust the level of the robot, for example to play with children, just turn down the acceleration and maximum speed of the robot (this could be improved in the future) 
  • Currently the robot is not able to detect goals but we could improve this in future. 
  • In future the robot can self-calibrating the camera using predefined movement at beginning (to avoid the camera calibration). 
  • We could mount two robots per table, one on each side. Competitions between robots?? Compare different strategies in a tournament? ... 
  • It's a great and fun project to teach science specially for childrens: 
    • Concepts of Physics: Friction, continuous and uniform motion, rebounds, concepts of position, speed and acceleration
    • Mathematical Concepts: Equation of the line through two points, prediction, XY Cartesian System
    • Robotics: Motors, Machine Vision, Control, Arduino
    • DIY Philosophy: Build your own Air Hockey table
    • Hacking: Using 3D printer parts to build something completely different. 

  What is the current robot skill? Well, now the robot could easily beat a child. An adult with some experience (myself, lol) can still win the robot, but I am sure that with some more small improvements it is going to be really hard to beat ... 
  The project is fully alive with undergoing improvements, both in code and the robot ... all contribution to the project are welcome ...



 Science & fun
   Jose Julio (@ jjdrones)

92 comentarios:

  1. This is really the best project I have seen in a long while!

    ResponderEliminar
  2. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  3. You are doing really great things! Thank you so much! :)
    I also like your past projects http://www.diydrones.com/profiles/blog/list?user=3n7oxlg4fanvy
    Now B-robot and Air Hockey. Quality design and documentation! Very very cool!

    Make sense to move it on Kickstarter! ;)

    p.s. Where you take time for all of your projects? :)

    ResponderEliminar
  4. You specified that camera is running at 60Hz at a resolution of 320x240.
    But PlayStation Eye 3 can give you 120hz at 320×240 (or 60hz with 640×480 resolution). Where more speed will give more precise with capturing point coordinates.

    ResponderEliminar
    Respuestas
    1. Thanks!
      I use 320x240 resolution at 60hz because my laptop is not able to process the 640x480 resolution...

      Eliminar
  5. Hi , great job. What is the price for this device ?

    ResponderEliminar
    Respuestas
    1. The price is a bit less than a typical reprap 3D printer (for example a prusa) because it has less motors/drivers and no need hotend and the cost of the wood for the table is cheap. I have no an exact calc but should be around 200€ (without the PS3 camera and laptop).

      Eliminar
  6. Found your project via a Dutch News Site:
    http://www.nu.nl/tech/3696347/3d-printer-omgebouwd-slimme-airhockeyrobot.html

    Cool project! Very nice how you describe it with enough but not too much detail.

    ResponderEliminar
  7. Very nicely done. Thanks for the post.

    Pero ¿qué significa cacharreo?

    ResponderEliminar
    Respuestas
    1. I don´t know the exact translate of "cacharreo" but could be something like tinkering, experimenting, play with electronics....

      Eliminar
  8. Impressive to see how fast your system responds. Opens my mind to possibilities. Thanks for sharing this.

    ResponderEliminar
  9. I _REALLY_ want to see what happens when you build a second robot, and have them play against each other ...

    ResponderEliminar
  10. Awesome work, Jose!
    I totally want to build one, too. Can you recommend any resources (such as books, online-resources) about the know-how required for this project (Arduino, etc.)?

    ResponderEliminar
  11. Wow! Well Done - the robot has impressing reaction time and skill! Very good job and world class idea! I´ve written a small article on it in my blog to (in german) http://www.ddd-druck.at/3d-drucker-umbau-in-air-hockey-robot/

    ResponderEliminar
  12. Amazing! Great job!
    How do I increase the size of 160cm x 90cm table?

    Thank you.

    ResponderEliminar
    Respuestas
    1. Yes, you could build it bigger but maybe you would need to change the motors to something bigger like NEMA23´s...

      Eliminar
  13. Fantastic job Jose !!!

    Do you think it could be possible to do the same but down sizing ?
    Nema14, CoreXY system (only 2 motors for all) and especially in A3 format (so portable) ?

    Many thanks for your creativity and sharing.

    Gilles

    ResponderEliminar
    Respuestas
    1. http://www.corexy.com/corexyr1/index.html

      CoreXY system maybe increase speed and reactivity because of no motor to move...

      Eliminar
    2. Thanks for your suggest, yes we could build a smaller version (I think that is always easier to shrink than grow). An small and portable version could be very attractive...
      I was thinking in something like a CoreXY (an H-BOT configuration) but the problem of this configurations is that it needs a robust base or you have problems with belt tensions and also it has the problem that a diagonal move has less torque (beacause it uses only one motor) but it would be a good test.

      Eliminar
  14. Respuestas
    1. Beacuse of the frictionless enviroment (because of air) the trajectories are really straight, one problem is that the puch could have effect and this change the bounce trajectory and could fool the robot until it "reads" the new trajectory...

      Eliminar
  15. thank you to you Jose for this answer so rapid.
    Could keep NEMA17 (not so big in fact) and all pulleys on bearings and using fishing line sea, which resists at big tension.
    The heart of your project is really the part of optical processing that you wrote, which interface with the arduino! ... For a portable version, do you think it would be possible (CoreXY) to use only 2 Polulu stepper + Arduino UNO for example, or the work frequency is too high?

    @ +

    ResponderEliminar
    Respuestas
    1. Oh ! and only one carbon tube would be necessary for the X axis ?
      What do you think ?

      Gilles.

      Eliminar
    2. CoreXY could be a good option (specially for a little version) with the advantage of use only 2 motors. The code is small enough for an Arduino UNO but maybe you could have problems with RAM memory (not enough on the UNO).

      Eliminar
  16. I had a look at the Pixy sensor. Will the robot get even better with those 50 fps the camera offers or is it just a more elegant solution? It would also be interesting to know if the positioning algorithm would also work if the camera is positioned above the robots goal (and not centered above the table), with triangulation?
    Thanks anyway for posting this, you totally got me hooked on microcontroller stuff. ;)

    ResponderEliminar
    Respuestas
    1. I was thinking on the Pixy sensor (CMUCAM5) because this way we don´t need an external laptop, so i will be an arduino only (plus camera) project. Actually the vision system runs at 60Hz 320x240 resolution, with Pixy it will run at 50Hz but 640x480 resolution. I think it would perform in a similar way... I will compare ;-)
      If you put the camera above the robot goal you will need to make a perspective correction but it´s posible (this was the first option I thinked). With the actual position the calculations are easier.

      Eliminar
  17. REALLY impressive,

    nice work, and nice smile at the end, you did it :)

    ResponderEliminar
  18. Hello Jose, why didn't you chose the RASPBERRY-PI + RPI CAMERA BOARD a such very cheap package for a standalone system ?

    ResponderEliminar
    Respuestas
    1. I have seen some projects running OpenCV on Raspberry PI and I think they could not reach the 50-60fps processed needed for a real time robot like this...

      Eliminar
  19. I'd like to see two of these playing against each other!

    ResponderEliminar
  20. Fantastic! What a great project. Have you thought about taking this to production?

    ResponderEliminar
    Respuestas
    1. I have no plans for production now but it seems to be many people interested in projects like this. Now I am working to improve the project...

      Eliminar
  21. This is a very powerful design

    I really want a Air Hockey Robot

    ResponderEliminar
  22. Great Job Jose Julio!
    Your explanation makes it seems easy, but it's not!

    Are you thinking about a 3D ping-pong game with two cameras and one quadcopter? It would be a challenge!!

    ResponderEliminar
  23. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  24. Hey. Could you clarify exactly what specifications with NEMA17 motors are used on the project. On ebay a huge amount of different versions of this engine.

    ResponderEliminar
    Respuestas
    1. I used NEMA17 motors like this: 42BYGHW811. Motors with 4.8kg/cm of torque. This are the same that most people use for reprap 3D printers....

      Eliminar
  25. Wonderful project and implementation. Well done!

    ResponderEliminar
  26. excuse me, how do you choose the stepper motor?

    ResponderEliminar
    Respuestas
    1. Este comentario ha sido eliminado por el autor.

      Eliminar
  27. Hi, Nice project congratulations. Can we develop this project and made a product for a commercial? Nice toy. May have a big market poriton in toy machines sector.You should think for a commercial.

    ResponderEliminar
  28. What specification is the OpenCV computer? CPU name, core number, clock frequency, RAM, etc. USB2 (not USB3) is used, right?

    ResponderEliminar
  29. I modified an inexpensive air hockey table for this project and made floating x carriage and pusher.
    The files are at http://www.thingiverse.com/thing:266316. This seems to work quite well Julio. Completely 3D printed,only two parts,no screws and less weight on the X carriage. I'm able to use a thinner ,lighter puck and the pusher height issue is solved even if the MDF board warps slightly.
    Thoughts?

    ResponderEliminar
  30. Hi Robert, thanks for share!, it seems a good idea, specially if you have problems with the flatness of the surface... Beacuse the two parts are not screwed together do you think that you could lose some power on the hit? In your video it seems to work pretty well... Congratulations...

    ResponderEliminar
  31. Power doesn't seem to be a problem. Inertia keeps the carriage flush with the pusher at point of impact regardless of trajectory. I am not getting 1/8 stepping though. I am going to replace the step sticks (they are old) and see if i can travel 5cm on the motor test. Currently I'm only getting 2.5cm . I am using the proper tooth count on the belts and the gears came out great. Looking forward to any updates you might have. I value your opinion.
    Respectfully Robert

    ResponderEliminar
    Respuestas
    1. Great!. If you are getting only 2,5cm move it seems (as you say) that you are using 1/16 microstepping (this is the default). You need to remove one of the jumpers on the RAMPS (it´s documented on the build manual) in order to configure the 1/8 Microstepping. I am testing the new DRV8825 drivers (they are more powerfull) and it seems to work well, but I need to modify the code to make it compatible with this drivers. I will probably update the code this week (with some improvements in strategy also).
      Keep us informed with your progress...
      Robert, if you need to contact me (by email) you could use the contact form on the right side of the blog (Name, email and message).
      Jose.

      Eliminar
  32. Flipante!!
    (lo encontré vía http://3dprintingindustry.com/2014/03/12/3d-printing-air-hockey-robot/?utm_source=Facebook&utm_medium=social&utm_campaign=3DPI%2BFacebook)

    ResponderEliminar
  33. excuse me, how to tracking the ball?
    I dont't how to define the function

    ResponderEliminar
  34. Hi

    I start biuld AirHockey ... I have working PS3 camera ( with test program from CL-EYE Test) but when i start program CHECK_HSV - program start-... show some frame and close - exactly same like without Camera ( Win7 64bit I3 DELL Vostro 4GB RAM ) --- Have You any ide why ??

    ResponderEliminar
  35. ... I use driver from this link.. http://codelaboratories.com/get/cl-eye-driver/
    CL-Eye-Driver-5.3.0.0341.exe

    ResponderEliminar
  36. :-) problem solved.... after switch of build in CAMERA in my laptop - program start correctly with external CAM PS3 :-)

    ResponderEliminar
    Respuestas
    1. I am happy you could resolve your problem. I have tested on two different laptops and works fine.

      Eliminar
    2. As I wrote - probelm was internal camera start with Your APK as default...

      Eliminar
  37. I'm wondering... If two robots are playing against each other - will it be the "perfect" game? If the mechanics, electronics and the software is the same will they be able to score a goal? :)
    Great project, Jose! I love the air hockey game, too! I think that I will try to make this robot after finishing my Prusa i3 that I'm building right now... :) Thank you!

    ResponderEliminar
  38. Thank you for posting the updates Julio. I will be able to try them out early next week.
    Respectfully,
    Bob

    ResponderEliminar
  39. Hello, we are a group of four french students working on a project at school. Basically, it is a camera tracking a moving object. You seems to know a lot about open CV and we would like to know if we could talk using E-mail. You can contact us at projetlava@gmail.com
    Thank you very much
    Lucille, Alice, Vincent and Adam

    ResponderEliminar
  40. What a great project!
    I have a question:
    Did you put a gearbox between the stepper motors and the belts? Or are they connected straight forward?

    ResponderEliminar
    Respuestas
    1. The steppers are connected directly to the pulley and belts...

      Eliminar
  41. Fantastic work, congratulations!
    Given that I want to accomplish your project, you wonder if you have made ​​substantial changes to the software / ardware.
    Thank you,
    regards,
    Gerry.

    ResponderEliminar
  42. Updates worked well Julio. Thanks again.

    ResponderEliminar
  43. Hi Julio,

    Thank you for making your project public and providing such detailed instructions! A couple of us at the University of Maryland are replicating your project. For future reference, however, we'd recommend that in the instructions you list 5 meters of GT2 timing belt, not 3 meters. We found that 3 meters was a bit too short. Also, it'd be helpful to mention how you connected the timing belt together - we ended up stapling the ends together.

    Thanks again!

    ResponderEliminar
    Respuestas
    1. Thanks! updated to 5 meters on the build manual...

      Eliminar
  44. :-) job in progress >>>. https://www.youtube.com/watch?v=sY7W6-kVB1c - this really works ... ;-)

    ResponderEliminar
    Respuestas
    1. Thanks for share!!! Nice work! keep me informed of your progress please...

      Eliminar
    2. Este comentario ha sido eliminado por el autor.

      Eliminar
    3. Some test VISION system https://www.youtube.com/watch?v=Dlu3sy-MVnI

      Eliminar
  45. This is an awesome project!

    I'm going to be setting it up on a big table with a black (instead of white) table. Will this effect the tracking of the puck? If so, how can I tell the camera which colors to ignore, and which colors to focus on for the puck and the pusher? (I am printing it out on green ABS)

    ResponderEliminar
    Respuestas
    1. I think that there would be no problem on use a black surface. The vision system looks for the color of the puck and the robot mark. You define the colors on the vision system call (is documented on the doc)

      Eliminar
    2. Este comentario ha sido eliminado por el autor.

      Eliminar
  46. Do you think NEMA 14 motors would be powerful enough if I adapted the printed parts to fit? I have an unfinished RepRap Huxley that I could salvage parts from.

    ResponderEliminar
    Respuestas
    1. NEMA 14 have not enough power for this project, you will need to build something much more smaller for these motors...

      Eliminar
    2. Thanks, I figured they might be, I've already built the table so I'll buy some NEMA 17s for it. My Hackspace has a A0 laser cutter which I've been making use of for this project, I'll post all of my design files soon but you can see some photos of my progress: https://plus.google.com/photos/115399656207465585576/albums/6027665582157139521?authkey=CLeq5Jvzs96tiQE

      Eliminar
    3. Wow! Excelent work! I want one of this laser cutters for christmas ;-)

      Eliminar
  47. I will be doing this on a VERY big table: (90inch x 50 inch). Will the NEMA 17 be strong enough for this size? Should I use something stronger? Will the rods start flexing/bending at these lengths?

    ResponderEliminar
    Respuestas
    1. That is too big for this motors in my opinion! This motors are a bit weak for this project, you will need something more powerfull... Also you need bigger rods...

      Eliminar
  48. I am getting a lot of compiling errors when I try to upload the software to the Arduino. Here are the errors I am getting:

    (This is from the Motor test program)


    AHR_Motor_Test.ino: In function 'void setup()':
    AHR_Motor_Test:47: error: 'Z' was not declared in this scope
    AHR_Motor_Test:47: error: 'ENABLE' was not declared in this scope
    AHR_Motor_Test:47: error: expected `;' before ':' token
    AHR_Motor_Test:59: error: 'A8' was not declared in this scope
    AHR_Motor_Test:119: error: 'TCCR3B' was not declared in this scope
    AHR_Motor_Test:121: error: 'TCCR3A' was not declared in this scope
    AHR_Motor_Test:132: error: 'OCR3A' was not declared in this scope
    AHR_Motor_Test:134: error: 'TCNT3' was not declared in this scope
    AHR_Motor_Test:145: error: 'TIMSK3' was not declared in this scope
    Steppers.ino: In function 'void __vector_11()':
    Steppers:32: error: 'PORTF' was not declared in this scope
    Steppers.ino: In function 'void TIMER3_COMPA_vect()':
    Steppers:58: error: 'PORTF' was not declared in this scope
    Steppers:59: error: 'PORTL' was not declared in this scope
    Steppers.ino: In function 'void positionControl()':
    Steppers:92: error: 'PORTF' was not declared in this scope
    Steppers.ino: In function 'void setMotorXSpeed(int16_t, int16_t)':
    Steppers:174: error: 'PORTF' was not declared in this scope
    Steppers:183: error: 'PORTF' was not declared in this scope
    Steppers.ino: In function 'void setMotorYSpeed(int16_t, int16_t)':
    Steppers:236: error: 'PORTF' was not declared in this scope
    Steppers:242: error: 'PORTL' was not declared in this scope
    Steppers:252: error: 'PORTF' was not declared in this scope
    Steppers:258: error: 'PORTL' was not declared in this scope
    Steppers:274: error: 'OCR3A' was not declared in this scope
    Steppers:276: error: 'TCNT3' was not declared in this scope

    ResponderEliminar
    Respuestas
    1. Make sure you have selected the correct board from the "Tools" menu, it should be the Arduino Mega.

      Eliminar
    2. Thanks for the help Rob, I agree, it seems that you selected another board...

      Eliminar
  49. Hi, Mr. Jose Julio i would like to ask what language did you used in your air hockey robot...and what software did you used in the camera to locate the puck

    ResponderEliminar
    Respuestas
    1. I use Arduino for the robot and C for the camera software. Check the documentation links above, you have all the info...

      Eliminar