Home

Final Report () - School of Electrical and Computer Engineering

image

Contents

1. Save byte in buffer No Process parse packet Actuate appropriate servo Figure 8 PIC18F4520 main program flow chart Team FIFA ECE 4007 L01 90 ey Autonomous Foosball Table The initialization sets up all of the necessary required peripheral components and configures all of the input output ports of the PICISF to their proper values Once initialized the main loop continuously waits for a byte from the MAX3100 through the RBO INTO pin Once a byte is received it is verified and determined if it is the first or second byte of an instruction packet If it s the first byte it is placed in a buffer and then waits for the next byte If it is the second byte the instruction in the buffer is parsed and the proper function of the instruction is carried out either moving a AX 12 or a PWM servo to a certain position For more information on the specific function of the instruction packets refer to Section 5 3 The main program source code is shown in its entirety in Appendix B The code for all of the PICI2F615 PWM controllers was written in assembly Their programs simply continuously monitor the control and direction pins and change the duty cycle of the PWM module as required The program flow for the PICI2F PWM controllers is shown in Figure 9 Initialize PWM module Read control and direction pins Set duty cycle 1 5 ms Set duty cycle 2 0 ms Set duty cycle 1 0 ms Figure 9 PICI2F615
2. interrupt every second while true framecount if visionl imageAvailable imagel visionl getBufferedImage grab an image t relocate imagel find the new human players locations findBall imagel find the ball if stage gt 2 we ve located the players int controlrow t findController p getFutureX find which row is most likely to control the ball next time if p getFutureX lt t getRowXPosition 1 true ball behind midfield if c getRaised 1 false c getRaised 0 false c setOffenseUp sleep artificially delay the next command else if p getFutureX gt t getRowXPosition 0 true ball ahead of strikers a strikerIntercept c t getMaxY p findStrikerPosition t getRowSpacing 0 t getMaxY t getPlayerHeight if c getRaised 0 true c getRaised 1 true c setOffenseDown sleep artificially delay the next command else if p getFutureX lt t getRowXPosition 0 true ball behind strikers a midfieldIntercept c t getMaxY p findMidfieldPosition t getRowSpacing 1 t getMaxY t getPlayerHeight if c getRaised 0 false c setUp 0 sleep artificially delay the next command if c getRaised 1 true c setDown 1 sleep artificially delay the next command kick players if they have control of the ball Team FIFA ECE 4007 L01 A25 ey Autonomous Foosball Table if
3. try to open the serial port try serialPort SerialPort portId open Foosball 2000 catch PortInUseException e System out println Port in use continue try outputStream catch IOException e Team FIFA ECE 4007 L01 serialPort getOutputStream A34 amp Autonomous Foosball Table there is a weird bug in the version of java that was used limiting the setSerialPortParams command the workaround is to use up a little time internally while we wait for the stream to settle if the stream does not settle in time initiate the connection a second time below we attempt to the workaround is done via the System out print commands sending null characters to the command line try System out print serialPort setSerialPortParams defaultBaudRate defaultDatabits defaultStopbits defaultParity System out print catch Exception e try 1 System out print serialPort setSerialPortParams defaultBaudRate defaultDatabits defaultStopbits defaultParity System out print catch Exception e try 1d serialPort setFlowControlMode SerialPort FLOWCONTROL_NONE try 1 System exit 1 if portFound catch UnsupportedCommOperationException e O serialPort notifyOnOutputEmpty true catch Exception e System out println Error setting System out println e toString System out println p
4. Set fast moving speed AX TxPacket SERVO DEFENSE I delay 5ms delay 5ms Set high torque WRIT Autonomous Foosball Table TE DATA movingSpeed 3 TE DATA maxTorque 3 TE DATA movingSpeed 3 TE DATA maxTorque 3 TE DATA movingSpeed 3 AX TxPacket SERVO DEFENSE I delay 5ms WRI1 Set fast moving speed AX TxPacket SERVO KEEPER delay 5ms delay 5ms Set high torgue AX TxPacket SERVO KEEPER delay 5ms I WRITE DATA I WRITE DATA E DATA maxTorque 3 movingSpeed 3 maxTorque 3 while 1 LED1 LED1 LEDO 0 PB1 PButtonl PB2 PButton2 if PORTBbits RBO I rxData PC ReadData if pc index 0 if rxData amp 0x80 pc buffer 0 rxData pc index 1 else pc buffer 1 rxData pc index 0 packet 0 pc buffer 0 packet 1 pc buffer 1 packetReady 1 LEDO 1 if packetReady 1 if packet 0 amp 0x20 0x20 Check if its a special command specialCommand else servoCommand packetReady 0 Team FIFA ECE 4007 L01 B4 amp BRK KK k kok k kok k k kok k kok AAA ke ke ke ke e specialCommand X Parameters none Returns void ck ck ck ck ck ck ck ck ck ck kk kk AA A ko ko AKA ko Sk ko ko ko kokok void specialCommand Autonomous Foosball Table ck ck ck ck 0k ck ck ck ck ck ck ck ck ck Ck 0k 0k 0k
5. e Chuck E Cheese http www chuckecheese com e Celebration Station http www celebrationstation com e Malibu Grand Prix http www malibugrandprix com e Dave and Busters http www daveandbusters com Local bars and pubs may also be a potential market for such a foosball table as they are also popular entertainment locations where customers would consider playing such a game and where similar games already exist In order to be successful the foosball table must be a challenging and fun experience to the player Such a machine can be tailored towards the intermediate to expert foosball player who has trouble finding a challenging human competitor A successfully designed computer controlled foosball player has the potential to approach perfection and challenge any expert level player Given a high expectation of victory a computer controlled opponent motivates an expert player to invest in playing the game hence the marketable appeal of an AFT Various difficulty Team FIFA ECE 4007 L01 35 ey Autonomous Foosball Table levels would also open up the marketability to the beginner level foosball player The marketing appeal is strong for a game that does not require a human opponent Figure 13 Star Kick foosball arcade game Currently there is only one AFT on the market the Star Kick shown in Figure 13 The Star Kick has its roots in a project by the School of Computer Science at the University of Freiburg in
6. lostballframes if lostballframes 10 try Random randNum new Random if xLocation deltaX lt tableWidth tableMinX 2 opponent scored oppscore playfile badGoals randNum nextInt badGoals length else computer scored playfile goodGoals randNum nextInt badGoals length myscore InputStream in new FileInputStream playfile AudioStream as new AudioStream in AudioPlayer player start as play the audio file catch Exception e Public accessor to return the computer s score return The computer s score 2 public int getMyScore return myscore Public accessor to return the human s score return The human s score SCH public int getOppScore return oppscore Public mutator to set the ball radius param br The radius of the ball in pixels S public void setBallRadius int br ballRadius br Sets the search size in RGB for locating objects on the table Team FIFA ECE 4007 L01 A10 ey Autonomous Foosball Table param value An integer representing the maximum value any R G B data can be away from a determined color value kf public void setColorSearchSize int value colorSearchSize value This calculates the diameter of the ball being used by searching within the localized space for similar colors param x A webcam An image from the webcam param r Th
7. playerMaxPos startPlayerPos ypos xpos countpx playerMaxPos 0 rowcount startPlayerPos maxY loopl 20 skip forward to the next row break break the vertical search else false positive ypos xpos countpx playerMaxPos 0 startPlayerPos maxY i if rowcount 4 System out println Found all player rows Moving on break break after we find 4 rows find the average player height playerHeight playerHeight rowcount System out println Average player height playerHeight px now find the distance between players on the row for i 0r X 4 i 1 if rows i 0 gt X 4 ypos 0 System out println Searching for more players on row i at xpos rows i 2 pixel getRed pixel getGreen pixel getBlue n loop3 colorSearchSize r colorSearchSi colorSearchSize g colorSearchSi colorSearchSize b colorSearchSi startPlayerPos loop3 countpx rowdist 0 startPlayerPos maxY lastPlayerPos rows i 3 for j rows i 3 2 playerHeight j lt maxY j if onS i 2 gt 10 1 startpos 10 else startpos 1 rows i 2 for int n startpos n lt 1 startpos n pixel new Color x getRGB rows i 2 n j if pixel getRed gt r colorSearchSize amp amp lt r colorSearchSize amp amp pixel getGreen gt g colorSearchSize amp amp lt g colorSearch
8. Team FIFA ECE 4007 L01 A1 amp x m Ob ZS A Ko ok OR Autonomous Foosball Table Al java This class initiates a movement of a row of players to a specified location author Team FIFA ECE4884L01 Georgia Institute of Technology version 1 0 December 2007 public class AI private double pixelsPerInch 0 Class constructor specifying the pixels per inch of the table Tf param ppi The number of pixels per inch defined on the table public AI double ppi pixelsPerInch ppi Uses the goalie to intercept a ball going toward the goal param c The serial controller object used to send data to the servo control board param yInterceptPosition The predicted future location of the ball given in pixels from the bottom of the table or public void goalIntercept WriteS c double yInterceptPosition if yInterceptPosition 1 we use the 8 75 because the hard stoppers imposed on the goalie do not permit the goalie s movement to the absolute edge of the table c move 3 yInterceptPosition pixelsPerInch 8 75 Uses the defensemen to intercept a ball going toward the goal param c The serial controller object used to send data to the servo control board param yInterceptPosition The predicted future location of the ball given in pixels from the bottom of the table Ss RO a public void defenseIntercept WriteS c double yInterceptPositi
9. EnableInterrupts end PC WriteString Team FIFA ECE 4007 L01 unsigned char length B16 ey Autonomous Foosball Table Appendix C PIC12F615 PWM Controller Source Code Team FIFA ECE 4007 L01 C1 amp Team FIFA PWM Servo Controller Developed By Michael Aeberhard Date October File main as 31st m 2007 Autonomous Foosball Table Purpose Generate a PWM signal for a PWM module based on the input signals List include Contig MOVLF macro movlw movwf endm rGonst nts backCCP backCCPL idleCCP idleCCPL kickCCP kickCCPL PR2value peer ei Vectors literal dest literal dest p 12F615 P12F615 INC LP OSC amp PWRTE OFF amp WDT OFF CP OFF egu egu egu egu egu egu egu Oxic 0x0C 0x2C 28 12 7L6 Ue dt tat a il A A a a a a TT T TT TT TT TT T TT Zt Zc org 0x0000 goto Main org 0x0004 goto Reset vector interrupt vector CECE ER CER EEE ER ERE UR EEC CE EE CEE CECE CEE CEE O ER EE ECE E CE ER CECE CECE EEC EECEEECCECCEECCE tnnt Initial Test0 Main MainLoop Team FIFA ECE 4007 L01 bof bcf bsf bsf bst T MOVLF bet Pet bof bot bsf bst MOVLF MOVLF bt ss goto best bcf bot return call Dtfsc call DUtss call Initial GPIO 0 STATUS IRP STATUS RP STATUS RPO TRISIO TRISIOO IRISIO TRISIO1 ANSEL PR2value PR2 TRISLO TRISIOZ STATUS RPO PIR1 TMR2IF T2CON
10. c disconnect System exit 0 Constructor for the Track class Ed public Track tAllUp lift all players temporarily c se try ca c se ca Thread sleep 250 tch Exception e System out println Thread timing error tAllDown set all players back down Thread sleep 250 tch Exception e System out println Thread timing error c startPosition move all rows against the wall found false start up without the ball found predefined colors for the ball we overwrite these rBallColor 200 gBallColor 200 bBallColor 20 xloc yloc framecount 0 set up the webcam controller and grab a new image visionl new FrameGrabber Team FIFA ECE 4007 L01 A24 ey Autonomous Foosball Table visionl start imagel visionl getBufferedImage imHeight 240 imWidth 320 define the GUI controls and setup addWindowListener new WindowListener setTitle Foosball Tracking setSize imWidth 10 imHeight 105 set window size setVisible true make the window visible addMouseListener new CalcPixel findBall imagel ActionListener secondElapse new ActionListener this interrupts every second public void actionPerformed ActionEvent evt repaint show the data we have every second FPS framecount camFrameRate visionl getFrameCount framecount 0 D I new Timer 1000 secondElapse start
11. int i for i 0 i lt 4 i myrows i 1 myrows i 2 myrows i 3 rows i 1 assume the same number of players on either side maxX rows i 2 minX set the x location of each row maxY rows i 3 minY set the minimum y location of each row myrows i 4 myrows i 3 set the current y location from the minimum y location Team FIFA ECE 4007 L01 A17 ey Autonomous Foosball Table Determines the location of each player row and then computes the distances between players on that row After this is done the robot s positions are determined assuming a symmetrical table param mousex The x location to analyze for color of the human players param mousey The y location to analyze for color of the human players see findMyPlayers SE public void findRows BufferedImage x int mousex int mousey x blur x blurring smoothes out color fluctuatoins Color pixel new Color x getRGB mousex mousey int r pixel getRed int g pixel getGreen int b pixel getBlue rOppColor r param x An image from the webcam gOppColor g bOppColor b The following code works to visually locate the players However due to inconsistent lighting concerns it was taken out of the final code to be replaced with predefined values int i j loopl loop2 loop3 loop4 startpos rowdist 0 lastPlayerPos int ypos 0 xpos 0 countpx 0 r
12. iparam x An image from the webcam loop through all rows Se public void findRange BufferedImage x int i j for i 0 i lt 4 i for j minY j lt maxY Color pixel pixel getRed ir rOppColor colorSearchSize amp amp pixel getGreen lt gOppColor colorSearchSize amp amp pixel getBlue bOppColor colorSearchSize j new Color x getRGB i j rOppColor colorSearchSize amp amp pixel getRed lt gt gOppColor colorSearchSize amp amp pixel getGreen gt bOppColor colorSearchSize amp amp pixel getBlue lt rows i 4 break to calculate the distance between players Team FIFA ECE 4007 L01 rows i 3 j we only need to find the first 2 players on a row ey Autonomous Foosball Table Finds the minimum and maximum x and y locations of the table through color analysis of the outline param x An image from the webcam param mousex The x location to analyze for color of the table outline param mousey The y location to analyze for color of the table outline i public void findOutline BufferedImage x int mousex int mousey x blur x Color pixel new Color x getRGB mousex mousey rOutlineColor pixel getRed gOutlineColor pixel getGreen bOutlineColor pixel getBlue ant i j int imHeight x getHeight imWidth x getWidth Ss first find the leftmost location of the table minX boo
13. 3 lt 12 i 4 packet i 0 packet 13 1 packet 14 0 packet 15 0 sendPacket Special command to the servo to set all rows to a centered position Qsee startPosition ird public void centerAll Command packet packet 2 1 for int i 3 i lt 14 packet i 0 10100000 00000001 i packet 15 sendPacket 1 Moves a row to a specified hexidecimal position param ID The row number of the servo to move param pos The hexidecimal position the servo where the position is the same as that used internally by the servo T public void moveHex int ID packet 2 0 packet 3 0 packet 4 ID 2 packet 5 ID 2 int pos Team FIFA ECE 4007 L01 raised 1 Should be to between 0x000 and Ox3FF A31 ey Autonomous Foosball Table for int i 0 i lt 9 i packet i 6 pos int Math pow 2 9 i pos pos int Math pow 2 9 i sendPacket Public accessor indicating whether a PWM servo currently is in limbo i e it is executing a previous command param ID The row number of the servo return A boolean indicating if the determined servo is currently moving K public boolean inLimbo int ID return timeleft ID gt 0 Moves a row to a specified physical position This function internally converts the inch position to a servo position param ID The row number of
14. Germany However the marketed arcade version of the Star Kick is listed at a price of 27 000 which is out of the range for smaller arcade centers and local bars 20 The goal of the proposed prototype is to compete with this product by improving the gameplay and significantly lower the cost of this unique type of arcade machine 8 2 Cost Analysis The final cost of an AFT should be competitive with other similar entertainment devices that the customer would place in their facility Such devices include pool tables pinball machines air hockey driving simulators and arcade video games The short list in Table 8 shows the price for some of these typical entertainment machines Team FIFA ECE 4007 L01 36 amp Table 10 Typical entertainment machine prices Autonomous Foosball Table Source ArcadeGameSuperstore Name Description Price NASCAR Pinball Coin operated NASCAR themed pinball machine new 4 395 Dracula Pinball Bram Stroker s Dracula themed pinball machine 1993 3 249 Great American Air Hockey 8ft air hockey table with electronic overhead scoring 3 470 Table Bubble Hockey Machine Signature Stick Hockey bubble hockey machine 1 245 Ford Racing Full Blown Driving arcade game based on recognizable Ford cars by 8 795 Sega Dance Dance Revolution Arcade version of the DDR video game 2 Players 13 895 Supernova Golden Tee Live 2007 The latest installment of the famo
15. ID 2 for int i 0 i lt 8 i packet i 6 1 Team FIFA ECE 4007 L01 A33 packet 15 1 sendPacket Sets a PWM servo in to the down position param ID The row number of the servo to move Qsee setUp Autonomous Foosball Table E public void setDown int ID nextval ID false if raised ID if ID 3 1 timeleft ID 10 the goalie is a different slower servo else timeleft ID 5 default servo behavior packet 2 0 packet 3 1 packet 4 ID 2 packet 5 ID 2 for int i 0 i lt 9 i packet i 6 0 sendPacket Closes the serial port s public void disconnect serialPort close Connects the serial port to the motor control board at 115 200 bps 8 data bits packet 1 stop bit no parity no flow control SCH public void connect int defaultBaudRate 115200 int defaultDatabits SerialPort DATABITS_8 int defaultStopbits SerialPort STOPBITS_1 int defaultParity SerialPort PARITY_NONE boolean portFound false String defaultPort dev ttyS0 open serial port 0 in linux portList CommPortIdentifier getPortIdentifiers while portList hasMoreElements portId CommPortIdentifier portList nextElement if portId getPortType CommPortIdentifier PORT_SERIAL if portId getName equals defaultPort System out println Found port defaultPort portFound true
16. T2CKPS1 T2CON T2CKPSO T2CON TMR20N idleCCP CCP1CON idleCCPL CCPR1L PIR1 TMR2IF Test0 STATUS RPO TRISIO TRISIO2 STATUS RPO ServoKick GPIO 0 ServoIdle GPO as input GPl as input PR2 for 50 Hz GP2 for PWM use Se Se Set Timer 2 prescalar of 4 Turn Timer 2 on for PWM mode and set duty cycle duty cycle of PWM Skip if GPO is 0 idle servo GPO is 1 call to change duty cycle Skip if GPO is 1 kick action C2 amp goto ServoActive call btfsc call btfss call goto ServoBack MOVLF MOVLF return ServoKick MOVLF MOVLF return ServoIdle MOVLF MOVLF return END MainLoop ServoKick GPIO 1 ServoBack GPIO 1 ServoKick MainLoop backCCP CCPICON backCCPL CCPRIL kickCCP CCP1CON kickCCPL CCPR1L idleCCP CCP1CON idleCCPL CCPR1IL Team FIFA ECE 4007 L01 Autonomous Foosball Table Skip if GPl is 0 kick Reverse servo defend Skip if GPl is 1 defend Set Set Set Set Set Set for PWM mode and set duty cycle duty cycle of PWM for PWM mode and set duty cycle duty cycle of PWM for PWM mode and set f duty cycle duty cycle of PWM C3 ey Autonomous Foosball Table Appendix D Servo Controller Board Schematic and PCB Design Team FIFA ECE 4007 L01 D1 Autonomous Foosball Table MCLRA PP RADIRNO HTH RAZANZVREF RAJANAVREF RAUTOCK RASESIAN UDIN REVRDANS RETANRANG
17. else if servoAddress 2 AX TxPacket SERVO DEFENSE I WRITE DATA data 3 else if servoAddress 1 AX_TxPacket SERVO_MIDFIELD I_WRITE_DATA data 3 else AX TxPacket SERVO OFFENSE I WRITE DATA data 3 BR KKK KKK kok KK kok kok k kok kok kok kok kok k k k kok k ke kk ke kok kk kok kok kk k IK k kk k k kk k kk k k kk k k kk ke ke kk k k k delay ls Delays for 1 second Parameters none Returns void CK kk k kk kk kk k kk k kk k kk k kk k kk kk kk k kk k kk k kk k K k kk Ck ke kk ko ke void delay 1s unsigned char delayCount delayCount 200 while delayCount 0 delay 5ms delayCount BRK kk ke kk ke ke kk ke kk ko ke kk KRK kk ke ke kk ke kk Sk ke kk Sk ke kk ke kk Sk ke kok ke ke kk ke kk Sk ke kok ke ke kk ke kk kc ke kok ke ke kk ARA delay 5ms Delays for 5 milliseconds Parameters none Returns void K A e e e e kk kk kk kk e k kk k k kk kok k k kok k k k k k k k k kk k k k k k k k k k k k k k k kk k kk k ke kk k kk k kkk k kkk void delay_5ms Team FIFA ECE 4007 L01 B6 ey Autonomous Foosball Table while PIRlbits TMR2IF 0 E PIRlbits TMR2IF 0 TMR2 0 Team FIFA ECE 4007 L01 B7 ey Autonomous Foosball Table ifndef AXI2 H define __AX12_H BR KKK KK kok k kok kok kok kok kok k kok kok kok kk k kok kok kok kok k kok kok kok kok k kok kok kok k AA kok kk KK Dynamixel AX 12 Servo Control Librar
18. 0k 0k 0k 0k 0k ck 0k 0k 0k ck ck ck ck ck ck ck ck ck ck ck ck KKK ck k Parses a special command packet and carries out the necessary servo action CK Ck ko ke kk ke ko kk ke kk ke kk kk ke kk ke kk k kk ke ke kk kk d if packet 1 0x01 center all AX12s AX TxPacket SERVO ALL I WRITE DATA center 3 else if packet 1 0x02 start position all AX12s AX TxPacket SERVO OFFENSE I WRITE DATA offenseStart 3 AX TxPacket SERVO MIDFIELD I WRITE DATA midfieldStart 3 AX TxPacket SERVO DEFENSE I WRITE DATA defenseStart 3 AX TxPacket SERVO KEEPER I WRITE DATA keeperStart 3 else if packet 1 0x03 kick all PWM KEEPER CTRL 1 PWM DEFENSE CTRL 1 PWM MIDFIELD CTRL 1 PWM OFFENSE CTRL 1 else if packet 1 0x04 idle all PWM KEEPER CTRL 0 PWM DEFENSE CTRL 0 PWM MIDFIELD CTRL 0 PWM OFFENSE CTRL 0 else if packet 1 0x05 kick offense midfield PWM MIDFIELD CTRL 1 PWM OFFENSE CTRL 1 else if packet 1 0x06 idle offense midfield PWM_MIDFIELD_CTRL 0 PWM_OFFENSE_CTRL 0 BRK KK k kok kok k KK KK KKK k k k k k k k k e servoCommand zz Parameters none Returns void ck ck ck ck ck ck ck ck Ck 0k 0k ck Ck 0k ck 0k 0k ck 0k ck 0k 0k Ck Ck ck KKK KKK ck ak ck ck ak kak ck KKK ck ck ck ko kk Parses a servo command packet and carries out the necessary servo action CK Kk k kk kk kk Ck ke kk ke kk kk kk ke kk ke kk Ck
19. Determines if a byte from an AX12 servo is ready to be read L oc boc Parameters none Returns char 1 if byte is ready 0 if not KCKC kk kk kk ke k k ke kk k kk kk kk k ke kk ke kk k k kk k kk k k ke kk k kk ke kk ke kk Sk ke kk ke ke kk ke kk kc ke kk ke ke ke ke ke e ke ke ke char AX ByteRdy return DataRdyUSART end AX ByteRdy BR kk kk ke kk ko ke KORK kk ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kk Sk k k k k kk Sk ke kk k ke kk ke kk Sk ke kok ke ke k k ke I ke k k AX TxPacket Transmits a packet on the AX12 servo data line Parameters id char the ID of the AX12 which should receive the packet instruction char the instruction type of the packet parameters char data array of the packet paramLength char length of the data array Returns void Kk kk k kk kk kk k kk k kk ee k k k kk k k k k k k k k k k k k k k k k k k k k k k k kk k kkk ke ke ek void AX_TxPacket char id char instruction char parameters char paramLength char length i checksum length 2 paramLength checksum 0 AX_SendByte 0xFF required by AX12 protocol to initiate a packet AX_SendByte 0xFF cequired by AX12 protocol to initiate a packet AX_SendByte id checksum checksum id AX_SendByte length checksum checksum length Team FIFA ECE 4007 L01 B11 ey Autonomous Foosball Table AX SendByte instruction checksum checksum instruction for
20. REZCSANT voo vss OSCICLK OSC2CLKD RAS RCOTIOSO TICKI RC UTIOSWCC P2 RC2CCP1 RC3SC KSCL ROOPSPO ROWSP1 RB3CCP2 RB2 NT2 RBIANTI REMNTO D2 o ME im gt 1 von EF GPS T1C KVOSC HC LKIN GPORANOAIN ACSP OAT o e 32 768 kHz x2 GP UANACIN 1 TIGIOSC2IC LKD UTP LAN UC 1IN ACSPCLK ie we gt von mr GPS T1C KVOSC HC LKIN GPOANOAIN ACSP DAT GP UANACIN 1 TIGIOSC2IC LKD UP VAN C 1IN ACSPCLK GPOVANOAIN HICSP DAT GP WANS IN1 TIGOSC2C LKD UTP LAN UC 1IN ACSPCLK o H GP3MCLRAIPP GP2AANZ TIC K INTICO UTICC P 1 SCHEM 1 2 ECE 4007 Senior Design Team FIFA Designed by Checked by Approved by date File name Date Scale Michael Aeberhard MPA 00 00 00 controller dch 11 1 2 2007 NIA Georgia Institute of Technology Foosball Table School of Electrical and Computer Engineering Servo Controller Board Advisor Edition Sheet Dr Hamblen 1 11 Team FIFA ECE 4007 L01 Autonomous Foosball Table o ECB E 22 I me PE o D o f o 00000000000000000000 k ROP oo doovu oococoog NS ZL a M F A ii NA 6000590 000000 e O O Clay oio e nooini S dp Er e ocoooooO0 ZAIN aE o K oo 7 o o Yo dgo too M Fa an Os NEE n o n Team FIFA ECE 4007 L01 D3 ie Autonomous Foosball Table Appendix E Mechanical Design Drawings Team FIFA ECE 4007 L01 E1 Autonomous Foosball Table E2 Team FIFA ECE 4007 L01 ey Autonomous Foosball Tab
21. Sk ke kk kok kok kok k Sk ke kk kok kk ke kk oko kok kok k k ke ke k I ke ke k PC ReadData Reads a byte from the UART Parameters toWrite byte to write Returns char 1 if byte is ready 0 if not CK kk ke ke kk ke kk ko ke kok ke ke kk ke kok ke ke kk ke kk Sk ke kk k kk ke ke kk ke kk kk ke kk kk k kk ke kk kc ke ke ke ke ke kk koe ke eek char PC ReadData unsigned char data 2 0x00 0x00 unsigned char read 2 0 0 unsigned char i PC UART SELECT 0 for i 0 i lt sizeof data i while WriteSPI data i OxFF H read i SSPBUF PC_UART_SELECT 1 return read 1 Team FIFA ECE 4007 L01 B15 amp end PC_ReadData Autonomous Foosball Table BR OK OK OK ok okok ok ok okok ok ko kok kok kok ok ok okok ok kok kok k kk IK ke kk ke IK KR ke kk ke IK k k k kok kk ke kk k k kk kok kk kok kk ke ek PC_WriteString void PC WriteString unsigned char toWrite Outputs a string for transmission to the UART Parameters toWrite pointer to the string to write length length of the string Returns void CK kk ke ke k kok kok Sk ke kok ke ke kk ke kk Sk ke kok ke ke kk ke kk Sk ke kk ke ke kk ke kk unsigned char i unsigned char readConfig 2 0 0 Amt jj DisableInterrupts for i 0 i length i PC WriteData toWrite i DelaylOTCYx 100 while PC UART IRO 1 DelaylOTCYx 100
22. The full schematic and a parts list reguired to manufacture the servo controller board can be found in Appendix D 5 4 2 Software Design The PIC18F4520 source code is written in C and compiled with the Microchip C18 compiler 14 In addition to the main program code two libraries were written that implemented the Team FIFA ECE 4007 L01 20 ey Autonomous Foosball Table functions necessary for setting up and communicating with the AX 12 servos and the image processing PC The AX 12 lateral motion servos are controlled via a bi directional UART data bus which is connected to the PICI8F4520 s internal UART module The AX 12 servos have their own communications protocol that must be implemented in software in order to successfully communicate with them The most common instruction is a WRITE instruction which writes a value into memory to a specific AX 12 servo The AX 12s are identified on the common data bus by a unique ID which is specified in the instruction For more information on how to implement the various instructions that are supported by the AX 12 communications protocol please refer to the AX 12 User Manual 6 A special library was written to easily implement all of the necessary functions to communicate with the AX 12 servos Table 6 shows an overview of these functions from the AX 12 library Table 6 AX 12 library function overview Function Name Description AX SetlId Assigns a new ID to a conne
23. center of mass xloc xpos numpos yloc ypos numpos found true p addPosition xloc yloc add the new location to the predictor else if found p clear clear out old locations in the predictor if stage gt 3 p missedFrame t getMinx t getTableWidth see if we need to register a goal found false This starts a new instance of our class gi public static void main String args System out println Click the outline of the table to begin new Track This processes mouse events within the window Ef private class CalcPixel extends MouseAdapter public void mouseClicked MouseEvent event grab the x and y location of the click int mousex event getPoint x int mousey event getPoint y if mousex gt 10 amp amp mousey gt 30 amp amp mousex lt imWidth 10 amp amp mousey lt imHeight 30 Color pixel new Color imagel getRGB mousex 10 mousey 30 switch stage case 0 the user selected the table outline color t setColorSearchSize colorSearchSize 2 t findOutline imagel mousex 10 mousey 30 if t getTableWidth 20 amp amp t getTableHeight 20 stage t t calcScale a new AI t pixelsPerInch System out println Table found Please pull all opponent players as far out as possible and click one to begin else System out println Not a large enough table area pixel getRed pixel getGreen
24. char void AX SendByte char void AX SetupUSART void endif Team FIFA ECE 4007 L01 B9 ey Autonomous Foosball Table BRK kok k k ok ok ke kk ke kk ck ok kk k kk Ck ke kok k kok k k kk Ck ke kk k ke kk k kk Sk ke kk k ke kk k kk k k kk k ke kk ke kk k kk ke ke kk ke ek Dynamixel AX 12 Servo Control Library Filename ax12 c THIS IS THE CODE FILE kk kk kk kk kk kk kk kk kk kk kk kk kk ke AZ AZ kk kk oko ck ck ck ck ck ck ck ck ck ck ck ck KKK KKK KKK KKK kckckckckckckckckockck Developed By Michael Aeberhard michael aeberhard gatech edu Date October 5th 2007 Purpose Easy to use function for controlling the AX 12 servos Restrictions This library assumes the use of the PIC18F4520 microcontroller from Microchip along with the C18 Compiler Instructions for changing from USART to SPI ck ck ck ck ck ck ck 0k 0k ok ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck 0k 0k ck ck ck 0k ck ck ck 0k Ck ck ck 0k ck ck ck 0k ck ck 0k ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck KKK This file contains numerous functions that can be used to control a AX 12 Servo motor Some of the functions are more generic while others are much more specific The original purpose of this library was to write a set of useful functions to be used in the automated foosball table senior design project by Michael Aeberhard Shane Connelly Evan Tarr and Nardis Walker at the Georiga Institute of Technology Kk k
25. ck ck ck ck ck ck ckckckckckckckckokok Developed By Michael Aeberhard michael aeberhard gatech edu Date October 26th 2007 Purpose This program reads in data packets from the PC and carries out their instructions to the servo motors that ultimatley manipulate the handles on the foosball table XR zz Xo X CK k kok kk ke kk Sk ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kok ke ke kk ke kk Sk ke kok ke ke kk I kk Sk ke kk ke ke kk kok kk ke ke ke ex pragma config OSC HSPLL WDT OFF LVP OFF include p18f452 h Use PIC184520 naming conventions include lt timers h gt Timer functions for the PIC18F include lt ax12 h gt Functions for AX12 servos include lt pc_uart h gt Functions for PC UART communication PIC macros define EnableInterrupts INTCONbits GIEH 1 define DisableInterrupts INTCONbits GIEH 0 Servo motor IDs for Foosball table define SERVO_ALL OxFE define SERVO_KEEPER 0x04 define SERVO_DEFENSE 0x03 define SERVO_MIDFIELD 0x02 define SERVO OFFENSE 0x0 define SERVO TEST 0x0 PWM Servo Macros define PWM_OFFENSE_CTRL PORTDbits RD4 define PWM_OFFENSE_DIR PORTDbits RD5 define PWM_MIDFIELD_CTRL PORTBbits RB5 define PWM_MIDFIELD_DIR PORTBbits RB4 define PWM_DEFENSE_CTRL PORTDbits RD6 define PWM_DEFENSE_DIR PORTDbits RD7 define PWM_KEEPER_CTRL PORTEbits REO define PWM_KEEPER_DIR PORTEbits RE1 Port macros define AX_DATA_DIRECTION PORTCbits
26. control board across the serial connection on the computer It communicates at 115 200 bps 1 stop bit 8 data bits no parity bits and no flow control author Team FIFA ECE4884L01 Georgia Institute of Technology version 1 0 December 2007 SI import java io import java util import javax comm import java awt event import java lang String import java lang Character import java lang Math import javax swing Timer public class Writes static Enumeration portList static CommPortIdentifier portId static SerialPort serialPort static OutputStream outputStream static boolean outputBufferEmptyFlag false private boolean raised new boolean 4 private boolean nextval new boolean 4 private int timeleft new int 4 private int packet 1 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 initialize packet 2 not sets Class constructor public WriteS connect connect to the motor control board for int i 0 i lt 4 i loop through all rows assuming all players are down and have no future agenda timeleft i 0 raised i false nextval i false this actionlistener is used in a state variable configuration to tell the PWM servos what to do next after they complete their current action ActionListener checkservos new ActionListener public void actionPerformed ActionEvent evt for int i 0 i lt 4 i if timeleft i gt 1 there is
27. controlrow 7 amp amp p getFutureX gt t getRowXPosition 3 true c kick 3 else if controlrow 6 amp amp p getFutureX gt t getRowXPosition 2 true c kick 2 else if controlrow 5 amp amp p getFutureX gt t getRowXPosition 1 true c kick 1 else if controlrow 4 amp amp p getxPosition gt t getRowXPosition 0 true c kick 0 always move the defense and goalie to intercept double gi t getMaxY p findGoalIntercept t getRowXPosition 3 true t getPlayerHeight a goalIntercept c gi double di t getMaxY p findDefenseIntercept t getMinX t getRowXPosition 2 true t getMinY t getMaxY t getRowSpacing 2 t getPlayerHeight try Thread sleep 2 artificially delay the next command catch Exception e System out println Error a defenseIntercept c di sleep for 1 ms to check the next frame try 1 Thread sleep 1 catch Exception e System out println Error Finds the current location of the ball Limits the search to a window about the predicted location param x The most recent webcam capture private void findBall BufferedImage x int xpos ypos numpos xlower xupper ylower yupper xpos ypos numpos 0 if found ball was found on last frame localize the search p recalculate try to find the new positions xlower p getxPosition searchSize xupper p getxPosition searchSi
28. costs the company to develop the product Parts 1 600 Labor 22 400 Fringe Benefits of Labor 5 600 Subtotal 29 600 Overhead of Matl Labor amp Fringe 16 280 Total 45 880 Determination of Selling Price What the customer pays the company for the finished product units 43 2 Based on 500 Parts Cost 710 Assembly Labor 25 Testing Labor 50 Total Labor 75 Fringe Benefits of Labor 19 Subtotal 804 Overhead of Matl Labor amp Fringe 442 Subtotal Input Costs 1 246 Sales amp Marketing Expense 1 250 Warranty amp Support Expense 250 Amortized Development Costs 92 Subtotal All Costs 2 838 Profit 2 162 Selling Price 5 000 Total Revenue 2 500 000 Total Profit 1 081 214 Team FIFA ECE 4007 L01 F2 e Autonomous Foosball Table Appendix G Prototype Development Gantt Chart Team FIFA ECE 4007 L01 G1 Autonomous Foosball Table Projected Prototype Development b ask Name Duration Start Finish September 2007 October 2007 November 2007 December 2007 31 3 6 9 12 15 18 21 24 27 30 3 6 8 12 15 18 21 24 27 30 2 5 8 111 14 17 20 23 26 29 2 5 8 11 14 1 PIC Microc
29. ke kk ke ek PC ReadConfiguration Receives a byte from an AX12 servo data line Parameters readResult buffer to store the result of the configuration read Returns void Kk kk k kk kk kk ck ke kk kk Ck Ck kk kk kk ke kk Ck k kk ke k kk k kk k kk ke ke kk ke kk k kk ke ke kk ke kk kc ke kk ke ke ke ke koe ke ke ek void PC ReadConfiguration unsigned char readResult unsigned char config 2 0x40 0x00 unsigned char i PC UART SELECT 0 for i 0 i lt sizeof config i while WriteSPI config i OxFF readResult i SSPBUF PC_UART_SELECT 1 end PC_ReadConfiguration BR KK k k ok ok kok k k kok kok kok k kok kok kok kok kk ke kk Ck ke kk ke kok k k kk kok kk k kk kk kk k k kk k kk kk k kk okok ok Ok PC WriteData Outputs a byte for transmission to the UART Parameters X boo toWrite byte to write Returns char 1 if byte is ready 0 if not CK Kk kk kk kk k kk k kk kk ke ke kk k kk Ck k kk k kk k kk k ke kk ke ke kk ke kk k k kk k ke kk ke kk ko ke kk ke ke ke ke ke e ke ke ek void PC WriteData unsigned char toWrite unsigned char data 2 0x80 toWrite unsigned char read 2 0 0 unsigned char i PC_UART_SELECT 0 for i 0 i lt sizeof data i while WriteSPI data i OxFF read i SSPBUF PC_UART_SELECT 1 end PC WriteData BK ok k k ok KOKK KROK RK KORK KORR KRK kok kok ok Sk ke kok kok ok
30. ke kk ke ke kk k kk k kk ke ke kk k kk Ck ke kk k ke kk ke k k kc ke k k ke ke kk koe ek ke ek void servoCommand unsigned char unsigned char unsigned char unsigned char unsigned char servoType control data 3 if servoType 1 servoAddress servoValue 2 direction char gt gt 2 packet 0 packet 0 packet 0 amp OxOC amp 0x10 gt gt 4 0x03 packet 1 amp OxFF PWM servo control direction AT else i Team FIFA ECE 4007 L01 amp 0x01 amp 0x02 servoValue 0 servoValue 0 gt gt servoAddress 3 if control 1 PWM_KEEPER_CTRL else PWM_KEEPER_CTRL if direction 1 PWM_KEEPER_DIR else PWM_KEEPER_DIR E ZE servoAddress 2 control 1 PWM DEFENSE CTRL else PWM DEFENSE CTRL B5 ey Autonomous Foosball Table if direction 1 PWM DEFENSE DIR 1 else PWM DEFENSE DIR 0 else if servoAddress 1 if control 1 PWM MIDFIELD CTRL 1 else PWM MIDFIELD CTRL 0 if direction 1 PWM MIDFIELD DIR 1 else PWM MIDFIELD DIR 0 else if control 1 PWM OFFENSE CTRL 1 else PWM OFFENSE CTRL 0 if direction 1 PWM OFFENSE DIR 1 else PWM OFFENSE DIR 0 else AX 12 Servo data 0 OxlE data 1 servoValue 1 data 2 servoValue 0 if servoAddress 3 AX_TxPacket SERVO_KEEPER I_WRITE_DATA data 3
31. ke kk ke kk Ck ke kk ke ke kk k kk Ck ke kk ke kk k ke kk Sk ke kk k kk k k kk k k kk ke ke kk k kk k kk k ke ke ke Ok AX RxPacket Receives a packet from an AX12 servo M Team FIFA ECE 4007 L01 B10 ey Autonomous Foosball Table Parameters none Returns char pointer to the retrieved string CK Kk k kk kk kk Ck ke kk ke kk Ck k kk ke kk k kk Ck k kk k ke kk k kk k kk k ke kk ke kk Ck ke kk ke ke kk ke kk kc ke kk ke ke ke ke koe ek ke char AX RxPacket char length id errorByte checksum i curByte char i length char packet 32 packet 0 AX RxByte 0xFF packet 1 AX RxByte O0xFF packet 2 AX RxByte length packet 3 AX RxByte error length packet 3 3 for i 3 i lt length i packet i AX RxByte return packet end AX_RxPacket BR KK k k KK KROK KK I KK kk ke ke k k k kk Sk ke kk Sk ke kk ke kk Sk k kk ke k k k k kk Sk ke kk ke k kk ke kk Sk ke k k k k k k kk k k k k e k AX RxByte Receives a byte from an AX12 servo data line Parameters none Returns char the received byte ee kk k kk Sk ke kk ke kk Sk ke kk ke ke kk ke kk ko ke kk ke ke ke ke ke ke ke ke ke ek char AX RxByte while DataRdyUSART 0 H return ReadUSART end AX RxByte BR KK k k k k k kok kk kok kok k kok kok kok kok kok kk k kk Ck ke kok k k kk k kk k kk k k kk k k kk k ke kk k kk k kk k k k k k ke ek AX RxByteRdy
32. known y location of the ball this function clears the last known positions of the ball Autonomous Foosball Table the y velocity of the ball in pixels per frame last calculated x velocity of the ball the x velocity of the ball in pixels per frame predicted x location of the ball the predicted x location of the ball in pixels predicted x location of the ball the predicted x location of the ball in pixels predicted x location of the ball the last known x location of the ball in pixels last known y location of the ball in pixels to avoid making false assumptions of the velocity see addPosition S Team FIFA ECE 4007 L01 A9 ey Autonomous Foosball Table public void clear int i count 0 for i 0 i lt 3 i lastPositions 0 i 0 lastPositions 1 i 0 Upon a lost frame this function determines whether a goal was likely scored or not 10 missing frames of the ball indicate a likely goal If a goal is determined to be scored play an audio clip depending on the most likely scorer Ey public void missedFrame int tableMinX int tableWidth String goodGoals goal wav chant wav cheer wav crowd wav goal2 wav freesoundGoal wav computer error wav destroyed wav no ordinary machine wav String badGoals boo wav about time wav doh wav doing my best wav error wav dah duh duh wav String playfile n
33. locating objects on the table param value An integer representing the maximum value any R G B data can be away from a determined color value ay public void setColorSearchSize int value colorSearchSize value Draws the players onto a Graphics object return The modified graphics object see Graphics Ef public Graphics drawPlayers Graphics g int i j xpos ypos g setColor Color RED Draw in Red for i 0 i lt 4 i xpos rows i 2 for j 0 j lt rows i 0 j loop through the number of players on a row ypos rows i 4 j rows i 1 playerHeight 2 compute the y location of each player g fillOval xpos 5 ypos 25 10 10 draw circles over the players return g Determines the row that is in control of a ball given the x location of that ball param x The x location of the ball return A control row 0 3 indicates the human s row is in control while 4 7 indicates the robot s row is in control KE public int findController int x int i r 0 min 9999 for i 0 i lt 4 i loop through all rows if Math abs rows i 2 x lt min min Math abs rows i 2 x uis if Math abs myrows i 2 x lt min min Math abs myrows i 2 x r i 4 return r Locates the computer s players from data about the human s players assuming a symmetrical table ky public void findMyPlayers
34. maxX zk ww amp H X Public accessor to compute the width of the table in pixels return The minimum x position subtracted from the maximum x position of the table in pixels see getMinx see getMinY see getMaxX see getMaxY see getTableHeight if public int getTableWidth return maxX minX S zz amp 0X Public accessor to compute the height of the table in pixels return The minimum y position subtracted from the maximum y position of the table in pixels see getMinx see getMinY see getMaxX see getMaxY see getTableWidth public int getTableHeight return maxY minY F Public mutator to set the x position of a given row param row The row number 0 3 to set param pos The x position in pixels id public void setXPos int row int pos rows row 2 pos Public mutator to set the minimum y position of a given row param row The row number 0 3 to set iparam pos The minimum y position in pixels Py public void setTop int row int pos rows row 3 pos Public accessor to get the minimum y position of a given row param row The row number 0 3 to set return The minimum y position of the row in pixels 7 public int getTop int row Team FIFA ECE 4007 L01 A16 ey Autonomous Foosball Table return rows row 3 Sets the search size in RGB for
35. pixel getBlue Click the outline again break case 1 the user selected the player color rOppColor pixel getRed Team FIFA ECE 4007 L01 A27 amp players 3 gOppColor bOppColor to begin Autonomous Foosball Table gOppColor pixel getGreen bOppColor pixel getBlue t setColorSearchSize colorSearchSize 2 t findRows imagel mousex 10 mousey 30 find the System out println Tracking new color RGB rOppColor stage 2 System out println Players found Please click the ball break case 2 null case antiguated case 3 the user selected the ball color c centerAll center all the players after the ball is found rBallColor pixel getRed gBallColor pixel getGreen bBallColor pixel getBlue System out println Tracking new color RGB rBallColor gBallColor bBallColor mousex 10 mousey 30 searchSize p setColorSearchSize colorSearchSize p calcBallSize imagel rBallColor gBallColor bBallColor stage t break default the default behavior is just to track a new ball color rBallColor pixel getRed gBallColor pixel getGreen bBallColor pixel getBlue System out println Tracking new color RGB rBallColor i gBallColor bBallColor Team FIFA ECE 4007 L01 A28 ey Autonomous Foosball Table WriteS java This class is used to communicate with the motor
36. program flow chart Team FIFA ECE 4007 L01 23 ey Autonomous Foosball Table The full assembly source code for the PICI2F615 PWM controllers is shown in Appendix C 5 5 Mechanical Design The table construction centers on a simple DMI Sports foosball table Attached directly to it are an overhead webcam mount and a side table to support the servos and circuitry SolidWorks was used to create a preliminary mechanical design A photograph of the actual prototype and the SolidWorks design are shown in Figure 10 Figure 10 SolidWorks and actual mechanical design In order to fit the entire playing surface into the field of view of the webcam it had to be placed at least 53 above the table A metal frame reaching 54 above the table is attached to each corner of the table with a one foot wide medium density fiberboard MDF crosspiece attached centered over the table This crosspiece has a 3 hole bored into its center for the webcam to look down through The webcam itself is attached with a 12 machine screw into its tripod mounting hole A small piece of wood cut at 45 degrees must be mounted between the MDF and the webcam in order to yield a downward orientation Team FIFA ECE 4007 L01 24 ey Autonomous Foosball Table In order to support the servos a table must be built extending 3 feet from the original foosball table two inches below the handles The table is made of MDF with 2 x2 legs to maintain a light weight
37. rows 5 items of interest per row 1 Players on that row 2 Distance between players on that row 3 X position of the row 4 Minimum Y position 5 Current Y position private int rows new int 4 5 private int myrows new int 4 5 Class constructor f public Table char i j rows 0 0 rows 1 0 3 players in attack row 5 players in midfield row rows 2 0 2 players in defense row rows 3 0 1 player as the goalie for i 1 i lt 4 i for j 0 j lt 4 rows j il myrows j i PN OW Ne Ne Me j 0 for i 0 i lt 4 i playerCount rows i 0 myrows i 0 rows i 0 the same number of players Calculates the pixels per inch in the foosball table playing surface of 24 by 48 inches physical dimensions average player height total number of players on the board opponent color bOutlineColor private int minX 0 minY 0 maxX 0 maxY 0 calculated later Once we have the boundary as found by the picture in pixels table outline color 0 initialize all locational data to 0 count the total number of players assume a fair game where the computer has A standard foosball table has a we can verify the This data is stored internally in the pixelsPerInch variable Qsee fgetInches wi public void calcScale double wcalc getTabl
38. the idea of man versus machine makes an automated foosball table an interesting and fun challenge to play against The autonomous foosball table AFT falls within the same category as typical arcade games found in entertainment centers such as pinball air hockey and arcade videogames Currently there is no such automated foosball arcade machine in mass production therefore there is an excellent opportunity to market such a product By offering an AFT at a competitive arcade machine price the potential for profitability is great This document will examine the underlying technology used in building an AFT and prove that a challenging computer controlled opponent can be developed The completed prototype plays fairly well against an average foosball player and functions reliably showing the potential for a finalized table The issues encountered which hinder the AFT were budgetary With faster motors and larger gears the table would function at an advanced level with ease After the successful demonstration of the prototype further development can be made to improve presentability and gameplay mechanics for a marketable and manufacturable arcade machine Team FIFA ECE 4007 L01 3 ey Autonomous Foosball Table 2 Introduction A prototype foosball table with a robotic opponent was designed and constructed by project engineers An autonomous foosball table will effectively bring a fast paced multi player game to lone players or team
39. the servo to move param loc The number of inches away from the wall the row s stopper should end at Z public void move int ID double loc packet 2 0 packet 3 0 packet 4 ID 2 packet 5 ID 2 convert pos from physical position to servo position double ipp 11 0 5 0 6 0 1024 0 inches per postional bit int maxPos 0 int start_pos 0 starting position of servo varies by handle we have to avoid over pulling or over pushing the servos past the physical bounds of the table if we do that the servos will go into a torque overload setting and shut down switch ID case 3 start_pos OxAF maxPos 0x350 break case 2 start_pos 0 maxPos Ox3FF break case 1 start pos 0x130 maxPos 0x2B0 break case 0 start pos Ox8F maxPos 0x350 break int pos int loc ipp start pos if pos gt maxPos pos maxPos else if pos lt start_pos pos start_pos while the goalie does have specific physical bounds we want to software limit it as well so as to avoid going beyond the goal range if ID 3 amp amp pos start_pos pos 0x11E the physical servo location of the minimum goal value else if ID 3 amp amp pos maxPos pos 0x2E1 the physical servo location of the maximum goal value Team FIFA ECE 4007 L01 A32 ey Autonomous Foosball Table convert the positional data into a packet if pos lt m
40. while providing ample support and rigidity On top of the side table underneath each robotically controlled handle drawer slides are mounted in order to keep the servo assembly rigid and parallel to the extended table The assemblies units are attached to the drawer slides by an aluminum L bracket This serves to keep the servos at a constant height while still allowing smooth lateral motion Alongside each slide a nylon rack is attached while an accompanying 3 5 gear is mounted directly to the AX 12 The AX 12 and HS 81 servos are mounted on opposite sides of a small piece of MDF with the HS 81 being attached directly to a rod holding players on the foosball table As the AX 12 spins it can now traverse the length of the rack pushing and pulling the players with it and as the HS 81 spins the players will spin as well Double sided foam tape is placed between the racks and the table in order to keep the rack in place and at the proper height Should the racks be too low the gear and rack will not meet properly and slippage can occur The SolidWorks design and the implemented design of the full servo assemblies can be found Figure 11 Figure 11 SolidWorks design and actual mechanical design of the servo assemblies Team FIFA ECE 4007 L01 23 ey Autonomous Foosball Table The servo controller board and PWM controller boards are also mounted directly to the top of the extended side table with the necessary wiring for the assemblies r
41. 2 lastPositions 0 1 2 0 yLocation lastPositions 1 2 int deltaY xLocation lastPositions 0 2 int deltaX yFutureLoc yLocation int deltaY 1 75 There is a lag of approximately 1 75 frames from the webcam xFutureLoc xLocation int deltaX 1 75 else xLocation lastPositions 0 2 yLocation lastPositions 1 2 yFutureLoc yLocation xFutureLoc xLocation Class Constructor SE Team FIFA ECE 4007 L01 A11 ey Autonomous Foosball Table public Predictor int i deltaY deltaX 0 0 for i 0 i lt 3 i initialize all previous locations to 0 0 lastPositions 0 i 0 lastPositions 1 i 0 yFutureLoc 0 xFutureLoc 0 Team FIFA ECE 4007 L01 A12 Table java This class creates a virtual foosball table information on the table color and size author Team FIFA ECE4884L01 version 1 0 December 2007 s odpo ob ok O O import java awt import java awt image public class Table Autonomous Foosball Table It includes player information as well as Georgia Institute of Technology private int colorSearchSize 0 distance to search in color space for colored objects private int playerHeight 0 private int playerCount 0 private int rOppColor gOppColor private int rOutlineColor bOppColor gOutlineColor public double pixelsPerInch 1 0 boolean foundPlayers false 4
42. 2 Servo 4 40 x 4 160 HS 81 Servo 4 15 x 4 60 Cheap Laptop 1 100 Serial Cable 5ft 1 2 Power Supply 1 50 9V DC Adapter 1 5 PIC 18F4520 1 20 PIC 12F615 4 1x4 4 MAX3100 1 6 MAX232 1 3 Voltage Regulators 1 6 Wiring 1 5 Oscillators 4 1x4 4 Assorted ICs 1 3 MDF lumber 1 20 Assorted Hardware 1 10 Drawer Slide 4 10 x 4 40 Shelf Rack 6 4 5 x 6 27 Total 1 710 00 Autonomous Foosball Table In conclusion the market for such an arcade machine is well established and the void for such a unique machine gives it a great amount of selling power Given costs of parts and labor selling such an arcade machine at a competitive price compared to other machines in the market allows the manufacturer to make a substantial profit Team FIFA ECE 4007 L01 38 ey Autonomous Foosball Table 9 Summary and Conclusions The prototype has been completed and is in full operation yet some things would have to be changed before the design can be finalized The biggest change would be to switch from a computer based system to an FPGA board for central processing This is necessitated by the image acquisition portion of the project As currently implemented there is a large latency between a visual event and the computer receiving the image of it By using a CCD or CMOS image sensor directly coupled to an FPGA board the system would be capable of receiving and processing hundreds of frames per second Thes
43. ART USART TX INT OFF amp USART RX INT OFF amp USART BRGH HIGH amp USART EIGHT BIT amp USART ASYNCH MODE 9 TXSTAbits BRGH 1 500 kbps SPBRG 0x04 end AX SetupUSART Team FIFA ECE 4007 L01 B12 ey Autonomous Foosball Table ifndef PC UART H define PC UART H ck ck ck ck ck ck ck ck ck ak 0k 0k ck ck ck ck ck ck ck ck ck ak ak ck ak 0k ak 0k 0k 0k okok 0k 0k Ck ak Ck ck ak ok 0k ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck KKK PC SPI UART with MAXIM 3100 Library Filename pc uart h THIS IS THE HEADER FILE ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ak ck ak 0k ck ck ck ak ck 0k 0k ck Ck Ck ak 0k 0k ak ck ck ck ck ck ck ck ck ck ck ck ck ck ck ak ck ck kc ck ck ck ck ck ck ck ck ck ck ck ck ck KKK Developed By Michael Aeberhard michael aeberhard gatech edu Date October 11th 2007 Purpose Easy to use functions sending and receiving data via the MAXIM 3100 UART chip using the PIC s onboard SPI module Restrictions This library assumes the use of the PIC18F4520 microcontroller from Microchip along with the C18 Compiler ck ck kk kk kk ok KKK KKK KKK KKK KKK KKK KKK ck ck ck ok ck ck ck ck ck ck ck ck ke ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck kk ck ck ck ck ck ck ck ck ckckckckckckckokck This file contains numerous functions that can be used to communicate with a PC Some of the functions are more generic wh
44. E Make revisions to project sumi 3days Mon 10 807 Wed 10 10 07 25 F4 Final Project Summary due 1day Thu10 11 07 Thu 10 11 07 1011 26 ES Work on website 15days Mon9 7 07 Fri 10 5 07 nl 27 E Website live 1 day Wed 10 10 07 Wed 10 10 07 1010 28 Eg Wiork on PDR Sdays Fri 1022 07 Wed 10 24 07 29 E Preliminary Design Review 1day Thu 10 25 07 Thu 10 25 07 10 25 30 A Design Report 15days Mon11 2 07 Fri 11 30 07 Actual Prototype Development D Tea Name Duration Start Finish Predecessors Saztember 2007 October 2007 November 2007 December 2007 31 3 e 9 12 15 18 21 24 27 30 3 6 9 12 45 18 21 24 27 30 2 5 8 11 14 17 20 23 26 29 2 s 8 11 14 1 PIC Microcontroller Board 54 days Thu 9 13 07 Tue 1127 07 2 Assemble PIC board 11days ThuS A3 07 Thu 9 27 07 3 Demonstrate PIC Board 1day Fri 10 5 07 Fri 10 5 07 2 4 Servo motor communication 8days Wed 10 17 07 Fri 10 26 07 3 5 Communications with compute 37 days Mon 10 8 07 Tue 11 27 07 6 Mechanical Assembly 54 days Mon 9 2407 Thu 12 6 07 7 Work on basic assembly 15days Mon 9 24 07 Fri10 12 07 8 Basic assembly finished 1day Mon 10 15 07 Mon 10 15 07 7 9 Continue assembly improveme 38 days T
45. ECE 4007 Team FIFA FINAL REPORT Single Player Foosball Table with an Autonomous Opponent Design and Final Report By Michael Aeberhard Shane Connelly Evan Tarr Nardis Walker Submitted December 10 2007 Instructor Dr James Hamblen Fall 2007 ECE 4007 L01 Georgia Institute of Technology School of Electrical and Computer Engineering ey Autonomous Foosball Table Table of Contents lx SCEXecudye Summary ee desides ida tette sd enh ola esr ot DUM etus da nc 3 NET Sedi oco Go dns ata kose bsatoncst ate us Pete Osten se B PASE aptus dan bap et DR eco ante 4 2 1 ODS Ves eed nit tu i a E un s Mt AE 4 2 2 0 Zeta RR RR Qu o uter aai mtd dE efe nca 4 2 3 BACK SOU E ENN SARA 4 Si BrojectDescriplianand e EE 6 A Technical Specifications zas ee u Fb nd TRU RA WERTE Ea c Ee Da VETE UR BAe 8 S DesremApproach and DetaHls 5o iacere yw eti ue Soca I ERSTER ET MEL ERES pel AR odd ZK SLA VER 10 5 1 Design Overview os gies Det 10 2 2 Image Processing DeSIg0 i iisscesssensddrs ressanssdnusdrensssransrsndessnsussirnsisnssdensessan sed v dp d tad 11 5 3 PC Controller Communications 22 0 2s olcds Green Nanna 14 5 4 Servo Controller BOSE eene ttti ete te a te Eeer eege 16 5 4 1 Hardware osud ee redacti eed oy ie oe lend e a e 16 5 4 2 Software EE 20 5 5 Mechanical Desitin oS eti cd nee arcte tea o ooo SE 24 2 07 Codesand Standards oae rette ie
46. Intelligence AI Overview 2007 Online Available http www aaai org AITopics html welcome html Accessed Sept 12 2007 Tribotix Robotis Technical Staff Dynamixel AX 12 User s Manual Tribotix Jun 16 2006 Online Available http www tribotix info Downloads Robotis Dynamixels AX 12 english pdf Accessed Oct 3 2007 Hi Tec Technical Staff HS 81 Micro Servo Specification Hi Tec Online Available http www robotshop ca PDF hs8 1 pdf Accessed Nov 3 2007 Java Media Framework JMF API 2007 Online Available http java sun com products java media jmf Accessed Oct 1 2007 Team FIFA ECE 4007 L01 42 9 10 11 12 13 14 15 16 Autonomous Foosball Table Microchip Technical Staff PIC18F4520 Datasheet Microchip 2007 Online Available http ww1 microchip com downloads en DeviceDoc 39631D pdf Accessed Sept 20 2007 Microchip Technical Staff PICI2F615 Datasheet Microchip 2006 Online Available http ww 1 microchip com downloads en DeviceDoc 41302A pdf Accessed Oct 28 2007 Maxim IC Technical Staff MAX3100 Datasheet Maxim IC Dec 2001 Online Available http datasheets maxim ic com en ds MAX3100 pdf Accessed Oct 15 2007 Maxim IC Technical Staff MAX232 Datasheet Maxim IC Jan 2006 Online Available http datasheets maxim ic com en ds MAX220 MAX249 pdf Accessed Oct 10 2007 DipTrace Homepage Online Available http www di
47. RCO define LEDO PORTAbits RAO define LED1 PORTAbits RA1 define PButtonl PORTAbits RA4 define PButton2 PORTBbits RB2 Assignment macros define AX_DATA_RX 0 define AX_DATA_TX j function prototypes void delay 1s void void delay 5ms void void servoCommand void void specialCommand void pragma code Global Variables unsigned char pc buffer 2 unsigned char pc index unsigned char packetReady unsigned char packet 2 unsigned char numberPackets char center 3 OxlE 0x00 0x02 Team FIFA ECE 4007 L01 B2 amp AX12 Start Position Autonomous Foosball Table char offenseStart 3 OxlE Ox8F 0x00 char midfieldStart 3 Ox1E 0x30 0x01 3 char defenseStart 3 Ox1E 0x00 0x00 char keeperStart 3 OxlE OxAF 0x00 char offenseEnd 3 OxlE OxBF 0x00 char midfieldEnd 3 1 Ox1E 0x30 0x01 char defenseEnd 3 OxlE OxFF 0x03 char keeperEnd 3 Ox1E OxAF 0x00 BRK kk ke KK ke KK kk ke I KK IK I kk ke ke kk A kk Sk ke kk Sk ke kk kok o o ke kk ke ke kk kok k oko kok kok k k kok k oko kok ke ke ke ke ke k Begin main program code CK kk kok kk ke kk ko ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kk ke ke void main char movingSpeed 3 0x20 OxFF 0x03 char maxTorque 3 0x22 OxFF 0x03 unsigned char PCread 2 0 0 ist 1 pc index 0 pc buffer 0 pc buffer 1 packetReady packet 0 packet 1 nu
48. Size amp amp pixel getBlue gt b colorSearchSize amp amp lt b colorSearchSize for loop3 j 5 loop3 lt j 15 loop3 pixel new Color x getRGB rows i 2 if pixel getRed gt r amp amp pixel getRed lt ze amp amp pixel getGreen gt g amp amp pixel getGreen lt ze amp amp pixel getBlue b amp amp pixel getBlue ze if loop3 lt startPlayerPos countpx Team FIFA ECE 4007 L01 A19 Autonomous Foosball Table if countpx gt 2 1 rowdist startPlayerPos lastPlayerPos lastPlayerPos startPlayerPos j playerHeight 2 startPlayerPos maxY countpx 0 rows i 1 rowdist rowdist 0 break else countpx 0 startPlayerPos maxY else rows i 1 ay 0 The following represents the predefined values that replaced the above code These values were found through simple image analysis playerHeight 6 distance between players on the row rows 0 1 52 rows 1 1 31 rows 2 1 78 rows 3 1 0 x location data rows 0 2 98 rows 1 2 169 rows 2 2 241 rows 3 2 277 y location data rows 0 3 rows 0 4 52 rows 1 3 rows 1 4 52 rows 2 3 rows 2 4 55 rows 3 3 rows 3 4 104 findMyPlayers foundPlayers true Finds the maximum distance any player on a row can move
49. Team FIFA ECE 4007 L01 7 ey Autonomous Foosball Table 4 Technical Specifications Table 1 shows the projected technical specifications versus the actual tested specifications of the implemented automated foosball table Table 1 Automated foosball table technical specifications Item Specification Goals Demonstrated Specifications Camera frame rate min 60 frames per second 30 frames per second Camera resolution min 30 pixels per sq in 39 5 pixels per sq in Localized ball tracking success rate 80 of frames minimum 93 of frames Kick rate ball velocity up to 10 feet per second 1 5 feet per second Lateral player speed up to 2 5 feet per second 0 77 feet per second Lateral player position resolution atleast 1 cm 0 228 mm Move and kick success rate 75 of attempts minimum 3396 of attempts Unopposed goal rate 50 of attempts minimum 10 of attempts Goalie blocking success rate 90 of attempts minimum 72 of attempts Reaction time from webcam 200 ms maximum 100ms Power requirements TBD 4 3A 9 5V Weight TBD 69 Ibs Table dimensions TBD 5 x4 x8 WxLxH The first issue that we ran into involved the webcam The Phillips SPC900NC was chosen due to its listed framerate of 90 fps and resolution of 1280x1024 pixels Upon using it it was discovered that the camera used only USB 1 1 which supplies a
50. al design completed begin implementing 10 10 Initial mechanical assembly of 1 handle completed 10 17 Team FIFA ECE 4007 L01 31 e Autonomous Foosball Table PWM to microcontroller communication 10 24 Completed PC to microcontroller communications 11 7 Webcam mounted onto foosball table 11 21 Completed assembly of all 4 handles 11 28 Final component integration and testing completed 12 6 Refer to the Gantt chart in Appendix G to get a better overview of when these milestones were met compared to their projected date Team FIFA ECE 4007 L01 32 ey Autonomous Foosball Table 7 Project Demonstration For the technical demonstration of the project a game of foosball was played This exhibited how all of the subsystems of the prototype worked together to form the completed design Instructions for operation of the AFT can be found in Figure 12 below The prototype performed well although slower than desired The primary failure of the AFT was that the players moved and kicked at less than one third of what was determined necessary in the initial technical specifications This in turn caused goals to be missed in the form of scoring and blocking success rates as well Testing the movement specifications was simply a matter of watching the game and using a stopwatch to measure timing From the distance moved and the time required to do so a speed was determined Movement resolution was cal
51. am tableYMax The maximum y location of the foosball table param playerSpacing The spacing between defensive players return A double predicting the pixel location the midfield should go to Autonomous Foosball Table in pixels in pixels int rowXPos int tableYMin int 5 this is used as a sort of schmitt trigger where in the ttempt to gain control of the ball tableYMin tableYMax tableYMin 0 the y location to go to bleYMax tableYMax tableYMin trolZone false goalLocation goalLocation yLocation deltaX Pos goalXPos playerSpacing tableYMax pixelControlZone true goalLocation Pos goalXPos Control 136 go to the maximum position controlZone y i2 yLocation deltaX goalLocation 0 go to a zero position Aligns the midfield to block kicks from the opponent in pixels in pixels int tableYMax yLocation deltaY tableYMax playerSpacing returnLocation playerSpacing return returnLocation see findGoalIntercept see findDefenselIntercept see findMidfieldPosition public double findStrikerPosition int playerSpacing double returnLocation while returnLocation lt param tableYMax The maximum y location of the foosball table param playerSpacing The spacing between defensive players return A double predicting the pixel location the strikers should g
52. ate bounces private int colorSearchSize distance to search in color space for colored objects private double deltaY deltaX x and y slopes private boolean bottomDefenseControl false this determines which defenseman should grab control of the ball private int myscore 0 oppscore 0 lostballframes 0 used in scoring algorithm Adds a new ball location to the stack param xloc The new x location of the ball in pixels param yloc the new y location of the ball in pixels see clear A public void addPosition int xloc int yloc lostballframes 0 int 1 for i 0 i lt 2 i lastPositions 0 i lastPositions 0 i 1 lastPositions 1 i lastPositions 1 i 1 lastPositions 0 2 xloc lastPositions 1 2 yloc count if count gt 2 count 3 if we have more than 2 frames of interest we do not care of previous values Predicts the goalie intercept path with the predicted y location of the ball iparam xpos The new x location of the ball in pixels return A double predicting the pixel location the goalie should go to see findDefenseIntercept see findMidfieldPosition see findStrikerPosition A public double findGoalIntercept int xpos deltaY lastPositions 1 0 lastPositions 1 2 2 0 average of the last 2 y slopes y3 y2 y2 yl return yLocation deltaY Aligns the de
53. axPos amp amp pos gt start_pos for int i 0 i lt 9 i packet i 6 pos int Math pow 2 9 i pos pos int Math pow 2 9 i sendPacket Sets a PWM servo in either the up or down position param ID The row number of the servo to move param value A boolean indicating if the servo should be Sy public void setLiftID int ID boolean value if value setUp ID else set Down ID up Initiates a temporal function where the PWM servo first is lifted and after a timeout is set back down param ID The row number of the servo to kick ud public void kick int ID if timeleft ID 0 SetUp ID nextval ID false Initiates a kick and move function The PWM servo will be kicked at the current position and as the lateral movement begins iparam ID The row number to move and kick param pos The number of inches away from the wall the row s stopper should end at S public void kickhere int ID double pos move ID pos kick ID Sets a PWM servo in to the up position param ID The row number of the servo to move Qsee setDown Z public void setUp int ID nextval ID true if raised ID if ID 3 timeleft ID 10 the goalie is a different slower servo else timeleft ID 5 default servo behavior packet 2 0 packet 3 1 packet 4 ID 2 packet 5
54. cted AX 12 servo AX Ping Pings the connected AX 12 servos AX RxByte Receives a byte from an AX 12 servo AX ByteRdy Determines whether a byte is ready to be ready on the AX 12 data bus Sends a valid instruction packet to a connected AX 12 servo as per the AX 12 PRAP communications protocol AX SendByte Sends a single byte onto the AX 12 data bus AX_SetupUSART Initializes the USART module for AX 12 communication The source code for the AX 12 library for the PIC18F4520 is shown in its entirety in Appendix B Team FIFA ECE 4007 L01 21 ie Autonomous Foosball Table A second library was written for the PIC18F4520 to communicate with the MAX3100 SPI to UART chip in order to simplify the communication code from the main program code This library includes functions to initialize configure read configuration and read write data to the MAX3100 chip The source code and descriptions for the functions can be found in Appendix B The main program code for the PIC18F4520 listens to the image processing PC s instruction packets through the MAX3100 SPI to UART chip and once an instruction is received parses it and then carries out the appropriate servo function as specified by the PC to Servo Communications Protocol in Section 5 3 The main program flow for the PIC184520 is shown in Figure 8 Initialize peripheral modules iir Poll MAX3100 IRQ input Byte ready First byte of a packet
55. culated based on the circumference of the gear used and the fact that the servo has 1024 positions over 300 degrees of rotation Camera frame rate and resolution was determined by viewing the output of the webcam on the laptop Success rates were calculated by watching the game and dividing successes by attempts Team FIFA ECE 4007 L01 33 ey Autonomous Foosball Table Turn on laptop and connect webcam and serial line Connect servo and microcontroller power supplies at 9 5 and 9 volts respectively Run Track java Select the border of the table when prompted Select a human controlled player when prompted Place the ball within the field of view of the webcam and select it when prompted Enter the ball into the field and play Figure 12 Instructions for starting a game with the automated foosball table Team FIFA ECE 4007 L01 34 ey Autonomous Foosball Table 8 Marketing and Cost Analysis 8 1 Marking Analysis The targeted market for an AFT is the arcade entertainment industry While individual customers are not likely to purchase such a foosball machine a few such sales to very active wealthy foosball enthusiasts looking for a unique in home game may be expected However arcades or fun centers have the resources to purchase a more sophisticated form of a foosball table to offer a variety of challenges to their customers The following is an example list of potential customers to which the AFT may be marketed
56. d lateral player movement and servos for Team FIFA ECE 4007 L01 4 ey Autonomous Foosball Table accurate player rotation KiRo a project out of the University of Freiburg in Germany uses a top mounted camera as in this design and has defeated 8596 of its opponents including expert players 2 It however uses much more expensive equipment than what the proposed prototype will use and is thus not commercially viable The underlying technology of the table lies largely within three fields each of which has vast amounts of research available Accurate tracking through computer vision is integral to the success of the device and several resources are available at Georgia Tech The Computational Perception Laboratory for example currently has a project underway to track eyes as people approach a camera 3 This project is a rather complex task compared to following a colored ball but the underlying research is vast and readily available PIC control of the servos used to control the players is another important aspect of the device and another area with a great amount of available resources The technology has been around since the 70 s and has been used in a wide variety of projects due to its low cost and extensive collection of application notes 4 The final field in use will be simple artificial intelligence used to decide the best strategies for both offense and defense in a given scenario Artificial intelligence has been applied i
57. d programming of the microcontroller and its circuitry 1 development that will manage the communication between the control motors of the foosball table and the image processing computer Image processor Development of the computer software that will interpret the 1 development images from the overhead mounted webcam and run the necessary processing for ball detection and path prediction Computer controlled Design of the communications protocol between the processing 1 communication computer and the motor controller Presentation materials Development of the materials required for properly presenting the 4 prototype development including the final design documents 6 3 Milestones During the development phase there are certain milestones that needed to be achieved before development could continue to the next phase It was important to identify these milestones and make sure that they are met in a timely fashion in order to keep the development of the prototype on schedule The important milestones and the date on which they were met are shown in Table 9 Table 9 Development milestones and the date that they were met Milestone Date Met Preliminary parts search and selection of proper motors 8 28 Initial parts order made 9 5 Complete Proposal 9 12 Foosball table built 9 19 Basic AX 12 servo to microcontroller communication 10 3 Basic vision processing completed 10 3 Basic mechanic
58. e frames could be processed directly by the hardware with much lower limitations from software and bus latency With a webcam linked to a computer latency is introduced by the webcam itself the USB chip at both sides of the line the device s drivers and the operating system Implementing an FPGA board would add a good deal of complexity to the design but it would eliminate many of those latency sources A suitable FPGA board would likely cost more than a cheap computer but it would be able to handle the duties of all of the PIC boards and allows the use of an image sensor much cheaper than an equivalent webcam The price of the system as a whole would remain similar to the current projection but due to the large change a new prototype cycle would have to begin to handle the alteration in system architecture and rewriting of the code Another major change that would be introduced if another cycle were to begin would lie with the chosen motors In order to achieve the speeds desired for lateral movement gears of at least 10 inches in diameter would be needed This would be large and expensive to implement so movement would likely switch to a pulley system with a high speed servo A faster servo would cost more but gears would no longer be needed so the overall price should not change much Team FIFA ECE 4007 L01 39 ey Autonomous Foosball Table The speed of the kicking servos is also far too slow so DC motors with an H bridge and an e
59. e oe ne AR di te eae 26 5 7 Constraints Alternatives and Tradeoffs sssssesssssesssrrrrrerrrreerrrrrrrrrrrrrrrrrrrrrrsr nee eene 28 D Schedule Tasks and Milestones 2 0 0 cece ccesseeeseccccccsssssessseccccccseeussscesccscssseuseneescessesaes 30 7 Project Demonstration sereni tr tevaasesesareenteevgusseeanndevsdedeucgucavwaessecktasseantednstesventdeaae 33 O Marketme dnd Cost Analy STS d a es sedge tuse eed asma ea ee wees 35 8 1 Marking Anal E 35 8 2 E 36 H Summary and COME SIONS teac ste sn er pue RN os os ERE seascape rea 39 10 arriere P 42 Appendix A Image Processing Source CO ie rep eto e aor adeo estep equ onde une OIN Ra e rna Al Appendix B PIC18F4520 Servo Controller Main Program and Library Source Code Bl Appendix C PIC21F615 PWM Controller Source Code AAA Cl Appendix D Servo Controller Board Schematic and PCB Design eese DI Appendix E Mechanical Design DIaWih2S ssssessrserssrrsrrseresrrsrrssresrrserssrrsrresrrsrrsr reses rss ere pa bes El Appendix F Cost Analysis saneren cem F1 Appendix G Prototype Development Gantt Chart Gl Team FIFA ECE 4007 L01 2 ey Autonomous Foosball Table 1 Executive Summary An automated foosball table offers a challenging player versus computer match up in a game of table football foosball In addition to being challenging for the expert foosball player it allows one to play without the need of finding a formidable human opponent Furthermore
60. e players is shown in Figure 2 above This is done by scanning all pixels at the x axis value for each row within a 5 pixel range in any direction until the top player of the row is found At this point the distance between players on any given row is already known as a fixed value so the locations of each of the other players on the row can be quickly computed The overall software flow for the image processing is summarized by the software flow chart in Figure 3 below Team FIFA ECE 4007 L01 13 ey Autonomous Foosball Table Ball Found Yes Predict the most likely position and path of the ball Move all players ahead of the ball to intercept No Kick with Ball in robot s control controlling row Acquire new webcam image Figure 3 Image processing software flow chart 5 3 PC Controller Communications The computer is linked to the microcontroller via an RS 232 serial link This provides an easy to use interface with sufficient bandwidth for sending commands The commands sent from the PC are in the form of a 2 byte packet created specifically for the AFT Each packet is generated to follow the form shown in Table 3 The packet will always start with the two most significant bits as 10 This serves to prevent the misreading of ambiguous all high Team FIFA ECE 4007 L01 14 e Autonomous Foosball Table or all low packets The third bit establishes the function of the packet If the packet will be running s
61. e red pixel value of the ball param g The green pixel value of the ball param b The blue pixel value of the ball param xpos The x position of the ball param ypos The y position of the ball param searchDist The pixel distance to search in each direction for similar colors Sg X SI public void calcBallSize BufferedImage x int r int g int b int xpos int ypos int searchDist int i j numpos 0 for i xpos searchDist i lt xpos searchDist i for j ypos searchDist j lt ypos searchDist j Color pixel new Color x getRGB i j if pixel getRed gt r colorSearchSize amp amp pixel getRed lt r colorSearchSize amp amp pixel getGreen gt g colorSearchSize amp amp pixel getGreen lt g colorSearchSize amp amp pixel getBlue gt b colorSearchSize amp amp pixel getBlue lt b colorSearchSize numpos assume a round circular ball area pi r r r sqrt area pi ballRadius Math sqrt numpos Math PI Recalculate the most most likely position of the ball in the next frame Tf public void recalculate use y mx b if count gt 2 average of the last 2 y slopes y3 y2 y2 y1 deltaY lastPositions 1 1 lastPositions 1 0 lastPositions 1 2 lastPositions 1 1 2 0 average of the last 2 x slopes x3 x2 x2 x1 deltaX lastPositions 0 1 lastPositions 0 0 lastPositions 0
62. eWidth 48 0 double hcalc getTableHeight 24 0 if wcalc gt 1 2 hcalc wcalc lt System out println Warning foosball table Team FIFA ECE 4007 L01 48 inches wide 24 inches tall 0 8 heale Table dimensions do not agree with standard A13 ey Autonomous Foosball Table pixelsPerInch wcalc hcalc 2 approximate the pixels per inch between the height and width System out println Found pixelsPerInch pixelsPerInch pixels per square aneh gt Calculates the inch value from a pixel value using the getInches return A double representing the physical number of inches Qsee calcScale ui public double getInches double p return p pixelsPerInch Public accessor to return the average player diameter in pixels return The player cross section height or diameter in number of pixels public int getPlayerHeight return playerHeight Public accessor to return the distance between players on a given row param row The row number 0 3 to return data about return The distance between the centers of each player on a row ua public int getRowSpacing int row return myrows row 1 Public accessor to return the minimum y location of a given row S param rownum The row number 0 3 to return data about param myPlayers A boolean representing if the data to be returned is about the com
63. earchSize amp amp pixel getBlue bOppColor colorSearchSize amp amp pixel getBlue bOppColor colorSearchSize rows i 4 j update the new position break we only need to know the top player of a row because the others are fixed positions away Public accessor to return the minimum x position in pixels of the table return The minimum x position of the table see getMinY see getMaxX see getMaxY see getTableWidth see getTableHeight ff public int getMinX return minX t 0X 0X HF E Public accessor to return the minimum y position in pixels of the table return The minimum y position of the table see getMinx see getMaxY see getMaxX see getTableWidth see getTableHeight i public int getMinY return minY Public accessor to return the maximum y position in pixels of the table return The maximum y position of the table see getMinY see getMinx see getMaxX see getTableWidth see getTableHeight d public int getMaxY return maxY HF Team FIFA ECE 4007 L01 A15 ey Autonomous Foosball Table Public accessor to return the maximum x position in pixels of the table return The maximum x position of the table see getMinx see getMaxY see getMinY see getTableWidth see getTableHeight public int getMaxX return
64. elopment phase 6 1 Schedule The projected and actual prototype development schedules can be found in Appendix G E Mail proved to be a more effective way of communicating amongst the team member in terms of staying up to date with actual develop as opposed to using the Google Calendar application The original schedule was designed to give the development team a month of test and revision time thus ensuring enough time to come up with solutions to all problems and to finalize the design Since the team ended up falling behind an several important aspects of the prototype design this month was fully utilized to complete a working prototype of the project 6 2 Tasks There were several components of the prototype that were isolated into tasks that could be completed by one or more persons The responsibility for completing each task was assigned to specific members of the development team Table 8 describes these tasks that were required to complete the automated foosball table and how many people worked on each task Team FIFA ECE 4007 L01 30 ey Autonomous Foosball Table Table 8 Overview of the tasks that were required to complete the prototype Task Description Persons Mechanical assembly Assembly of the mechanical parts required to move the handles of 2 the foosball table which includes the enclosures for the electrical components and a mounting mechanism for the ball sensing camera Microcontroller Design an
65. fense to block shots by computing the angle between the ball and the goal param goalXPos The x location of the robot s goal in pixels param rowXPos The x location of the robot s defense line in pixels param tableYMin The minimum y location of the foosball table in pixels Team FIFA ECE 4007 L01 A7 see findGoalIntercept see findMidfieldPosition see findStrikerPosition e 3 tf public double findDefenseIntercept int goalXPos tableYMax int playerSpacing double controlZone the middle 10 of the table 0 4 defensive players do not sporadically a double pixelControlZone double returnLocation double goalLocation ta if yLocation lt pixelCon bottom return goalXPos if yLocation gt bottom returnLocation goalXPos rowX if bottomDefense returnLocation return Location rowX tax else xLocation del ltaY else xLocation del else Location return returnLocation see findGoalIntercept see findDefenselIntercept see findStrikerPosition public double findMidfieldPosition int playerSpacing double returnLocation while returnLocation param tableYMax The maximum y location of the foosball table param playerSpacing The spacing between defensive players return A double predicting the pixel location the defense should go to DefenseControl DefenseControl par
66. getRGB i j if pixel getRed gt rOutlineColor colorSearchSize amp amp pixel getRed lt rOutlineColor colorSearchSize amp amp pixel getGreen gt gOutlineColor colorSearchSize amp amp pixel getGreen lt gOutlineColor colorSearchSize amp amp pixel getBlue gt bOutlineColor colorSearchSize amp amp pixel getBlue lt bOutlineColor colorSearchSize found true else if found wait until we fall off the outline to assign the location minY j Team FIFA ECE 4007 L01 A21 ey Autonomous Foosball Table break j finally find the bottommost location of the table maxY found false for j imHeight 1 j gt 0 j pixel new Color x getRGB i j if pixel getRed gt rOutlineColor colorSearchSize amp amp pixel getRed lt rOutlineColor colorSearchSize amp amp pixel getGreen gt gOutlineColor colorSearchSize amp amp pixel getGreen lt gOutlineColor colorSearchSize amp amp pixel getBlue gt bOutlineColor colorSearchSize amp amp pixel getBlue lt bOutlineColor colorSearchSize found true else if found wait until we fall off the outline to assign the location maxY j break System out println Found outline x minX maxX y minY meet Computes a blurred image blurring 1 pixel in each direction param x An image to blur return The blurred image see BufferedImage S public Buffe
67. gurations 11 The RQ pin from the MAX3100 is connected to the RBO INTO pin on the PIC18F controller so that a signal can be produced for the PIC18F when a new byte has arrived from the image processing PC The transmit and receive pins on the MAX3100 are further connected to a MAX232 transceiver 12 From the MAX232 transceiver the transmit and receive pins are wired into a standard DB9 connector to which a standard RS 232 cable can be attached to The servo controller board required two different power sources one for the microcontrollers and one for the servos A separate power source is required for the servos because of their high rate of power consumption Separating these two sources of power protects the microcontrollers Team FIFA ECE 4007 L01 19 e Autonomous Foosball Table from being over powered and therefore increases reliability Both sources of power can range from 9 0 12V from which a voltage regulator then produces the required 5V for the microcontrollers and PWM servos The AX 12s are directly connected to the high power 9 12V Source As a final hardware design a printed circuit board was design using DipTrace in order to keep the size and complexity of the servo controller board down 13 The resulting PCB design is shown in Figure 7 ooon o o ee Reo es tststs OOO00000 D o oo0 o n Oo0000009000Qq0 900p 000 o e O o O Figure 7 Servo controller board PCB design
68. he use of linear actuators and stepper motors However linear actuators provide much less control than servos and stepper motors have an added complexity while not providing anything other than a slightly decreased cost in addition to not having the resolution available in Team FIFA ECE 4007 L01 28 ey Autonomous Foosball Table most servos An alternative to using a computer and USB webcam would be to design all of the software on an FPGA and then interface it directly to a CMOS or CCD camera This would have added increased processing and acquisition speed However at the onset of the design the specifications of the SPC 900NC webcam suggested a higher frame rate than what was actually possible in the hardware providing little reason to approach the problem with the FPGA and CMOS CCD combination Team FIFA ECE 4007 L01 29 ey Autonomous Foosball Table 6 Schedule Tasks and Milestones In the development phase of the prototype it was important to maintain a schedule and continuously readjust the schedule to meet actual development time It was also necessary to identify the various tasks required to complete the project so that the work can be split up amongst the development team and a proper plan for component integration can be made Asa whole the development team was behind compared to the project schedule but was able to make up time through efficient communication and development towards the end of the prototype dev
69. i 0 i lt paramLength i AX SendByte parameters i checksum checksum parameters i checksum checksum AX SendByte checksum while BusyUSART wait for last byte to be sent end AX_TxPacket BR RK k k k KK IK ko ke KORK KOKK kk ke ke kk ke kk Sk I ok ke ke kok A kk Sk ke kk Sk ke kk kok k kok k k k k k k kok oko kok ke ke k k k k k k k k k k AX SendByte Sends a single byte onto the AX12 data line Parameters Goch 3k oo toSend char byte to send onto the data line Returns void EK A Ck k ke kk ke kk ko ke kok ke ke kk ke kk ok kk ke kk kk k kk ke kk kk k kk ke kk Sk ke kk k ke kk ke ke kk ke kk ke ke kk ke ke koe void AX SendByte char toSend while BusyUSART wait for transmit register to be ready WriteUSART toSend AX SendByte BRK kk ke kk ke ke KK kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kk ke k kk ke kk AAA k k Sk ke kok ke ke k k k k k AX SetupUSART Setup the PIC USART to transmit at 1 MBit s Parameters id char the ID of the AX12 which should receive the packet id instruction char the instruction type of the packet parameters char data array of the packet paramLength char length of the data array Returns void CK kk ke ke kk ke kk ko ke kk ke ke kk ke kk ke ke kok ke kk Sk ke kk ke ke kok kok k Sk ke kok ke ke kk ke kk Sk ke kk k ke kk ke ke ke kk ke ke kk ke ke ke ke ke void AX SetupUSART OpenUS
70. ile others are much more specific The original purpose of this library was to write a set of useful functions to be used in the automated foosball table senior design project by Michael Aeberhard Shane Connelly Evan Tarr and Nardis Walker at the Georiga Institute of Technology CK kk koe kk ke kk ke ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk Sk ke kok include p18f452 h Use PIC184520 naming conventions PIC macros define EnableInterrupts INTCONbits GIEH 1 define DisableInterrupts INTCONbits GIEH 0 MAX3100 Pin assignments to the PIC define PC_UART_SELECT PORTDbits RDO define PC UART IRO PORTBbits RBO define PC UART SHUTDN PORTDbits RD1 Function prototypes for all of the function in the library Please refer to the pc uart c file for instruction on how to use these functions void PC SetupSPI void void PC WriteConfiguration void void PC WriteData unsigned char char PC ReadData void void PC ReadConfiguration unsigned char void PC WriteString unsigned char unsigned char endif Team FIFA ECE 4007 L01 B13 ey Autonomous Foosball Table BR KK Ck k ok ok kok k ke kk kok kk ke kk Ck ke kok ke ke kk k kk Sk ke kk ke ke kk k kk Sk kok k kk k k kk kok kk k kk k kk k kk ke ke kk ke ek PC SPI UART with MAXIM 3100 Library Filename pc uart c THIS IS THE CODE FILE ck ck kk kk kk kk kk kk kk kk kk kk kk KKK KK KEK KKK kk kk ck ck ck ck ck oko ck ck ck ck c
71. imple servo control the bit is set to O If the bit is set as 1 the packet serves some special function as described in Table 4 where the second byte of the packet determines the function of the command If the packet is used for servo control bits 3 5 are used for selecting which of the eight servos is to be used and bits 6 15 tell the selected servo where to rotate to For the AX 12 servos these ten bits indicate a physical position For the HS 81 PWMS the ten bits are either all ones to raise the player 90 degrees or all zeros to lower the player to a downward position Table 3 Packet formation for servo control Bits 0 1 2 3 5 6 15 Usage Reliability Packet Function Addressing Positional Data Table 4 Packet formation for special commands Second Byte Function 0x01 Center all handles 0x02 Move all handles to start position 0x03 Move all handles into kick position 0x04 Move all handles into idle position 0x05 Move offense and midfield into defend position 0x06 Move offense and midfield into idle position On the PC end serial communication is handled by WriteS java which houses various functions for generating the proper packet and then writing it to the serial port of the PC The microcontroller then receives the packets and converts them to servo control messages as described in the next section Team FIFA ECE 4007 L01 15 ey Autonomous Foosball Table 5 4 Servo Co
72. k ck ck ck ck ck ck ck ck ck ck ck ok kckckckckckckckckckck Developed By Michael Aeberhard michael aeberhard gatech edu Date October 11th 2007 Purpose Easy to use functions sending and receiving data via the MAXIM 3100 UART chip using the PIC s onboard SPI module from Microchip along with the C18 Compiler ck ck ck ck ck ck ck ck ck ck 0k ck ck ck ck ck ck ck ck 0k ck ak ck ak ck 0k ak ck ak 0k ck 0k ak 0k 0k 0k ck 0k 0k ck 0k ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ko ck ck ck ck ck ck ck ck ck ck ck KKK This file contains numerous functions that can be used to communicate with a PC Some of the functions are more generic while others are much more specific The original purpose of this library was to write a set of useful functions to be used in the automated foosball table senior design project by Michael Aeberhard Shane Connelly Evan Tarr and Nardis Walker Restrictions This library assumes the use of the PIC18F4520 microcontroller at the Georiga Institute of Technology KCKC kk ke kk kk kk Ck ke kk k ke kk Ck kk kok kk ke kk kk kk Ck e kk kk kk k kk include p18f452 h Use PIC184520 naming conventions include lt spi h gt Functions for the on chip SPI include lt delays h gt Functions for delays include lt pc_uart h gt Prototype declarations for PC UART library BRK HK k k k k kok k k ko kok kok kk KR ke
73. k k kk kk kk kk k kk kk kk kk kk k ke kk ke kk k kk k ke kk k kk k kk finclude p18f452 h Use PIC184520 naming conventions include lt usart h gt Functions for the on chip EUSART include ax12 h Prototype declarations for AX12 library BR KK k kok k OK OK OK OK okok ok ok okok okok ok ok okok okok kok k kok kok oko k k kok k kok kok A kok kok kok kok kok kok kk k kk k k kk k k kk k OK AX SetId Returns void kok kok kok kok k kok ko oko kok kok k kk kok kok kok k kok kok kok k kok kk kok kk kk k void AX SetId char oldid char newid char parameters 2 paramLength parameters 0 CT ID parameters 1 newid paramLength 2 AX TxPacket oldid I WRITE DATA parameters paramLength end AX SetId Changes the ID of an AX12 servo to a new value Parameters oldid char the old id of the AX12 servo d newid char the new id 4 to which to change to BRK KK ke kk k ko kk Ck kk ck ke kk ke kk Ck ke kok ke ke kk k kk Ck ke kk ke ke k k kk Ck ke kk k ke kk ke kok kok kk k kk k ke kk k ke kk ke ke k k k k k AX Ping Pings an AX12 servo for a status packet Parameters id char the id of the AX12 to ping Returns void CK Kk k kk kk kk k kk kk kk kk kk ke k kk k kk kk kk k ke kk k kk Ck ke kk k ke kk k kk Ck ke kk k ke kk ke kk ko ke kk ke ke ke ke koe ke ke ke void AX Ping char id AX TxPacket id I PING 0 0 end AX Ping BR KK k k ok ok kk Ck k kk ck
74. kok ke ke k kok kok kok kok ke kok k k kok kok kk k kok kok kok k ke kk A k k kk k kk k k k k k k k k PC SetupSPI Sets up the SPI module to communicate at 1 MBit s Parameters none Returns void CK kk kk kk kk k kk kk kk kk kk kk k kk k kk k kk k kk k kk k k k kk Sk k KA ke ke kk ke kk kc ke kk k ke ke ke ke ke ke ke ke void PC SetupSPI SPI Setup for RS 232 UART communication OpenSPI SPI FOSC 4 MODE 00 SMPMID DelaylOTCYx 1 PC WriteConfiguration end PC SetupSPI BR OK ok okok k kk ke ke kk ke kk ke ke kk k ke kk ke kok ke kok kk kk Ck ke kk k kk k k kk Sk k kk k kk k k kk k k kk k kk k ke kk k ke kk k ke kk ke ek PC WriteConfiguration Send a write configuration to the MAX3100 UART chip X Parameters none Returns void CK kk ke ke k kok kok ke ke kk ke ke kk ke kok ke ke kok ke kk Sk ke kk ke ke kk ke kk Sk ke kk ke ke kk ke kk kk k kk ke kk kc ke kk ke ke kk ke ke koe void PC WriteConfiguration unsigned char config 2 unsigned char read 2 unsigned char i PC UART SELECT 0 for i 0 i lt sizeof config i while WriteSPI config i OxFF OxCC 0x00 0 0 M 9 read i SSPBUF PC_UART_SELECT 1 end PC WriteConfiguration Team FIFA ECE 4007 L01 B14 ey Autonomous Foosball Table BR kok k Ck ke KK kk Ck ke kk ck ke kk ke kk Ck ke kok ke ke kk ke kk Ck ke kok ke ke kk kok kok kk k kok kok kok k kk kok k ke kk k ke kk ke
75. ld not be as costly and therefore a Kalman filter could be used which would provide more accurate predictions to the future state of the ball and players Team FIFA ECE 4007 L01 40 ey Autonomous Foosball Table While the AFT does not meet the initial design goals we had it does operate at enough of a capacity to serve as a proof of concept prototype The tracking software works well as well as control of the servos With a better frame rate from the camera and faster physical operation the game could easily be very difficult to beat By scaling the speed of operation and prediction algorithms virtually any level of difficulty could be attained Team FIFA ECE 4007 L01 41 10 Autonomous Foosball Table References 1 2 3 4 5 6 7 8 Wikipedia Foosbot 2007 Online Available http en wikipedia org wiki Foosbot Accessed Sept 11 2007 University of Freiburg KiRo The Table Soccer Robot 2007 Online Available http www informatik uni freiburg de kiro english Accessed Sept 12 2007 Georgia Tech s Computational Perception Laboratory Eye Detection and Tracking 2007 Online Available http www cc gatech edu cpl projects pupil index html Accessed Sept 12 2007 Wikipedia PIC Microcontroller 2007 Online Available http en wikipedia org wiki PIC_microcontroller Accessed Sept 11 2007 Association for the Advancement of Artificial
76. le Top View REPRODUCTION IN PART OR AS A WHOLE TWEHOUE THE WHITTEN PERMISSION OF pw o DEET COMPANY NAME HERE E HFAO2 FRUI sc p Je Bena0e Team FIFA ECE 4007 L01 E3 ey Autonomous Foosball Table REPRODUCTION IN PART OR AS A WHOLE WWEHOUE THE WHITTEN PERMISSION OF DURT COMPANY NAME HERE S PROHIBITED Team FIFA ECE 4007 L01 E4 ey Autonomous Foosball Table REPRODUCTION IN PART OR AS A WHOLE WWEHOUE THE WHITTEN PERMISSION OF DURT COMPANY NAME HERE S PROHIBITED Team FIFA ECE 4007 L01 E5 Autonomous Foosball Table T Tease sm LI s EC Ge Y CON TORA MCING PER COMMENTS 4 3 N Servo Mount DWG NO REV al rios 1 E6 Team FIFA ECE 4007 L01 Autonomous Foosball Table sw LL SCALE 1 JWEIGHT SHEET6OF7 1 DWG NO FIFAO06 be E7 Team FIFA ECE 4007 L01 Autonomous Foosball Table CO p EE e E E8 Team FIFA ECE 4007 L01 ie Autonomous Foosball Table Appendix F Cost Analysis Team FIFA ECE 4007 L01 F1 e Autonomous Foosball Table Cost and price calculations for a an automated foosball table with a selling price of 5 000 Example of Cost and Price Calculations Fringe Benefits 2596 of labor of materials labor amp Overhead 55 fringe Sales amp Marketing Expense 25 of selling price Warranty amp Support Expense 5 of selling price Development Cost Non recurring Cost What it
77. lean found false j imHeight 2 assume the table falls somewhere in the middle of the image for i 0 i lt imWidth i pixel new Color x getRGB i j if pixel getRed gt rOutlineColor colorSearchSize ss pixel getRed lt rOutlineColor colorSearchSize amp amp pixel getGreen gt gOutlineColor colorSearchSize amp amp pixel getGreen lt gOutlineColor colorSearchSize amp amp pixel getBlue bOutlineColor colorSearchSize amp amp pixel getBlue bOutlineColor colorSearchSize found true else if found wait until we fall off the outline to assign the location minX i break then find the rightmost location of the table maxX found false for i imWidth 1 i gt 0 i pixel new Color x getRGB i j if pixel getRed gt rOutlineColor colorSearchSize 48 pixel getRed lt rOutlineColor colorSearchSize amp amp pixel getGreen gt gOutlineColor colorSearchSize amp amp pixel getGreen lt gOutlineColor colorSearchSize amp amp pixel getBlue gt bOutlineColor colorSearchSize amp amp pixel getBlue lt bOutlineColor colorSearchSize found true else if found wait until we fall off the outline to assign the location maxX i break then find the topmost location of the table minY found false i imWidth 2 assume the table falls somewhere in the middle of the image for j 0 j lt imHeight j pixel new Color x
78. lectric stop mechanism would be used While the price of this system would not change much it does increase the complexity of the system The electrical stop would stop the motor by discharging the electromechanical energy stored in the motor through a series of transistors to ground which would only be turned on when a stop command is issued Without it the motor would slow to a stop and the system would be unsure of the precise locations of the motors One addition to the table would be to augment the basic scoring system While a scoring system has been partially implemented in the prototype it was not refined due to time constraints Adding a simple seven segment LED display would be inexpensive and easy to implement and could display the current score accurately If more time and money were devoted to this system a small LCD screen could be used for aesthetic appeal A high end model could go as far as to store user profiles and statistics Another modification would be to modify the predictive algorithm In the prototype that was implemented a linear average of previous locations is used to predict the most likely path of the ball This is due to the limitations in computing power as well as the general inaccuracies introduced in the webcam Without a faster processing device and more real time data there is little advantage to implementing a more complex prediction algorithm However with a FPGA design the acquisition and processing wou
79. m FIFA ECE 4007 L01 27 ie Autonomous Foosball Table The data rate for the USB 1 1 ranges from 1 5Mbps 12Mbps depending of the device being used Typically 1 5Mbps is the data rate for devices that do not require much bandwidth and 12Mbps for larger devices utilize high speed transfer The Java Media Framwork JMF was used to develop the image processing aspect of the prototype 19 Java Media Framework applications allow real time images to be easily incorporated with Java This API application program interface within the program allows users to write applications consistent with the operating environment therefore giving the application cross platform compatibility 5 7 Constraints Alternatives and Tradeoffs The most significant constraint in the design and build of the autonomous foosball table is that of funding With a budget under 500 the supply of parts that can be purchased becomes the primary limiting factor for building a prototype For example the lateral velocity could be increased by custom machining gears with a larger radius However in doing so there would be a tooling setup cost of 1500 a cost well beyond the budget Another constraint is to abide by standard foosball rules which forbids spinning of the handles Because of this there could not be a continuous motor on the handles for kicking Other design alternatives were also considered in regards to the motion system instead of servos including t
80. m the microcontroller to the PC 17 The receiving and transmission of data to and from the microcontroller is controlled by pins 2 and 3 the transmit and receive pins of a standard RS 232 pinout The RS 232 connector standards need to be followed The AFT does not use parity or stop bits features of the RS 232 standard As the baud rate is increased the length of the RS 232 cable must be decreased in order to maintain reliable data transfer The maximum cable length is 50ft or a capacitance of 2500 pF However at lower speeds the length of the cable can be increase It has been know for cables lengths to surpass 150 feet with higher quality cables Table 7 below lists some common cable lengths and their maximum transmission rate Table 7 Typical RS 232 baud rates and maximum cable lengths Baud Rate Maximum Cable Length ft 19200 20 9600 50 2400 100 The baud rate used in the AFT is 115200 and the cable length was 5ft This cable length allows for reliable transmission at this baud rate USB 2 0 was originally intended to be used in the AFT design to meet the bandwidth requirements of high speed web cam data transform but due to hardware constraints of the purchased web cam USB 1 1 was used instead In order to get the maximum efficiency out of the available bandwidth it was necessary to careful interface with the web cam The standards set in the Universal Serial Bus Specifications were used 18 Tea
81. mat import javax media util import javax media control import javax media protocol import java util import java awt import java awt image import java awt event import java util Properties import javax swing Timer public class FrameGrabber private DataSource dataSource null private Player player null private CaptureDeviceInfo di null private MediaLocator ml null private FormatControl formatControls private Buffer buf null private Image img null private VideoFormat vf null private BufferToImage btoi null private YUVFormat userFormat null private FrameGrabbingControl fgc null private boolean newFrame false private final static String DEFAULT DEV NAME v41 Philips SPC 900NC webcam 0 private final static int FRAMERATE 15 Class Constructor ay public FrameGrabber di CaptureDeviceManager getDevice DEFAULT DEV NAME locate the predefined image source Dimension viewSize new Dimension 320 240 preset the size to 320x240 px Format cfmt di getFormats get available formats for int i 0 i cfmt length i if cfmt i instanceof YUVFormat userFormat YUVFormat cfmt i Dimension d userFormat getSize if viewSize equals d find the dimensional format we want break userFormat null ml di getLocator create the CaptureDeviceInfo object we want Grab a new frame and store it internally pri
82. mberPacket 0 0 0 0 0 sa 0 Setup Control Registers Set all A D ports as digital I O Set RA4 as input all others output Input for RBO and RB2 Set bit 7 and 6 of PortC as inputs Set all bits of PortD as outputs others as outputs 16 255 2 microseconds S 1 16 ADCON1 0x07 LATA 0 LATB 0 LATE 0 PORTA 0 PORTB 0 PORTE 0 TRISA 0b00010000 TRISB 0b00000101 TRISC 0b11000110 TRISD 0b00000000 TRISE 0b00000000 Timer2 Registers Prescaler TMR2 PostScaler 16 PR2 Freq 200 Hz Period 499 OpenTimer2 T2 POST 1 16 amp T2 P PR2 195 TMR2 0 SPI Setup for RS 232 UART communication PC SetupSPI PC UART SELECT PC UART SHUTDN 1 1 Setup internal USART AX SetupUSART LEDO LED1 0 0 Initialize the PWMs PWM OFFENSE DIR 0 PWM OFFENSE CTRL 0 PWM MIDFIELD DIR 0 PWM MIDFIELD CTRL 0 PWM DEFENSE DIR 0 PWM DEFENSE CTRL 0 PWM KEEPER DIR 0 Team FIFA ECE 4007 L01 for servo communication B3 PWM_KEEPER_CTRL 0 AX DATA DIRECTION AX DATA TX Set fast moving speed AX TxPacket SERVO OFFENSE delay 5ms delay 5ms Set high torque AX TxPacket SERVO OFFENSE delay 5ms I WRIT I WRIT Set fast moving speed AX TxPacket SERVO MIDFIELD I delay 5ms delay 5ms Set high torque AX TxPacket SERVO MIDFIELD I delay 5ms WR WR
83. n varying degrees to machines for decades to accomplish goals as simple as case based reasoning in a recommendation system or as complex as defeating a world champion chess player 5 All of these combined can form a challenging and playable autonomous foosball robot Team FIFA ECE 4007 L01 5 ey Autonomous Foosball Table 3 Project Description and Goals The main project goal was to complete a working prototype for an AFT where a human player faces a robotic opponent From the human perspective of the game the foosball table is very similar to a regular table The player s on the human side are controlled via a series of four handles that can be moved in and out and rotated to move the players linearly across the playing field and to kick the ball towards the opponent s goal The autonomous side consists of e Eight servo motors used to manipulate the handles of the foosball table e A microcontroller to activate the servo motors and communicate with the computer e Anover head mounted webcam to track the ball and players e A computer to process the webcam images implement artificial intelligence and communicate with the microcontroller The initial prototype goals were to make a simple functioning automated player to play against one that is at least able to defend the goal and make an effort to kick the ball toward the other end of the table Once a simple level of gameplay was established the next goal was to improve the ar
84. ndPacket Special command to the servo to set just the midfield and striker PWM servos to the up position see setAllUp Qsee setAllDown Qsee setOffenseDown i public void setOffenseUp Command packet 10100000 00000101 nextval 0 nextval 1 raised 0 raised 1 true timeleft 0 5 timeleft 1 5 packet 2 1 for int X 3 lt 12 i 3 packet i 0 packet 13 1 packet 14 0 packet 15 1 sendPacket Special command to the servo to set the midfield and striker PWM servos to the down position Team FIFA ECE 4007 L01 A30 Autonomous Foosball Table raised 2 Qsee setAllUp see setAllDown see setOffenseUp e public void setOffenseDown Command packet 10100000 00000110 nextval 0 nextval 1 raised 0 raised 1 false timeleft 0 5 timeleft 1 5 packet 2 1 for int i 3 i lt I2 i 4 packet i 0 packet 13 1 packet 14 1 packet 15 0 sendPacket Special command to the servo to set all PWM servos to the down position see setAllUp see setOffenseDown see setOffenseUp public void setAllDown Command packet 10100000 00000100 nextval 0 nextval 1 nextval 2 nextval 3 raised 0 raised 3 false timeleft 0 timeleft 1 timeleft 2 5 timeleft 3 10 packet 2 1 for int i
85. ntroller Board The servo controller board interprets the instruction packets across the serial connection coming from the image processing computer The controller then parses these instructions packets and then carries out the proper action required to control the correct servo There are two major parts to the controller board design the hardware design and the software design The picture of the prototype servo controller board as implemented is shown in Figure 4 Figure 4 Prototype servo controller board 5 4 4 Hardware Design The hardware design connects all of the components of the servo controller board together onto a single printed circuit board PCB required to carry out the functions of communicating with the eight servos and the image processing PC A block diagram overview of the servo controller board is shown in Figure 5 Team FIFA ECE 4007 L01 16 ey Autonomous Foosball Table TO Mbit maxaioo 115 2kbps Maxoso 115 2 Kbps ege UART UART Transiever RS 232 PC PWM PWM PWM PWM icki i PIC18F4520 I O Pins AX 12 AX 12 AX 12 AX 12 Lateral Moti Servo Servo Servo Servo ateral Motion 500 kbps UART USART Figure 5 Servo controller board block diagram The main processor on the servo controller board is a Microchip PIC18F4520 microcontroller 9 This microcontroller has all of the features necessary to implement the required functions of the servo controller The internal UART Uni
86. o ke kk include p18f452 h Use PIC184520 naming conventions Servo motor control table addresses EEPROM define CT ID 0x03 define CT BAUD RATE 0x04 define CT_RETURN_DELAY 0x05 define CT_CW_ANGLELIMIT_L 0x06 define CT_CW_ANGLELIMIT_H 0x07 define CT CCW ANGLELIMIT L 0x08 define CT CCW ANGLELIMIT H 0x09 define CT MAX TORQUE L OxOE define CT MAX TORQUE H OxOF define CT STATUS RETURN 0x10 define CT ALARM LED 0x11 RAM define CT TORQUE ENABLE 0x18 define CT GOAL POSITION L OxlE define CT_GOAL_POSITION_H 0x1F define CT MOVING SPEED L 0x20 define CT MOVING SPEED H 0x21 define CT PRESENT POS L 0x24 define CT PRESENT POS H 0x25 define CT PRESENT SPEED L 0x26 define CT PRESENT SPEED H 0x27 define CT PRESENT LOAD L 0x28 define CT PRESENT LOAD H 0x29 define CT PRESENT VOLTAGE 0x2A define CT REGISTERED INST 0x2C define CT MOVING 0x2E Servo Motor Instruction Set define I PING 0x01 define I READ DATA 0x02 define I WRITE DATA 0x03 define I REG WRITE 0x04 Team FIFA ECE 4007 L01 B8 ey Autonomous Foosball Table define I ACTION 0x05 define I RESET 0x06 define I SYNC WRITE 0x07 Function prototypes for all of the function in the library Please refer to the axl2 c file for instruction on how to use these functions void AX SetId char char void AX Ping char char AX RxPacket void char AX RxByte void char AX ByteRdy void AX TxPacket char char char
87. o to Aligns the strikers to block kicks from the opponent in pixels in pixels int tableYMax yLocation deltaY tableYMax playerSpacing returnLocation playerSpacing return returnLocation Public accessor to return the Team FIFA ECE 4007 L01 last calculated y velocity of the ball A8 amp return A double representing see xVelocity public double yVelocity return deltaY Public accessor to return the return A double representing see xVelocity xy public double xVelocity return deltaX Public accessor to return the see getFutureY see getxPosition see getyPosition ay public int getFutureX return xFutureLoc return A double representing Public accessor to return the return A double representing see getFutureXx see getxPosition see getyPosition SCH public int getFutureY return yFutureLoc X Public accessor to return the return A double representing see getyPosition see getFutureX see getFuturey public int getxPosition return xLocation F F HF xXx Public accessor to return the see getxPosition see getFutureXx see getFutureYy public int getyPosition return yLocation amp amp Upon a lost frame return A double representing the last
88. on if yInterceptPosition 1 c move 2 yInterceptPosition pixelsPerInch Uses the midfielders to intercept a ball going toward the goal param c The serial controller object used to send data to the servo control board param yInterceptPosition The predicted future location of the ball given in pixels from the bottom of the table 2j public void midfieldIntercept WriteS c double yInterceptPosition if yInterceptPosition 1 c move 1 yInterceptPosition pixelsPerInch e Uses the strikers to intercept a ball going toward the goal param c The serial controller object used to send data to the servo control board param yInterceptPosition The predicted future location of the ball given in pixels from the bottom of the table SCH public void strikerIntercept WriteS c double yInterceptPosition if yInterceptPosition 1 Team FIFA ECE 4007 L01 A2 ey Autonomous Foosball Table c move O yInterceptPosition pixelsPerInch Team FIFA ECE 4007 L01 A3 ey Autonomous Foosball Table FrameGrabber java This class is used to grab an image from the webcam It uses an internal timeout to prepare an image author Team FIFA ECE4884L01 Georgia Institute of Technology version 1 0 December 2007 Se package jmfYUV import javax swing import javax swing event import java io import javax media import javax media for
89. ontroller Board 32 days Thu 9 1307 Fri 10 26 07 2 El Assemble PIC board 11 days ThuSAM3 07 Thu 9 27 07 3 53 Demonstrate PIC Board 1 day Fri 9 28 07 Fri 9 28 07 4 a Servo motor communication 8days Mon 10 1 07 Wed 10 10 07 5 H Communications with compute 15 days Mon 10 8 07 Fri 10 26 07 6 Mechanical Assembly 25 days Mon 92407 Fri 10 26 07 L a Work on basic assembly 7 days Mon 9 24 07 Tue 10 2 07 8 F3 Basic assembly finished 1 day Wed 10 3 07 Wed 10 3 07 9 SC Continue assembly improveme 17 days Thu10 4 07 Fri 10 26 07 10 Image Processing Computer 45 days Mon 9 17 07 Fri 11 16 07 11 a Ball detection 10days Mon 97 07 Fri 9 28 07 12 a Ball path prediciting Sdays Mon 10 07 Fri 10 507 13 E Communication with microcon 13 days Wed 10 3 07 Fri 10 19 07 14 a Artificial Intelligence 20 days Mon 10 2207 Fri 11 16 07 15 Prototype Integration Mileston 39 days Fri 10 12 07 Wed 12 5 07 16 E Lateral movement of one hanc 1day Fri10 42 07 Fri 10 12 07 17 ES Lateral and kick movement of 1 day Wed 10 24 07 Wed 10 24 07 1024 18 E Automated movement towards 1 day Fri11 9 07 Fri 11 9 07 a 119 19 E Prototype completed 1 day Wed 11 21 07 Wed 11 21 07 1121 20 E Prototype Presentation 1day Wed 12 5 07 Wed 12 5 07 125 21 Presentation Materials 55 days Mon 9 17 07 Fri 11 30 07 22 Eg Work on project summary 3days Mon 9 24 07 Wed 9 26 07 23 ES Draft finished 1day Mon 104 07 Mon 10 1 07 24
90. ort defaultPort not found Sends a packet across the serial port consisting of 2 bytes ZS public void sendPacket char packet_char 0 byte packet_bytes new byte 2 char i shift_packet array construct the first byte packet_char rs for i20 i lt 8 i shift packet char packet il shift packet 7 i packet char shift packet packet bytes 0 construct the second byte packet char 0 for i 8 i lt 16 i shift packet char packet i shift packet lt lt 15 i packet char shift packet packet_bytes 1 try byte packet char amp OxFF byte packet char amp OxFF convert from unicode convert from unicode event notification Ee The packet is a set of bits in the packet Team FIFA ECE 4007 L01 outputStream write packet bytes catch IOException e System out println SERIAL ERROR A35 e Autonomous Foosball Table Team FIFA ECE 4007 L01 A36 ie Autonomous Foosball Table Appendix B PIC18F4520 Servo Controller Main Program and Library Source Code Team FIFA ECE 4007 L01 B1 ey Autonomous Foosball Table BR k kok ko k kk ok kk Ck ke kk ck ke kk ke ke kk ke kok ke Sk kk k kk Ck ke kk ke kok k k kk Sk ke kk k kk k k kk kk kk k ke kk ke kk ke ke kk ke ke kk ke ek Team FIFA Servo Controller Program File servo c kk ck kk kk kk 0k kk kk kk kk kk kk kk ke K AZ ke NN ockock ck
91. owcount 0 startPlayerPos maxY playerMaxPos 0 for loopl int maxX minX 2 loopl lt maxX loopl for loop2 minY loop2 lt maxY loop2 pixel new Color x getRGB loopl loop2 if pixel getRed gt r colorSearchSize amp amp pixel getRed lt r colorSearchSize amp amp pixel getGreen gt g colorSearchSize amp amp pixel getGreen lt g colorSearchSize amp amp pixel getBlue gt b colorSearchSize amp amp pixel getBlue lt b colorSearchSize for loop3 loopl 5 loop3 lt loopl 15 loop3 for loop4 loop2 5 loop4 lt loop2 15 loop4 pixel new Color x getRGB loop3 loop4 if pixel getRed gt r colorSearchSize amp amp pixel getRed lt r colorSearchSize amp amp pixel getGreen gt g colorSearchSize amp amp pixel getGreen lt g colorSearchSize amp amp pixel getBlue gt b colorSearchSize amp amp pixel getBlue lt b colorSearchSize if loop4 lt startPlayerPos startPlayerPos loop4 if loop4 gt playerMaxPos playerMaxPos loop4 ypos loop4 xpos loop3 countpx af countpx gt 2 1 rows rowcount 2 int Math floor xpos countpx set x rows rowcount 3 startPlayerPos set top System out println Found player row rowcount at rows rowcount 2 startPlayerPos Team FIFA ECE 4007 L01 A18 Autonomous Foosball Table playerHeight
92. port java awt image import javax swing Timer import jmfYUV public class Track extends Frame private BufferedImage imagel the last image from the webcam private FrameGrabber visionl the image acquiring object private int xloc yloc imHeight imWidth framecount 0 FPS 0 private float camFrameRate the frame rate we re acquiring at private int rBallColor gBallColor bBallColor ball colors private int rOppColor gOppColor bOppColor opponent colors private int colorSearchSize 20 colors within this RGB distance will be matched private int searchSize 20 number of pixels to look for the ball in each direction private boolean found boolean indicating if the ball is found private int stage 0 private Predictor p new Predictor private Table t new Table private WriteS c new WriteS private AI a Delay the main process for 2 milliseconds yr public void sleep try I Thread sleep 2 catch Exception e System out println Error Redraw everything in the GUI param g The graphics object to draw on SCH public void paint Graphics g int xline yline g drawImage imagel 10 30 this first add the last webcam image if stage gt 0 g setColor Color BLUE draw the table s bounding box g drawRect t getMinX 10 t getMinY 30 t getTableWidth t getTableHeight if stage gt 2 g t drawPlayers g draw the human s playe
93. ptrace com Accessed Nov 15 2007 Microchip Technical Staff Microchip C18 Compiler User s Guide Micrchip 2005 Online Available http ww1 microchip com downloads en DeviceDoc C18 User Guide 51288j pdf Accessed Oct 3 2007 United States Table Soccer Association USTSA Rules of Play 2007 Online Available http www foosball com learn rules ustsa Accessed Sept 14 2007 Underwriter Laboratories Inc UL 22 Amusement and Gaming Machines Standard Online Available http ulstandardsinfonet ul com scopes scopes asp fn 0022 html Accessed Dec 2 2007 Team FIFA ECE 4007 L01 43 17 18 19 20 Autonomous Foosball Table Electronics Industries Association EIA Standard RS 232 C Interface Between Data Terminal Equipment and Data Communication Equipment Employing Serial Data Interchange August 1969 reprinted in Telebyte Technology Data Communication Library Greenlawn NY 1985 Compaq Computer Corporation et al Universal Serial Bus Specification USB Implementers Forum Inc April 27 2000 Rev 2 0 Sun Develpoment Network Java Media Framework API Sun Microsystems 2007 Online Available http java sun com products java media jmf Accessed Oct 10 2007 Merkur Star Kick 2007 Online Available http www merkur starkick de default htm Accessed Sept 13 2007 Team FIFA ECE 4007 L01 44 ey Autonomous Foosball Table Appendix A Image Processing Source Code
94. puter s players S as opposed to the human s players return The minimum y location in pixels of a particular row Si public int getRowMinY int rownum boolean myPlayers int y 0 if myPlayers y myrows rownum 1 3 else 1 y rows rownum 1 3 return y Public accessor to get the x position of a given row param row The row number 0 3 to set param myPlayers A boolean representing if the data to be returned is about the computer s players a as opposed to the human s players return The x position of the row in pixels SS public int getRowXPosition int row boolean myPlayers int x 0 if myPlayers x myrows row 2 else x rows row 2 return x Team FIFA ECE 4007 L01 A14 ey Autonomous Foosball Table Relocates all of the opponent players to track them as they move param x The image to locate the players on T public void relocate BufferedImage x int i j if foundPlayers basic error check to ensure we CAN locate the players for i 0 i lt 4 i loop through all rows for j minY j lt maxY j start looping through all y pixels in a specified x position Color pixel new Color x getRGB rows i 2 1 j if pixel getRed gt rOppColor colorSearchSize amp amp pixel getRed lt rOppColor colorSearchSize amp amp pixel getGreen gt gOppColor colorSearchSize amp amp pixel getGreen gOppColor colorS
95. r of mass near that pixel After this is done the distance between players on that row is calculated b The table is assumed to be symmetrical about the midfield and thus the computer controlled player locations are calculated by subtracting the x axis value of each row in pixels from the maximum table x axis value in pixels 3 The user selects the color of the foosball a The center of mass of the foosball is found by nearby color comparisons b All future searches for the ball are localized if possible given the previous location At this point if the user reselects a color it is assumed the user is choosing a new foosball color to track The localization of the foosball is done by taking a predictive location and then searching in a 20 pixel distance in every direction If the ball is not found the entire table is rescanned so as to find the ball If in 10 consecutive frames the ball is not found a goal is registered in the direction of the side the ball was last predicted to be going into Team FIFA ECE 4007 L01 12 ey Autonomous Foosball Table 7 Wi VITT H Current position 169 136 Processing 55 FPS Camera providing 15 0 FPS My Score 3 Your score 2 Figure 2 Java tracking graphical user interface In addition to tracking the ball on every frame the location of each of the human controlled players is recalculated The graphical user interface used to visually show the tracking of the ball and th
96. redImage blur BufferedImage x int blurWidth 1 int w x getWidth int h x getHeight int i j r 0 g 0 b 0 Pr G int blursize 2 blurWidth 1 2 blurWidth 1 BufferedImage res new BufferedImage iw bh BufferedImage TYPE_INT_RGB for i blurWidth i lt w blurWidth i for j blurWidth j lt h blurWidth j r g b 0 for p 1 blurWidth p lt blurWidth p blur 1 px left and right for q 1 blurWidth q lt blurWidth q blur 1 px up and down Color c new Color x getRGB i p j q r c getRed g c getGreen b c getBlue Color n new Color r blursize g blursize b blursize average all the pixels in the region res setRGB i j n getRGB assign the new value to the created image return res Team FIFA ECE 4007 L01 A22 ey Autonomous Foosball Table Track java This class is the main control class to all the foosball files It initiates all the required objects from assistant classes AI FrameGrabber Predictor Table and WriteS It tracks the foosball via a limited search Space on every frame checking the FrameGrabber object for whenever a new image is available It also initiates a GUI to draw the location of the ball as well as crosshairs over the ball author Team FIFA ECE4884L01 Georgia Institute of Technology version 1 0 December 2007 S import java awt import java awt event im
97. relatively low data rate This only allowed the camera to capture 30 fps at 320x240 pixels The drivers supplied by Phillips read in this data and triple each frame and quadruple each pixel in order to achieve the listed values Since this internally modified data is of no use to the vision software written the framerate and fps used had to be lowered The image size was still sufficient to supersede our required resolution and the software was able to track the ball well over our goal of 8096 of frames Team FIFA ECE 4007 L01 ie Autonomous Foosball Table The kicking and movement speeds achieved were well under our goals due to budget constraints The kicking speed can be easily increased with the purchase of faster servos In order to increase the lateral movement speed we chose to gear up the AX 12 servos What was not anticipated was that gears of the size we needed must be custom made and therefore have very high setup costs Both of these issues could be remedied in a final product with a higher budget Without the appropriate speed the players could only get to their desired location if the ball was moving very slowly so many of the other specifications failed as well Team FIFA ECE 4007 L01 9 amp 5 Autonomous Foosball Table Design Approach and Details 5 1 Design Overview The AFT consists of six main components 1 2 A standard foosball table with a playing field of 24 by 48 inches Fo
98. ressed 352x288 Yes Compressed Compressed Compressed Compressed Compressed 640x480 Compressed Compressed Compressed No No No The implemented system runs at a compromise of 320x240 pixels at 30 compressed frames per second In order to accommodate the simplest algorithm and largest realized visual area the camera is aligned such that the y axis the short direction of the table uses the 240 pixel range while the x axis from goal to goal of the table uses the 320 pixels To process the image data the Java programming language was chosen This is because the Java Media Framework JMF API allows for developer friendly commands to acquire images while the rest of the Java platform handles high level classes to handle image and color data 8 By utilizing these features fast effective image processing is attained The software runs in three stages 1 The user selects the foosball table outline color Team FIFA ECE 4007 L01 11 ie Autonomous Foosball Table a The playing surface is found by finding a rectangular object consisting of similar colors to the selected color b The number of pixels per square inch is calculated a posteriori by the knowledge that a foosball table is 24x48 inches 2 The user selects the color of the human controlled foosball players a The locations of each of the rows of players are calculated by finding the first instance of a similar color and calculating the cente
99. rs if found draw the crosshairs xline 10 xloc yline 30 yloc g setColor Color GREEN g drawLine xline 30 xline imHeight 30 Team FIFA ECE 4007 L01 A23 amp searchSize 2 Autonomous Foosball Table g drawLine 10 yline imWidth 10 yline g drawRect xline searchSize yline searchSize searchSize 2 write the text under the image g setColor Color BLACK g clearRect 0 imHeight 30 imWidth 10 60 clear out the old text g drawString Current position xloc yloc 10 imHeight 45 else write the text under the image g setColor Color BLACK g clearRect 0 imHeight 30 imWidth 10 60 clear out the old text g drawString Could not locate ball 10 imHeight 45 g drawString Processing FPS FPS 10 imHeight 60 g drawString Camera providing camFrameRate FPS 10 imHeight 75 g drawString My Score p getMyScore Your score p getOppScore 10 imHeight 90 Repaint the graphics on a GUI update param g The graphics object to draw on y public void update Graphics g paint g Listen for window closes If one occurs return all players to their center position and set them down ey then disconnect the controller and exit the program class WindowListener extends WindowAdapter public void windowClosing WindowEvent e c centerAll c setAllDown
100. s of players 2 1 Objective The ultimate goal was to create an automated foosball opponent that can compete with a human player It is challenging but not overly so thereby encouraging players of all skill levels With this level of playability attained it could be sold to a number of commercial locations as well as occasional individuals Bars arcades theme parks and locations with small fun centers like some airports and movie theaters would be interested in the product at a competitive price 2 2 Motivation There currently is only one AFT on the market however it is very expensive and has low functionality The goal was to develop an AFT that can be offered at a competitive arcade machine price and has more functionality than what is currently on the market With a competitive price the AFT will be easily marketed to the customer and offer the manufacturer a big profit 2 3 Background Robotic foosball tables have been created in recent years by students at a few universities but as of yet there have been no commercial applications The Foosbot a project of students at Rice University used a series of infrared LEDs and phototransistors to track the ball as it traversed the table and potentiometers on the gears to track player position 1 It is said to be undefeated but has yet to play against experienced foosball players To achieve better tracking the system will utilize a camera above the table for tracking the ball an
101. still time left on the last action timeleft i timeleft i 1 decrement the timer else if timeleft i 1 time has expired timeleft i 0 raised i raised i if nextval i raised i perform the next action if applicable setLiftID i nextval i D I new Timer 10 checkservos start interrupt every 10ms Returns the kick status of a PWM servo iparam ID The ID of the PWM servo 0 3 return A boolean indicating if the PWM is in the up position S Team FIFA ECE 4007 L01 A29 Autonomous Foosball Table public boolean getRaised int ID return raised ID Special command to the servo to set all rows in their initial position against the wall see centerAll E public void startPosition Command packet 10100000 00000010 packet 2 1 for int i 3 i lt 13 i packet i 0 packet 14 1 packet 15 0 sendPacket Special command to the servo to set all PWM servos to the up position Qsee setAllDown Qsee setOffenseDown see setOffenseUp KE public void setAllUp Command packet 10100000 00000011 nextval 0 nextval 1 nextval 2 nextval 3 raised 0 raised 1 raised 2 raised 3 true timeleft 0 5 timeleft 1 5 timeleft 2 5 timeleft 3 10 packet 2 1 for int i 3 i lt 13 i packet i 0 packet 14 1 packet 15 1 se
102. tificial intelligence AI of the automated player in order to increase the challenge of the game for the human player The project prototype proves that an automated foosball table is feasible and cost effective and that a simple level of AI can be achieved for a somewhat challenging game to the novice foosball player At a target price of 5 000 the table will also be affordable to various establishments such as bars and arcades Team FIFA ECE 4007 L01 6 ey Autonomous Foosball Table Budget constraints for the prototype slowed the project some and kept its functionality to a minimum Proper motors to move the players at a competitive speed were found to be very expensive so lower end servos had to be used The prototype was still able to exhibit the desired gameplay but at an undesirable speed Gearing the motors up to achieve faster lateral movement was chosen but even the gears proved to be much more expensive than allowed by the limited budget available Budget constraints for the prototype slowed the project some and kept its functionality to a minimum Proper motors to move the players at a competitive speed were found to be very expensive so lower end servos had to be used The prototype was still able to exhibit the desired gameplay but at an undesirable speed Gearing the motors up to achieve faster lateral movement was chosen but even the gears proved to be much more expensive than allowed by the limited budget available
103. turn img Public accessor for the internal image from the last grab in BufferedImage form return The last grabbed image Qsee getImage id public BufferedImage getBufferedImage return BufferedImage getImage Public accessor to tell a calling class when a new image from the webcam is available return A boolean indicating if a new image is available y public boolean imageAvailable return newFrame Public accessor for the frame rate of the frame grabber y public int getFrameCount return FRAMERATE Team FIFA ECE 4007 L01 A5 e Autonomous Foosball Table Team FIFA ECE 4007 L01 A6 ey Autonomous Foosball Table Predictor java This class is used to predict locations determine when goals are scored and predict y intercept locations of a row of players It uses a simple prediction based upon average slopes of x and y locations When a goal is Scored this class plays a random audio clip depending on the most likely scorer author Team FIFA ECE4884L01 Georgia Institute of Technology version 1 0 December 2007 K import java awt image import java awt import sun audio import java io import java util Random public class Predictor private int xLocation yLocation yFutureLoc xFutureLoc count private int lastPositions new int 2 3 3 frames 30fps 0 1s private double ballRadius 0 we need this to calcul
104. ue 10 16 07 Thu 12 6078 10 Image Processing Computer 59 days Mon 9 17 07 Thu 12 6 07 11 Ball detection 20days Mon9SA7 07 Fri102 07 12 Ball path prediciting 35 days Mon 10 1507 Fri 11 30 07 11 13 Communication with microconl 40 days Wed 10 3 07 Tue 11 27 07 14 Artificial Intelligence T days Wed 11 28 07 Thu 12 6 07 13 15 Prototype Integration Mileston 33 days Wed 102407 Fri 12 7 07 16 Lateral movement of one hanc 1day Fri11 23 07 Fri11 23 07 8 4 17 Lateral and kick movement of 26 days Wed 10 24 07 Wed 11 28 07 18 Automated movement toward 3days Mon 12 3 07 Wed 12 5107 12 13 5 25 18 Prototype completed 1 day Fri 12 7007 Fri 12 7 07 14 127 20 Prototype Presentation 1day Frit2707 Fri 12 7 07 127 21 Presentation Materials 63 days Mon 9 17 07 Wed 12 1207 22 Work on project summary 3days Mon 9 2407 Wed 9 26 07 23 Draft finished 1day Mon10 07 Mon 10 1 07 22 oe 24 Make revisions to project zum 3days Mon 10 8 07 Wed 10 10 07 23 25 Final Project Summary due 1day Thu 10010 Thu 10 11 07 24 10 11 26 Work on website 15days Mon n 70 Fri 10 5007 O 27 Website live 1 day Wed 10 10 07 Wed 10 10 07 26 1010 28 Work on PDR Sdays Fri 1042 07 Wed 10 24 07 28 Preliminary Design Review 1 day Thu 10 25 07 Thu 10 25 07 28 d 10 25 30 Design Report Sdays Thu 12 607 Wed 12 12 07 mm Team FIFA ECE 4007 L01 G2
105. uired PWM signal for the kicking servo The PICI2F615 controllers produce a 50 Hz PWM signal with a duty cycle varying between 1 0 ms and 2 0 ms This is the standard type of signal accepted by most PWM servos on the market including the HS 81 servos used in this design Table 5 shows the produced PWM signals from the PIC12F controllers based on the input control and direction signals from the PIC18F Team FIFA ECE 4007 L01 18 ey Autonomous Foosball Table Table 5 PICI2F615 PWM servo input output signals Input Signals PWM Duty cycle PWM Period Servo Position pube 1 5 ms 50 Hz Idle down direction 0 FORO 2 0 ms 50 Hz Kick forwards direction 0 i control i 1 0 ms 50 Hz Defend backwards direction 1 contol kii Not Implemented Not Implemented Not Implemented direction 1 To communicate with the image processing PC the PIC18F uses its internal SPI module to communicate with an external MAX3100 SPI to UART chip The MAX3100 simply converts a SPI synchronous peripheral interface communications interface toa UART interface It was necessary to implement a second UART for the PC communications externally because the PIC18F only has one internal UART module The MAX3100 UART can be configured for several different baud rates but in this design a baud rate of 115 2 kbaud was used in order to maximize the bandwidth Refer to the MAX3100 datasheet for more information on its features and confi
106. un underneath the MDF For the complete mechanical design drawings refer to Appendix E 5 6 Codes and Standards The United States Table Soccer Association outlines the rules to which a game of foosball should be played 15 The automated foosball table is to conform to these rules including the rule about not spinning the rods beyond 360 degrees This prevents the servo motors from turning continuously and prevents the motors from over torque and unfair game play In order for the machine to function properly and safely a final product would need to abide by UL 22 the Underwriter Laboratories Standard for Amusement and Gaming Machines 16 This standard defines various aspects of the machine s design including the wiring and circuitry Due to the interactive nature of the game it must be able to withstand the wear and tear specified by the standard guaranteeing a reliable product An example specification from the UL 22 standard that would need to be followed would be that electrical loads can not exceed 60A at 250V The AFT uses two different power supplies so that the motors do not interfere with the power to the electronics A 9V 300mA was used to power the microcontroller and the electronics and a 9V 4A power supply was used to power the motors The prototype is well below the UL 22 standard Team FIFA ECE 4007 L01 26 ey Autonomous Foosball Table The RS 232 connector standards must be followed to allow communication fro
107. ur high torque AX 12 UART controlled servos for lateral movement 6 Four high speed HS 81 PWM controlled servos for the kicking motion 7 A servo control board utilizing a PIC microcontroller for instruction processing A webcam to visually acquire images of the foosball table as it is played A PC to process image data track the ball and opponent players make intelligent decisions of how to play and send servo control commands to the servo control board Figure I shows a basic system overview of the AFT and all of its components and interconnections Serial Link Serial Link PIC Servo Controller Figure 1 Automated foosball table system overview Team FIFA ECE 4007 L01 10 amp 5 2 Image Processing Design The image detection is done via a Philips SPC 900NC which is a standard USB 1 1 webcam Autonomous Foosball Table The webcam supports a maximum resolution of 640x480 pixels and a maximum frame rate of 30 uncompressed frames per second Due to bandwidth problems imposed by USB1 1 the maximum resolution and frame rate may not be achieved at the same time as seen below in Table 2 Table 2 Supported frame rates and resolutions of the SPC 900NC Source Linux PWC Wiki FAQ 5 FPS 10 FPS 15 FPS 20 FPS 25 FPS 30 FPS 128x96 Yes Yes Yes Yes Yes Yes 160x120 Yes Yes Yes Yes Yes Yes 176x144 Yes Yes Yes Yes Yes Compressed 320x240 Yes Compressed Compressed Compressed Compressed Comp
108. us Golden Tee arcade 5 395 machine Great American Eagle Billiard Standard bar quality coin operated billiard table 1 825 Table Tornado Cyclone II Foosball Typical quality human vs human foosball table 1 195 Table Average Price 4 829 From the list in Table 10 of typical arcade machines a targeted price range can be determined for an AFT The higher priced arcade machines are typically larger more complex and usually have a computer opponent component therefore it is viable to put the AFT into a similar range depending on the extra features that the final product may have A realistic selling price for such an arcade machine would fall in the price range of 5 000 8 000 The cost of each unit comes out to 710 based upon the parts list in Table 11 Engineering costs based upon four engineers working 16 hours a week for 14 weeks at 25 per hour come to a total of 22 400 Assuming that the AFT would sell at 5 000 a large profit can be made from such a product Appendix F shows the profitability of an AFT at this price given costs for parts cost of labor and the selling of 500 units For a selling price of 5 000 a profitability of 43 2 can be achieved which amounts to 1 081 214 in profit Team FIFA ECE 4007 L01 37 Table 11 Prototype parts cost Item Quantity Price DMI Foosball Table 1 100 Phillips SPC 900NC Webcam 1 90 AX 1
109. vate void grabFrame fgc FrameGrabbingControl player getControl javax media control FrameGrabbingControl buf fgc grabFrame grab a buffer of the frame Team FIFA ECE 4007 L01 A4 second Autonomous Foosball Table Convert it to an image btoi new BufferTolImage VideoFormat buf getFormat img btoi createImage buf Initialize frame grabs calculating the internal refresh rate to grab at ui public void start try dataSource Manager createDataSource m1 dataSource start formatControls CaptureDevice dataSource getFormatControls for int i20 i lt formatControls length i System out println i formatControls i toString formatControls 0 setFormat userFormat player Manager createRealizedPlayer dataSource player start fgc FrameGrabbingControl player getControl javax media control FrameGrabbingControl catch Exception e ActionListener grabNewFrame new ActionListener this interrupts every public void actionPerformed ActionEvent evt grabFrame newFrame true D I int framerateTimeout int 1 0 FRAMERATE 1 0 1000 1 new Timer framerateTimeout grabNewFrame start interrupt timeout Public accessor for the internal image from the last grab return The last grabbed image see Image see getBufferedImage gt s public Image getImage newFrame false re
110. versal Asynchronous Receiver Transmitter is used to directly communicate with the AX 12 lateral motion servos at a speed of 500 kbps The AX 12 servos communicate on a single data bus where receiver and transmitter function are implemented on a single line Therefore external circuitry is required for the transmit and the receive pins on the microcontroller in order to control which function is currently connected to the common data bus Figure 6 shows this circuitry as specified in the AX 12 User Manual 6 Team FIFA ECE 4007 L01 17 ey Autonomous Foosball Table DIRECTION PORT 74HC126 TXD VDD PIN2 GND PIN1 TAHCOA Figure 6 AX 12 communication circuit Source AX 12 User Manual The TXD and RXD pins are connected to the RX and 7X pins on the PICISF and the DIRECTION PORT signal is connected to an output pin on the PIC18F pin RCO in this design In order to produce the pulse width modulated signal for the PWM kicking motion servos a separate 8 pin PIC12F615 microcontroller is used for each PWM servo 10 The main PIC18F communicates with each of these PIC12F controllers through two output signals a control signal and a direction signal The control signal indicates that a kicking motion is required and the direction signal indicates in which direction that the kicking motion should go forwards for kicking or backwards for defending The PICI2F controllers then interpret these signals and produce the req
111. y Filename ax12 h THIS IS THE HEADER FILE Instructions Include this file in your main program source code and define the following header directives depending on which serial line is used to interface with the AX12 data line ck ok ok ok ok ok kk kk kk kk oko ck 0k oko ok 0k ok 0k KKK ck ck ok KKK ck 0k 0k 0k 0k 0k ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ckckckckckckockockck Developed By Michael Aeberhard michael aeberhard gatech edu Date October 5th 2007 Purpose Easy to use function for controlling the AX 12 servos Restrictions This library assumes the use of the PIC18F4520 microcontroller from Microchip along with the C18 Compiler kk ok kk ok kk ok kk kk KKK KKK KKK kk ok ok 0k 0k kk ck 0k ck ck ck ck ck ck ck ck ck 0k 0k ck ck ck 0k ck ck ck ck ck ck ck ck ck ck ckckck ck ck ck ck ckckckckckckckockockck This file contains numerous functions that can be used to control a AX 12 servo motor Some of the functions are more generic while others are much more specific The original purpose of this library was to write a set of useful functions to be used in the automated foosball table senior design project by Michael Aeberhard Shane Connelly Evan Tarr and Nardis Walker at the Georiga Institute of Technology Kk kk Ck kk kk kk Ck kk k kk kk kk k k kk ke kk kk kk Ck kk k kk kk kk k kk ke ke kk k kk k
112. ze ylower p getyPosition searchSize yupper p getyPosition searchSize if xlower lt t getMinX make sure we re only looking on the table xlower t getMinX else if xupper gt t getMinX t getTableWidth xupper t getMinX t getTableWidth if ylower lt t getMinY make sure we re only looking on the table ylower t getMinY else if yupper gt t getMinY t getTableHeight yupper t getMinY t getTableHeight else default to searching the entire image space computationally expensive xlower t getMinX ylower t getMinY xupper t getMinX t getTableWidth yupper t getMinY t getTableHeight Team FIFA ECE 4007 L01 A26 ey Autonomous Foosball Table for int loopl xlower loopl lt xupper loopl for int loop2 ylower loop2 lt yupper loop2 Color pixel new Color x getRGB loopl loop2 if pixel getRed gt rBallColor colorSearchSize amp amp pixel getRed lt rBallColor colorSearchSize amp amp pixel getGreen gt gBallColor colorSearchSize amp amp pixel getGreen lt gBallColor colorSearchSize amp amp pixel getBlue gt bBallColor colorSearchSize amp amp pixel getBlue bBallColor colorSearchSize xpos loopl ypos loop2 numpos count the number of pixels in the area near in the color search space if numpos gt 0 ensure we found the image calculate the

Download Pdf Manuals

image

Related Search

Related Contents

Acme Made GW01  THE PERFECT  こちら  A肛0 enSPR。 - 株式会社ホーマーイオン研究所  Labour Force Survey User Guide  【NETC-RW052】取扱説明書 (ファームウェア ver1.20対応) [PDF:1.1MB]  Please read the user manual prior the installation  CAN-Mini-Datenlogger I  Warehouse of Tiffany RL13841 Instructions / Assembly  THRUSTREAM EXTENDED Bombas Centrífugas Horizontais de  

Copyright © All rights reserved.
Failed to retrieve file