Difference between revisions of "F19: Tower Defense in Space"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Grading Criteria)
 
(328 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[File:temp_logo.jpg|thumb|500px|caption|right|Logo]]
+
[[File:start_menu.jpg|thumb|500px|caption|right|Logo]]
  
== ABSTRACT ==
+
== Abstract==
My abstract goes here.<br />
+
This project involves creating and developing a video game where output is displayed on a LED matrix. Development of the relevant hardware/software components and modules was divided among 4 team members. Each team member lead or significantly contributed to the development of multiple components. The project was focused on not only technical skills, but team building as well, and working with others towards a common goal.
 +
 
 +
This project provides us hands-on experience using freeRTOS in a real application. Our objective is to apply what we have learned in class and develop a video game using our SJtwo Board. In this project, we create different tasks for different modules, such as a display task for displaying the game objects on LED matrix, a tower task for detecting nearby enemies and shoot them, a stage task to manage each game stage etc. We need to use both cooperative scheduling and preemptive scheduling technique to make this video game run efficiently. In order to make this game run in a particular sequence, we also need to synchronize and sequentialize each task by setting the task priorities carefully and using binary semaphore correctly. <br />
 
<br />
 
<br />
  
== INTRODUCTION AND OBJECTIVES ==
+
== Introduction and Objectives ==
 
+
[[File:AlienInvasion.jpeg|300px|thumb|right|Alien Invasion]]
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
+
Like most traditional tower defense games, the player needs to defend our planet from the invasion of aliens. The gameplay can be split into 2 phases, <b>Combat Phase</b> and <b>Intermission Phase</b>. During the intermission phase, the player can place different kinds of towers strategically that will attack the invading aliens from entering into our homeland by shooting the enemies. During the combat phase, spaceships follow the path and try to land on our planet. If any enemy spaceship reaches the end of the path, then the player loses. If there are no more spaceships remaining in a wave, the player can build a stronger tower that has a longer attack range and can shoot a more powerful laser to the spaceships in the next wave. The player wins the game after surviving 5 waves of attack.
|- style="vertical-align: top;"
 
! colspan="5" style="background:#000000;" |  
 
<span style="color:#FFFFFF"> RC CAR OBJECTIVES </span>
 
|-
 
! style="text-align: left;" |
 
<br />  
 
<br />  
 
<br />  
 
<br />  
 
|}
 
 
 
 
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
|- style="vertical-align: top;"
 
! colspan="5" style="background:#000000;" |
 
<span style="color:#FFFFFF"> TEAM OBJECTIVES </span>
 
|-
 
! style="text-align: left;" | 
 
*
 
* <br />
 
*  <br />
 
* <br />
 
*  <br />
 
*  <br />
 
|}
 
 
 
  
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
+
This game can be separated into 4 different modules:
|- style="vertical-align: top;"
+
#<b>Game Logic</b>: SJtwo Board - handles the game logic. (For example: detect and shoot nearby enemies, switch between intermission phase and combat phase)
! colspan="5" style="background:#000000;" |
+
#<b>Display</b>: Adafruit 64x64 LED matrix - displays the animation of the game.
<span style="color:#FFFFFF"> CORE MODULES OF TOWER DEFENSE</span>
+
#<b>Gamepad Controller</b>: The input of this game. The gamepad controller consists of a joystick and two buttons. The player can use the joystick to move the cursor and decide where to place the towers. After that, the user needs to press the black button to select and confirm the location of the towers. If the player knows that he/she has made a mistake in the middle of the game and will eventually lose the game, the player can press the red button and restart the game.
|-
+
#<b>Sound</b>: MP3 Decoder and speaker. Players can enjoy cool music during the game. This is done on an additional SJtwo board, which will play the song on repeat.
! scope="col"  style="text-align: left;" | 
 
* <span style="color:#008000">LED Matrix</span>
 
* <span style="color:#008000">User Input</span>
 
* <span style="color:#36c">Game Logic</span>
 
* <span style="color:#FF8C00">Hardware</span> <br />
 
|}
 
 
 
 
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
|- style="vertical-align: top;"
 
! colspan="5" style="background:#000000;" |
 
<span style="color:#FFFFFF"> PROJECT MANAGEMENT ADMINISTRATION ROLES </span>  
 
|-
 
! style="text-align: left;" | 
 
* <span style="color:#000000">Team Lead</span> <br />
 
* <span style="color:#808080">Finance Manager</span> <br />
 
* <span style="color:#808080">Git Repository Manager</span> <br />
 
* <span style="color:#808080">Wiki Report Manager</span> <br />
 
* <span style="color:#808080">Bill of Materials Manager</span> <br />
 
|}
 
  
 +
== Team Members ==
  
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
Line 79: Line 36:
 
* [Ryan Zelek]
 
* [Ryan Zelek]
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* '''Team Lead'''<br />
+
'''Team Lead'''<br />
* <span style="color:#808080">a role</span> <br />
 
* <span style="color:#808080"></span> <br />  
 
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* <span style="color:#FF8C00"></span> <br />  
+
* <span style="color:#FF8C00"></span>Game Design Lead<br />  
* <span style="color:#696969"></span> <br /> 
 
* <span style="color:#8A2BE2 "></span> <br /> 
 
  
 
|-
 
|-
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
 
! scope="row" style="text-align: left;" |  
 
! scope="row" style="text-align: left;" |  
* [Zach Smith]
+
* [https://www.linkedin.com/feed/ Zach Smith]
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
 +
Git Repo Manager<br /> 
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* <span style="color:#EE82EE"></span> <br />
+
* <span style="color:#EE82EE"></span>Hardware Design Lead<br />
* <span style="color:#8A2BE2 "></span> <br /> 
 
* <span style="color:#FF8C00"></span> <br /> 
 
 
   
 
   
 
|-
 
|-
Line 102: Line 54:
 
* [Chong Hang Cheong]
 
* [Chong Hang Cheong]
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* <span style="color:#808080"></span> <br />
+
Wiki Report Manager<br/>  
* <span style="color:#808080"></span> <br />  
 
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* <span style="color:#008000"></span>
+
* <span style="color:#008000"></span>LED Matrix API<br />
* <span style="color:#696969"></span> <br /> 
 
* <span style="color:#8A2BE2 "></span> <br />
 
  
 
|-
 
|-
Line 114: Line 63:
 
* [Polin Chen]
 
* [Polin Chen]
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
 +
Bill of Materials Manager<br />
 
| style="text-align: left;" |   
 
| style="text-align: left;" |   
* <span style="color:#008000"></span> <br />
+
* <span style="color:#008000"></span>Joy Sticker && Decoder API<br />
* <span style="color:#EE82EE"></span> <br /> 
 
* <span style="color:#8A2BE2 "></span> <br /> 
 
  
 
|}
 
|}
 
<br />
 
<br />
  
== SCHEDULE ==
+
== Schedule ==
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
{| class="wikitable" style="margin-left: 0px; margin-right: auto;"
 
! colspan="5" style="background:#000000;" |  
 
! colspan="5" style="background:#000000;" |  
Line 140: Line 88:
 
! scope="row"| 10/15/19
 
! scope="row"| 10/15/19
 
|  
 
|  
* Share team contact information <br \>
+
* Share team contact information<br>
* Create Git Repository <br \>
+
* Create Git Repository<br>
* Set up Slack <br \>
+
* Set up group Slack channel<br>
* Invite Preet to Slack <br \>
+
* Invite Preet to Slack<br>
* Establish Code Guidelines and Standards <br \>
+
* Establish Code Guidelines and Standards<br>
 
|  
 
|  
* <span style="color:#008000">Complete</span> <br />
+
* <span style="color:green">Complete</span> <br>
* <span style="color:#008000">Complete</span> <br />
+
* <span style="color:green">Complete</span> <br>
* <span style="color:#008000">Complete</span> <br />
+
* <span style="color:green">Complete</span> <br>
* <span style="color:#008000">Complete</span> <br />
+
* <span style="color:green">Complete</span> <br>
* <span style="color:#008000">Complete</span> <br />
+
* <span style="color:green">Complete</span> <br>
  
 
|-
 
|-
Line 156: Line 104:
 
! scope="row"| 10/22/19
 
! scope="row"| 10/22/19
 
|  
 
|  
* Identify hardware components (BOM)<br />
+
* Identify major hardware components (BOM)<br />
 
* Begin purchasing major items<br />
 
* Begin purchasing major items<br />
 
* Finalize game architecture<br />
 
* Finalize game architecture<br />
 +
* Have Git Repo Setup<br/>
  
 
|  
 
|  
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
 +
* <span style="color:green">Complete</span> <br />
  
 
|-
 
|-
Line 169: Line 119:
 
! scope="row"| 10/29/19
 
! scope="row"| 10/29/19
 
|  
 
|  
* Solidify individual roles and responsibilities <br />
+
* Solidify individual roles and responsibilities<br/>
* Begin implementing basic code structure<br />
+
* Establish baseline software architecture design and guidelines going forward<br/>
 
 
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
 
 
  
 
|-
 
|-
 
! scope="row"| 4
 
! scope="row"| 4
 
! scope="row"| 11/5/19
 
! scope="row"| 11/5/19
|
 
* <span style="color:#000000">Interface the software with the hardware</span>
 
 
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
'''Kelvin'''
 
+
* Verify functionality of LED matrix and gather resources for further understanding<br/>
 +
|
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
  
 
|-
 
|-
Line 191: Line 139:
 
! scope="row"| 11/12/19
 
! scope="row"| 11/12/19
 
|  
 
|  
* <span style="color:#000000">First hardware design implementation complete</span>
+
'''Kelvin'''
 
+
* Find out feasibility of creating an LED matrix driver in C<br/>
 
+
'''Polin'''
 +
* Have APIs ready for joystick and buttons<br/>
 +
'''Ryan'''
 +
* Have basic user interface for the game displayed through serial port<br/>
 +
'''Zach'''
 +
* First controller PCB design complete<br/>
 +
* Specify any remaining hardware components and coordinate purchase<br/>
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
<br/>
 
+
* <span style="color:green">Complete</span><br/>
 +
<br/>
 +
* <span style="color:green">Complete</span><br/>
 +
<br/>
 +
* <span style="color:green">Complete</span><br/>
 +
<br/>
 +
* <span style="color:green">Complete</span><br/>
 +
* <span style="color:green">Complete</span><br/>
  
 
|-
 
|-
Line 202: Line 163:
 
! scope="row"| 11/19/19
 
! scope="row"| 11/19/19
 
|  
 
|  
* <span style="color:#008000">First implementation of individual subsystems complete</span>
+
'''Kelvin'''
* <span style="color:#008000">Send out for fabrication</span>
+
* Complete baseline API for LED matrix<br />
 +
'''Polin'''
 +
* Determine feasibility of MP3 decoding and integration into system
 +
'''Ryan'''
 +
* Complete first pass at basic tower defense level with straight pathway
 +
'''Zach'''
 +
* Controller PCB sent out for fabrication<br />
 +
* Design break-out PCB for LED matrix + IO expander />
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
<br/>
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
 
+
<br/>
 
+
* <span style="color:green">Complete</span> <br />
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
 +
* <span style="color:green">Complete</span> <br />
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
 
! scope="row"| 11/26/19
 
! scope="row"| 11/26/19
 
|  
 
|  
* <span style="color:#000000">Integration of major subsystems</span>
+
'''Kelvin'''
 
+
* LED matrix driver should be reviewed and complete<br/>
 +
'''Polin'''
 +
* Work with '''Zach''' to identify remaining hardware components and, if applicable, MP3 decoder requirements<br/>
 +
'''Ryan'''
 +
* Work with '''Kelvin''' to integrate his API into the game<br/>
 +
* Game should be running with LED matrix display involvement<br/>
 +
* Advanced game logic design/implementation is near feature complete<br/>
 +
'''Zach'''
 +
* PCB assembled and tested. Problems identified and solutions proposed<br/>
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
<br/>
 
+
* <span style="color:green">Complete</span> <br />
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
 +
* <span style="color:green">Complete</span> <br />
 +
* <span style="color:green">Complete</span> <br />
 +
<br/>
 +
* <span style="color:green">Complete</span> <br />
  
 
|-
 
|-
Line 223: Line 212:
 
! scope="row"| 12/3/19
 
! scope="row"| 12/3/19
 
|  
 
|  
* <span style="color:#008000">Testing and Validation </span>
+
* Complete game testing and validation<br/>
 
+
* Critical bugs (software AND hardware) identified and a clear path towards closure has been identified<br/>
 
 
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
* <span style="color:green">Complete</span> <br />
 
+
* <span style="color:green">Complete</span> <br />
  
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
 
! scope="row"| 12/10/19
 
! scope="row"| 12/10/19
|
 
* <span style="color:#008000"> Reserve time for debugging issues </span>
 
* <span style="color:#008000"> Identify and fix critical bugs (hardware and software) </span>
 
* <span style="color:#008000"> Finish any optimizations and visualization features </span>
 
 
 
|
 
|
* <span style="color:#008000">Incomplete</span> <br />
+
* Continuation of previous week activities (bug fixes, etc)
* <span style="color:#008000">Incomplete</span> <br />
+
* Implement any potential optimizations and/or expansions
* <span style="color:#008000">Incomplete</span> <br />
+
|
 
+
* <span style="color:green">Complete</span> <br />
 +
* <span style="color:green">Complete</span> <br />
  
 
|}
 
