WIRELESS GESTURE CONTROLLED TANK TOY - Cornell University

4 downloads 65 Views 2MB Size Report
May 10, 2011 ... Report for ECE 4760 project for school of electrical and computer engineering. By,. Rick Wong (rw363). Professor: Bruce Land. Date: 2011-05- ...
 

  WIRELESS GESTURE CONTROLLED  TANK TOY     

Report for ECE 4760 project for school of electrical and computer  engineering    By,  Rick Wong (rw363)      Professor: Bruce Land      Date:  2011‐05‐10     

 

 

 

                  WIRELESS GESTURE CONTROLLED TANK CAR   

TABLE OF CONTENTS 1  2 













ABSTRACT ............................................................................................................................................... 4  INTRODUCTION ...................................................................................................................................... 5  2.1  Project Overview ................................................................................................................. 5  2.2  System Block Diagram ......................................................................................................... 6  MAJOR COMPONENTS ........................................................................................................................... 8  3.1  ATMega168 ......................................................................................................................... 8  3.2  Features ............................................................................................................................... 8  3.3  Gyro Scope .......................................................................................................................... 9  3.4  Wi.232DTS Wireless‐Serial Module ..................................................................................... 9  3.5  SRF05 Ultra‐Sonic Distance Sensor ................................................................................... 11  SOFTWARE HIGHLIGHTS ....................................................................................................................... 12  4.1  Software Reset using Watch‐Dog ...................................................................................... 12  4.2  Smooth Motor Control with Safety Features .................................................................... 13  Circuit ................................................................................................................................................... 14  5.1  Original Plan ‐ PCB ............................................................................................................. 14  5.2  Backup Plan – Solder Board .............................................................................................. 16  CONCLUSION ........................................................................................................................................ 19  6.1  Summary ........................................................................................................................... 19  6.2  Lessons I learned ............................................................................................................... 19  6.3  Intellectual Property Considerations ................................................................................. 19  6.4  Ethical Considerations ....................................................................................................... 19  6.5  Legal Considerations ......................................................................................................... 20  APPENDIX ............................................................................................................................................. 21  7.1  Budget ............................................................................................................................... 21  7.2  Demonstration Video ........................................................................................................ 21  7.3  Schematics ........................................................................................................................ 21  7.4  Acknowledgement ............................................................................................................ 24  7.5  Code Files .......................................................................................................................... 24  REFERENCE ........................................................................................................................................... 25  8.1  Datasheets ......................................................................................................................... 25  8.2  Vendors ............................................................................................................................. 25  8.3  Code Borrowed from Others ............................................................................................. 25 

   

 

 

 

 

 

   

   

   

  Page 2 of 25 

 

 

                  WIRELESS GESTURE CONTROLLED TANK CAR   

LIST OF FIGURES Figure 1 Conventional Wireless Controller .............................................................................................. 5  Figure 2 Gesture Wireless Controller ...................................................................................................... 5  Figure 3 Remote Controlled Tank ............................................................................................................ 6  Figure 4 System Block Diagram ............................................................................................................... 7  Figure 5 ATMega168 system block diagram ............................................................................................ 8  Figure 6 Wi.232 Wireless‐Serial Module ............................................................................................... 10  Figure 7 SRF05 Ultra‐Sonic Senor .......................................................................................................... 11  Figure 8 SRF05 Timing Diagram............................................................................................................. 11  Figure 9 Schematic of the Remote Tank ................................................................................................ 14  Figure 10 Schematic of partial of the Gesture Controller ..................................................................... 15  Figure 11 PCB Drawing of the Remote Tank .......................................................................................... 15  Figure 12 Defected PCB Boards on the left and Re‐made PCB on the right .......................................... 16  Figure 13 Top Side of the Solder Board on the Remote Tank ................................................................ 16  Figure 14 Bottom Side of the Solder Board on the Remote Tank ......................................................... 17  Figure 15 Top Side of the Solder Board on the Remote Tank ................................................................ 17  Figure 16 Bottom Side of the Solder Board on the Remote Tank ......................................................... 18 

   

 

 

 

 

 

   

   

   

  Page 3 of 25 

 

 

                  WIRELESS GESTURE CONTROLLED TANK CAR   

1 ABSTRACT The objective of this project is to build a tank car that can be controlled by gesture wirelessly. User is able to control motions of the tank by wearing the controller glove and performing predefined gestures. This tank can detect block objects and stop automatically; in addition, feedback messages are sent to the controller and warn the user by a vibration motor. This project provides a basic platform for many potential applications such as wireless controlled car racing games, gesture human-machine interfacing, and etc. For this project, ATMega168 microcontroller and gyro scope are employed for the controller; ATMega168, H-bridge, and ultra-sonic sensor are employed for the controlled tank. A pair of wireless UART module, Wi.232, is used to communicate between the controller and tank. However, the hardware is also ready for ZigBee wireless protocol.

   

 

 

 

 

 

   

   

   

  Page 4 of 25 

 

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

