Home
Full Report - ECE - Cornell University
Contents
1. begin if mVGA R gt 10 b1011000000 mVGA G gt 10 b1011000000 mVGA B gt 10 b1011000000 begin if NEW FRAME 1 1 amp amp mVGA X 32 amp amp avoid left border mVGA X 305 amp amp to avoid being cut mVGA Y 112 amp amp avoid top border mVGA Y 388 avoid bottom border begin CENTER X 1 lt mVGA X CENTER Y 1 lt mVGA Y NEW FRAME 1 lt 1 b0 end if NEW FRAME 2 amp amp mVGA X gt 335 amp amp to avoid being cut mVGA X lt 608 amp amp avoid right border mVGA Y 112 amp amp avoid top border mVGA Y 388 avoid bottom border begin CENTER X 2 lt mVGA X CENTER Y 2 lt mVGA Y NEW FRAME 2 lt 1 b0 end end state test2 end test2 calculate diff begin DIFF X 1 lt mVGA X CENTER X 1 DIFF Y 1 lt mVGA Y CENTER Y 1 DIFF X 2 lt mVGA X CENTER X 2 DIFF Y 2 lt mVGA Y CENTER Y 2 DIFF CENTER X mVGA X PUCK CENTER X 43 end test3 begin DIFF_C state lt test3 draw padd draw puck if P les UCK CENTER X DIFF CENTER DIFF CENTER DIFF CENTER DIFF CEN
2. c eeeeeee eene eee eene ee ette ettet ta setas etas ea 38 Appendix D User s Manual siccisccscsncscoscsetssoussnessoesccesssecsunseasescessoiessedsssavsessdesascassvaeseesteoveseeseses 41 Appendix E M T 42 INTRODUCTION Upon starting my Masters of Engineering design project my goal was to create an embedded systems project that would utilize both knowledge of hardware organization and software development To achieve this goal the idea to create a video game that was both interactive and intuitive to play was born The idea of physical movements controlling the game was influenced by the present state of the gaming industry and provides an added fun factor for the user who feels more involved in the game play Even a seemingly simple game such as air hockey involves a great deal of electrical and computer engineering knowledge By organizing the hardware on the FPGA for fast response as well as programming a general purpose CPU instantiated on the FPGA to run high level logic I was able to create the game environment I aimed for Through use of the system one can immediately see that it is highly responsive to the user s movements and the dynamics of the game emulates the real experience very well DESIGN REOUIREMENTS There were three main reguirements for this video game which ultimately shaped the resulting product The most important design reguirement was the responsiveness of the system
3. 0 end else begin same direction end freeze collision FREEZE CONST end COLLISION 2 if speed x positive Speed y positive begin bounce down amp left if puck is below amp left of paddle if y diff gt 0 amp amp x diff lt 0 begin Speed x positive Speed y positive end bounce down amp right if puck is above amp left of paddle else if y diff gt 0 amp amp x diff gt 0 begin Speed y positive flag 1 end bounce up amp left if puck is above amp left of paddle else if y diff lt O amp amp x diff lt 0 lag 1 amp amp lag 0 amp amp freeze collision Fh Fh ua lag 0 lag 1 Fh Fh begin Speed x positive flag 0 end else begin same direction end freeze collision FREEZE CONST end COLLISION 3 if speed x positive flag 0 amp amp Speed y positive flag 1 amp amp freeze collision begin bounce up amp right if puck is above amp right of paddle if y diff 0 amp amp x diff O0 begin Speed x positive flag 1 Speed y positive flag 0 end bounce up amp left if puck is above amp left of paddle else if y diff 0 amp amp x diff lt 0 begin Speed y positive flag 0 end bounce down amp right if puck is below amp right of paddle else if y diff gt O amp amp x diff gt 0 begin Speed x positive flag 1 63 end else begin same dir
4. amp amp DIFF_X_1 lt 8 amp amp the square DIFF X1 gt 8 amp amp DIFF_Y_1 lt 8 amp amp DIFF Y 1 8 DIFF X 1 9 amp amp the right arc DIFF_Y 1 lt 6 amp amp DIFF Y 1 gt 6 DIFF_X_1 10 amp amp DIFF_Y_1 lt 5 amp amp DIFF_Y_1 gt 5 DIFF X 1 11 amp amp DIFF_Y_ 1 lt 3 amp amp DIFF_Y_1 gt 3 DIFF_X_1 12 amp amp DIFF _Y 1 DIFF_X_1 9 amp amp the left arc DIFF_Y 1 lt 6 amp amp DIFF Y 1 gt 6 DIFF X 1 10 amp amp DIFF Y 1 lt amp amp DIFF_Y_1 gt 5 DIFF X 1 11 amp amp DIFF Y 1 lt amp amp DIFF Y 1 gt 3 DIFF X 1 12 amp amp DIFF_Y_1 0 45 DIFF_Y_1 9 amp amp the top arc DIFF X1 lt 6 amp amp DIFF X 1 6 DIFF Y 1 10 amp amp DIFF_X_1 lt 5 amp amp DIFF X_1 gt 5 DIFF Y 1 11 amp amp DIFF_X_1 lt 3 amp amp DIFF X 1 gt 3 DIFF Y 1 12 amp amp DIFF X1 DIFF_Y_1 9 amp amp the bottom arc DIFF_X 1 lt 6 amp amp DIFF X 1 gt 6 DIFF Y 1 10 amp amp DIFF X1 lt 5 amp amp DIFF X1 gt 5 DIFF Y 1 11 amp amp DIFF X_1 lt 3 amp amp DIFF X 1 3 DIFF Y 1 12 amp amp DIFF X 1 0 begin blue paddle green 10 b1010100000 red lt 10 b 0000000000 blue lt 10
5. end else 18 LED begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 18 end if abs speed y relevant 1 begin y speed increase INCREASE 1 end else if abs speed y relevant 1000 begin y speed increase INCREASE 2 end else if abs speed y relevant 2000 begin y speed increase INCREASE 3 end else if abs speed y relevant 3000 begin y Speed increase INCREASE 4 end else if abs speed y relevant 4000 begin y speed increase INCREASE 5 end else if abs speed y relevant 5000 begin y speed increase INCREASE 6 end else if abs speed y relevant lt 6000 begin y speed increase INCREASE 7 end else if abs speed y relevant 7000 begin y speed increase INCREASE 8 end else if abs speed y relevant 8000 59 16383 Lf 5 T Lr 32767 16 Ll Lr 65535 IF Ade TH Gl 131071 262143 Ed Ed tr tr tr tr tr Ed Ej begin y speed increase INCREASE 9 end else if abs speed y relevant 9000 10 LED begin y speed increase INCREASE 10 end else if abs speed y relevant 10000 11 LED begin y Speed increase INCREASE 11 end else if abs speed y rele
6. amp mVGA Y 403 begin green 10 50000000000 red lt 10 50000000000 blue lt 10 b1010100000 end draw top left border else if mVGA X gt 19 amp amp mVGA X 320 amp amp mVGA Y 98 mVGA Y 99 begin green 10 50000000000 red lt 10 50000000000 blue lt 10 b1010100000 end draw bottom left border else if mVGA X gt 19 amp amp mVGA X lt 320 amp amp mVGA Y 401 mVGA Y 402 begin green 10 50000000000 red lt 10 50000000000 blue lt 10 b1010100000 end blacken all else on left side else if mVGA_X gt 20 amp amp mVGA_X lt 320 begin red lt 10 50000000000 47 blue lt green lt end 2nd paddle 10 p0000000000 10 p0000000000 O amp amp CENTER Y 2 0O amp amp amp amp the square the right arc the left arc 9 amp amp the top arc if CENTER X 2 DIFF X 2 8 DIFF X2 gt 8 amp amp DIFF_Y_ 2 lt 8 amp amp DIFF_Y_ 2 gt 8 DIFF_X_2 9 amp amp DIFF_Y_ 2 lt 6 amp amp DIFF Y 2 gt 6 DIFF X 2 10 amp amp DIFF_Y_2 lt 5 amp amp DIFF_Y_2 gt 5 DIFF_X_2 11 amp amp DIFF_Y_2 lt 3 amp amp DIFF_Y_2 gt 3 DIFF_X_2 12 amp amp DIFF_Y_2 DIFF X 2 9 amp amp DIFF_Y_2 lt 6 amp amp DIFF_Y_2 gt 6 DIFF_X_2 10 amp amp D
7. speed y speed y 2 if abs speed x relevant 1 1 LED begin IOWR ALTERA AVALON PIO DATA OUT1 BASE 1 X speed increase INCREASE 1 end else if abs speed x relevant lt 1000 2 LI begin IOWR ALTERA AVALON PIO DATA OUT1 BASE 3 X speed increase INCREASE 2 end tj J 57 else if abs speed x relevant 2000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 3 end else if abs speed x relevant 3000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 4 end else if abs speed x relevant 4000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 5 end else if abs speed x relevant 5000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 6 end else if abs speed x relevant 6000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 7 end else if abs speed x relevant 7000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 8 end else if abs speed x relevant 8000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 9 end else if abs speed x relevant 9000 begin IOWR ALTERA AVALON
8. PIO DATA OUT1 BASE X speed increase INCREASE 10 end else if abs speed x relevant 10000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 11 end else if abs speed x relevant 11000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 12 end else if abs speed x relevant 12000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 13 end else if abs speed x relevant 13000 begin 58 r r r 3 W GI 4 Wi Gl 15 13535 El Lu 31 6 Ll LH 63 TLl Lu 127 8 Ll Lu 255 9 1 bt 511 10 Li CJ 1023 11 Ll 2047 12 Ll Lu 4095 13 Li Lu 8191 14 Ll LH Lu IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 14 end else if abs speed x relevant 14000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 15 end else if abs speed x relevant 15000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 16 end else if abs speed x relevant 30000 begin IOWR ALTERA AVALON PIO DATA OUT1 BASE X speed increase INCREASE 17
9. To create a realistic game experience many possible implementations and ideas were considered Much cost benefit analysis had to be taken into account and the following were things that were considered in ultimately coming up with the project solution Game Input Upon coming up with the idea of the air hockey game the first possibility for game input was to use accelerometers in conjunction with a camera so that I could measure actual acceleration and therefore determine the force at the time of contact The accuracy of the collision force made this option fairly attractive However in researching wireless radio transmissions it was determined that the overhead of both cost and time did not warrant that level of precision measuring Instead simply using the change in position from the imaging would have to provide sufficient data for the dynamics of the system The next idea was to use just a camera to determine the position of the paddles The Sony PlayStation 2 EyeToy camera uses edge detection and various signal processing techniques to determine the user s movements against the background Conveniently Terasic Technologies makes a CCD camera for the FPGA board that was ultimately used for this project My idea was to draw upon principles similar to the EyeToy but to make the processing easier by detecting distinct colors for example The camera has a fairly high resolution that is capable of 1 3 Mega pixels which is more than en
10. began 0 p 0 nt delay counter 0 nt collision count nsigned i nt dummy c p nt nt nt nt nt nt ned ned ned ned ned ned notes 9 262 msg 0 freq 0 nsig nsig nsig nsig nsig nsig ecececde H H H H H H head tail Fit the nsigned i nsigned int y_position nt x_speed 0x00000000 nt y_speed 0x00000700 u u I i llision 0 p nt freeze col jtag uart variables FILE uart file int freq val int wave val 7 p P 0 1 notecount no change head tail 0 0 Speed y relevant 0 294 x_position_history CIR BUFE y position history CIR BUFF 330 349 392 440 494 523 0 ER SIZ ER SIZ E E entire puck within border nt x position 0x1400 4 0x6400 RADIUS 8 RADIUS 8 th open lcd devic lcd fd fopen dev lcd if lcd fd NULL nam 1 while begin game began 0 x speed 0x00000000 y speed 0x00000400 X position 0x00013100 y position 0x00006400 IOWR ALTERA AVALON PIO DA from system h w E printf Unable to open lcd display n RADIUS 8 RADIUS 8 A OUT9 BAS 0 cr 54 Paddle address x address y Paddle np position in int IORD ALTERA AVA IORD ALTERA AVA LON PIO DA LON PIO DA A INO BAS A IN2 BAS position i
11. collision with the puck is then categorized again This time we are interested in which area of the paddle makes contact with the puck If you think of the puck being at the origin of a two dimensional graph then the x and y axis divide the paddle into 4 guadrants Similar to the Cartesian coordinate system the design refers to the top right as quadrant I bottom right as quadrant II and so on Once these two parameters of the collision scenario are known the appropriate reflecting direction is determined In referring to the figure below please remember that it is not a complete representation of the dynamics engine No vee v y Counter lt Start ae Save prev Reflect off walls Counter is O No DOS amp and change update pos speeds if needed No B Update speed amp freeze collisions Bounce puck up and left Bounce puck moving moving up up and right down amp ue ight amp right Yes Bounce puck m No direction down and right change No No Y Etc J Figure 8 23 Lastly the speed of the puck resulting from a paddle collision occurs as a function of the paddle speed A conscious decision was made to transfer energy from the paddle to the puck non linearly so that at low speeds the resolution of speed differen
12. computer logic to simulate Newtonian physics models using variables like mass velocity friction and acceleration Cartesian coordinate system a two dimensional coordinate system consisting of an abscissa x coordinate and an ordinate y coordinate where two points can uniguely identify every point in the plane also known as the rectangular coordinate system Elastic collision a physical collision where the total kinetic energy of the system is the same before and after the collision Inelastic collision a physical collision where the total kinetic energy of the system is not the same before and after the collision the kinetic energy that is not conserved is transferred to other forms of energy such as heat and sound 36 APPENDIX B Hardware Schematics and Diagrams Paddle Circuit Schematic 750 9V System Diagram See Figure 4 37 APPENDIX C Virtual Air Hockey Photos TRDB DC2 1 3 Megapixel CCD Camera www terasic com eu a ie C i E m Pea Taris d pha M S 38 Homemade Paddles System Setup Pt 1 Top 39 System Setup Pt 2 Bottom Game Screen Shot 40 APPENDIX D User s Manual l 2 12 13 14 15 16 Select a surface that is non reflective Remove DE2 board and TRDB camera from packaging Note You must handle the boards only on the ESD mat Connect the camera and the FPGA via the ribbon cable to the GPIO 1
13. define TOP_WALL 100 RADIUS define BOTTOM WALL 400 RADIUS define MAX SPEED 6 define MIN_SPEED 0x0080 define FREEZE CONST 12 define INCREASE 1 0x0000 define INCREASE 2 0x0010 define INCREASE 3 0x0020 define INCREASE 4 0x0040 define INCREASE 5 0x0080 define INCREASE 6 0x0100 define INCREASE 7 0x0140 define INCREASE 8 0x0180 define INCREASE 9 0x0200 define INCREASE 10 0x0280 define INCREASE 11 0x0300 define INCREASE 12 0x0380 define INCREASE 13 0x0400 define INCREASE 14 0x0480 define INCREASE 15 0x0500 define INCREASE 16 0x0580 define INCREASE 17 0x0600 define INCREASE 18 0x0600 define float2fix a int a 256 0 define mfix a b int long a long b gt gt 8 int main void begin int address x valid address y int address x 2 address y 2 int x positionl y positionl int x position2 y position2 no change int sw key notecount int left half 1 int x diff y diff diff in x and y centers of puck amp paddle int speed memory 1 speed memory 2 int x speed increase y speed increase int friction distance char collision flag char speed x positive flag 1 char speed y positive flag 1 unsigned char LEFT PLAYER SCORED 0 unsigned char RIGHT PLAYER SCORED 0 53 nsigned char nsigned char LEFT_SCOR RIGHT SCO c nt nt nt nt nt Speed x Speed y speed x 2 speed y 2 Speed x relevant H H H H H p nt speed har game
14. expansion slot on the DE2 board Fit the camera into slot in the middle of stand with the lens in the center and the FPGA resting on the stand Connect the monitor s VGA cable to the VGA port on the DE2 Connect the speakers to the green port labeled LINE OUT Connect the PC to the DE2 using the USB cable to the port labeled BLASTER Connect the power cable Turn on the power supply with the red switch on the DE2 board Open the DE2_CCD Detect project file using the Quartus II IDE on the PC Program the board by clicking on the third icon from the top right labeled Programmer and click Start Note Make sure the device is on USB Blaster Press the pushbutton labeled KEY3 on the DE2 to start the camera Open the Nios II IDE and select the workspace to be ADE2 CCD detect noosisoftware In the Run menu at the top of the window click on Run and click on Run in the bottom right of the new window When ready to play each player must move their paddle into their respective white boxes on the air hockey table First player to 10 goals wins 41 APPENDIX E Code Verilog Code Instantiated Nios II module Nios II bigNios nios2 CLOCK 50 KEY 0 parallel i o current dram addr x InO addr valid Inl current dram addr y In2 current dram addr x 2 In3 current dram addr y 2 In4 start game In5 DIFF X 1 IN In6 DI
15. mVGA X 520 amp amp mVGA Y 225 mVGA Y 224 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress boxes 0 amp amp mVGA X 470 amp amp mVGA X 520 amp amp mVGA Y 274 mVGA Y 275 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end draw right top border else if mVGA_X 621 mVGA X 622 amp amp mVGA_Y gt 98 amp amp mVGA Y lt 225 begin green 10 b 0000000000 red lt 10 b0000000000 blue lt 10 b1010100000 49 end draw right goal else if mVGA X 621 mVGA X 622 amp amp mVGA Y gt 225 amp amp mVGA Y 275 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end draw right bottom border else if mVGA X 621 mVGA_X 622 amp amp mVGA_Y gt 275 amp amp mVGA_Y lt 403 begin green lt 10 50000000000 red lt 10 50000000000 blue lt 10 b1010100000 end draw top right border else if mVGA X gt 320 amp amp mVGA X lt 621 amp amp mVGA Y 98 mVGA Y 99 begin green 10 50000000000 red lt 10 50000000000 blue lt 10 51010100000 end draw bottom right border else if mVGA X gt 320 amp amp mVGA X 621 amp amp mVGA Y 401 mVGA Y 402 begin green 10 50000000000 red lt 10 50000000000 blue lt 10 51010100000
16. moderately fast collision The reason for this was that the updating of the puck s position at high speeds would draw the puck overlapped with the paddle This of course is a collision scenario and the puck s direction and speeds are updated In the very next 26 update the puck is still somewhere overlapping the paddle and another direction and speed update occurs This problem of multiple collisions detected as a result on one collision was compounded by the fact that the user is moving the paddle usually further towards the center of the puck The solution was to set the aforementioned flag and to not allow another collision to occur until that flag is de asserted through counting down a variable Finally there were some obscure problems as a result of using the two integrated development environments IDEs First the Ouartus II IDE s SOPC builder s naming convention caused one problem where the orders of the Parallel Input Out PIO busses ended up in the wrong order The reason for this was that the naming convention used for this project was numbering all inputs and outputs seguentially This worked fine for Out0 through Out9 but as soon as Out10 was added everything stopped working Digging into the generated Verilog file bigNios v it was later revealed that the order used by the SOPC builder was Out0 Out1 Out10 Out2 etc which is in alphanumerical order Once the bus ordering in the high level Verilog code was switched the code
17. of color red green and blue The other major difference is that there are separate lines for horizontal and vertical sync pulses The basic premise of VGA is that the output device will send a repeating series of horizontal and vertical sync pulses to the monitor which specifies the exact pixel to brighten or darken Each horizontal sync pulse indicates to the monitor to shift its focus to the next pixel on the same line while each vertical sync pulse tells the monitor to move on to the next line Each pixel can be set to a specific red green and blue value depending on the voltage level of the respective color input with a higher voltage level corresponding to a brighter color Figure 3 is an example of what a sample VGA video signal may look like for the green color with respect to the sync pulses Green HSync 11 T IH FU YW WI FWY TF WU VSync E Figure 3 Sound Output The aim for this project is to create a rich gaming experience and no game would be complete without sound effects There are many viable techniques for generating 10 sounds and the one chosen for this project is direct digital syntheses DDS The general functionality of DDS is explained as follows a calculated constant number called a phase increment is added to an n bit register every N clock cycles causing the n bit register to overflow at some constant rate At the same time the top x bits where x n of that register are used as index values for a ta
18. on speaker begin DLY_cont2 lt 0 51 end else begin end if DLY cont2 24 h08ffff play for 589823 cycles 50MHz begin DLY cont2 lt DLY_cont2 1 SP2 lt 1 Sound Select 2 h01 end else begin SP2 lt 0 end if chime sound if datected turn on speaker begin DLY cont3 0 end else begin if DLY cont3 24 h300000 play for 3145728 cycles 50MHz begin DLY cont3 lt DLY cont3 1 SP3 lt 1 Sound Select 2 end else if DLY cont3 24 h600000 play for another 3145728 begin DLY cont3 lt DLY cont3 1 SP3 lt 1 Sound Select lt 3 end else if DLY cont3 24 h900000 play for another 3145728 begin DLY cont3 lt DLY cont3 1 SP3 lt 1 Sound_Select lt 4 end else if DLY_cont3 lt 24 hc00000 play for another 3145728 begin DLY cont3 lt DLY cont3 1 SP3 lt 1 if DLY cont3 1 0 Sound_Select lt 5 else Sound_Select lt 6 end else begin SP3 lt 0 end end end Id End Speaker Control 52 C Code Game Dynamics C Main Program define begin define end define position_delta 0 define CIR_BUFFER_SIZE 10 define RADIUS 13 define LEFT WALL 8 RADIUS define RIGHT_WALL 620 RADIUS
19. results from the air hockey game were overall very positive Taking into consideration all of the unforeseen bugs and problems I ran into the end product has met the high expectations set at the beginning of the project The paddle control is very precise and smooth at moderate speeds which are sufficient for the game play and the video output is very stable with no flickering or breaking whatsoever The sound output is also very neat and adds significant depth to the game play The system is robust enough to play in different light settings although care needs to be taken to ensure there are no reflective objects within the range of the camera In addition to the positive performance of the system I have learned a great deal about game and gaming console design Having previous experience in designing a simple video game on an 8 bit microcontroller the Nios II was a much more pleasant experience With its pipelined architecture the faster throughput for computing was instrumental in creating a rich gaming experience that reguired many calculations per frame of video In addition to the power of the CPU creating dedicated audio and video generation hardware was also a powerful tool This hardware had a simple interface with wires or busses to and from the CPU creating instant audio and video results with no additional time spent by the CPU I feel that I was able to achieve the intuitive factor which I set out to accomplish from the beginning Muc
20. worked flawlessly The problem encountered with the Nios II IDE was also non intuitive and the problem occurred when I made a copy of my source code and placed the copy in the same directory as the original source file This was done because I was about to make dramatic changes to the code and I wanted to retain a copy of the working code Subseguent changes to the original source code made no differences in the behavior of the program which was extremely puzzling The reason for this turned out to be that the copy of the original was being compiled and run on the board instead of the original source file because the name of the copy file came before the name of the original file and the builder took the first main function it saw In this scenario I would have at least expected the code to not run or throw some warnings during compilation but it did neither of those 27 RESULTS The overall results were very positive The video output of the puck movement showed no artifacts when the game speed was increased during testing The puck lost video continuity when the puck began traveling at about 13 pixels per frame which makes sense since the radius of the puck is also about 13 pixels Generally during the course of play the puck velocity never reached 1 3 pixels per frame 1096 of 13 pixels per frame which is a fairly conservative measure of video continuity Furthermore fear of discontinuity is not even an issue in this application since a pu
21. D 8 if y speed y speed increase MAX SPEED 8 begin if y speed 0x0500 begin y Speed y speed increase 2 end else y Speed y speed increase end else y speed MAX SPEED 8 end notecount 0 end if x_position gt gt 8 320 begin the puck is in the left half left half 1 end else if x_position gt gt 8 gt 320 begin the puck is in the right half left half 0 end IOWR ALTERA AVALON PIO DATA OUTA BASE 0 IOWR ALTERA AVALON PIO DATA OUT5 BASE x_position gt gt 8 IOWR ALTERA AVALON PIO DATA OUT6 BASE y_position gt gt 8 end end end End C Main Program 65
22. FF Y 1 IN In7 DIFF X 2 IN In8 DIFF Y 2 IN In9 GPIO 0 0 OutO LED RED Outl chime sound Out10 stupid naming convention SPEED Out2 Actually left player s score X ADDRESS Out3 Actually right player s score Y ADDRESS Out4 PUCK CENTER X Out5 PUCK CENTER Y Out6 sound signal Out7 collision sound Out8 suppress boxes Out9 1 bit Suppress Boxes signal lcd LCD EN LCD RS LCD RW LCD DATA the sram 16bit 512k 0 SRAM ADDR SRAM CE SRAM D RAM L RAM OI RAM UB N RAM WE N OQ o uo End Nios II Paddle Detection amp Video Generation Paddle Detection amp Drawing always8 posedge CLOCK 50 begin if mVGA X 20 amp amp mVGA Y 20 begin NEW FRAME 1 lt 1 bl NEW FRAME 2 lt 1 bl end if KEY 3 42 begin reset pressed 1 bl end if reset synch reset assumes KEYO is held down 1 60 second begin initialize variables CENTER X 1 20 CENTER Y 1 20 CENTER X 2 lt 620 CENTER Y 2 20 state init first state in regular state machine end else if VGA VS VGA HS modify display during sync begin case state init begin state lt testl end testl locate center
23. FPGA Virtual Air Hockey A Design Project Report Presented to the Engineering Division of the Graduate School of Cornell University in Partial Fulfillment of the Reguirements for the Degree of Master of Engineering Electrical amp Computer by Ping Hong Lu Project Advisor Dr Bruce R Land Degree Date May 2008 Abstract Master of Electrical and Computer Engineering Cornell University Design Project Report Project Title FPGA Virtual Air Hockey Author Ping Hong Lu Abstract A virtual air hockey game was designed that blends together many aspects of embedded systems design in electrical and computer engineering to create an interactive game that is sophisticated yet intuitive to play The video game is implemented on the DE2 FPGA educational development board made by Terasic for Altera s Cyclone II processor The FPGA is used in combination with a CCD camera for video input as well as a monitor and speakers for game output The camera tracks movements of LED paddles through image processing technigues and the players move the paddles to strike a virtual puck which is displayed on the monitor along with the on screen paddles In addition to synthesizing basic hardware on the DE2 a general purpose CPU called the Nios II is also instantiated on the board which runs high level C code The dynamics of the game is coded in C The result is a fully interactive game in which the users movements of LEDs register as movements of paddles
24. For the most part this meant that the image capturing and outputting needed to be fast and therefore implemented in hardware which reguired no additional software logic The game dynamics could take a little longer since the game needed to be slow enough for humans to play and was accordingly implemented in software running on the Nios II CPU Other reguirements were that the video game run smoothly with no lags or glitches in the game play and simply that it should feel like a real game of air hockey This last reguirement is a bit subjective and reguired adjustments made by iterative trial and errors The reguirements of this project are summarized as the following Good responsiveness the actions feel like an extension of the user s body Precise and accurate game dynamics Overall experience like playing real air hockey BACKGROUND Interactive Gaming With the recent burst of interactive video game consoles hitting the market it is clear that there is much consumer interest in interactive gaming The accelerometer gyroscope technologies combined with infrared position triangulating in the Nintendo Wii allow users to aim a gun or slash a sword while the SIXAXIS tilt sensitive controller for the Sony Playstation 3 allows players to guide a flying object with the tilt their hands instead of the motion of their thumbs Other forms of interactive games also exist such as stepping on pressure sensitive pads or playing musical instru
25. I found out later in the project this was actually the largest constraint in the project and this will be discussed further in the RESULTS section of the report Another constraint on the system is that the camera will pick up light reflection from the paddle LED In order to avoid false position calculations the system needs to be used in an environment free of reflective objects in the camera s field of view This includes the actual playing surface and during development and testing a large non smooth black piece of paper was used under the playing area Paddle Control Hardware The paddle detection hardware is one of the more complex sections of this project with many steps in the process First the red green and blue data for each pixel in the SDRAM is processed by image filtering hardware to even out extraneous data That filtered data set is used to determine the center locations of the two paddles and finally when each pixel is output on the VGA it s proximity to the center of the paddles are checked and the right action is taken in drawing the pixel To perform the image filtering on the red green and blue values of each pixel in SDRAM there are three special shift registers called taps that shift in the information every clock cycle The taps are unigue because as their name suggests they allow the hardware to tap each position of the shift register to access its bits The taps were created using the MegaWizard Plug In Manager i
26. IFF_Y_2 lt 5 amp amp DIFF Y 2 gt 5 DIFF X 2 11 amp amp DIFF Y 2 amp amp DIFF Y 2 gt 3 DIFF X 2 12 amp amp DIFF_Y_2 0 DIFF_Y_2 DIFF_X_2 lt 6 amp amp DIFF_X_2 gt 6 DIFF Y 2 10 amp amp DIFF_X_2 lt 5 amp amp DIFF_X_2 gt 5 DIFF Y 2 11 amp amp DIFF_X_2 lt 3 amp amp DIFF_X_2 gt 3 DIFF Y 2 12 amp amp DIFF X 2 DIFF Y 2 9 amp amp DIFF X 2 lt amp amp the bottom arc 48 DIFF X2 DIFF Y 2 DIFF X2 DIFF X2 DILEE Y 2 DIFF X2 DIFF X_2 DIFF_Y_2 DIFF X2 begin white red lt blue lt green lt end gt 6 10 amp amp lt 5 amp amp gt 5 11 amp amp lt 3 amp amp gt 3 12 amp amp 0 paddle 10 p1010100000 10 p1010100000 10 p1010100000 draw right start box else if suppress boxes 0 amp amp mVGA X 471 mVGA X 470 amp amp mVGA Y gt 224 amp amp mVGA Y lt 276 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress boxes 0 amp amp mVGA X 520 mVGA X 521 amp amp mVGA Y gt 224 amp amp mVGA Y 276 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress boxes 0 amp amp mVGA X 470 amp amp
27. PIO DATA OUT10 BAS RIGHT PLAYER SCORED 1 RIGHT SCORE t if RIGHT SCORE 10 rj m T game began 0 end BOTTOM WALL if y position gt BOTTOM WALL lt lt 8 begin if speed y positive flag 1 begin if y speed MIN SPEED y speed 0x0040 Speed y positive flag 0 end IOWR ALTERA AVALON PIO DATA OUT7 BASE 1 end TOP WALL if y position lt TOP WALL 8 begin if speed y positive flag 0 begin if y speed MIN SPEED y speed 0x0040 Speed y positive flag 1 end IOWR ALTERA AVALON PIO DATA OUT7 BASE 1 end if collision flag 1 PADDLES begin to look convincing on video collision countrr collision flag 0 Collision sound effect IOWR ALTERA AVALON PIO DATA OUT8 BASE 1 COLLISION 1 if speed x positive flag 1 amp amp Speed y positive flag 1 amp amp freeze collision begin bounce up amp left if puck is above amp left of paddle if y diff O amp amp x diff O0 begin Speed x positive flag 0 Speed y positive flag 0 end bounce up amp right if puck is above amp right of paddle else if y diff O amp amp x diff gt 0 begin Speed y positive flag 0 end bounce down amp left if puck is below paddle 62 else if y diff gt 0 amp amp x diff lt 0 begin Speed x positive flag
28. TER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER DIFF CENTER __ DIFF CENTER DIFF CENTER KXK O XAK XXK KX KKM KKK KKM KX KKM KKM KKM KKXX xK ENTER Y lt mVGA Y PUCK CENTER Y O amp amp PUCK CENTER Y 0 amp amp um 8 amp amp the square 8 amp amp 8 amp amp 9 amp amp the right arc 9 amp amp the left arc 12 amp amp es109 9 amp amp the top arc 6 amp amp 6 10 amp amp 5 amp amp 44 DIFF CENTER Y 9 amp amp the bottom arc DIFF CENTER X lt 6 amp amp DIFF CENTER X 6 DIFF CENTER Y 10 amp amp DIFF CENTER X amp amp DIFF CENTER X gt 5 DIFF CENTER Y 11 amp amp DIFF CENTER X amp amp DIFF CENTER X gt 3 DIFF CENTER Y 12 amp amp DIFF CENTER X 0 begin green 10 b1010100000 red lt 10 b1010100000 blue lt 10 50000000000 end else begin if CENTER X 1 O amp amp CENTER Y 1 00
29. aight with very little friction just like real air hockey The velocity vector changes directions with some speed loss upon colliding with static objects on the table with the energy being transferred from kinetic energy to friction heat and sound energy This is done in software reducing the absolute value of the velocities upon a collision and asserting an output line to the AUDIO DAC module 2 to create a sound For simplicity the speed of the puck was not taken into account and a constant energy loss was implemented although future implementations could certainly improve upon this by making the energy loss more accurate to the physical world Energy input is achieved by striking the puck with the paddle with more energy transferred to the puck when the paddle is moving faster This is good in that there is never any constant acceleration we ignore force of friction because this is virtual air hockey after all The tricky part is that the paddle has a much larger mass compared to the puck and the paddle s velocity remains unchanged after the collision Therefore the concept of conservation of momentum where the momentum of the entire system consisting of n objects with mass m and velocity v defined below n nts i 0 before the collision is equal to the momentum of the entire system after the collision is computationally hard because there is no known mass of the paddle There was some leeway in designing the non completely elasti
30. as developed the foundation for a simple yet robust video game With some modifications one can imagine implementing many other games which feature similar physics For example games like virtual Pong are possible using the same image tracking concept to control paddle movements Some changes to implement elastic collision physics would enable a game like billiards where the players control the pool cues via image tracking Collaborative games like curling where one player throws the rock and another player sweeps the ice with the broom is extremely conducive of the image tracking technology as well as the distance calculating hardware already in existence from this project While reguiring slightly more work it is also conceivable to take advantage of the DE2 s Fast Ethernet Network Controller to implement a cross board game where each player has their own DE2 TRDC camera and monitor As an example if the air hockey game is used each player may only see their half of the table their own paddles and the puck when it is in their playing space With so many features available on this hardware the gaming possibilities are guite extensive In addition to other possible games I believe that this project or parts of it would be useful as laboratory teaching material for academic purposes as this project incorporates many aspects of DE2 programming like state machines video generation CPU synthesis and high level C code 32 CONCLUSIONS The
31. b1010100000 end draw left start box else if suppress boxes 0 amp amp mVGA X 120 mVGA X 119 amp amp mVGA Y gt 224 amp amp mVGA Y lt 276 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress_boxes 0 amp amp mVGA_X 170 mVGA_X 169 amp amp mVGA_Y gt 225 amp amp mVGA_Y lt 275 begin green lt 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress_boxes 0 amp amp mVGA_X gt 120 amp amp mVGA_X lt 170 amp amp mVGA Y 225 mVGA Y 224 begin green 10 b1111100000 46 red lt 10 b1111100000 blue lt 10 b1111100000 end else if suppress boxes 0 amp amp mVGA X 120 amp amp mVGA X 170 amp amp mVGA Y 274 mVGA Y 275 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end draw left top border else if mVGA_X 19 mVGA_X 18 amp amp mVGA_Y gt 98 amp amp mVGA_Y lt 225 begin green lt 10 50000000000 red lt 10 50000000000 blue lt 10 b1010100000 end draw left goal else if mVGA X 19 mVGA X 18 amp amp mVGA Y gt 225 amp amp mVGA Y 275 begin green 10 b1111100000 red lt 10 b1111100000 blue lt 10 b1111100000 end draw left bottom border else if mVGA X 19 mVGA X 18 amp amp mVGA Y gt 275 amp
32. ble with y elements 2 gt y This table is the digital values of a single sine wave spread out evenly over y elements These digital values are sent to the DAC and an analog since wave is generated To change freguencies simply change the constant value that is added to the n bit register Mathematically expressed the formula is Hed N increment clk By correctly choosing the phase increment based on your known clock and N values a sine wave with the desired freguency can be created Notice that as you increase the sine freguency by using higher increment values the time resolution of the sine wave gets worse and worse Final Project Definition The final project is summarized as follows Game input of detecting LED movements through a digital camera Game dynamics engine based solely on LED positions Video output via VGA interface Sound generation through Direct Digital Synthesis 11 DESIGN AND IMPLEMENTATION This section details the video input hardware paddle control hardware video output hardware sound output hardware and other miscellaneous hardware as well as the game dynamics software The block diagram of the virtual air hockey system is show below SDRAM LED Controller GOD Camere pene Paddles Input Image Filter 1 Display VGA i Logic Hardware Contoler Monit
33. c collision because the precise amount of energy lost to sound and friction depend on many factors in the real world In adding energy to the puck my design based the speed increase on the current speed of the puck and the speed of the paddle at the time of collision with a saturation point near the maximum allowed puck speed defined by the constant MAX SPEED For exact implementation details please refer to APPENDIX E Even though the code is quite lengthy the actual logic for changing directions and speeds based on collisions with walls and paddles is fairly straightforward The wall collisions require simply detecting the x or y address of the puck to be greater than or less than the boundary depending on the wall in question For the paddles the design broke down the different scenarios in which collisions could occur Based on the code prior to the dynamics calculations a flag is set based on the distance between the paddle and puck being greater or less than or equal to twice the radius of the puck and paddle they share the same radius lengths Figure 8 is an accompanying partial flow chart meant to facilitate the understanding of the collision logic and is not representative of the entire code It was determined that the logic would first determine which direction the puck was traveling positive x amp positive y positive x amp negative y negative x and positive y 22 or negative x and negative y In each of these scenarios the
34. ck traveling that fast is not conducive to a realistic gaming environment The paddle detection was very precise with LED position detection resolution of approximately 1 cm when played from 2 feet away from the camera This was far better than my expectation In contrast the speeds at which the user could move the LED and have the movement registered in a continuous manner were somewhat disappointing This was the result of the CCD camera taking so long to capture one frame of information and moving onto the next frame This result forced the game dynamics to be more exaggerated at medium speeds so that users can still perform hard shots while not losing their paddle on the screen In general users became accustomed to the limits of the camera very quickly and controlled the paddle expertly I was also satisfied by the overall ease of use of the system New users required virtually no instructions and learned the system through using The sound generation hardware worked quite well for the range of sine waves which was 1 2 3 4 5 and 8 K Hz As shown in Figures 11 and 12 below the 1 KHz signal had plenty of samples and a solid time resolution to define a clean sine wave 28 Figure 11 Figure 12 29 Figure 13 Figure 14 30 In Figure 13 and 14 the 8 KHz signal begins to show some distortions in the waveforms However this worked perfectly as the 8 KHz sound was used to create a harsh sharp noise of the puck reflec
35. d add or reduce functionality where needed This last point is certainly relevant considering the existing game consoles on the market today already support firmware updates through internet connections The entire project was done on the DE2 FPGA development board and TRDB_DC2 1 3 Megapixel camera both made by Terasic Technologies a speaker a VGA monitor and two LED mounted paddles The hardware was programmed in Verilog and the Nios II CPU was programmed in embedded C The project was a great success and the game play is both natural and fun I am extremely satisfied with the results and found the entire process very rewarding Table of Contents Virtual Air Hockey oid M 2 Executive Summary eu si 3 INtroduction P 5 Design REQUiIreMents ERR 5 Back SrOunid e osonro oaeo eous osere op OTP V aooo or r00 E SESS 6 noci cni 6 A r MOCK CY m RER 6 Rane OF o ODLI LNS EP E CTI 7 Game Input siia E E AEE E EEE E 7 bnc GY YF SE 9 Sound Outpult i e EEUU 10 Final Project DefrnitlOn eei citet oa tee iii e ed Fra eda EEEE 11 Design and Implementation sesesosesooesoosscosssoesooeesosssosssosesosesocesocososssscossesssecesesesecesecesecesecesosee 12 Vadeo Input HardWare eanes ttp rer a asa RR TARE 12 Paddle Con
36. e sort of mechanism to decide which pixel would represent the paddle In other words how do we process the peak values i e 5 in Figure 2 in an orderly and systematic fashion The solution for this will be discussed in the DESIGN AND IMPLEMENTATION section Video Output The idea is to play this game on a large display For that reason considerable time was spent considering the form of the video output Digital outputs like HDMI or DVI are fairly standard in new televisions and monitors HDMI and DVI have the ability to output tremendously high resolution video of 1920 x 1080 and 1920 x 1200 pixels respectively In addition to the digital video formats there is also NTSC video used in standard television coaxial cables and VGA for computer monitors After considering the multitude of video output formats a VGA interface was chosen for several reasons First the high definition digital formats are completely excessive for the type of video this system expects to output which are simple geometric shapes with solid colors The digital formats are also strictly specified so the time put into implementing and debugging the video output to conform to the strict standards would not be worth the benefits which this project will be unable to make use of anyway The VGA specifications are very similar to the NTSC protocol used for standard analog television sets with two differences One difference is that there are separate analog lines for each
37. e the current pixel is If the current pixel is a within a defined radius of the center that pixel is illuminated according to the corresponding paddle color And lastly the illumination of the puck is done in the same way as the paddles with a slight difference in that the x and y coordinates of the puck s center are passed from the NIOS II CPU via a bus instead of being detected by the camera When this is all done the state variable is set back to testl and the process begins anew Users should note that there are limitations on the camera and its refresh rate It is possible for the user to move the LED faster than the camera s refresh rate which results in a huge jump in the paddle s position This is because the time between the previous 15 position and the new position detected by the camera is so long This was exactly the problem that was described in the Video Input Hardware and really has no solution in hardware While it is possible to detect the huge jump in software and extrapolate some trajectory a straight line for example this was not done because of the additional complexity that such a scheme would introduce Video Output Hardware The VGA Controller is clocked at 25 MHz and provides the monitor with the information to be displayed on the screen The outputs of the module are on five lines VGA Red VGA Green VGA Blue VGA HSYNCH and VGA VSYNCH The VGA Controller module keeps track of incrementing and
38. ection end FREE freeze collision E CONST end COLLISION 4 if speed x positive flag Speed y positive flag begin 0 amp amp 0 amp amp freeze collision bounce down amp right if puck is below amp right of paddle if y diff gt 0 amp amp x diff gt 0 begin Speed x positive flag 1 Speed y positive flag 1 end bounce down amp lef else if y diff gt 0 begin Speed y positive end bounce up amp right if else if y diff lt 0 amp amp begin Speed x positive flag end else begin same direction end flag t if puck is amp amp x diff below amp left of paddle 0 1 puck is above amp right of paddle x diff gt 0 1 FREE E CONST freeze collision end if x speed 0 Tf lt abs x_diff do nothing else if abs x_diff lt 1 4 x_speed MIN_SPE ED y speed 0x0040 else if abs x diff x speed 0x0050 y Speed else X speed 0x0060 y Speed lt 8 0x0050 0x0060 64 ALL COLLISIONS DONE CHANGE SPEEDS if x speed x speed increase lt MAX SPEED 8 begin if x speed 0x0500 begin X speed x speed increase 2 end else X speed x speed increase end else X Speed MAX SPEE
39. end blacken all else on left side else if mVGA X gt 320 amp amp mVGA X 640 begin red lt 10 50000000000 blue lt 10 50000000000 green 10 b 0000000000 end end state lt testl end endcase end Apply black thresholding if Read DATA1 14 10 gt 5 b10110 Read DATA1 9 5 gt 5 b10110 Read DATA1 4 0 gt 5 b10110 begin Temp Read DATA1 lt 15 b111111111111111 end else begin 50 Temp_Read_DATA1 15 b000000000000000 end end BI End Paddle Detection amp Drawing Audio DAC module AUDIO DAC modul AUDIO DAC u9 Audio Side OAUD BCK AUD BCLK OAUD DATA AUD DACDAT OAUD LRCK AUD DACLRCK Control Signals iSrc Select SP ISP2 SP3 iCLK 18 A AUD CTRL CLK iRST N DLY RST 1 iSound Select Sound Select y End AUDIO DAC modul Sound Generation Hardware Speaker Control reg SP reg 23 0 DLY_cont reg SP2 reg 2 0 Sound Select reg 23 0 DLY cont2 reg SP3 reg 23 0 DLY cont3 always8 posedge CLOCK 50 begin if sound signal if datected turn on speaker begin DLY cont lt 0 end else begin if DLY cont 24 h00ffff play for 65535 cycles 50MHz begin DLY cont lt DLY_cont 1 SP lt 1 Sound_Select lt 0 end else begin SP lt 0 end end if collision_sound if datected gt turn
40. ents of the system to reach a known steady state before continuing The on off signal is asserted for example when a 16 sound effect is needed In the AUDIO DAC module a DDS system is used to generate sine waves of different freguencies based on a phase increments which is depend on the source select The foundation of the code was used from Teraic s TRDB camera s motion detection example and more design details can be found at http www terasic com tw cgi bin page archive pl Language English amp No 50 In extending the code multiple sounds for different circumstances with various frequencies were added This was accomplished by adding a source select bus to the AUDIO DAC module which controlled the phase increment Each source can play for different time intervals by having separate control lines for the on off signal For example when the puck reflects off of a border ten cycles of 10 KHz sine wave is generated but when the puck enters a goal a chime with increasing frequencies is played The duration of the tone was controlled by the on off signal which can be controlled precisely by using a 24 bit counter Because the sound generation hardware that is an input to the AUDIO DAC is clocked at 50 MHz asserting the on off signal for 50 million counts generates a one second tone In the case of the chime that is played when a player scores a goal four different thresholds were used for the 24 bit counter and during each threshold a di
41. ept Such a case would be possible only if the LED leaves the camera view or is turned off Once these steps are completed the state variable is updated to test2 State test2 is used to determine the surrounding pixels of the paddle centers which were recorded in state testl To do this the paddle center s x and y addresses have mVGA_X and mVGA Y subtracted and that difference is stored in registers DIFF X 1 DIFF Y 1 DIFF X 2 and DIFF Y 2 Unlike programming in sequential languages like C and Java Verilog cannot perform the calculations in states test1 and test2 in the same cycle because instructions are actually dedicated hardware on the DE2 board and happen concurrently at the clock edge with no knowledge of data dependencies In addition the puck s x and y addresses are also subtracted from the VGA x and y address and recorded The state variable is then set to test3 In state test3 the actual drawing of borders paddles and puck occur The borders are drawn by using absolute addresses of mVGA_X and mVGA Y where the border is a rectangle defined by the points 20 100 620 100 20 400 and 620 400 Please note that in the VGA coordinate system the Cartesian coordinate system has been reflected over the y axis or in other words the positive direction of y is down In drawing the paddles the previously calculated difference values are used to determine how far away from the center of the paddl
42. fferent source select value was used causing the AUDIO DAC to use phase increments corresponding to each of the different source selects The result is a chime that increases in frequency three times every 63 ms for a total 252 ms and it sounds quite good For a waveform of the output signals please see the RESULTS section In hindsight if I were to do the project again I would write the AUDIO DAC module from scratch rather than start with Terasic s code as a foundation The main reason is that the lookup table only has 48 elements because the original hardware only output a 1 KHz sine wave The sound output is very good when simply multiplying the frequency but in trying to create musical notes i e frequencies less than 1 KHz the DDS was limited by the number of A D values it had in the table and the output suffered as a result Miscellaneous Hardware The DE2 s on board 7 segment displays were used to indicate each player s current numerical score To do this a lookup table module was created which took a 4 17 bit input and output 7 bits The four bits represent 16 possible values ranging from 0x0 to Oxh and a lookup table maps each of the 16 values to a corresponding 7 bit pattern that make up alphanumeric outputs on the 7 segment display In addition to the 7 segment displays 18 general purpose red LEDs exist on the DE2 which were used during development to blink on and off depending on the specific need of the task The 7 segme
43. h like the Wii users were able to pick up a paddle and play the game with a very small learning curve I am extremely pleased to have undertaken this project as I was able to turn my interests in gaming into an academic endeavor which was both enlightening and educational 33 ACKNOWLEDGEMENTS There are some individuals to whom I am grateful in completing this project First I owe many thanks to Dr Bruce Land whose inputs and suggestions were vital to my progress I would like to thank Elissa Chin for all her support and for putting up with my lack of communication during the long hours of solitude spent in lab And lastly the facilities crew responsible for the maintenance of Phillips 238 digital lab has done a tremendous job in making my second home an enjoyable place 34 REFERENCES 1 VGA Specifications lt http web mit edu 6 111 www s2004 NEWKIT vga shtml gt 2 Fixed Point Arithmetic lt http instruct1 cit cornell edu courses ee476 Math index html gt 3 Elastic and Inelastic Collisions lt http hyperphysics phy astr gsu edu HBASF elacol html gt 4 Terasic TRDB_DC2 Camera Specifications and Documentation lt http www terasic com tw cgi bin page archive pl Language English amp No 50 gt 5 Altera Nios II CPU Specifications and Documentation lt http www altera com products ip processors nios2 ni2 index html gt 35 APPENDIX A Glossary of Terms Used Dynamics Physics engine
44. here upon reset of the current pixel has paddles Also calculate address and proximity wrapped back to the distance of the to the paddles and beginning current pixel from the puck center of the puck Figure 5 The state machine is clocked by the rising edge of 50 MHz clock and begins in the init state If at any time KEY 0 s pressed the state machine returns to the init state No action is taken in the init state except to set the state variable to test1 In the state test1 the goal is to record the most recently known location of the LEDs in each playing space Each cycle of the 50 MHz clock also increments the mVGA X and mVGA Y variables which have red green and blue values of mVGA R mVGA G and mVGA B Using this the values in mVGA R mVGA G and mVGA B are checked against the filtering threshold to determine the center of the LED Undoubtedly there will be multiple pixels who satisfy this condition and to avoid having a moving virtual paddle for a static LED a first satisfied scheme is utilized where one a fresh frame has started and a LED center has been detected the state machine does not 14 attempt to update the paddle center addresses until a new frame begins which is defined by mVGA X 20 and mVGA Y 20 For example in Figure 2 the algorithm would always identify the top left most pixel labeled 5 as the center of the paddle If no LED center is found the previous paddle locations are k
45. in the virtual air hockey game accompanied by sound Report Approved by Project Advisor Date Executive Summary This design project was inspired by my interest in games and gaming console design With the current generation of gaming consoles incorporating cameras microphones and motion sensors as inputs to the games it was decided that a similar approach would be used It takes a simple game like air hockey and incorporates image processing to mimic actual hand controlled motion of the on screen paddle The image processing accurately captures the velocities of the users movements to realistically affect the dynamics of the game The game utilizes sophisticated dynamics for controlling the puck movements as well as many low level hardware modules including video output audio Digital to Analog Conversion and image processing Since the VGA only has whole numbered pixel resolution 32 bit fixed point arithmetic allowed guick conversions of puck position between integer values and mixed fractional values A high resolution camera for the system used in conjunction with various digital image processing technigues such as dilating and eroding allowed accurate position detection for the paddles Originally I had envisioned implementing the game on a traditional microcontroller However the idea of using reconfigurable hardware was appealing in that future firmware upgrades could also potentially change the features of the hardware an
46. ionl r y_position y_position2 RIGHT WALL if y position lt 225 lt lt 8 RADIUS lt lt 8 y_position gt 285 lt lt 8 RADIUS lt lt 8 amp amp x_position gt RIGHT WALL lt lt 8 begin if speed x positive flag 1 begin if x speed MIN SPEED x speed 0x0040 Speed x positive flag 0 end IOWR ALTERA AVALON PIO DATA OUT7 BASE 1 end RIGHT GOAL if y position gt 225 lt lt 8 RADIUS lt lt 8 amp amp y position lt 285 8 RADIUS 8 amp amp x position gt RIGHT_WALL RADIUS 1 lt lt 8 begin Generate chim IOWR ALTERA AVALON PIO DATA OUT10 BASE 1 EFT PLAYER SCORED 1 EFT _SCORE if LEFT SCORE 10 game_began 0 end LEFT WALL if y_position lt 225 lt lt 8 RADIUS lt lt 8 y position gt 285 8 RADIUS 8 amp amp x position lt LEFT_WALL RADIUS 1 lt lt 8 begin if speed_x_positive_flag 0 begin if x_speed gt MIN_SP x speed 0x0040 Speed x positive flag 1 end IOWR ALTERA AVALON PIO DATA OUT7 BASE 1 end LEFT GOAL I ED if y position gt 225 lt lt 8 RADIUS lt lt 8 amp amp y position lt 285 lt lt 8 RADIUS lt lt 8 amp amp x position lt LEFT WALL lt lt 8 begin 61 Generate chim IOWR ALTERA AVALON
47. k 0x00000800 Oxo00008207 gt 1 PIO Parallel 1 0 000000820 OxOO000082f In1 PIO Parallel l O clk 0x00000830 Ox0000083f timer_0 Interval Timer clk 000000840 Ox00000825f 11 In2 PIO Parallel IO clk 0x00000860 Oxo000086f Out0 PIO Parallel O clk 0x00000870 Ox0000087f Out1 PIO Parallel lO clk 0x00000880 Ox0000088f Out2 PIO Parallel 1 0 clk 0200000890 Oxo000089f Out3 PIO Parallel l O clk 0x000008a0 Ox000008af Out4 PIO Parallel 1 0 clk 0x000008b0 Ox000008bf In3 PIO Parallel IO clk 0x000008c0 Ox000008cf In4 PIO Parallel O clk 0x000008d0 Ox000008df Outs PIO Parallel lO clk 0x000008e0 Ox000008ef Out6 PIO Parallel 1 0 clk 0x000008f0 Ox000008ff Out PIO Parallel l O clk 0x00000900 0x0000090f Outs PIO Parallel lO clk 0200000910 Oxo00009l1f Ind PIO Parallel l O clk 000000920 Oxo000092f Outs PIO Parallel l O clk 000000930 0x00000923f Out10 PIO Parallel 1 0 clk 000000940 Ox0000094f In6 PIO Parallel 1 0 clk 000000950 Oxo0000095f In PIO Parallel l O clk 0x00000960 0x0000096f In amp PIO Parallel lO clk 0x00000970 Oxo000097f In9 PIO Parallel IO clk 000000980 Oxo000098f Figure 6 The Nios II f has several advantages over the Nios II e economy and Nios II s standard in that it has a six stage pipeline to achieve greater throughput or instructions per second and also has single cycle hardware multiply and barrel shift operations something that is very useful for
48. k so that impossible conditions are avoided when possible However it is possible that the puck s velocity is such that in one time step it moves from near an object wall or paddle to overlapping the object and this is not checked prior to moving the puck This usually happens for only a single frame and is virtually undetectable by the human eye at game speeds The code will reflect the object in the appropriate direction assuming the point of collision to be where it should have been rather than where it currently is See APPENDIX E for implementation details There are rare instances where the puck can move completely through a paddle in one cycle of the main loop While it is possible for this to happen the occurrences are rare because the speed of the puck needs to be near the maximum allowed value and the user must be moving the paddle in the opposite direction at a high speed as well I decided that the complexity of detecting this corner case is not worth the payoff in the context of this project especially since there is no protection against the user moving the LED too fast for the camera and having the paddle jump discontinuously Future work may include exploring the many possible solutions for corner cases Physics Modeling The physics involved in air hockey is modeled in this game by keeping track of the puck s x and y velocities as well as calculating the paddles x and y velocities in real time The puck s movements are str
49. man player The results of applying the algorithm on the data in Figure 9 are shown below in Figure 10 Adjusted X Position Delta Calculated X Calculated X Sample Delta Sample Delta 1 0 26 45 2 0 27 45 3 76 28 64 4 76 29 64 5 76 30 64 6 76 31 64 7 46 32 64 8 46 33 83 9 46 34 83 10 21 35 83 11 21 36 AT 12 21 37 AT 13 21 38 48 14 21 39 48 15 57 40 48 16 57 41 23 17 64 42 23 18 64 43 23 19 64 44 23 20 23 45 45 21 23 46 45 22 23 AT 45 23 23 48 49 24 45 49 49 25 45 50 49 Figure 10 Starting Scoring amp Ending Rules In order to start a game both players must be ready To indicate this a start condition must be satisfied before the Nios II will populate the puck The starting condition is met by each player placing his or her paddle within a specified area on the 25 screen This area is highlighted by the display logic hardware and will remove the box when a signal from the Nios II indicates that the game has begun After asserting this logic line the Nios II will populate the puck in the middle of the table in the reach of both players In the course of play if the puck hits the goal white region on the east west walls the scoring condition is met and a point is awarded to the player opposite of the goal that was scored upon Afterwards the puck is re populated on the side of the player that was scored upon Debugging The debugging process was a conducted by utilizing the hardware s LED s and print statemen
50. ments along with a specific rhythm While the packaging and forms may be different the goals of these systems are all the same provide control input to the game through the user s physical motion or sounds instead of key presses The game input devices can be either digital in the case of games like Guitar Hero or analog like in Karaoke Revolution Air Hockey The game of air hockey adheres to fairly straightforward rules that can be modeled by a physics engine quite nicely The game can be represented on a two dimensional space from a bird s eye perspective which is also ideal for displaying relatively simple graphics The energy input to the system are typically all impulses which translates to a sudden change in the puck s acceleration or jerk and small amounts of friction and energy dissipation due to inelastic collisions will remove kinetic energy from the puck and slow it down The physics differ from elastic collisions like many billiard ball simulators One reason is that the mass of the paddle is considerably larger than the mass of the puck because the user holds onto the paddle In other words the conservation of momentum p m v is trickier to express assuming an extremely large mass of the paddle with a non completely elastic collision However aside from paddle puck collision math the overall behavior of the system like position and velocity can be modeled nicely in a 2 dimensional coordinate system RANGE OF SOLUTIONS
51. n int address x 2 2 address y 2 if if begi IO if el if if if Xx game_bega RIGHT_SCO address_ address IORD ALTERA AVALON PIO DATA IN3 BAS IORD ALTERA AVALON PIO DATA INA BAS x gt 135 amp amp address x lt 155 _y gt 240 amp amp address y lt 260 address x 2 gt 485 amp amp address x 2 505 n RI EFT game began n WR ALTI msg se msg ERA AVALON PIO DATA OUT9 BAS 0 _ SCORI msg 1 AY E P be en el be LEFT P gin IOWR ALTI delay coun while del delay co dummy delay_coun Fit the x_position y_position x_speed y_speed LEFT PLAY d se if gin IOWR ALTI delay coun while del delay co dummy Pi RIG ERA AVALON PIO DATA OUT10 BAS ERA AVALON PIO DATA OUT10 BAS ER SCORED ter 0 ay counter 1500000 untertt delay_counter ter 0 entire puck within border 0x01D600 RADIUS 8 0x6400 RADIUS lt lt 8 0x0000 0x0300 R SCORE P 0 HT PLAYER SCORED ter 0 ay counter 1500000 unter tt delay counter 55 address_y_2 gt 240 amp amp address_y_2 lt 260 delay counter 0 Fit the entire puck within border x position OxAA00 RADIUS lt lt 8 y
52. n the Ouartus II IDE For more information on how these work see http www altera com literature ug ug alt shift taps pdf The taps are used to perform two morphological image processing technigues called erode and dilate which fade away the edge of the foreground and background respectively The information is then used to compare against the next state of the shift register and if it can detect whether change motion has occurred or not If no motion has been detected the VGA output address going to the Nios II retains the value from the previous position Next a finite state machine was utilized in determining the location and drawing of the two paddles for many reasons One of the reasons is that a scheme is necessary to 13 manipulate the video memory only while the sync signals are asserted so that no video artifacts show Another reason is that the FSM provides a systematic way to detect motion in which the playing space which has been divided into two regions one for each paddle Use the figure below as a guide in following the FSM description While there are only a few number of states in the state machine the last state is fairly complex with a lot of parallel hardware so please review the following carefully o E E o Init test1 test2 test3 ww wr Calculate the distance Assert New Frame of the current pixel from llluminate the current if x and y coordinates the centers of the two pixel based on its Enter
53. nt displays are active low while the LEDs are active high As mentioned previously in the Sound Output Hardware section there is a Reset_Delay module on the board that detects the KEY 0 button press When this button is pressed three different delay lines are controlled each with its own time delay before it is asserted The delay values used by the Sdram Control module is approximately 41 9 ms the delay for the CCD_Capture RAW2RGB and AUDIO DAC modules are approximately 62 9 ms and the delay for the VGA Controller is 83 9 ms Game Dynamics Software A Nios II f core fast was used in implementing the game dynamics The Quartus II IDE has a built in module called the SOPC System On Programmable Chip Builder which takes care of generating the general purpose CPU out of your high level design requirements See the figure below for the specific SOPC Builder parameters 18 Clock Settings Target Device Family Cyclone II v Name Source MHz clk External 50 0 Use Con Module Name Description Clock Base End IRQ El cpu_0 Nios ll Processor instruction master Avalon Master clk data_master Avalon Master IRO O IRO 31 P jtag_debug_module Avalon Slave 0x00000000 Ox000007ff E sram_16bit_512k_0 SRAM 16Bit 512K P avalon_slave_0 Avalon Slave clk 0x00080000 OxOOOfffff El Icd Character LCD control slave Avalon Slave clk 0x00000810 Ox0000081f El jtag uart JTAG UART avalon_jtag_slave Avalon Slave cl
54. or Outputs Paddle Nios II CPU Audio Pl Positioning Game Dynamics DAC m Speaker Figure 4 Video Input Hardware The CCD camera uses a 25 MHz clock that is derived from the internal 50 MHz clock divided by two The module takes control inputs to start stop and reset the camera and outputs 10 bits of raw data on the mCCD DATA bus That bus is an input to the module RAW2RGB which then separates the raw camera information into red green and blue values in for each pixel position Note that the CCD camera code is provided by Terasic with no changes made More design details of the code can be found from Terasic at http www terasic com tw cgi bin page archive pl Language English amp No 50 The CCD camera s information is stored in on board the SDRAM memory The SDRAM contains 307 200 pixels of information per frame 640 x 480 but less than 60 percent of those pixels are used because the video that is generated is a 600 x 300 It would have been desirable to have the camera skip the unused video space so that each frame took only 58 6 percent of the time it actually takes However after thorough research and analysis it was determined that the TRDB CCD camera cannot be hacked to 12 display less information and using anther camera was not a realistic option As a result the data path of the camera s information and identifying the source was a source of performance constraint As
55. ough for my desired application To ensure that the game can be played in all types of lighting I decided to use colored LEDs as inputs for the game Unfortunately the sensitivity of photo capture is different from human eyes and the colors of LEDs are not easily distinguishable as recorded through the camera The following figure is an example of what a blue and yellow LED look likes through the camera with the blue LED on the left and yellow on the right Figure 1 Notice that the blue LED while having some blue in the fringes is almost completely white The yellow LED looks completely white and differentiating the two in a reliable manner could prove to be complex Instead of color the next choice for detection was to simply use light intensity tracking a certain level of whiteness an intense mixture of red green and blue light and splitting the playing space among the two players so that player 1 cannot move into player 2 s space on screen Figure 2 is an example of what the light intensity of an LED looks like up close with a value of zero being the lowest intensity black and five being the highest white NOOR EEE o o o i gt gt gt gt gt x o o o gt gt gt gt gt io o gt s gt gt lo o o gt gt a 3 gt 1 lo o o i gt 3 ni Epp Figure 2 One limitation of this approach is that dispersed light sources in the same camera space would need som
56. position 0x6400 RADIUS lt lt 8 x speed 0x0000 y speed 0x0300 RIGHT PLAYER SCORED 0 end IOWR ALTERA AVALON PIO DATA OUTO BASE msg IOWR ALTERA AVALON PIO DATA OUT7 BASE 0 IOWR ALTERA AVALON PIO DATA OUT8 BASE 0 Check the validity of the data valid IORD ALTERA AVALON PIO DATA IN1 BASE x position history 0 x positionl1 Prev left paddle x pos y position history 0 y positionl Prev left paddle y pos x position history 1 x position2 Prev right paddle x pos y position history 1 y position2 Prev right paddle y pos Paddle 1 position in int address x IORD ALTERA AVALON PIO DATA INO BASE address y IORD ALTERA AVALON PIO DATA IN2 BASE address x address x lt lt 8 Paddle 1 x position in fixed point address y address y lt lt 8 Paddle 1 y position in fixed point Paddle 2 position in int address x 2 IORD ALTERA AVALON PIO DATA IN3 BASE address y 2 IORD ALTERA AVALON PIO DATA INA BASE address x 2 address x 2 lt lt 8 Paddle 2 x pos in fixed point address y 2 address y 2 lt lt 8 Paddle 2 y pos in fixed point x position y position x position is 1 2 address x address y address x 2 y position2 address y 2 no change 0 Speed sqrt double x positionl x positionl y positionl y positionl abs x
57. position history abs x position history abs y position history 0 0 0 abs y position history 0 x_positionl amp amp y positionl x position history 0 y position history 0 begin if speed memory 1 0 begin 56 speed x x position history 0 x positionl Speed y y position history 0 y position Speed memory 1 100 end else Speed memory 1 end else begin speed x x position history 0 x positionl Speed y y position history 0 y position Speed memory 1 3000 end if x position history 1 x position2 amp amp y position history 1 y position2 begin if speed memory 2 0 begin speed x 2 x position history 1 x position2 speed y 2 y position history 1 y position2 Speed memory 2 100 end else speed memory 2 end else begin speed x 2 x position history 1 x position2 speed y 2 y position history 1 y position2 Speed memory 2 3000 end commented out because printf takes a loooong time will use LEDR and HEX0 7 instead printf x dAny dMnspeed d n address x address y speed IOWR ALTERA AVALON PIO DATA OUT2 BASE LEFT SCORE IOWR ALTERA AVALON PIO DATA OUT3 BASE RIGHT SCOR ax 7 E Speed x relevant left half 1 speed x speed x 2 Speed y relevant left half 1
58. resetting the horizontal and vertical synch values so that it outputs the correct sequence of horizontal and vertical sync pulses The inputs to the module are the red green and blue information we wish to output based on the red green and blue values stored at the x and y coordinate in SDRAM The red green and blue values we wish to output are set by the state machine discussed earlier and use a blue value for the air hockey table border white for the goals blue for player 1 s paddle white for player 2 s paddle yellow for the puck and black everywhere else There are also two white boxes that are necessary to satisfy the start game condition which will be covered further in the Starting Scoring amp Ending Rules section of the report Again these pixel values are only altered while the VGA HSYNCH and VGA VSYNCH lines are asserted Sound Output Hardware A phased locked loop PLL is used to take one of the FPGA s internal clocks of frequency 27 MHz and output a 18 4 MHz clock which is subsequently used as the audio control clock A Quartus II IDE wizard which generates PLL modules with a few high level design inputs was utilized to create the PLL The three other inputs into the audio module are a reset delay line an on off signal and a source select signal The reset delay signal is asserted by the Reset Delay module when KEY 0 or the system reset button is pressed The delay is to provide enough time for all compon
59. s shifting left by 8 but keeps the correct data type and to cast the result as an int to keep the 32 bits Therefore when displaying video of a puck whose address is 450 25 300 5 will result in the puck being at location 450 300 Puck Velocity Integration amp Position Calculation In each iteration of the Nios II main loop a simple integral is performed to determine the new position of the puck In performing this integral it is assumed that the main loop runs at a regular interval so that the time between each position update is constant To validate this assumption a simple exercise was conducted where the Nios II toggled a GPIO on the DE2 board each iteration of the main while loop The CPU s tight loop takes at 40 us with slight variance at times The worst observed variance was 48 us However the frequency of the variances was very low about 4 out of every 100 20 iterations With the worst possible variance being 20 but only occurring 4 of the time one can see that the variance is fairly insignificant With such low margins of error it was determined that this method of calculating integrals was acceptable Having established that a mostly constant time interval exists between position updates the integration is performed by simply adding the current velocity to the current position Of course collisions with the boundaries of the air hockey table as well as paddles and the goal conditions are checked prior to moving the puc
60. this project The default memory available to the Nios II is either SDRAM or M4K memory and the choice can be configured through the Nios II IDE project settings Since our project utilizes the SDRAM to store the CCD camera s data and M4K blocks are not sufficiently large enough to contain this code space Instead the Nios II instantiated for this project utilizes a 512k block of SRAM whose implementation was made available by Terasic in the module SRAM_ 16bit 512k 19 Fixed Point Arithmetic Fixed point arithmetic was used to represent non integer values In the Nios II architecture int values are 32 bit values so the top three bytes are used for the whole number value and the lower byte is used for fractional values The virtual decimal point was located between the first and second low order bytes and values to the right of the decimal represented one divided by two raised to the position s value see figure 7 Whole Whole Whole Fraction number number number o Decimal pt Figure 7 For example a hex value of 0x00000040 is 1 4 because there is no whole number value and the fraction value is 1 divided by two squared Conversion back to a rounded whole number basically a floor function is to shift the fixed point variable to the right 8 bits Conversion from integer would be to shift the value to the left 8 bits and conversion from a floating point value is to multiply the value by 256 0 same a
61. tiation is large but as the paddle moves faster the speed increases in larger step intervals This is to provide precise control at low speeds when users want to control the puck using finesse but can also take hard shots at high speeds The calibration for this was done over many trials and was largely subjective to what I felt was a good level of game control There was one design problem that surfaced during the testing the sampling rate of the paddle positions is so fast that the difference in the LED positions from the user s movements were registered as zero for a majority of the movement duration See Figure 9 below for one example of the perceived X position differences when moving the LED at a constant low speed Original X Position Delta Calculated X Calculated X Sample Delta Sample Delta 1 0 26 0 2 0 27 0 3 76 28 64 4 0 29 0 5 0 30 0 6 0 31 0 7 46 32 0 8 0 33 83 9 0 34 0 10 21 35 0 11 0 36 47 12 0 37 0 13 0 38 48 14 0 39 0 15 57 40 0 16 0 41 23 17 64 42 0 18 0 43 0 19 0 44 0 20 23 45 45 21 0 46 0 22 0 47 0 23 0 48 49 24 45 49 0 25 0 50 0 Figure 9 24 The problem was remedied by inserting logic to detect a lengthy period of zero movement before registering the speed as zero in this case 15 consecutive zeros This is not unreasonable since calculations are separated by about 40 us so 0 6 ms after user has stopped moving the game will register that the paddle is static which is virtually unnoticeable to the hu
62. ting off of the border The goal to play this game in most conditions was also met as testing in different lighting conditions showed no artifacts Of course the testing was carried out with the black paper below the camera and no other reflective objects in the view screen of the camera The game dynamics felt very natural even though some calibrations were purely subjective The approximations made for reflection angles were convincing for the players while not introducing too much complexity into the physics engine When the puck is traveling at high speeds there is an element of unpredictability in the reflection when striking the puck with the paddle which provides an experience just like in real air hockey There were conscious design decisions to not address certain corner cases such as paddles disappearing at one coordinate and reappearing at another or a puck traveling at high speeds going through a paddle These cases were ignored in an interest to keep the code relatively straightforward but some possible solutions were considered and discussed in the DESIGN AND IMPLEMENTATION section of the report The lack of accelerometers was somewhat noticeable as sometimes there were variances in the resulting puck speeds after collisions of seemingly similar speeds However the variances were on the order of 3 speed increments or 1 5 pixels per position update which is noticeable but certainly acceptable 3l FUTURE WORKS This project h
63. trol Hardware esses eene ener ener enne 13 Video Output Hardware seis Yu repete toe Leo toa een E seda sete Te AR nd 16 Sound O tput Hardware esee teer tee ea ee ded ANS e Rp na Een en eee Ra O AFU DDAN ARB9 16 Miscellaneous Hardware cei iine a suae c o tuae retia e ned Ren aede de go NR wn 17 Game Dynamics Software ieir n e ore e Ede eio ry FRYN eire d ee eiae dior oe 18 Fixed point Arithmetic ssssssssesseseeeeneee enne enne nnne 20 Puck Velocity Integration amp Position Calculation sese 20 Physics Modeling nette e ie EORR ERR DERE COR ENTER Eee FORD 21 Starting Scoring amp Ending Rules essere 25 Debugemg p P FA 26 uu 28 lunc aou 32 Conclusions 33 Acknowledgements oc cicccsssisssesssssncesssccecsversvenssntsnsesoessseetsdevnssdneessenssvenasesstes seessssneec eesessusss snvedesesees 34 P Oigglp E 35 Appendix A Glossary of Terms Used e eeeeee eee esee ee ee ee eren een setae etna tna stas stas eese ewon 36 Appendix B Hardware Schematics and Diagrams eeeee eene eee ee ee eee seen setas ea atta stta 37 Appendix C Virtual Air Hockey Photographs
64. ts as well subjective methods for the look and feel aspects The 18 red LEDs on the DE2 helped show the state of certain variables in real time and were a low cost method of debugging without introducing extra delays because it is completely done in hardware For more complex tasks that required more details print statements were used through the JTAG UART on the DE2 The print statements were extremely useful but they introduced some delay into the calculations that depend on constant time so they were avoided when possible Additionally I used my own judgment in determining what a realistic reaction to collisions was This included decisions like how much to increase the puck s speed based on how hard velocity you hit the puck This was fairly arbitrary because there is no known mass of the two objects and no good way to determine just how the energy is conserved Some interesting bugs were observed in the course of this project In my first try at VGA video through the FPGA I encountered problems where the pixel changes were not where I expected them to be This was a result of executing two calculations that needed to be done sequentially in the same state in the FSM That meant that while I wanted the code to be run one after the other they were actually being run simultaneously in hardware Another bug was seen which eventually led to the addition ofthe Freeze Collision flag The symptoms were erratic puck paddle collisions upon a
65. vant 1100 12 LED begin y Speed increase INCREASE 12 end else if abs speed y relevant 12000 13 LED begin y speed increase INCREASE 13 end else if abs speed y relevant 13000 14 LED begin y Speed increase INCREASE 14 end else if abs speed y relevant 14000 15 LED begin y Speed increase INCREASE 15 end else if abs speed y relevant 15000 16 LED begin y Speed increase INCREASE 16 end else if abs speed y relevant 30000 17 LED begin y speed increase INCREASE 17 end else 18 LED begin y Speed increase INCREASE 18 end if x_diff gt gt 8 x diff 58 y diff gt gt 8 y diff gt gt 8 lt 4 RADIUS 1 RADIUS 1 Radius 1 makes collision closer if freeze collision collision flag 1 DYNAMICS if notecountrr 200 slowing down puck movement begin if freeze collision 0 freeze collision Previous puck x and y positions x position history 2 x position y position history 2 y position if speed x positive flag 1 60 x_position x speed x coordinate of puck else X position x speed x coordinate of puck if speed y positive flag 1 y position y speed y coordinate of puck else y position y speed y coordinate of puck x diff left half 1 x position x positionl x position x position2 y diff left half 1 y position y posit
Download Pdf Manuals
Related Search
Related Contents
Sony VCL HG0737X User's Manual SICOR S.p.A. - LIFT COMPONENTS Installation Guide 循環器看護 早わかりチェックリスト Safety Angel Manual ング プ リ Goodman Mfg RT6332013r1 User's Manual le magazine 29 - mars 2011 T hank You… Copyright © All rights reserved.
Failed to retrieve file