|}
 
<BR/>
 
<BR/>
  
== BILL OF MATERIALS (GENERAL PARTS) ==
+
== Bill of Materials ==
 
{| class="wikitable"  
 
{| class="wikitable"  
 
! colspan="5" style="background:#000000;" |  
 
! colspan="5" style="background:#000000;" |  
<span style="color:#FFFFFF"> MICRO-CONTROLLERS </span>  
+
<span style="color:#FFFFFF"> Top Level </span>  
 
|-
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
Line 261: Line 245:
 
COST PER UNIT (USD)
 
COST PER UNIT (USD)
 
|-
 
|-
|  
+
| <s>'''32x64 RGB LED Matrix'''</s>
* '''Micro-controller'''
+
| <s>[https://www.sparkfun.com/products/14718]</s>
|  
+
| <s>2</s>
* LPC 1758 '''(Purchased from Preet Kang)
+
| <s>$49.95</s>
|
+
|-
* 5
+
| <s> ''' 64x64 RGB LED Matrix'''</s>
|  
+
| <s> [https://www.sparkfun.com/products/14824 Sparkfun] </s>
* $80.00
+
| <s> 1 </s>
 +
| <s> $79.95 </s>
 +
|-
 +
| <s> '''NovaeLED 64x64 RGB LED Matrix (2-Pack)''' </s>
 +
| <s> [https://www.amazon.com/gp/product/B07LFJ73GQ/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 Amazon] </s>
 +
| <s> 1 </s>
 +
| <s> $80.99 </s>
 +
|-
 +
| '''64x64 RGB LED Matrix'''*
 +
| [https://www.adafruit.com/product/3649 Adafruit]
 +
| 1
 +
| $104.07
 +
|-
 +
| '''5V 4A PSU'''
 +
| -
 +
| 1
 +
| FREE
 +
|-
 
|}
 
|}
  
Line 274: Line 275:
 
{| class="wikitable"  
 
{| class="wikitable"  
 
! colspan="5" style="background:#000000;" |  
 
! colspan="5" style="background:#000000;" |  
<span style="color:#FFFFFF"> RC CAR </span>  
+
<span style="color:#FFFFFF"> Breakout Board PCB** </span>  
 
|-
 
|-
 +
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 +
Item #
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
PART NAME
 
PART NAME
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
PART MODEL & SOURCE
+
PART SOURCE
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
QUANTITY
 
QUANTITY
Line 285: Line 288:
 
COST PER UNIT (USD)
 
COST PER UNIT (USD)
 
|-
 
|-
|  
+
! scope="row"| 1
* '''RC Car'''
+
| IC REG LINEAR LD1117S33CTR
|  
+
| [https://www.digikey.com/product-detail/en/stmicroelectronics/LD1117S33CTR/497-1241-1-ND/586241 DIGIKEY]
[https://www.amazon.com/Traxxas-Slash-2-4GHz-Radio-Battery/dp/B01DU474B0 Traxxas 1/10 Slash 2WD RTR with 2.4GHz Radio]
+
| 5
|  
+
| $0.351
* 1
+
|-
|  
+
! scope="row"| 2
* $205.99
+
| MHS16N-ND 16POS CONN 2.54MM
 
+
| [https://www.digikey.com/product-detail/en/3m/N3408-6302RB/MHS16N-ND/1239801 DIGIKEY]
 +
| 2
 +
| $2.60
 +
|-
 +
! scope="row"| 3
 +
| CAP CER 0.1UF 25V X7R 1206
 +
| [https://www.digikey.com/product-detail/en/avx-corporation/12063C104JAT2A/478-11943-1-ND/8573579 DIGIKEY]
 +
| 5
 +
| $0.221
 +
|-
 +
! scope="row"| 4
 +
| CAP CER 10UF 16V X5R 1206
 +
| [https://www.digikey.com/product-detail/en/taiyo-yuden/EMK316BJ106MD-T/587-4881-1-ND/6563724 DIGIKEY]
 +
| 5
 +
| $0.202
 +
|-
 +
! scope="row"| 5
 +
| RES SMD 470 OHM 1% 1/4W 1206
 +
| [https://www.digikey.com/product-detail/en/te-connectivity-passive-product/CRG1206F470R/A106077CT-ND/3477734 DIGIKEY]
 +
| 10
 +
| $0.0267
 +
|-
 +
! scope="row"| 6
 +
| PTC RESET FUSE 24V 500MA 1206
 +
| [https://www.digikey.com/product-detail/en/bel-fuse-inc/0ZCJ0050AF2E/507-1803-1-ND/4156312 DIGIKEY]
 +
| 10
 +
| $0.1588
 
|-
 
|-
|
+
! scope="row"| 7
* '''Lithium-Ion Battery'''
+
| CONN SOCKET 40POS 0.1 TIN PCB
|  
+
| [https://www.digikey.com/product-detail/en/samtec-inc/ESQ-120-14-T-D/SAM11108-ND/6693975 DIGIKEY]
* [https://www.amazon.com/Traxxas-7600mAh-7-4V-2-Cell-Battery/dp/B00S1R0VEY/ref=pd_bxgy_img_2/144-5345940-5723349?_encoding=UTF8&pd_rd_i=B00S1R0VEY&pd_rd_r=e09ce3bf-3d35-11e9-b225-a780b44e51f2&pd_rd_w=VRlhQ&pd_rd_wg=VQ7ho&pf_rd_p=6725dbd6-9917-451d-beba-16af7874e407&pf_rd_r=0MECMTYSG4H3SDRR4GR8&psc=1&refRID=0MECMTYSG4H3SDRR4GR8 Traxxas 7600mAh 7.4V 2-Cell 25C LiPo Battery]
+
| 2
|  
+
| $5.03
* 1
 
|  
 
* $74.95
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 8
* '''Battery Charger'''
+
| Manufacturing x 5 boards *
|  
+
| [https://jlcpcb.com/ JLCPCB]
* [https://www.amazon.com/Traxxas-2970-EZ-Peak-Charger-Identification/dp/B00OAFYLJC/ref=pd_bxgy_img_3/144-5345940-5723349?_encoding=UTF8&pd_rd_i=B00OAFYLJC&pd_rd_r=e09ce3bf-3d35-11e9-b225-a780b44e51f2&pd_rd_w=VRlhQ&pd_rd_wg=VQ7ho&pf_rd_p=6725dbd6-9917-451d-beba-16af7874e407&pf_rd_r=0MECMTYSG4H3SDRR4GR8&psc=1&refRID=0MECMTYSG4H3SDRR4GR8 Traxxas 2970 EZ-Peak Plus 4-Amp NiMH/LiPo Fast Charger with iD Auto Battery Identification]
+
| 1
|  
+
| $29.81
* 1
 
|  
 
* $47.95
 
 
|}
 
|}
 
<BR/>
 
 
== <font color="696969"> HARDWARE INTEGRATION PCB </font> ==
 
 
=== <font color="696969"> Hardware Design </font> ===
 
[[File:RUN DBC PCB layout.jpeg |thumb| center | 800px|RunDBC PCB]]
 
 
 
The hardware integration PCB was designed with two goals:  <br>
 
 
'''1. Minimize the footprint of the onboard electronics''' <br>
 
'''2. Minimize the chances of wires disconnecting, during drives'''  <br>
 
 
To accomplish these goals,
 
 
The board consisted of 4 layers:
 
 
'''Signal''' <br>
 
'''3.3V''' <br>
 
'''5.0V''' <br>
 
'''GND''' <br>
 
 
=== <font color="696969"> Technical Challenges </font>  ===
 
 
 
==== <font color="696969"> Design </font> ====
 
* Balancing priorities between HW design and getting a working prototype
 
  
  
==== <font color="696969"> Assembly </font> ====
 
* Wireless antenna connector on master board not accounted for in footprint, it may have to be removed to avoid interference with one connector.
 
 
=== <font color="696969"> Bill Of Materials </font> ===
 
 
{| class="wikitable"  
 
{| class="wikitable"  
! colspan="5" style="background:#696969;" |  
+
! colspan="5" style="background:#000000;" |  
<span style="color:#FFFFFF"> HARDWARE INTEGRATION PCB </span>  
+
<span style="color:#FFFFFF"> Gamepad PCB** </span>  
 
|-
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> PART NAME </span>
+
Item #
 +
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 +
PART NAME
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> PART MODEL </span>
+
PART SOURCE
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> QUANTITY </span>
+
QUANTITY
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> COST PER UNIT (USD) </span>
+
COST PER UNIT (USD)
 
|-
 
|-
|  
+
! scope="row"| 1
* '''CAN Transceiver'''
+
| Analog 2-axis Thumb Joystick w/ select button
|  
+
| [https://www.amazon.com/gp/product/B00NAY2Q6O/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 Amazon]
* [https://www.digikey.com/product-detail/en/texas-instruments/SN65HVD230DR/296-11654-2-ND/404367 SN65HVD230-SOIC8]
+
| 1
|  
+
| $7.67
* 5
 
|  
 
* $2.38
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 2
* '''Buzzer'''
+
| SAM8205-ND 10POS 1.27MM
|  
+
| [https://www.digikey.com/product-detail/en/samtec-inc/EHF-105-01-L-D/SAM8205-ND/1106564 DIGIKEY]
* [https://www.digikey.com/products/en?keywords=CEM-1203 BUZZER-CEM-1203]
+
| 5
|  
+
| $3.38
* 2
 
|  
 
* $0.83
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 3
* '''Buzzer Switch'''
+
| LED GREEN 1206 SMD
|  
+
| [https://www.digikey.com/product-detail/en/lite-on-inc/LTST-C150GKT/160-1169-1-ND/269241 DIGIKEY]
* [https://www.digikey.com/product-detail/en/micro-commercial-co/MMBT2222A-TP/MMBT2222ATPMSTR-ND/717279 MMBT2222A-TP]
+
| 5
|  
+
| $0.24
* 1
 
|  
 
* $0.15
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 4
* '''3.3V Regulator'''
+
| LED RED 1206 SMD
|  
+
| [https://www.digikey.com/product-detail/en/lite-on-inc/LTST-C150CKT/160-1167-1-ND/269239 DIGIKEY]
* [https://www.digikey.com/product-detail/en/stmicroelectronics/LDL1117S33R/497-17239-1-ND/7102079 LDL1117S33R]
+
| 5
|  
+
| $0.257
* 1
 
|  
 
* $0.46
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 5
* '''5V Regulator'''
+
| RES 1K OHM 1% 1/2W 1206 SMD
|  
+
| [https://www.digikey.com/product-detail/en/stackpole-electronics-inc/RNCP1206FTD1K00/RNCP1206FTD1K00CT-ND/2240675 DIGIKEY]
* [https://www.digikey.com/products/en?keywords=LM1085IS-12 LM1085IS-12/NOPB-ND]
+
| 5
|  
+
| 0.0358
* 1
 
|  
 
* $2.36
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 6
* '''Red LED'''
+
| CAP CER 0.1UF 50V X7R 1206
|  
+
| [https://www.digikey.com/product-detail/en/kemet/C1206C104K5RAC7800/399-C1206C104K5RAC7800CT-ND/411524 DIGIKEY]
* [http://www.kingbrightusa.com/category.asp?catalog_name=LED&category_name=KCSOT-23%20SMD%20LED&page=1 LED-0603]
+
| 5
|  
+
| $0.088
* 1
 
|  
 
* $-.--
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 7
* '''Diode'''
+
| 12x12x7.3mm Tactile Push Button w/ cap (pack of 25)
|  
+
| [https://www.amazon.com/gp/product/B01NCQVGLC/ref=ppx_yo_dt_b_asin_title_o00_s01?ie=UTF8&psc=1 Amazon]
* [https://www.digikey.com/product-detail/en/diodes-incorporated/S1AB-13-F/S1AB-FDITR-ND/751512 Diode]
+
| 1
|  
+
| $7.89
* 1
 
|  
 
* $0.32
 
 
 
 
|-
 
|-
|  
+
! scope="row"| 8
* '''100uF Capacitor'''
+
| Manufacturing x 5 boards *
|  
+
| [https://jlcpcb.com/ JLCPCB]
* [https://www.digikey.com/product-detail/en/kemet/C1206C104KARACTU/399-4674-1-ND/992199 SMD 603 100uF Capacitor]
+
| 1
|  
+
| $14.21
* 1
+
|}
|  
 
* $0.44
 
  
|-
 
|
 
* '''10uF Capacitor'''
 
|
 
* [https://www.digikey.com/product-detail/en/kemet/C1206C104KARACTU/399-4674-1-ND/992199 SMD 603 10uF Capacitor]
 
|
 
* 1
 
|
 
* $0.44
 
  
|-
 
|
 
* '''4.7uF Capacitor'''
 
|
 
* [https://www.digikey.com/product-detail/en/kemet/C1206C104KARACTU/399-4674-1-ND/992199 SMD 603 4.7uF Capacitor]
 
|
 
* 1
 
|
 
* $0.44
 
  
|-
+
<nowiki>*</nowiki> Shipping and tax included in value shown in the cost per unit column <br>
|
+
<nowiki>**</nowiki> Only parts that were purchased are displayed. <br>
* '''1uF Capacitor'''
 
|
 
* [https://www.digikey.com/product-detail/en/kemet/C1206C104KARACTU/399-4674-1-ND/992199 SMD 603 1uF Capacitor]
 
|
 
* 1
 
|
 
* $0.44
 
 
 
|-
 
|
 
* '''10K Resistor'''
 
|
 
* [https://www.digikey.com/product-detail/en/stackpole-electronics-inc/CSR0603FKR250/CSR0603FKR250TR-ND/1742486 SMD 603 10K Resistor]
 
|
 
* 1
 
|
 
* $0.44
 
  
|-
 
|
 
* '''5.1K Resistor'''
 
|
 
* [https://www.digikey.com/product-detail/en/stackpole-electronics-inc/CSR0603FKR250/CSR0603FKR250TR-ND/1742486 SMD 603 5.1K Resistor]
 
|
 
* 1
 
|
 
* $0.44
 
 
|-
 
|
 
* '''1K Resistor'''
 
|
 
* [https://www.digikey.com/product-detail/en/stackpole-electronics-inc/CSR0603FKR250/CSR0603FKR250TR-ND/1742486 SMD 603 1K Resistor]
 
|
 
* 1
 
|
 
* $0.44
 
|}
 
 
<HR>
 
 
<BR/>
 
<BR/>
  
== CAN NETWORK ==
+
== Game Design ==
 +
=== <font color="000000"> Game Rules </font> ===
 +
Gameplay is split into 2 phases: <br>
 +
<b>Intermission</b> - Player sets up tower locations <br>
 +
<b>Combat</b> - Player watches round unfold <br>
  
In order
+
During the <b>Intermission Phase</b>: <br>
 +
#The player places towers strategically around the enemy path. <br>
 +
#The number of towers is fixed per round <br>
 +
#Towers can only be placed in marked areas that do not lie on a path <br>
 +
#The built-in software will find a valid tower location and move the cursor there automatically according to joystick input. <br>
 +
#There are 5 types of towers (increasing damages, ranges, and of different colors). Each tower type depends on the current wave.<br>
  
 +
During the <b>Combat Phase</b>: <br>
 +
#Enemies will enter the gameplay area at one end of the path and attempt to reach the other end <br>
 +
#Towers will automatically engage enemies when they come within range <br>
 +
#Towers shoot until the enemy is either dead or out of range <br>
 +
#Tower proximity is 8 directions (top, bot, left, right, top-right, top-left, bot-left, bot-right) and 1 unit (not necessarily 1 pixel) away <br>
 +
#Enemies that reach the end of path while being alive will result in losing the game. <br>
 +
#If any spaceship reaches the end of the path, the player loses and the game ends <br>
 +
#The round is over when the player loses or a set number of enemies have been defeated. <br>
 +
<br>
  
=== Hardware Design ===
+
[[File:combatPhase_0.JPG|300px|thumb|right|Dashboard (Combat Phase)]]
During
 
  
[[File:RUN DBC can chip sch.png | thumb |left| 200px| Electrical Pinout]]
+
There will be a <b>dashboard</b> on the LED matrix that displays basic UI information: <br>
[[File:RUN DBC can chip pinout.png | thumb |center| 200px| CAN Transceiver]]
+
<b>Intermission Phase:</b>
 +
#Time until combat phase <br>
 +
#Current wave number <br>
 +
#Number of towers left that you can still place <br>
 +
<b>Combat Phase:</b>
 +
#Current wave number <br>
 +
#Number of enemies still remaining in the current wave<br>
  
<br>
+
=== <font color="000000"> Game Objectives </font> ===
<br>
+
#There are 5 waves (rounds) total. <br>
<br>
+
#In each round, enemies in various amounts, groupings, and health levels (armor) pass through the path. <br>
 +
#If any enemies reach the end of the path, then the user loses. <br>
 +
#After each round, the user will be able to place more towers which are stronger and can shoot farther. <br>
 +
#Each round will have waves of enemies that are more difficult to stop. <br>
 +
#The user needs to carefully place their towers such that it will have a maximum number of opportunities to shoot at the enemies. <br>
 +
#The trick is that the user will need to preserve early level towers, otherwise they will not have enough room to place the high level towers in the optimal location. <br>
  
We used
+
=== <font color="000000"> How To Play </font> ===
  
[[File:system_block_diagram.png | thumb | center | 900px| Design of Run DBC Autonomous Car]]
+
The gamepad controller consists of a joystick and two buttons.  
 +
*Joystick - move the cursor and decide where to place the towers.
 +
*Black button - select and confirm the location of the towers.
 +
*Red button - restart the game (If the player knows that he/she has made a mistake in the middle of the game and will eventually lose the game, the player can press the red button and restart the game.)
  
 +
During the <b>Intermission Phase</b>: <br>
 +
# The player places towers strategically around the enemy path by using the joystick to move the cursor and pressing the black button to select the location of the towers.
 +
# The player needs to place all remaining towers under 45 seconds.
 +
During the <b>Combat Phase</b>: <br>
 +
# Cheer on your towers and watch them defend Earth from the alien invasion!
  
== <font color="green"> ANDROID MOBILE APPLICATION </font> ==
+
== <font color="000000"> Hardware Design - Electrical </font> ==
  
=== <font color="green"> Software Design </font> ===
+
=== <font color="000000"> Overview </font> ===
Development of the
 
  
 +
At a high level hardware integration requirements fell into two categories: <br>
  
 +
'''1.''' Reduce risk of unreliable cable connections and eliminate possibility of damage to components through unexpected disconnections, power surges, etc. <br>
 +
'''2.''' Provide a more fluid physical interface for the user to interact with the game via hardware <br>
  
==== <font color="green"> '''''Bluetooth Integration''''' </font> ====
 
  
the connection.
+
To accomplish these goals, two boards were designed: a breakout board and a gamepad controller. The breakout board serves as a connection hub between all system hardware components; power, the RGB matrix, the SJTWO board, etc. while the joystick provides a cleaner package to present the user with the games inputs. The diagram below shows the relationship between the main subsystems: <br>
  
  
==== <font color="green"> '''''Google Maps Integration''''' </font> ====
 
  
After t
+
[[File:tower_defense_in_space_hw_block_diagram.PNG]]
  
=== <font color="green"> Technical Challenges </font> ===
 
  
===== <font color="green"> '''''App Crash on Receiving NULL String''''' </font> =====
+
All board designs were done using [https://www.autodesk.com/products/eagle/overview EAGLE] and manufactured by [https://jlcpcb.com/ JLCPCB]. Both boards were only two layers and used passive components for the most part. <br>
  
The softwar
 
  
===== <font color="green"> '''''INTERNET Permission not enabled''''' </font> =====
+
=== <font color="000000"> Breakout Board Design </font> ===
  
One issu
+
The breakout board design requirement was to interface all external hardware components with the embedded system (SJTWO). The hardware connections are: <br>
  
===== <font color="green"> '''''Broken Android Phone''''' </font> =====
+
'''1.''' The 64x64 RGB Matrix <br>
 +
'''2.''' Output power to the RGB Matrix <br>
 +
'''3.''' User game controller (see next section) <br>
 +
'''4.''' Input power supply (5V) <br>
 +
'''5.''' The SJTWO embedded system <br>
  
During
 
  
=== <font color="green"> Bill Of Materials </font> ===
+
{|
{| class="wikitable"
+
|[[File:Breakout_Rev0.2.PNG|1000px|thumb|left|Breakout Board Schematic]]
! colspan="5" style="background:#008000;" |  
 
<span style="color:#FFFFFF"> ANDROID MOBILE APPLICATION </span>
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART NAME </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART MODEL </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> QUANTITY </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> COST PER UNIT (USD) </span>
 
|-
 
|
 
* '''Android Mobile Phone'''
 
|
 
* Samsung Galaxy S4
 
|
 
* 1
 
|
 
* N/A (Supplied by Nuoya Xie)
 
 
|}
 
|}
  
<HR>
 
<BR/>
 
  
== <font color="green"> BRIDGE CONTROLLER </font> ==
+
{|
 +
|[[File:breakout_board_layout_top.PNG|400px|thumb|left|Breakout Board PCB Top Layout]]
 +
|[[File:breakout_board_layout_bottom.PNG|400px|thumb|left|Breakout Board PCB Bottom Layout]]
 +
|}
  
=== <font color="green"> Hardware Design </font> ===
+
{|
The Brid
+
|[[File:breakout_pcb_top.jpg|400px|thumb|left|Breakout Board PCB Top Layout]]
 +
|[[File:breakout_pcb_bottom.jpg|400px|thumb|left|Breakout Board PCB Bottom Layout]]
 +
|}
  
 +
{|
 +
|[[File:breakout_pcb_mounted_assembled.jpg|800px|thumb|left|Populated and mounted to the SJTWO board]]
 +
|}
  
 +
==== <font color="000000"> Known Breakout PCB Issues </font> ====
  
 
 
==== <font color="green"> Bluetooth Module SJone connection </font>====
 
[[File:SJone_bluetooth_android.png |thumb|center|600px|Bluetooth Module (HC-05) to SJone connection]]
 
 
===== <font color="green"> '''''Bridge Controller Schematic''''' </font> =====
 
[[File:RUN DBC Bridge Sch.jpeg|thumb|center|800px|Bridge Controller Schematic]]
 
 
=== <font color="green"> Software Design </font> ===
 
 
==== <font color="green"> '''''Periodic Callback: Init''''' </font> ====
 
Upon startup,
 
 
 
==== <font color="green"> '''''Periodic Callback: 1Hz''''' </font> ====
 
In order to verify
 
 
 
==== <font color="green"> '''''Periodic Callback: 10Hz''''' </font> ====
 
As stated before,
 
 
[[File:RUN DBC Bridge Software Flowchart.jpg|thumb|center|600px|Bridge Module Flowchart]]
 
<br>
 
 
=== <font color="green"> Path-finding </font> ===
 
Because there
 
 
 
 
[[File:dijkstra_rundbc.jpg | thumb | center | 600px | Checkpoint Diagram]]
 
 
Here we have
 
 
[[File:dijkstra2_rundbc.jpg | thumb | center | 600px | Populated Distance Matrix]]
 
 
The c
 
 
==== <font color="green"> Path-finding sample code </font> ====
 
After t
 
 
 
=== <font color="green"> Technical Challenges </font> ===
 
 
===== <font color="green"> '''''UART Receive While Loop''''' </font> =====
 
The pri
 
 
===== <font color="green"> '''''Interfacing Bridge and Geographic Modules''''' </font> =====
 
Another
 
=== <font color="green"> Bill Of Materials </font> ===
 
 
{| class="wikitable"  
 
{| class="wikitable"  
! colspan="5" style="background:#008000;" |  
+
! colspan="5" style="background:#000000;" |  
<span style="color:#FFFFFF"> BRIDGE CONTROLLER </span>  
+
<span style="color:#FFFFFF"> Known Issues </span>  
 
|-
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> PART NAME </span>
+
Summary
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> PART MODEL </span>
+
Description
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> QUANTITY </span>
+
Version
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
<span style="color:#000000"> COST PER UNIT (USD) </span>
+
Status
 
|-
 
|-
|  
+
| 5V should not be routed to game controller.
* '''Bluetooth Serial Communication Module'''
+
| 3.3V should be routed to the game controller instead of 5V since the ADC pins are not 5V tolerant.
|  
+
| 0.1
* [https://www.amazon.com/LeaningTech-HC-05-Module-Pass-Through-Communication/dp/B00INWZRNC LeaningTech HC-05 Module Bluetooth Serial Pass-Through Module Wireless Serial Communication with Button for Arduino] '''(Supplied by Nuoya Xie)'''
+
| <span style="color:green">Resolved Rev 0.2</span><br/>
|  
+
|-
* 1
+
| Wrong silkscreen/not enough room near power input.
|  
+
| Power input silkscreen too small, part too big for 3.3V LED to fit
* N/A
+
| 0.1
 +
| <span style="color:green">Resolved Rev 0.2</span><br/>
 +
|-
 +
| Linear regulator not needed.
 +
| The schematic for the SJTWO board labels the input voltage pin as VIN RAW, which is different than the label on the
 +
optional input port. They are both the same, so this input feeds directly into the on-board 3.3V regulator. Essentially
 +
we're driving the regulator with the same voltage it outputs which just won't work well.
 +
| 0.1, 0.2
 +
| <span style="color:red">UNRESOLVED</span><br/>
 
|}
 
|}
  
<HR>
+
=== <font color="000000"> Gamepad Hardware Design </font> ===
<BR/>
 
  
== <font color="0000FF"> GEOGRAPHIC CONTROLLER </font> ==
+
The gamepad board design requirement was to provide a more packaged interface for the user to interact with the game. <br>
  
 +
{|
 +
|[[File:gamepad_schematic.PNG|1000px|thumb|left|Gamepad Schematic]]
 +
|}
  
==== <font color="0000FF"> Hardware Design </font> ====
 
The geographical
 
  
==== <font color="0000FF"> Geographic Controller Schematic </font>====
+
{|
 +
|[[File:gamepad_layout_top.PNG|600px|thumb|left|Gamepad PCB Top]]
 +
|[[File:gamepad_layout_bottom.PNG|600px|thumb|left|Gamepad PCB Bottom]]
 +
|}
  
[[File:RUN DBC geo sch.jpeg | thumb | center | 800px | Geographic Controller Schematic]]
+
{|
 +
|[[File:gamepad_pcb_assembled.jpg|800px|thumb|left|Gamepad PCB Fully Populated (no enclosure)]]
 +
|}
  
==== <font color="0000FF"> GPS Module SJone connection </font>====
+
== <font color="000000"> Hardware Design (Mechanical) </font> ==
  
[[File:geo_pin_connection.jpg | thumb | center | 500px | Geographic module pin connection]]
+
Only a few mechanical components were needed for this project. Namely simple brackets for mounting electrical hardware to the RGB matrix and displaying the matrix itself. All CAD designs were done using [https://www.onshape.com/ Onshape], a free CAD tool that can be used entirely through your web browser.
  
==== <font color="0000FF"> GPS Module </font>====
+
For displaying the RGB matrix, two brackets were 3D printed to prop it up. Their STL files can be found under our source repository.
  
 +
{|
 +
|[[File:matrix_bracket_1.PNG|100x|thumb|left|Mounting bracket design used to prop up the RGB matrix]]
 +
|}
  
[[File:S19_RUNDBC.jpg| thumb | left | 300px | Adafruit Ultimate GPS module]] 
+
== <font color="000000"> Hardware Integration </font> ==
[[File:S19_RUNDBC_antenna.jpg| thumb|center|300px | Cirocomm GPS antenna]]
+
=== RGB LED MATRIX ===
 +
The LED matrix that we use is 64 pixels by 64 pixels and is controlled through a 12-pin header consisting of the following pins:
  
<br>
+
*Five Mux pins (A,B,C,D,E) for Row Selection
<br>
+
**In order to select a specific row of the LED matrix, we need to control the output level of each mux pin. Since the LED matrix light up two rows of LEDs at one time, we can only select 1 out of 32 rows.
<br>
+
*Two sets of RGB pins (R1,G1,B1,R2,G2,B2) for Color Selection
<br>
+
**Since we are driving two rows of LED matrix at once, we need 2 sets of RGB pins. One set is used to control the color pixels of the upper half of the display and the other set for the bottom half of the display. 
<br>
+
*Output Enable Pin (OE)
As
+
**Output Enable (OE) pin is used to turn on or off the LEDs of the current row.
 +
*Latch Pin (LAT)
 +
**Latch pin is used to prevent the data being shifted into the shift registers and tells the shift register when it is time to switch to newly entered data.
 +
*Clock Pin (CLK)
 +
**triggers a shift on the shift registers
  
 +
All these pins are required to display a specific color on a specific pixel of the LED matrix display.
 +
{|
 +
|[[File:Pin assignment LED Matrix.jpg|500px|thumb|middle|Pin Connections between SJtwo Board and REG LED Matrix]]
 +
|[[File:scan116.gif|200px|thumb|right|LED Matrix - Row Scanning]]
 +
|}
  
[[File:RUN DBC geo table pic.png |thumb | center | 600px | GPRMC Sentence Structure]]
+
Apparently, it is impossible to driver all 4096 LEDs all at one time and thus, we can only drive two rows of LEDs at a time (one row on the upper half of the display and another row on the lower half of the display). By refreshing the LED matrix two rows at a time in a fast frequency, we can display all the game objects with animation on the LED matrix.
  
 +
=== Joysticker controller ===
 +
The joystick that we use is the product from Adafruit, the Analog 2-axis Thumb Joystick. This 2-axis Thumb Joystick provides the following pins:
  
The first 6
+
# Two ADC pins
 +
## In order to control the tower location, we need to control the Joysticker, since the direction has four: Up, Down, Left, Right, we use the Y and X-axis to implement this function.
 +
# Three GPIO pins
 +
## In order for selecting for the tool we need two GPIO pin for button and 1 GPIO pin for controlling the LED on the JOY STICKER controller
  
==== <font color="0000FF"> '''Compass Module''' </font>====
+
* Pin configuration
 +
[[File:Selection 999(032).png]]
  
[[File:compass_rundbc.jpg| thumb | center | 500px | CMPS14 Compass Module]]
+
=== MP3 Decoder ===
  
The compass modul
+
The MP3 decoder that we use is Sparkfun’s vs1053 shield MP3 decoder which is the board based on the vs1053b chip.
  
===== <font color="0000FF"> '''Read Compass Heading''' </font>=====
+
{|
Compass
+
|[[File:MP3DECODER PON.png|600px|thumb|left|MP3 Decoder Module Pinout]]
 +
|}
 +
{|
 +
|[[File:Selection 999(034).png|600px|thumb|left|MP3 Decoder Pin Table]]
 +
|}
 +
* Three SPI pin
 +
In order to communicate with the mp3 decoder with SJtwo Board, we choose the SPI as the protocol to control the decoder. Hence, we need the one pin SCK0
 +
(clock), one pin MOSI(Master In Slave Out) and one pin (Master Out Slave In).
 +
* Four GPIO pin for the decoder 
 +
There are four major GPIO pin for DREQ(Data Request Pin), Reset, CS(Chip Select), XDCS(Data Chip Select), this 4 GPIO pin is how we transfer data and send
 +
the command to activate the mp3 decoder work with SJ2 Board.
  
===== <font color="0000FF"> '''Check Compass Calibration''' </font>=====
+
== <font color="000000"> Software Design </font> ==
The cw:
+
=== <font color="000000"> RGB LED Matrix </font> ===
[[File:compass_calibration_rundbc.jpg| thumb | center | 800px | CMPS14 calibration register]]
+
[[File:RGB_data.jpg|400px|thumb|right|RGB Data Element]]
  
 +
All the LED Matrix data are stored in a buffer with its size equal to 32 by 64. Each element in this buffer store the color of two pixels, one pixel from the upper half of the display and one pixel from the lower half of the display.
  
==== <font color="0000FF"> '''Essential GPS Data''' </font>====
+
In order to display the gaming objects in animation, we need to refresh the display by displaying the color pixels on each row one by one very fast. Below is a simple flowchart that describes the process of refreshing the display.
  
  
===== <font color="0000FF"> '''''Bearing, Distance, and Deflection Angle Calculation'''''</font>=====
+
* Loop through each row of the LED display
 +
# Select Row (By controlling the output level of 5 mux pins, we can select one row at a time)
 +
# Disable the LED Display output (Turn off the LEDs of the current row of the display)
 +
# Unlatch the Data
 +
# Clock in Data for each column(Store the color of each pixel inside display_matrix buffer)
 +
# Latch the Data
 +
# Enable the LED Display output (Display the color of each pixel of the current row)
 +
# Delay for a 100us (Increase the light intensity of the LEDs by delay a short amount of time)
 +
# Disable the LED Display output (Turn off the LEDs of the current row of the display)
  
=== <font color="0000FF"> Software Design </font> ===
+
<syntaxhighlight lang="c">
 +
void refreshDisplay(void) {
 +
  for (uint8_t row = 0; row < LEDMATRIX_HALF_HEIGHT; row++) {
  
The
+
    select_row(row);
[[File:geo_diagram_rundbc.jpg | thumb | center | 500px | Geographic Module Flow Diagram]]
+
    led_matrix__disable_output(); // gpio__set(OE);
 +
    led_matrix__unlatch_data();  // gpio__set(LAT);
 +
    led_matrix__clock_in_data(row);
 +
    led_matrix__latch_data();    // gpio__reset(LAT);
 +
    led_matrix__enable_output(); // gpio__reset(OE);
 +
    delay__us(100);              // Change Brightness
 +
    led_matrix__disable_output();
 +
  }
 +
}
 +
</syntaxhighlight>
  
=== <font color="0000FF"> Technical Challenges </font> ===
+
<syntaxhighlight lang="c">
 +
void led_matrix__clock_in_data(uint8_t row) {
 +
  /* Clock in data for each column */
 +
  for (uint8_t col = 0; col < LEDMATRIX_WIDTH; col++) {
 +
   
 +
    /* Set all the RGB pins as low*/
 +
    LPC_GPIO1->PIN &= ~(0x1 << R1.pin_number | 0x1 << G1.pin_number | 0x1 << B1.pin_number);
 +
    LPC_GPIO2->PIN &= ~(0x1 << R2.pin_number | 0x1 << G2.pin_number | 0x1 << B2.pin_number);
  
'''Getting correct BAUD rate for GPS'''
+
    /* Set the RGB pins as High or Low depends on the data stored inside the buffer */
* When
+
    LPC_GPIO1->PIN |= ((((display_matrix[row][col] >> 0) & 0x1) << R1.pin_number) |
 +
                      (((display_matrix[row][col] >> 1) & 0x1) << G1.pin_number) |
 +
                      (((display_matrix[row][col] >> 2) & 0x1) << B1.pin_number));
  
'''Compass reading was not accurate and would deviate from initial calibration'''
+
    LPC_GPIO2->PIN |= ((((display_matrix[row][col] >> 4) & 0x1) << R2.pin_number) |
* The
+
                      (((display_matrix[row][col] >> 5) & 0x1) << G2.pin_number) |
'''Parsing NMEA sentences'''
+
                      (((display_matrix[row][col] >> 6) & 0x1) << B2.pin_number));
* When we
 
  
=== <font color="0000FF"> Bill Of Materials </font> ===
+
    gpio__set(CLK);
{| class="wikitable"
+
    gpio__reset(CLK);
! colspan="5" style="background:#36C;" |
+
  }
<span style="color:#FFFFFF"> GEOGRAPHIC CONTROLLER </span>
+
}
|-
+
</syntaxhighlight>
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART NAME </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART MODEL </span>  
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> QUANTITY </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> COST PER UNIT (USD) </span>
 
|-
 
|
 
* '''GPS'''
 
|
 
* [https://www.amazon.com/Adafruit-Ultimate-GPS-Breakout-External/dp/B00I6LZW4O/ref=sr_1_fkmrnull_5?keywords=Adafruit+Ultimate+GPS+Breakout+Kit&qid=1554334740&s=gateway&sr=8-5-fkmrnull Adafruit Ultimate GPS Breakout Kit]
 
|
 
* 1
 
|
 
* $69.13
 
  
|-
+
{|
|  
+
|[[File:RefreshDisplaySequence.jpg|300px|Process of refreshing display]]
* '''GPS antenna'''
+
|}
|
+
=== <font color="000000"> MP3 Decoder </font> ===
* [https://www.amazon.com/CIROCOMM-Antenna-Ceramic-25x25x2mm-Geekstory/dp/B078Y2WNY6 Cirocomm 5cm Active GPS Antenna]
+
The MP3 deocder is executed with the mainly two task: read task and play task.
|  
+
The reader task would read data from the sd card and sned queue data for the player task to play music.
* 1
 
|
 
* $8.79
 
  
|-
+
{|
|  
+
|[[File:MP3DECODERMODULE.png|600px|thumb|left|MP3 Decoder Module API]]
* '''Compass'''
 
|
 
* [https://www.robotshop.com/en/tilt-compensated-magnetic-compass-cmps14.html CMPS14 Tilt Compensated Magnetic Compass]
 
|  
 
* 1
 
|  
 
* $33.99
 
 
|}
 
|}
 +
* Read Task
 +
* Loop through each row of the LED display
 +
# Queue sned the target filename
 +
# Queue receive the target name
 +
# Find the mp3 file name is exit or not
 +
# Open the file(fopen)
 +
# Read data store to the buffer(Binary)
 +
# Sent the data from bufder with queuesend API
  
<HR>
+
{|
<BR/>
+
|[[File: READ TASK.png]]
 +
|}
  
== <font color="FF8C00"> MASTER CONTROLLER </font> ==
+
* Play Task
 +
Receive the data of the song from the queue, and use the receiving data and sent the command to make decoder to play music.
  
=== <font color="FF8C00"> Hardware Design </font> ===
+
* Read Task
The master
+
* Loop through each row of the LED display
 +
# Queue receive the data(music)
 +
# disable the chip select
 +
# Check the DREQ pin to know is ready or not
 +
# exchange the data to the decoder to play the music
 +
# Check the DREQ pin to know is ready or not
 +
# disable the chip select
 +
{|
 +
|[[File: Play Task.png]]
 +
|}
  
[[File:RUN DBC master sch.png |thumb| center | 800px|Master Module Schematic]]
+
=== <font color="000000"> JOY STICKER </font> ===
 +
The JOY_STICKER is using the task to pool the ADC channel data to get the direction from the Joysticker.
  
[[File:RunDBC_LCD.jpg |thumb| center | 800px |LCD Showing speed, steer and state information]]
 
  
=== <font color="FF8C00"> Software Design </font> ===
+
* Loop through each time to poll the enum type data to get direction
[[File:Master stateMachine.PNG |thumb| right | 400px| Master State Machine]]
+
# Receiving the data from two ADC channel(5=x, 4=y)
* LCD di
+
# Comparing which one has higher absolute data
 +
# If (X > Y == YES) ,then we go to the loop to compare It's closer to Right or Left
 +
# If (X > Y == YES && Right > LEFT == YES), then the status is Right
 +
# If (X > Y == YES && Right > LEFT == NO), then the status is Left
 +
# If (X > Y == NO) ,then we go to the loop to compare It's closer to Up or Down
 +
# If (X > Y == NO && Up > Down == YES), then the status is Up
 +
# If (X > Y == NO && Up > Down == NO), then the status is Down
  
=== <font color="FF8C00"> Technical Challenges </font> ===
+
{|
 +
|[[File:Joystickermodule.png|1000x|thumb|left|Game controller]]
 +
|}
  
* Qui
+
{|
 
+
|[[File:JOY STICKER ADC FLOW.png|1000x|thumb|left|Game controller flow chart]]
 
 
=== <font color="FF8C00"> Bill Of Materials </font> ===
 
{| class="wikitable"
 
! colspan="5" style="background:#FF8C00;" |
 
<span style="color:#FFFFFF"> MASTER CONTROLLER </span>
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART NAME </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART MODEL </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> QUANTITY </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> COST PER UNIT (USD) </span>
 
|-
 
|
 
* '''LCD'''
 
|
 
* N/A
 
|  
 
* 1
 
|  
 
* Supplied by Preet Kang
 
 
|}
 
|}
  
<HR>
+
=== <font color="000000"> System Flow Charts </font> ===
<BR/>
+
<br>
 +
<b> Basic Software Environment: </b> <br>
 +
[[File:Flow1 TDIS.png]]
  
== <font color="EE82EE"> MOTOR CONTROLLER </font> ==
+
<br>
 
+
<b> Game Master (how the user sees the game flowing): </b> <br>  
 
+
[[File:Flow2_TDIS.png]]
=== <font color="EE82EE"> Hardware Design </font> ===
 
The motor board
 
<b> <br>
 
1 pin  <br>
 
1 pin f <br>
 
1 pin  <br>
 
</b> <br>
 
 
 
The ESC was included with the RC we purchased and it was interfaced with 3 pins:
 
<b> <br>
 
1 pin fo <br>
 
</b> <br>
 
  
Manag <br>
 
<br>
 
Managing wheel spin was a more complicated process. The ESC also requires a PWM signal in order to operate, but is not as simple as the servo's operation. <br>
 
In or
 
<b><br>
 
S
 
</b><br>
 
 
<br>
 
<br>
 +
<b> Intermission Phase (what happens while the user is placing towers): </b> <br>
 +
[[File:Flow3_TDIS.png]]
  
 
===== <font color="EE82EE"> '''''Speed Control Timing Diagrams''''' </font> =====
 
 
[[File:Run DBC Speed timing diagrams.PNG |thumb| 600px|center| Speed Timing Diagrams]]
 
 
 
===== <font color="EE82EE"> '''''Steering Control Timing Diagrams''''' </font> =====
 
 
[[File:Run DBC Steering timing diagrams.PNG |thumb| 600px |center| Steering Timing Diagram]]
 
 
 
===== <font color="EE82EE"> '''''Motor Controller Schematic''''' </font> =====
 
 
[[File:RUN DBC motor sch.png |thumb| center | 800px | Motor Module Schematic]]
 
 
=== <font color="EE82EE"> Software Design </font>  ===
 
 
<br>
 
<br>
<b>Periodic Callback: Init (beginning of program)</b><br>
+
<b> Combat Phase (what happens when the aliens invade): </b> <br>
<br>
+
[[File:Flow4_TDIS.png]]
<b>Periodic Callback: 1Hz (every 1sec)</b><br>
 
- Che
 
<br>
 
<b>Periodic Callback: 10Hz (every 100ms)</b><br>
 
- Sen
 
 
 
=== <font color="EE82EE"> Technical Challenges </font>===
 
 
 
===== <font color="EE82EE"> '''''SJOne PWM''''' </font>=====
 
W
 
  
 +
== <font color="000000"> System Testing and Validation </font> ==
 +
{|
 +
|[[File:StartScreenTowerDefense.gif|400px|thumb|left|Start Screen]]
 +
|[[File:CombatPhase.gif|400px|thumb|left|Combat Phase]]
 +
|}
  
===== <font color="EE82EE"> '''''Encoder''''' </font>=====
+
{|
The
+
|[[File:EndGame.gif|400px|thumb|left|Player Loses the game]]
=== <font color="EE82EE"> Bill Of Materials </font> ===
+
|[[File:VictoryScreen TowerDefense.gif|400px|thumb|left|Player Wins the game]]
{| class="wikitable"
 
! colspan="5" style="background:#EE82EE;" |  
 
<span style="color:#FFFFFF"> MOTOR CONTROLLER </span>
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART NAME </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART MODEL </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> QUANTITY </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> COST PER UNIT (USD) </span>
 
|-
 
|
 
* '''Motor Encoder'''
 
|
 
* [https://www.digikey.com/product-detail/en/nidec-copal-electronics/RE12D-100-201-1/563-2051-ND/6469487, Nidec Copal Optical Rotary Encoder]
 
|
 
* 1
 
|
 
* $63.16
 
 
|}
 
|}
  
<HR>
+
== <font color="000000"> Technical Challenges </font> ==
<BR/>
 
 
 
== <font color="FF0000"> SENSOR CONTROLLER </font> ==
 
 
 
=== <font color="FF0000"> Hardware Design  </font>===
 
 
 
[[File:Image002.jpg |thumb| center | 800px | Pin connection of Different sensors to SJOne Board]]
 
 
 
[[File:sensors_rundbc.jpg |thumb| center | 600px | Placement of Sensors on RC Car]]
 
 
 
Sen
 
 
 
 
 
===== <font color="FF0000"> '''''Sensor Controller Schematic'''''  </font>=====
 
 
 
[[File:RUN DBC sensor sch.png|thumb| center | 800px | Sensor Module Schematic]]
 
 
 
===== <font color="FF0000"> '''''CAD Design'''''  </font>=====
 
 
 
We g
 
 
 
[[File:SW001.gif | thumb | left | 200px | Sensor Guard to Minimize Interference]]
 
[[File:SW002.gif | thumb | center | 200px | Sensor Guard Mount showing Vertical Adjustment]]
 
 
 
<br>
 
<br>
 
 
 
===== <font color="FF0000"> '''''Placement for the Ultrasonic Sensors''''' </font color="FF0000">=====
 
 
 
We r
 
===== <font color="FF0000"> '''''Sensor Value Conversion''''' </font color="FF0000">=====
 
 
 
In or
 
 
 
[[File:sensor_curve_rundbc.jpg |thumb| center | 800px | Sensor Graphical Representation]]
 
 
 
=== <font color="FF0000"> Software Design  </font>===
 
 
 
===== <font color="FF0000"> '''''Flowchart'''''  </font>=====
 
 
 
The f
 
 
 
[[File:software003.png | thumb| center | 500px |Flowchart of Sensor Module]]
 
 
 
===== <font color="FF0000"> '''''Timing Diagram''''' </font>=====
 
[[File:software002.jpg |thumb| center | 800px | Timing Diagram]]
 
 
 
=== <font color="FF0000"> Technical Challenges </font>===
 
 
 
 
 
===== <font color="FF0000"> '''''Sensor Interference''''' </font>=====
 
 
 
We saw :
 
  
* Higher
+
=== Game Map (2D array) to LED matrix (2D pixels) Conversion ===
 +
Issue:
 +
# The game map (consisting of the path as well as all of the active enemies and towers) is managed through the use of a 2D char array.
 +
# In order to display each object on the LED matrix, there needs to be a mechanism that converts the object along with its 2D array location to a row/column on the LED matrix.
 +
# An algorithm to do this conversion is not as straightforward as it may appear. This is because objects stored in the array take up more/less display space than what is available on the LED matrix.
 +
Solution:
 +
# In order to align the array locations with the LED matrix pixel locations, some areas on the 2D array needed to be marked as "ignore". <br>
 +
# If each array location is not carefully correlated to a specific pixel location, then there would be issues where objects are displayed overlapping each other on the LED matrix (or simply displayed in the wrong spot).
 +
# There were some simple algorithms that used math to help implement this conversion. <br>
 +
# However, a LUT is what was primarily used. It was not efficient in terms of code size, it took over 500 lines of code. <br>
 +
# But it was an effective solution and allowed us to easily decide exactly where each pixel of each object would be displayed.
  
* Instead of l
+
=== LED Matrix Flickering Issue ===
 +
Issue: While we are developing the game, we notice that some color pixels are turned on when they are supposed to be off.
  
===== <font color="FF0000"> '''''Power Deficiency''''' </font>=====
+
Investigation/Solution:
 +
# See [[Known Breakout PCB Issues]] as a possible cause. It's possible the SJTWO board is getting inconsistent power.
 +
# Refreshing the matrix should not be handled by an interrupt and not a task. The task should only push new display data and not have direct control of the matrix. Keeping the refresh interrupt driven would keep the refresh rate more consistent by removing the process being context switched out mid update.
  
At first
+
=== MP3 Decoder - SJtwo Board SPI Selection ===
  
===== <font color="FF0000"> '''''Unstable HR-04 Readings''''' </font>=====
+
Issue:
 +
# The mp3 decoder1053b's document is a kind of confusing for the mode when 1032b have several modes
 +
# It's hard to know the configuration is successful or not.
 +
Solution:
 +
# Doing the survey on the GitHub is really important. For example, using the sin wave and hello binary example to test how the Initialization and HZ parameter would save a lot of time.Moreover, in the document from the vs1053b, we could use the binary file line "hello", "sine wave" function for testing.
 +
# Besides, we also have to be careful to check the SJBoard's SPI because of the SD card reader is using for reading SDcard. Hence, I would recommend using other
 +
SPI0, SPI1 instead of using SPI2.
  
At fi
+
== <font color="000000"> Conclusion </font> ==
===== <font color="FF0000"> '''''ADC Supply Voltage''''' </font>=====
+
We successfully designed and implemented the video game "Tower Defense In Space". All of our team members now have a better understanding of how to use FreeRTOS to handle the synchronization of multiple tasks and to communicate with multiple hardware components in an embedded application system. After completing this project, we learned how to manage a project on a tight schedule. Starting from purchasing hardware components, developing hardware drivers and game logic and then integrating all of the drivers and APIs into the game logic. Furthermore, all of us are now better at coding and debugging code.
 +
For a game design project like this, we learned that it's not always best to assign tasks independently between the team members. We learned that this type of project would benefit moreso from pair programming and other cooperative tasks that enable collaboration between teammates. Otherwise, project tasks may be done in such a way that they only work for 1 specific configuration, and wouldn't help progress towards the end goal of the integrated system. We also learned that not every day was going to be perfect, but as long as we never gave up and worked hard, then the final result would not be disappointing!
  
The mid
 
===== <font color="FF0000"> '''''Slow car response to obstacle due to large queue size (running average)''''' </font>=====
 
During
 
 
=== <font color="FF0000"> Bill Of Materials </font> ===
 
{| class="wikitable"
 
! colspan="5" style="background:#D33;" |
 
<span style="color:#FFFFFF"> SENSOR CONTROLLER </span>
 
|-
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART NAME </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> PART MODEL </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> QUANTITY </span>
 
! scope="col" style="text-align: center;" style="background:#C0C0C0;" |
 
<span style="color:#000000"> COST PER UNIT (USD) </span>
 
 
|-
 
|
 
* '''Infrared Sensor'''
 
|
 
* [https://www.sparkfun.com/products/242, Infrared Proximity Sensor]
 
|
 
* 1
 
|
 
* $13.95
 
 
|-
 
|
 
* '''Front-left-right Distance Sensor'''
 
|
 
* [https://www.maxbotix.com/Ultrasonic_Sensors/MB1010.htm MB1010, LV-MaxSonar-EZ1]
 
|
 
* 2
 
|
 
* $29.95
 
 
|-
 
|
 
* '''Front-middle Distance Sensor'''
 
|
 
* [https://www.maxbotix.com/Ultrasonic_Sensors/MB1000.htm MB1000, LV-MaxSonar-EZ0]
 
|
 
* 1
 
|
 
* $29.95
 
|}
 
 
<HR>
 
<BR/>
 
  
== CONCLUSION ==
+
We would like to say thank you to Prof. Preet and all the ISAs for their precious suggestions and assistance during the development of this project!
This pr
 
  
 +
== Advice for Future Students ==
  
=== Project Video ===
+
==== Source Control ====
 +
Unless everyone in your group is comfortable using source control, don't use it. It will likely end up costing you time in the long run.
  
[https://youtu.be/zhRfc7wB4kA RUN-D.B.C project video]
+
==== Start working on your LED Matrix driver ASAP ====
 +
The first 64x64 LED Matrix that we got from Sparkfun suffers from a serious flickering issue. After spending for a week trying to debug what causes the flickering issue, we still have no idea whether it is a hardware issue or software issue. Later, we borrow another LED matrix from a student of our class and test our code. With the other student's LED matrix (we use our own power supply and ribbon cables), there is no flickering issue at all. According to some online resources, some matrix vendors scatter the selected rows and columns differently. It is possible that your designed driver may only work on some LED matrix vendors' displays.
  
=== Project Source Code ===
+
== <font color="000000"> Video Demonstration </font> ==
 +
[https://www.youtube.com/watch?v=b2isxUJta6Q Demo Video (Player Wins)]
  
[https://gitlab.com/run-dbc/autonomous-car RUN-D.B.C project source code]
+
[https://www.youtube.com/watch?v=fylwPk5g_3Q Demo Video (Player Loses)]
  
=== Advice for Future Students ===
+
== <font color="000000"> Source Code </font> ==
* '''FORM YOUR TEAM AS EARLY AS POSSIBLE AND START WORKING ON THE PROJECT AS EARLY AS POSSIBLE (WEEK 1 IF POSSIBLE)'''
+
* [https://gitlab.com/rollin_nolan/tower-defense-in-space Tower_Defense_In_Space_Gitlab]
* If you are
+
* [https://drive.google.com/file/d/1kggWmH2kcPciE4tFG8gYCbF9gfV2dXkk/view zip file (must have SJSU email address)]

Latest revision as of 23:33, 21 December 2019

Logo

Abstract

This project involves creating and developing a video game where output is displayed on a LED matrix. Development of the relevant hardware/software components and modules was divided among 4 team members. Each team member lead or significantly contributed to the development of multiple components. The project was focused on not only technical skills, but team building as well, and working with others towards a common goal.

This project provides us hands-on experience using freeRTOS in a real application. Our objective is to apply what we have learned in class and develop a video game using our SJtwo Board. In this project, we create different tasks for different modules, such as a display task for displaying the game objects on LED matrix, a tower task for detecting nearby enemies and shoot them, a stage task to manage each game stage etc. We need to use both cooperative scheduling and preemptive scheduling technique to make this video game run efficiently. In order to make this game run in a particular sequence, we also need to synchronize and sequentialize each task by setting the task priorities carefully and using binary semaphore correctly.

Introduction and Objectives

Alien Invasion

Like most traditional tower defense games, the player needs to defend our planet from the invasion of aliens. The gameplay can be split into 2 phases, Combat Phase and Intermission Phase. During the intermission phase, the player can place different kinds of towers strategically that will attack the invading aliens from entering into our homeland by shooting the enemies. During the combat phase, spaceships follow the path and try to land on our planet. If any enemy spaceship reaches the end of the path, then the player loses. If there are no more spaceships remaining in a wave, the player can build a stronger tower that has a longer attack range and can shoot a more powerful laser to the spaceships in the next wave. The player wins the game after surviving 5 waves of attack.

This game can be separated into 4 different modules:

  1. Game Logic: SJtwo Board - handles the game logic. (For example: detect and shoot nearby enemies, switch between intermission phase and combat phase)
  2. Display: Adafruit 64x64 LED matrix - displays the animation of the game.
  3. Gamepad Controller: The input of this game. The gamepad controller consists of a joystick and two buttons. The player can use the joystick to move the cursor and decide where to place the towers. After that, the user needs to press the black button to select and confirm the location of the towers. If the player knows that he/she has made a mistake in the middle of the game and will eventually lose the game, the player can press the red button and restart the game.
  4. Sound: MP3 Decoder and speaker. Players can enjoy cool music during the game. This is done on an additional SJtwo board, which will play the song on repeat.

Team Members

TEAM MEMBERS & RESPONSIBILITIES

Team Members

Administrative Roles

Technical Roles

  • [Ryan Zelek]

Team Lead

  • Game Design Lead

Git Repo Manager

  • Hardware Design Lead
  • [Chong Hang Cheong]

Wiki Report Manager

  • LED Matrix API
  • [Polin Chen]

Bill of Materials Manager

  • Joy Sticker && Decoder API


Schedule

TEAM MEETING DATES & DELIVERABLES

Week#

Date Assigned

Deliverables

Status

1 10/15/19
  • Share team contact information
  • Create Git Repository
  • Set up group Slack channel
  • Invite Preet to Slack
  • Establish Code Guidelines and Standards
  • Complete
  • Complete
  • Complete
  • Complete
  • Complete
2 10/22/19
  • Identify major hardware components (BOM)
  • Begin purchasing major items
  • Finalize game architecture
  • Have Git Repo Setup
  • Complete
  • Complete
  • Complete
  • Complete
3 10/29/19
  • Solidify individual roles and responsibilities
  • Establish baseline software architecture design and guidelines going forward
  • Complete
  • Complete
4 11/5/19

Kelvin

  • Verify functionality of LED matrix and gather resources for further understanding


  • Complete
5 11/12/19

Kelvin

  • Find out feasibility of creating an LED matrix driver in C

Polin

  • Have APIs ready for joystick and buttons

Ryan

  • Have basic user interface for the game displayed through serial port

Zach

  • First controller PCB design complete
  • Specify any remaining hardware components and coordinate purchase


  • Complete


  • Complete


  • Complete


  • Complete
  • Complete
6 11/19/19

Kelvin

  • Complete baseline API for LED matrix

Polin

  • Determine feasibility of MP3 decoding and integration into system

Ryan

  • Complete first pass at basic tower defense level with straight pathway

Zach

  • Controller PCB sent out for fabrication
  • Design break-out PCB for LED matrix + IO expander />


  • Complete


  • Complete


  • Complete


  • Complete
  • Complete
7 11/26/19

Kelvin

  • LED matrix driver should be reviewed and complete

Polin

  • Work with Zach to identify remaining hardware components and, if applicable, MP3 decoder requirements

Ryan

  • Work with Kelvin to integrate his API into the game
  • Game should be running with LED matrix display involvement
  • Advanced game logic design/implementation is near feature complete

Zach

  • PCB assembled and tested. Problems identified and solutions proposed


  • Complete


  • Complete


  • Complete
  • Complete
  • Complete


  • Complete
8 12/3/19
  • Complete game testing and validation
  • Critical bugs (software AND hardware) identified and a clear path towards closure has been identified
  • Complete
  • Complete
9 12/10/19
  • Continuation of previous week activities (bug fixes, etc)
  • Implement any potential optimizations and/or expansions
  • Complete
  • Complete


Bill of Materials

Top Level

PART NAME

PART MODEL & SOURCE

QUANTITY

COST PER UNIT (USD)

32x64 RGB LED Matrix [1] 2 $49.95
64x64 RGB LED Matrix Sparkfun 1 $79.95
NovaeLED 64x64 RGB LED Matrix (2-Pack) Amazon 1 $80.99
64x64 RGB LED Matrix* Adafruit 1 $104.07
5V 4A PSU - 1 FREE


Breakout Board PCB**

Item #

PART NAME

PART SOURCE

QUANTITY

COST PER UNIT (USD)

1 IC REG LINEAR LD1117S33CTR DIGIKEY 5 $0.351
2 MHS16N-ND 16POS CONN 2.54MM DIGIKEY 2 $2.60
3 CAP CER 0.1UF 25V X7R 1206 DIGIKEY 5 $0.221
4 CAP CER 10UF 16V X5R 1206 DIGIKEY 5 $0.202
5 RES SMD 470 OHM 1% 1/4W 1206 DIGIKEY 10 $0.0267
6 PTC RESET FUSE 24V 500MA 1206 DIGIKEY 10 $0.1588
7 CONN SOCKET 40POS 0.1 TIN PCB DIGIKEY 2 $5.03
8 Manufacturing x 5 boards * JLCPCB 1 $29.81


Gamepad PCB**

Item #

PART NAME

PART SOURCE

QUANTITY

COST PER UNIT (USD)

1 Analog 2-axis Thumb Joystick w/ select button Amazon 1 $7.67
2 SAM8205-ND 10POS 1.27MM DIGIKEY 5 $3.38
3 LED GREEN 1206 SMD DIGIKEY 5 $0.24
4 LED RED 1206 SMD DIGIKEY 5 $0.257
5 RES 1K OHM 1% 1/2W 1206 SMD DIGIKEY 5 0.0358
6 CAP CER 0.1UF 50V X7R 1206 DIGIKEY 5 $0.088
7 12x12x7.3mm Tactile Push Button w/ cap (pack of 25) Amazon 1 $7.89
8 Manufacturing x 5 boards * JLCPCB 1 $14.21


* Shipping and tax included in value shown in the cost per unit column
** Only parts that were purchased are displayed.


Game Design

Game Rules

Gameplay is split into 2 phases:
Intermission - Player sets up tower locations
Combat - Player watches round unfold

During the Intermission Phase:

  1. The player places towers strategically around the enemy path.
  2. The number of towers is fixed per round
  3. Towers can only be placed in marked areas that do not lie on a path
  4. The built-in software will find a valid tower location and move the cursor there automatically according to joystick input.
  5. There are 5 types of towers (increasing damages, ranges, and of different colors). Each tower type depends on the current wave.

During the Combat Phase:

  1. Enemies will enter the gameplay area at one end of the path and attempt to reach the other end
  2. Towers will automatically engage enemies when they come within range
  3. Towers shoot until the enemy is either dead or out of range
  4. Tower proximity is 8 directions (top, bot, left, right, top-right, top-left, bot-left, bot-right) and 1 unit (not necessarily 1 pixel) away
  5. Enemies that reach the end of path while being alive will result in losing the game.
  6. If any spaceship reaches the end of the path, the player loses and the game ends
  7. The round is over when the player loses or a set number of enemies have been defeated.


Dashboard (Combat Phase)

There will be a dashboard on the LED matrix that displays basic UI information:
Intermission Phase:

  1. Time until combat phase
  2. Current wave number
  3. Number of towers left that you can still place

Combat Phase:

  1. Current wave number
  2. Number of enemies still remaining in the current wave

Game Objectives

  1. There are 5 waves (rounds) total.
  2. In each round, enemies in various amounts, groupings, and health levels (armor) pass through the path.
  3. If any enemies reach the end of the path, then the user loses.
  4. After each round, the user will be able to place more towers which are stronger and can shoot farther.
  5. Each round will have waves of enemies that are more difficult to stop.
  6. The user needs to carefully place their towers such that it will have a maximum number of opportunities to shoot at the enemies.
  7. The trick is that the user will need to preserve early level towers, otherwise they will not have enough room to place the high level towers in the optimal location.

How To Play

The gamepad controller consists of a joystick and two buttons.

  • Joystick - move the cursor and decide where to place the towers.
  • Black button - select and confirm the location of the towers.
  • Red button - restart the game (If the player knows that he/she has made a mistake in the middle of the game and will eventually lose the game, the player can press the red button and restart the game.)

During the Intermission Phase:

  1. The player places towers strategically around the enemy path by using the joystick to move the cursor and pressing the black button to select the location of the towers.
  2. The player needs to place all remaining towers under 45 seconds.

During the Combat Phase:

  1. Cheer on your towers and watch them defend Earth from the alien invasion!

Hardware Design - Electrical

Overview

At a high level hardware integration requirements fell into two categories:

1. Reduce risk of unreliable cable connections and eliminate possibility of damage to components through unexpected disconnections, power surges, etc.
2. Provide a more fluid physical interface for the user to interact with the game via hardware


To accomplish these goals, two boards were designed: a breakout board and a gamepad controller. The breakout board serves as a connection hub between all system hardware components; power, the RGB matrix, the SJTWO board, etc. while the joystick provides a cleaner package to present the user with the games inputs. The diagram below shows the relationship between the main subsystems:


Tower defense in space hw block diagram.PNG


All board designs were done using EAGLE and manufactured by JLCPCB. Both boards were only two layers and used passive components for the most part.


Breakout Board Design

The breakout board design requirement was to interface all external hardware components with the embedded system (SJTWO). The hardware connections are:

1. The 64x64 RGB Matrix
2. Output power to the RGB Matrix
3. User game controller (see next section)
4. Input power supply (5V)
5. The SJTWO embedded system


Breakout Board Schematic


Breakout Board PCB Top Layout
Breakout Board PCB Bottom Layout
Breakout Board PCB Top Layout
Breakout Board PCB Bottom Layout
Populated and mounted to the SJTWO board

Known Breakout PCB Issues

Known Issues

Summary

Description

Version

Status

5V should not be routed to game controller. 3.3V should be routed to the game controller instead of 5V since the ADC pins are not 5V tolerant. 0.1 Resolved Rev 0.2
Wrong silkscreen/not enough room near power input. Power input silkscreen too small, part too big for 3.3V LED to fit 0.1 Resolved Rev 0.2
Linear regulator not needed. The schematic for the SJTWO board labels the input voltage pin as VIN RAW, which is different than the label on the

optional input port. They are both the same, so this input feeds directly into the on-board 3.3V regulator. Essentially we're driving the regulator with the same voltage it outputs which just won't work well.

0.1, 0.2 UNRESOLVED

Gamepad Hardware Design

The gamepad board design requirement was to provide a more packaged interface for the user to interact with the game.

Gamepad Schematic


Gamepad PCB Top
Gamepad PCB Bottom
Gamepad PCB Fully Populated (no enclosure)

Hardware Design (Mechanical)

Only a few mechanical components were needed for this project. Namely simple brackets for mounting electrical hardware to the RGB matrix and displaying the matrix itself. All CAD designs were done using Onshape, a free CAD tool that can be used entirely through your web browser.

For displaying the RGB matrix, two brackets were 3D printed to prop it up. Their STL files can be found under our source repository.

Mounting bracket design used to prop up the RGB matrix

Hardware Integration

RGB LED MATRIX

The LED matrix that we use is 64 pixels by 64 pixels and is controlled through a 12-pin header consisting of the following pins:

  • Five Mux pins (A,B,C,D,E) for Row Selection
    • In order to select a specific row of the LED matrix, we need to control the output level of each mux pin. Since the LED matrix light up two rows of LEDs at one time, we can only select 1 out of 32 rows.
  • Two sets of RGB pins (R1,G1,B1,R2,G2,B2) for Color Selection
    • Since we are driving two rows of LED matrix at once, we need 2 sets of RGB pins. One set is used to control the color pixels of the upper half of the display and the other set for the bottom half of the display.
  • Output Enable Pin (OE)
    • Output Enable (OE) pin is used to turn on or off the LEDs of the current row.
  • Latch Pin (LAT)
    • Latch pin is used to prevent the data being shifted into the shift registers and tells the shift register when it is time to switch to newly entered data.
  • Clock Pin (CLK)
    • triggers a shift on the shift registers

All these pins are required to display a specific color on a specific pixel of the LED matrix display.

Pin Connections between SJtwo Board and REG LED Matrix
LED Matrix - Row Scanning

Apparently, it is impossible to driver all 4096 LEDs all at one time and thus, we can only drive two rows of LEDs at a time (one row on the upper half of the display and another row on the lower half of the display). By refreshing the LED matrix two rows at a time in a fast frequency, we can display all the game objects with animation on the LED matrix.

Joysticker controller

The joystick that we use is the product from Adafruit, the Analog 2-axis Thumb Joystick. This 2-axis Thumb Joystick provides the following pins:

  1. Two ADC pins
    1. In order to control the tower location, we need to control the Joysticker, since the direction has four: Up, Down, Left, Right, we use the Y and X-axis to implement this function.
  2. Three GPIO pins
    1. In order for selecting for the tool we need two GPIO pin for button and 1 GPIO pin for controlling the LED on the JOY STICKER controller
  • Pin configuration

Selection 999(032).png

MP3 Decoder

The MP3 decoder that we use is Sparkfun’s vs1053 shield MP3 decoder which is the board based on the vs1053b chip.

MP3 Decoder Module Pinout
MP3 Decoder Pin Table
  • Three SPI pin

In order to communicate with the mp3 decoder with SJtwo Board, we choose the SPI as the protocol to control the decoder. Hence, we need the one pin SCK0 (clock), one pin MOSI(Master In Slave Out) and one pin (Master Out Slave In).

  • Four GPIO pin for the decoder

There are four major GPIO pin for DREQ(Data Request Pin), Reset, CS(Chip Select), XDCS(Data Chip Select), this 4 GPIO pin is how we transfer data and send the command to activate the mp3 decoder work with SJ2 Board.

Software Design

RGB LED Matrix

RGB Data Element

All the LED Matrix data are stored in a buffer with its size equal to 32 by 64. Each element in this buffer store the color of two pixels, one pixel from the upper half of the display and one pixel from the lower half of the display.

In order to display the gaming objects in animation, we need to refresh the display by displaying the color pixels on each row one by one very fast. Below is a simple flowchart that describes the process of refreshing the display.


  • Loop through each row of the LED display
  1. Select Row (By controlling the output level of 5 mux pins, we can select one row at a time)
  2. Disable the LED Display output (Turn off the LEDs of the current row of the display)
  3. Unlatch the Data
  4. Clock in Data for each column(Store the color of each pixel inside display_matrix buffer)
  5. Latch the Data
  6. Enable the LED Display output (Display the color of each pixel of the current row)
  7. Delay for a 100us (Increase the light intensity of the LEDs by delay a short amount of time)
  8. Disable the LED Display output (Turn off the LEDs of the current row of the display)
void refreshDisplay(void) {
  for (uint8_t row = 0; row < LEDMATRIX_HALF_HEIGHT; row++) {

    select_row(row);
    led_matrix__disable_output(); // gpio__set(OE);
    led_matrix__unlatch_data();   // gpio__set(LAT);
    led_matrix__clock_in_data(row);
    led_matrix__latch_data();    // gpio__reset(LAT);
    led_matrix__enable_output(); // gpio__reset(OE);
    delay__us(100);              // Change Brightness
    led_matrix__disable_output();
  }
}
void led_matrix__clock_in_data(uint8_t row) {
  /* Clock in data for each column */
  for (uint8_t col = 0; col < LEDMATRIX_WIDTH; col++) {
    
    /* Set all the RGB pins as low*/
    LPC_GPIO1->PIN &= ~(0x1 << R1.pin_number | 0x1 << G1.pin_number | 0x1 << B1.pin_number);
    LPC_GPIO2->PIN &= ~(0x1 << R2.pin_number | 0x1 << G2.pin_number | 0x1 << B2.pin_number);

    /* Set the RGB pins as High or Low depends on the data stored inside the buffer */
    LPC_GPIO1->PIN |= ((((display_matrix[row][col] >> 0) & 0x1) << R1.pin_number) |
                       (((display_matrix[row][col] >> 1) & 0x1) << G1.pin_number) |
                       (((display_matrix[row][col] >> 2) & 0x1) << B1.pin_number));

    LPC_GPIO2->PIN |= ((((display_matrix[row][col] >> 4) & 0x1) << R2.pin_number) |
                       (((display_matrix[row][col] >> 5) & 0x1) << G2.pin_number) |
                       (((display_matrix[row][col] >> 6) & 0x1) << B2.pin_number));

    gpio__set(CLK);
    gpio__reset(CLK);
  }
}
Process of refreshing display

MP3 Decoder

The MP3 deocder is executed with the mainly two task: read task and play task. The reader task would read data from the sd card and sned queue data for the player task to play music.

MP3 Decoder Module API
  • Read Task
  • Loop through each row of the LED display
  1. Queue sned the target filename
  2. Queue receive the target name
  3. Find the mp3 file name is exit or not
  4. Open the file(fopen)
  5. Read data store to the buffer(Binary)
  6. Sent the data from bufder with queuesend API
READ TASK.png
  • Play Task

Receive the data of the song from the queue, and use the receiving data and sent the command to make decoder to play music.

  • Read Task
  • Loop through each row of the LED display
  1. Queue receive the data(music)
  2. disable the chip select
  3. Check the DREQ pin to know is ready or not
  4. exchange the data to the decoder to play the music
  5. Check the DREQ pin to know is ready or not
  6. disable the chip select
Play Task.png

JOY STICKER

The JOY_STICKER is using the task to pool the ADC channel data to get the direction from the Joysticker.


  • Loop through each time to poll the enum type data to get direction
  1. Receiving the data from two ADC channel(5=x, 4=y)
  2. Comparing which one has higher absolute data
  3. If (X > Y == YES) ,then we go to the loop to compare It's closer to Right or Left
  4. If (X > Y == YES && Right > LEFT == YES), then the status is Right
  5. If (X > Y == YES && Right > LEFT == NO), then the status is Left
  6. If (X > Y == NO) ,then we go to the loop to compare It's closer to Up or Down
  7. If (X > Y == NO && Up > Down == YES), then the status is Up
  8. If (X > Y == NO && Up > Down == NO), then the status is Down
Game controller
Game controller flow chart

System Flow Charts


Basic Software Environment:
Flow1 TDIS.png


Game Master (how the user sees the game flowing):
Flow2 TDIS.png


Intermission Phase (what happens while the user is placing towers):
Flow3 TDIS.png


Combat Phase (what happens when the aliens invade):
Flow4 TDIS.png

System Testing and Validation

Start Screen
Combat Phase
Player Loses the game
Player Wins the game

Technical Challenges

Game Map (2D array) to LED matrix (2D pixels) Conversion

Issue:

  1. The game map (consisting of the path as well as all of the active enemies and towers) is managed through the use of a 2D char array.
  2. In order to display each object on the LED matrix, there needs to be a mechanism that converts the object along with its 2D array location to a row/column on the LED matrix.
  3. An algorithm to do this conversion is not as straightforward as it may appear. This is because objects stored in the array take up more/less display space than what is available on the LED matrix.

Solution:

  1. In order to align the array locations with the LED matrix pixel locations, some areas on the 2D array needed to be marked as "ignore".
  2. If each array location is not carefully correlated to a specific pixel location, then there would be issues where objects are displayed overlapping each other on the LED matrix (or simply displayed in the wrong spot).
  3. There were some simple algorithms that used math to help implement this conversion.
  4. However, a LUT is what was primarily used. It was not efficient in terms of code size, it took over 500 lines of code.
  5. But it was an effective solution and allowed us to easily decide exactly where each pixel of each object would be displayed.

LED Matrix Flickering Issue

Issue: While we are developing the game, we notice that some color pixels are turned on when they are supposed to be off.

Investigation/Solution:

  1. See Known Breakout PCB Issues as a possible cause. It's possible the SJTWO board is getting inconsistent power.
  2. Refreshing the matrix should not be handled by an interrupt and not a task. The task should only push new display data and not have direct control of the matrix. Keeping the refresh interrupt driven would keep the refresh rate more consistent by removing the process being context switched out mid update.

MP3 Decoder - SJtwo Board SPI Selection

Issue:

  1. The mp3 decoder1053b's document is a kind of confusing for the mode when 1032b have several modes
  2. It's hard to know the configuration is successful or not.

Solution:

  1. Doing the survey on the GitHub is really important. For example, using the sin wave and hello binary example to test how the Initialization and HZ parameter would save a lot of time.Moreover, in the document from the vs1053b, we could use the binary file line "hello", "sine wave" function for testing.
  2. Besides, we also have to be careful to check the SJBoard's SPI because of the SD card reader is using for reading SDcard. Hence, I would recommend using other

SPI0, SPI1 instead of using SPI2.

Conclusion

We successfully designed and implemented the video game "Tower Defense In Space". All of our team members now have a better understanding of how to use FreeRTOS to handle the synchronization of multiple tasks and to communicate with multiple hardware components in an embedded application system. After completing this project, we learned how to manage a project on a tight schedule. Starting from purchasing hardware components, developing hardware drivers and game logic and then integrating all of the drivers and APIs into the game logic. Furthermore, all of us are now better at coding and debugging code. For a game design project like this, we learned that it's not always best to assign tasks independently between the team members. We learned that this type of project would benefit moreso from pair programming and other cooperative tasks that enable collaboration between teammates. Otherwise, project tasks may be done in such a way that they only work for 1 specific configuration, and wouldn't help progress towards the end goal of the integrated system. We also learned that not every day was going to be perfect, but as long as we never gave up and worked hard, then the final result would not be disappointing!


We would like to say thank you to Prof. Preet and all the ISAs for their precious suggestions and assistance during the development of this project!

Advice for Future Students

Source Control

Unless everyone in your group is comfortable using source control, don't use it. It will likely end up costing you time in the long run.

Start working on your LED Matrix driver ASAP

The first 64x64 LED Matrix that we got from Sparkfun suffers from a serious flickering issue. After spending for a week trying to debug what causes the flickering issue, we still have no idea whether it is a hardware issue or software issue. Later, we borrow another LED matrix from a student of our class and test our code. With the other student's LED matrix (we use our own power supply and ribbon cables), there is no flickering issue at all. According to some online resources, some matrix vendors scatter the selected rows and columns differently. It is possible that your designed driver may only work on some LED matrix vendors' displays.

Video Demonstration

Demo Video (Player Wins)

Demo Video (Player Loses)

Source Code