2 INTROD DUCTION 2.1

Project Overview O

ollers  of  exxisting  remo ote  toys,  as  shown  in n  Figure  1,  require  users  to  Mosst  of  contro interface with joysticks and d push buttons.    Comparing to th hese conven ntional controllers,  I built a wirelesss gesture co ontroller wh hich enabless toys to mo ock hand motions in alll three  dimeensions  as  shown  in  FFigure  2.    To  T demonsttrate  this  wireless  w gessture  contro oller,  a  remote tank is aalso implem mented, as sshown in Figgure 3. 

  Figure 1 Conventional Wireless Controller

Figure 2 Gesture Wirelesss Controller    

 

 

 

   

   

  Pagge 5 of 25 

 

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

Figure 3 Remote Contro olled Tank

 

2.2

System Block Dia agram

m  block  diaggram  illustrrates  the  sttructure  of  the  system m,  the  The  below  oveerall  system mod dules and th he communication prottocols betweeen them.   The  whole  is  d divided  into o  four  main  parts:  Reemote  Tankk  and  Gestu ure  Controlller  as  desccribed  below w.    A  pair  of  wirelesss‐serial  mod dule  commu unicates  between  thesse  two  partts.    As sshown in Figgure 4, the  microcontrroller, MCU  collects anggular acceleeration dataa from  the  gyro  scopee  and  translates  these  motion  datta  into  corrresponded  ccommands  which  conttrol  the  motors  on  tthe  remotee  tank  befo ore  sendingg  these  co ommands  tto  the  wireeless‐serial m module via UART proto ocol.    The  remote tan nk reads thee command ds sent by th he gesture  controller vvia UART prrotocol  from m the wireleess‐serial mo odule and p performs thee required m motor contrrols.        On tthe other haand, feedbaacks from th he ultra‐son nic senor an nd encoder aare sent fro om the  remote tank baack to the ggesture conttroller wirelessly as thee way the ggesture controller  send ds command ds.     

 

 

 

   

   

  Pagge 6 of 25 

 

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

  Figuree 4 System Block k Diagram

   

 

 

 

   

   

  Pagge 7 of 25 

 

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

3 MAJOR COMPONENTS In th his chapter, the major ccomponentss are introdu uced.  3.1

ATMega a168

Simiilar  to  otheer  AVR  miccrocontrolleers,  includin ng  the  ATM Mega644  ussed  in  ECE  4760,  ATM Mega168 is aa member o of the AVR M MCU family from ATMEEL Inc.    It iss one of thee ideal  MCU U for simplee and inexpeensive emb bedded appllications.    TThe main reeason I chosse this  chip p  is  that  I  h have  a  coup ple  of  them m  denoted  for  free  and  clearly  itt  has  the  enough  perfformance to o do the exp pected jobs.    This MCU is briefly  introduced  and unnecessary  detaails are skipp ped due to tthe similaritties shared with the ATTMeg644.    3.2

Features s

Figu ure 5 is the ssystem block diagram o of the ATMeega168 MCU U used in thiis project.   

  Figure 5 ATM Mega168 system m block diagram    

 

 

 

   

   

  Pagge 8 of 25 

 

 

                  WIRELESS GESTURE CONTROLLED TANK CAR   

The features of the MCU that relate to this project are listed below.     High Performance, Low Power AVR® 8‐Bit Microcontroller   16K Bytes of In‐System Self‐programmable Flash program memory   1K Bytes Internal SRAM   In‐System Programming by On‐chip Boot Program   Two 8‐bit Timer/Counters with separate prescaler and compare mode   16‐bit Timer/Counter with separate prescaler, compare mode, and capture mode   Six PWM Channels   Programmable Serial USART   Byte‐oriented 2‐wire Serial Interface (Philips I2C compatible)   Programmable Watchdog Timer with Separate On‐chip Oscillator   Interrupt and Wake‐up on Pin Change   Power‐on Reset and Programmable Brown‐out Detection  3.3

Gyro Scope

The gyro scope used in this project is the ITG‐3200 from InvenSense Inc.    ITG‐3200 was  the  world’s  first  single‐chip,  digital‐output,  3  axis  MEMS  gyro  scope  that  has  built‐in  temperature  sensor  for  user  calibrations.    It  converts  the  low‐pass  filtered  angular  acceleration data using the three built‐in 16‐bit analog‐to‐digital converter and outputs  the digital data via I2C protocol.      The  features  of  this  gyro  scope  that  relate  to  this  project  are  listed  below  (abstracted  from the ITG‐2300 datasheet from InvenSense Inc.)     Digital‐output  X‐,  Y‐,  and  Z‐Axis  angular  rate  sensors  (gyros)  on  one  integrated  circuit  with  a  sensitivity  of  14.375  LSBs  per  °/sec  and  a  full‐scale  range  of  ±2000°/sec     Three  integrated  16‐bit  ADCs  provide  simultaneous  sampling  of  gyros  while  requiring no external multiplexer     Enhanced  bias  and  sensitivity  temperature  stability  reduces  the  need  for  user  calibration     Low  frequency  noise  lower  than  previous  generation  devices,  simplifying  application development and making for more‐responsive motion processing     Low 6.5mA operating current consumption for long battery life      3.4

Wi.232DTS Wireless-Serial Module

The Wi.232DTS wireless‐serial module from Radiotronix Inc. is a simple and inexpensive  wireless communication solution that supports CRC error checking, programmable UART  rate, and multiple transmission channels.    In short, it basically acts like a standard UART     

 

 

 

 

 

   

   

   

  Page 9 of 25 

 

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

cable.    The  on nly  tricky  paart  of  usingg  this  module  is  that  th he  UART  RX XD0  pin  fro om  the  MCU U shall be co onnected to o the TXD0 pin from this module, aand the UART TXD0 pin n from  the  MCU  shall  be  connectted  to  the  RXD0  pin  from  f this  module.  m   Th he  pin‐out  o of  this  mod dule  is  show wn  in  Figuree  6  and  Tab ble  1.    Please  note  th hat  this  figu ure  and  tab ble  are  from m the ITG‐32 200 datasheeet from Rad diotronix Inc.   

  Figure 6 W Wi.232 Wireless‐SSerial Module 

Table 1 Wi.2332 Wireless‐Seriall Module Pin‐out

   

 

 

 

 

 

   

    Pagee 10 of 25 

 

3.5

              NTROLLED TANK CAR  WIRELESS GESTURE CON  

SRF05 U Ultra-Sonic c Distance e Sensor

The  ultra‐sonic  distance seensor, SRF05 5, used in th his project h has a detecttion range ffrom 3  cm  up  to  4  m meters.    It  supports  dual‐pin  and d  single‐pin n  modes  an nd  the  singgle‐pin  conffiguration  aas  shown  in n  Figure  7 is  used  in  this  projecct  to  simplify  the  harrdware  conn nection.   

  Figure 7 SRF05 Ultra‐So onic Senor 

Usin ng this senso or is fairly eeasy.    The EEcho outputt of this sen nor is conneected to thee input  captture channeel of the ATM Mega168 an nd timer1 of the MCU iis used to m measure thee timer  period echo pulse which iss used to calculate the d distance usiing Equation 1.    The ccontrol  triggger pulse an nd resulting echo pulse timing diaggraming is sh hown in Figure 8.  Distance 

eecho pulse ttime ∗

.

 



Equation 1. C Calculate distancee from pulse time    

  Figuree 8 SRF05 Timing Diagram     

 

 

 

 

 

   

    Pagee 11 of 25 

 

 

                  WIRELESS GESTURE CONTROLLED TANK CAR   

4 SOFTWARE HIGHLIGHTS In this project, more than 2,000 lines have been coded; discussions of all the code are obviously unpractical and meaningless. Therefore, in this chapter, highlights of the software development are presented. 4.1

Software Reset using Watch-Dog

For reliability and safety concerns, the remote tank shall be able to be reset wireless in  case  of  system  hang  or  other  extreme  situations.    To  archive  that,  I  employed  a  watch‐dog  in  the  ATMega168  to  hot  reboot  the  MCU  whenever  the  system  hangs  or  received  reset  command  from  the  gesture  controller.    The  reboot  function  is  shown  below.    Please  note  that  after  calling  reboot  function,  the  MCU  will  fall  into  a  reboot  loop unless the watch‐dog is disabled within the pre‐set time after MCU reboot.    /*‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐    * Function details:      reboot the chip    * Name:        reboot()    * Usage:        call this function to reset the chip    * Input:         none    * Return:        none    * Attention:        TO BE UPDATED    * Notes:        none  ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐*/  void reboot(void)  {      wdt_enable(WDTO_15MS);      while (1) {;}  } 

  //watch dog define  #define DOG_SLEEP          {MCUSR &= (~(SET