Home

ECE 477 Final Report − Spring 2009 Team 12 − FlySpy

image

Contents

1. fine SPIOUTPORT PORTCbits Will generate an error if the cloc Defines for the HPC Explorer board SCK pin TRISCbits TRISC3 SDI pin TRISCbits TRISC4 SDO pin TRISCbits TRISC5 the SCK pin LATC3 the SDI pin LATC4 the SDO pin LATC5 pin RC3 pin RC4 pin RC5 Spring 2009 k speed is too low to interface to the RB1 ts TRISB1 RFO ts TRISFO if GetSystemClock lt 400000 error System clock speed must exceed 400 kHz endif f defined PIC24F Description SD SPI Chip Select Output bit define SD_CS PORTFbits RF5 PORTBbits Description SD SPI Chip Select TRIS bit define SD_CS_TRIS TRISFbits TRISF5 TRISBbi Description SD SPI Card Detect Input bit define SD_CD PORTFbits RF6 PORTFbits Description SD SPI Card Detect TRIS bit define SD_CD_TRIS TRISFbits TRISF6 TRISFbi Description SD SPI Write Protect Check Input bit define SD WE PORTFbits RFl Description SD SPI Write Protect Check TRIS bit tdefine SD WE TRIS TRISFbits TRISF1 Registers for the SPI module you want to use Description The main SPI control register define SPICON1 SPI2CON1 SPI1CON1 Description The SPI status register define SPISTAT SPI2STAT SPI1STAT Description The SPI Buffer define SPIBUF SPI2BUF SPI1BUF Description The receive buffer full bit in the SPI status register define SPISTAT R
2. Description This macro indicates that the SD card does not expect to transmit or receive more data define NODATA 0 Description This macro represents a floating SPI bus condition define MMC_FLOATING_BUS OxFF Description This macro represents a bad SD card response byte F 80 ECE 477 Final Report define MMC BAD RESPONSE The SDM M Description T fine Description fine cmdS Description fine cmdS Description fine cmdS Description lti block read fine Description T fine E Description T o QI H LH oO QI H Ina oO QI H iT Ps pi do H a H Q fine o cmdGO C Commands his macro de IDLE STATE his macro de ND OP COND his macro de ND CSD his macro de ND CID his macro de his macro de END STATUS his macro de ET BLOCKLEN M Description fine Description ME Q H o fine Description fine Description E QI a H Q fine cmdWR Description T erase operatio QI o w efine Description T an erase operatio efine cmdTA Description T blocks efine cmdER OLO E SO S N O OW lt O SLO O A L OG x O0 KO NO oO x Description T command inputs define cmdAP Description T information from define cmdRE Description T define cmdCR Description typedef enum R1 R1b R2 R3 ANA JRESP
3. float Accel_x float Accel_y float Accel_z float magnitude float average float xsample 0 float ysample 0 float zsample 0 float CurrentPitchVolt 0 float CurrentRollVolt 0 double PitchAnglea double RollAnglea int lov for lev 0 lov lt 10 levtt CurrentPitchVolt sampleADCPort GYRO Y VREF 1024 CurrentRollVolt sampleADCPort GYRO X VREF 1024 CurrentPitchVolt lcv CurrentRollVolt lcv PitchAngle CurrentPitchVolt 1 492412 002 50 RollAngle CurrentRollVolt 1 5058 002 50 F 87 ECE 477 Final Report Spring 2009 if fabs PitchAngle gt 180 for lev 0 lev lt 10 lov t xsample sampleADCPort ACCEL X ysample sampleADCPort ACCEL Y zsample sampleADCPort ACCEL 2 Accel_x sampleToG xsample lcv Accel y sampleToG ysample lcv Accel z sampleToG zsample lcv magnitude sqrt Accel x Accel x Accel y Accel y Accel z Accel z average 0 for lev 1 lev lt VarianceLogLength levtt average magnitudes lcv magnitudes lcv 1 magnitudes lcv magnitudes lcv magnitude average magnitude average VarianceLogLength 0 0 lev lt VarianceLogLength lcv Variance for lcv Variance magnitudes lcv average magnitudes lcv average Variance VarianceLogLength if fabs l magnitude
4. Definitions that apply to all 8 bit products PIC18 if defined 18CXX define attribute a define FAR Microchip C18 specific defines dif defined HI TECH C define ROM define strcpypgm2ram a char b endif far rom b strcpypgm2ram a far rom HI TECH PICC 18 STD specific defines if defined HI TECH C define ROM define rom define Nop define ClrWdt define Reset asm RESET fendif const asm NOP asm CLRWDT Definitions that apply to all 16 bit and 32 bit products PIC24F PIC24H dsPIC30F dsPIC33F and PIC32 else define ROM const 16 bit specific defines PIC24F PIC24H dsPIC30F dsPIC33F if defined C30 define Reset asm reset define FAR attribute far endif 32 bit specific defines PIC32 if defined C32 define persistent F 14 ECE 477 Final Report define define FAR define define far Reset ClrWdt WDTCON_WDTCLR_MASK endif endif define Nop endif Spring 2009 SoftReset WDTCONSET asm nop KKK Kk kA sk K ske Kk k k kk k k k k k k k k k k k KA KA KA KA kA k k KA KA KA k k k k KKK X k k FlySpy h Authors Project Jeremy Tillman William Ehlhardt FlySpy ECE477 Team 12 Spring 2009 KKK KKK KKK KKK Kk k X k k k k k k k k k k k k k k k K k k k
5. F 74 Spring 2009 ECE 477 Final Report Spring 2009 SPICLOCKLAT 1 clock MANUAL_SPI_CLOCK_VALUI Bi se while clock if SPIINPORT result 0x02 Bit 0 SPICLOCKLAT 0 clock MANUAL_SPI_CLOCK_VALU while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALU LJ se I se while clock if SPIINPORT result 0x01 SPICLOCKLAT 0 return result end ReadMedia endif End gt 25600000 endif End 18CXX KKK kk kk KKK K kk k kk kk Ck k k k Ck k KA KA KA KA KA KKK KA KA KA AXA KA AXA k k k k k k k k ke ke ke k e k k Function BYTE MDD SDSPI MediaInitialize void Summary Initializes the SD card Conditions The MDD MediaInitialize function pointer must be pointing to this function Input None Return Values TRUE The card was successfully initialized FALSE Communication could not be established Side Effects None Description This function will send initialization commands to and SD card Remarks None KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK ae BYTE MDD SDSPI MediaInitialize void WORD timeout BYTI status TRUE MMC RESPONSE response dif defined C30 defined C32 WORD spiconvalue 0x0003 endif SD_CS 1 Initialize Chip Select line Media powers up in the open drain mode and cannot handle a clock
6. And wait for its completion while MYSPISTAT SPIRBF Wait for a byte reply MYSPIBUF amp OxFF ECE 477 Final Report Spring 2009 printf 0x 02x int reply return reply And feed it back static void writereg8 unsigned char addr unsigned char value Convert the address into the write to this address command to be sent over the SPI bus addr addr lt lt 2 0500000010 BAROMETER_CS 0 Select the barometer spi_comm addr Throw the data onto under the bus spi_comm value BAROMETER_CS 1 Deselect the barometer I don t think there are any 16 bit writable registers William if 0 static void writeregl6 unsigned char addr unsigned int value Convert the address into the write to this address command to be sent over the SPI bus addr addr lt lt 2 0b00000010 BAROMETER_CS 0 Select the barometer spi_comm addr Throw the data onto under the bus spi_comm value gt gt 8 amp OxFF Send the high byte first spi comm value amp OxFF and then the low byte BAROMETER CS 1 Deselect the barometer endif static unsigned char readreg8 unsigned char addr unsigned char ret 0 Convert the address into the read from this address command to be sent over the SPI bus addr addr lt lt 2 amp 0b11111100 BAROMETER_CS 0
7. F 44 ECE 477 Final Report Spring 2009 ifdef PIC24FJ256GA110__ void ioMap Analog device pins Set them all to analog mode AD1PCFGbits PCFGO AD1PCFGbits PCFGL AD1PCFGbits PCFG2 AD1PCFGbits PCFG3 AD1PCFGbits PCFG4 ADIPCFGbits PCFG5 C3 CX 09 C 6 TODO Do the ICD pins need some magic setup here They overlap some analog channels Also do I need to specifically disallow ICD2 action on the AN0 AN1 channels Presumably not but it s worth a check William Autopilot manual TRISD7 1 CTRL SW input TRISD6 1 GEAR SW input Camera I O _TRISA2 1 CAM_POW_FB input RA2 _TRISG2 0 CAM_SHUTTER output RG2 _TRISG3 0 CAM POWER output RG3 SPI fl Barometer RPOR4bits RP9R SCK1OUT IO SCK1 output RP9 TRISB9 0 AKA RB9 AD1PCFGbits PCFG9 1 AKA AN9 RPOR15bits RP31R SDOL IO SDO1 output RP31 _TRISF13 0 AKA RF13 RPINR20bits SDIIR 32 SDI1 input RPI32 _TRISF12 1 AKA RF12 I ll manage the EN bit manually as the barometer uses variable length frames RPOR14bits RP29R SS1OUT_IO SST1 output RP29 TRISB15 0 AKA RB15 ADIPCFGbits PCFG15 1 AKA AN15 SPI 2 MicroSD TODO enable the pullup on this pin _TRISF6 1 SD chip detector input RF 6 RPINR22bits SDI2R 43 SDI2 input RPI43 TR
8. gpsBuffer gpsBufferTail length gpsReceiveBuffer length se gpsBufferTail gpsBufferTail 1 GPSBUFFERSIZE gpsSentenceStarted 0 gpsReceiveTail 0 else if gpsReceiveBuffer gpsReceiveTail gpsSentenceStarted 1 gpsReceiveTail 0 else printf GPS SENT Sc r n gpsReceiveBuffer gpsReceiveTail gpsReceiveTailtt IFSObits UlRXIF 0 else Passthrough mode hooks GPS straight through to serial port void initgps void UIBRG BAUDRATEREGL IPC3bits UlTXIP 0x01 IPC2bits U1RXIP 0x01 U1STA 0x0000 U1MODE 0x8000 U1STAbits UTXEN 1 gpsSendMessage gpsOutputSetup 47 gpsSendMessage gpsEnableSbas 15 gpsSendMessage gpsEnableWAAS 15 F 22 ECE 477 Final Report define BUFLEN 256 char buffer BUFLEN int to_write 0 int to_read 0 static char dequeue void char ret buffer to_read to_read to_read 1 SBUFLEN return ret static void enqueue char val buffer to_write val to write to write 1 BUFL Ez z lt static char drdy void return to_read to_write void gps_passthrough void printf gogogo r n initgps U1STAbits OERR 0 while 1 int byte getchar int byte 1 if 0 if byte 1 Spring 2009 pull character from gpserial printf ECHO xNrWMn i
9. if targetDistance 020 if Distance is less than 20 meters if wayPoints wp_index Picture 1 setPitch 0 setRoll 0 logPicturePoint amp CurrentGPS takePicture wp index else bearingDifference fmodf targetBearing CurrentGPS Heading 540 360 180 Roll bearingDifference MAX_ROLL 180 ZL sensorInfo inuse 1 ZAVA if sensorInfo Altitude 100 25 gt wayPoints wp index Altitude Pitch MAX PITCH else if sensorInfo Altitude 100 wayPoints wp index Altitude 25 Pitch MAX_PITCH sensorinfo inuse 0 Equate how much turn should be given at the time Call setOrientation to guide the plane in that direction setRoll Roll setPitch Pitch setRoll ROLL ZERO setPitch PITCH ZERO if SecondFlag 1 read_PWM_IN amp man_l_ail amp man_r_ail man_throttle amp man_elev amp man_rudder read PWM OUT amp auto_l_ail amp auto r ail amp auto throttle amp auto elev amp auto rudder sensorInfo inuse 1 ECE 477 Final Report Spring 2009 logCoord amp wayPoints wp index amp CurrentGPS targetDistance targetBearing sensorInfo Altitude sensorInfo Pitch sensorInfo Roll sensorInfo Clearing auto throttle auto elev auto rudder auto I ail auto r ail man throttle man elev man rudder man 1 ail man r ail Log information to SD Card sensorInfo inuse 0 SecondF
10. card card card PORTE PORTE TRISE TRIS register output latch register chip select output latch bit latch bit bit RD11 chip select TRIS bit _TRISD11 output enable strobe latch bit ZRS output enable strobe TRIS bit _TRISD5 writ nable strob _RD4 write enable strobe TRIS _TRISD4 reset signal latch bit _RDO reset signal TRIS bit _TRISDO ready signal port bit _RD12 ready signal TRIS bit _TRISD12 detect signal port bit F 36 Spring 2009 for h definition for h definition for h definition for tion for PIC24 30 33 32 tion for PIC24 30 33 32 tion for PIC24 30 33 32 tion for PIC24 30 33 32 ECE 477 Final Report IC24 IC24 IC24 IC24 define CF BT CD1 _RC4 Description The CF card detect signal TRIS bit define CF BT CDIDIR _TRISC4 felif defined __dsPIC33F__ Address lines Description The CF address bus bit 0 output latc 30 33 32 define ADDRO LATB15 Description The CF address bus bit 1 output latc 30 33 32 define ADDR1 LATB14 Description The CF address bus bit 2 output latc 30 33 32 define ADDR2 _LATG9 Description The CF address bus bit 3 output latc 30 33 32 define ADDR3 _LATG8 Description The CF address bus bit 0 TRIS defini define ADRTRISO TRISB15 Description The CF address bus bit 1 TRIS defini define ADRTRIS1 _TRISB14 Description The CF a
11. k k KA I k k k k k k k ke k ke e k ke X KKK define define define define typedef PROGRAMF OLDER FLYSPY INPUTFILE WAYPTS TXT OUTPUTFILE FLYINFO XML MAXWAYPOINTS 20 struct userwaypoint double Latitude double Longitude float Altitude int Picture WAYPOINT F 43 ECE 477 Final Report Spring 2009 typedef struct int TakeOff int Delay int Landing double TakeOff_Altitude double Landing_Altitude double Landing_Latitude double Landing_Longitude TAKEOFF LANDING void initio void KKK KR RR KKK KKK K I kk k k kk k k k k k k k k k k k KA KA k k k k k k k k KG Ck KG kk Author Daeho Hong Function int logEnd Summary Writing the very last part of the log which is xml closer KKK KKK KKK AA KKK kA kA k k k k k k KK k KA KA KA KA KA A KA KA KA KK int logEnd KKK kk kk k KKK Kk k k k kk kk kk k kk kk k k k k k k k KKK KA k k k k k k k k k kk Author Daeho Hong Function int logStart Summary Writing the very first part of the log which is xml initialization KKK KKK KA KA K A kCk K KKK K kA kk k k k k Ck k KA KA KA k k KKK KKK KKK KKK KKK KKK KK int logStart void logPicturePoint GPSINFO Gps f KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KK KKK k k KKK k k k k k kk Author Daeho Hong Function int logCoord int i
12. k k k k k k k k KA KA k k k KA KA KA KC k k k k KA k k KKK YETI i Authors Jeremy Tillman William Ehlhardt Project FlySpy k ECE477 Team 12 Spring 2009 KCKCKCKCKCK ske sk KKK sk k KKK K K K k K K k k k k k k k k k k k k k KA k k k k k k kk k k k k k k k sk ke k k Xe ke kk finclude util h long linmap long x1 long yl long x2 long y2 long x return y2 yl x x1 x2 x1 yl long limit long min long max long x if x lt min x min if x gt max x max return x S KKK KKK KKK KKKK KKK KKK KKK KKK KKK KK KKK KKK k k KKK KKK KKK KKK KKK KKK KKK KKK KKK Ota lh Authors Jeremy Tillman William Ehlhardt Project FlySpy ki ECE477 Team 12 Spring 2009 KCKCKCK skok ske sk ske sk ske KKK KKK k X k X k k k A k k k k k k k k k k KA I k k k k k kk k sk ke k k k ke ke e x k f ifndef UTIL H define UTIL H Je Performs linear interpolation of a line defined by two points xl yl and x2 y2 to return the value of y corresponding to the given x on the line long linmap long x1 long yl long x2 long y2 long x F 95 ECE 477 Final Report Spring 2009 Limits x to the range min max long limit long min long max long x dendif F 96 ECE 477 Final Report Appendix G FMECA Worksheet Fall 2008 Failure Failure Mode Possible Causes Failure Effec
13. proxy purchasin 2 We would probably have to rely on United States export regulations 6 1 4 FAA Regulations 24 ECE 477 Final Report Spring 2009 The Federal Aviation Administration has rules that affect model aircraft including FlySpy In particular a pilot must have an inexpensive FAA permit in order to legally fly the aircraft this would be noted in the user manual Also the FAA restricts flight in certain areas such as airport approach and takeoff corridors and security related no fly zones We cannot directly prevent the user from flying the plane into such zones under manual control at least not without compromising the reliability of the manual autonomous switching system but we could conceivably load GPS coordinates of no fly zones into the firmware to prevent the user overflying them in autonomous mode This could be difficult to keep up to date however As such the only option may be to simply note the existence of such zones in the manual and to remind the user to check with local aviation authorities including a disclaimer that we are not responsible for user misuse 6 2 Environmental Impact Analysis 6 2 1 Material Disposal FlySpy has three major classes of material posing environmental concerns the airframe the control circuitry and the LiPo battery Since the plane is meant to be used outdoors and has a nontrivial chance of getting lost outdoors the wild blue yonder failure mode the risk of its mater
14. se se se se se se se se se se unsigned ERASE G unsigned SECTOR unsigned C SIZE MU unsigned C SIZE MU unsigned VDD W CURR MAX R R R se se se ee unsigned VDD W CUR unsigned VDD R CU unsigned VDD R CU unsigned C SIZE L unsigned C SIZE H unsigned C SIZE unsigned RESERV unsigned DSR IM unsigned READ BLK MISALIGN unsigned WRITE BLK MISALIGN unsigned READ BL PARTIAL unsigned READ BL LEN unsigned CCC L unsigned CCC H unsigned TRAN SPE unsigned NSAC unsigned TAAC unsigned RESERV unsigned SPEC V unsigned CSD ST se se se se se se U ti Oc N Se Ne se se se se se se JJ U se se se D 3 RS UCTURE se se No N200000000 4S IS Hr HE P PO P2 OOo PO CO CO CO CO PO I O1 PO CO C1 EN UNYV E UF E E ES PO 9 Ik s se DER bi b ESD Summary A description of the card information register Description This union represents different ways to access information in a packet with SD card CID register informaiton For more information on the CID register consult an SD card user s manual typedef union struct F 84 ECE 477 Final Report DWORD _u320 DWORD _u321 DWORD _u322 DWORD _u323 l struct 1 BYTE _byte 16 li struct unsigned NOT_USED unsigned CRC unsigned MDT DWORD PSN unsigned PRV char PNM 6 WORD OID unsigned MID l
15. unsigned int pb clk unsigned int spi clk Summary Calculate the PIC32 SPI BRG value Conditions None Input pb clk The value of the PIC32 peripheral clock spi clk The desired baud rate Return The corresponding BRG register value Side Effects None Description The SPICalutateBRG function is used to determine an appropriate BRG register value for the PIC32 SPI module Remarks None KKK KKK KKK k kk Ck Ck kk kk X k k k kA k k k k k k k k k KK KK kk static inline __attribute__ always_inline unsigned char SPICalutateBRG unsigned int pb clk unsigned int spi clk F 56 ECE 477 Final Report unsigned int brg brg pb clk 2 spi_clk if pb clk 2 spi clk brgtt if brg gt 0x100 brg lt 0x100 if brg brg return unsigned char brg endif ED KK kk sk sk KKK KKK K I kk kk k kk kk kk kk kk kk k KK k kk ke ko ke k k k e Function BYTE MDD_SDSPI_MediaDetect Summary Determines whether an SD card is present Conditions The MDD_MediaDetect function pointer must be configured to point to this function in FSconfig h Input None Return Values TRUE Card detected FALSE No card detected Side Effects None Description The MDD SDSPI MediaDetect function will determine if an SD card is connected to the microcontroller by polling the SD card detect pin Remarks None KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK k k KK KK KK k e e
16. Ck k k k k k k k KA KA KA k k KA KA KA CK k k k k k k A KKK pwm h Authors Jeremy Tillman William Ehlhardt Project FlySpy ki ECE477 Team 12 Spring 2009 KCKCKCKCKCKCKCk ske KKK KKK KKK K k I ke kk A k k k k k k k k k k k k k k k k kk k k KKK define PERIODCLK 5000 20ms count for the TIMER1 Clock sources which is Fosc 2 64 32Mhz 2 64 define PERIODMS 20 0 The PWM period in milliseconds define THROTTLEREG OCIR define LAILERONREG OC2R define RAILERONREG OC3R define ELEVATORREG OC4R define RUDDERREG OC5R void initpwm void void initOutputCompare void void initInputCapture void float clkToMs int int msToClk float void read PWM IN float 1 ail float r ail float throttle float elev float rudder void read PWM OUT float 1 ail float r ail float throttle float elev float rudder J KKK KKK KKK KKKK Kk kA I kk Ck k k k k k k k KKK KK k k KA KA kA k k KA KKK k k k k k k k k k k k k SD SPI c Authors Jeremy Tillman William Ehlhardt Project FlySpy Di ECE477 Team 12 Spring 2009 KCKCKCKCKCK KKK CK CK Ck Ck Kk Ck X k kk k k k k k k k k k k k k k k I k kk k k k ke k ko ke k ke k KKK KKK kk k kk kk KX k ck Sk kk kk k KR KK k k k k k k kk Ck KA k KC k k k k k k k k k k k CK k k k k k k k k k k kk Microchip Memory Dis
17. QI sl Data bus Description define Description define Description define The CF address bus bit 0 output latch definition T ADDRI T T T RTRISO T RTRISI T RTRIS2 T RTRIS3 he CF he CF he CF he CF he CF he CF he CF address address address address address address address TRISEbits The CF card detect signal PORTCbits The CF card detect signal TRISCbits _LATB15 bus bit 1 TRISE2 port bit RC2 TRIS bit TRISC2 output latc _LATB14 bus bit 2 _LATG9 bus bit LATG8 bus bit 0 _TRISB15 bus bit 1 _TRISB14 bus bit 2 TRISG9 bus bit 3 _TRISG8 output latc output latc TRIS defini TRIS defini TRIS defini TRIS defini The Manual CF data bus port register control bus lines Description The CF define CF_CE Description The CF define CF_CEDIR Description The CF define CF_OE Description The CF define CF_OEDIR Description The CF define CF_WE Description The CF define CF_WEDIR Description The CF define CF_BT_RST Description The CF define CF_BT_RESETDIR Description The CF define CF_BT_RDY Description The CF define CF_BT_READYDIR Description The CF DD_CFBT_DATABIN The Manual CF data bus DD_CFBT_DATABOUT The Manual CF data bus DD CFBT DATADIR card card card card card card card card
18. The CF card chip select output latch bit define CF_CE LATEbits LATEL Description The CF card chip select TRIS bit define CF_CEDIR TRISEbits TRISEL Description The CF card output enable strobe latch bit define CF OE LATAbits LATA5 Description The CF card output enable strobe TRIS bit define CF OEDIR TRISAbits TRISA5 Description The CF card writ nable strobe latch bit define CF WE LATAbits LATA4 Description The CF card writ nable strobe TRIS bit define CF WEDIR TRISAbits TRISA4 Description The CF card reset signal latch bit define CF BT RST LATEbits LATEO Description The CF card reset signal TRIS bit define CF BT RESETDIR TRISEbits TRISEO Description The CF card ready signal port bit define CF BT RDY PORTEbits RE2 Description The CF card ready signal TRIS bit F 35 ECE 477 Final Report define CF BT R Description define CF BT C Description D1 define CF BT C EADYDIR DIDIR elif defined __dsPIC30F__ IC24 IC24 IC24 IC24 30 30 30 30 Address lines Description 33 32 define ADDRO Description 33 32 fine Descri 3 32 fine ADDR2 Description 3 32 fine ADDR3 Description fine A Descri fine A Descri fine A Descri fine A o ption KN SESS M o tion M o tion M oO A0 OP NOSNO OR O Coe STO Go o tion p D p D p D p D
19. ZERO RUDDER Setting 1 5ms Pulse Width Midpoint OC5RS PERIODCLK Period of 20ms OC5CON2bits SYNCSEL 0x0B Synchronized by Timerl 50Hz OC5CON1bits OCTSEL 0x04 Select Timerl as the clock source OC5CON1bits OCM 6 Setting PWM Output in Edge Aligned Mode void initInputCapture IPCObits IC1IP 0x05 IFSObits IC1IF 0 Clear the interrupt status flag IECObits IC1IE 1 Enable Interrupts IC1CON1 0 IC1CON2 lt 0 IC1CONlbits ICTSEL lt 0x0 Input Capture Timer is Timer 1 IC1CON2bits SYNCSEL 0x0D Synchronized by Timerl IClcoNlbits ICM 0x01 Edge Detect Capture mode IPClbits IC2IP 0x05 IFSObits IC2IF 0 Clear the interrupt status flag IECObits IC2IE 1 Enable Interrupts F 49 ECE 477 Final Report Spring 2009 IC2CON1 0 IC2CON2 0 IC2CONlbits ICTSEL 0x0 Input Capture Timer is Timer 1 IC2CON2bits SYNCSEL 0x0D Synchronized by Timerl IC2CONlbits ICM 0x01 Edge Detect Capture mode IPC9bits IC3IP 0x05 IFS2bits IC3IF 0 Clear the interrupt status flag IEC2bits IC3IE 1 Enable Interrupts IC3CON1 0 IC3CON2 0 IC3CONlbits ICTSEL 0x0 Input Capture Timer is Timer 1 IC3CON2bits SYNCSEL 0x0D Synchronized by Timerl IC3CON1bits ICM 0x01 Edge Detect Capture mode IPC9bits IC4IP 0x05 IFS2bits ICAIF 0 Cl
20. define GetPeripheralClock define GetInstructionClock elif defined RUN_AT_60MHZ define GetSystemClock define GetPeripheralClock define GetInstructionClock else error Choose a speed fendif Clock valu define MILLI a tick timer define a tick timer define a tick timer endif Select your interface type TIMI TIMER PRESCALER es SECONDS PER TICK ER PERIOD 48000000UL System clock 48000000UL Peripheral GetSystemClock Instruction 24000000UL 24000000UL GetSystemClock 60000000u1 GetSystemClock GetSystemClock 10 Definition for use with TIMER PRESCALER 8 Definition for use with 37500 Definition for use with This library currently only supports a single physical interface layer at a time Description Description define USI s Description transaction c and MANUAL CF INTI define US ha Description library define US B CE USB INTERFACE acro used to enable the SD SPI physical layer define USE SD INTERFACE WITH SPI acro used to enable the CF PMP physical layer INTERFACE WITH PMP acro used to enable the CF Manual physical layer h acro used to enable the USB Host physical layer ERFACE SD SPI c and h CF PMP c and h CF Bit USB host MSD KK KR kk KAZ kk kk kk kk kk k
21. double sinEndingLatitude sin endingLatitude double cosStartingLatitude cos startingLatitude double cosEndingLatitude cos endingLatitude double cosDeltaLongitude cos deltaLongitude double haversineA sinHalfDeltaLatitude sinHalfDeltaLatitude cosStartingLatitude cosEndingLatitude sinHalfDeltaLongitude sinHalfDeltaLongitude distance EARTH RADIUS 2 atan2 sqrt haversineA sqrt l haversineA F 26 ECE 477 Final Report Spring 2009 bearing fmod atan2 sin deltaLongitude cosEndingLatitude cosStartingLatitude sinEndingLatitude sinStartingLatitude cosEndingLatitude cosDeltaLongitude 180 PI 360 360 KKK RR ske K K sk ske sk ske K K K K K kk kk k kk k k k IR k k k k k KA KA KA k k KA k k k k k k k k k k k k IG k k k gpserial c Authors Jeremy Tillman William Ehlhardt Project FlySpy k ECE477 Team 12 Spring 2009 KKK KKK KK KKK Ck K kA KX KX k k kk k k k k k k k k k k K KKK k kA KKK KKK KKK include FlySpy h OK k kk kk K KK K K kk k k kk kk k k k Ck k KA KA KA KA KA k k KA KA KA KA AXA KA AXA k k k k kk k k k kk k k k k U2BRG register value and baudrate mistake calculation Taken from Microchip s Explorer 16 sample code KKK KKK KKK KKK X kA k X kA k k kk k k k k KKK KA KA KA KA KA KA KA KA KA KA k k k k k ke kk k k ke ke k k k define BAUDR
22. gps h Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KCKCKCKCKCK KKK KKK KKK k X k X A kk k k k k k k k k k Ck k kk k k kk KKK kk ke k ke Xe ke k Baudrate define BAUDRATE1 38400 define GPSBUFFERSIZE 5 define EARTH RADIUS 6371 typedef struct gpsinformation int Hour int Minute int Second int Mils double Latitude double Longitude double Speed double Heading int SVs int Signal double Altitude GPSINFO void initgps void void gpsSendMessage char int int validateCheckSum void int gpsMessageType void void retrieveGpsData void void calculatePath double double double double double double KKK kk k KKK KKK kk KK KKK KKK KKK k k k k k k k k CK KA KA k k k k k k k k k k KA CK k k k k k k KKK KKK HardwareProfile h Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKK CK CK KK Ck Ck Kk Ck K K Sk kk k k k k k k k k k A k KA k k k k k k k k kc ske k k sk ck k k X ke k KKK kk k kk KKK k kk k kk kk kk kk kk kk k kk k k k k k kA k KA k k k k k k k k k k k k k k k k k k e k k k k k Microchip Memory Disk Drive File System F 28 ECE 477 Final Report Spring 2009 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkak F
23. if status 1 F 11 ECE 477 Final Report finish shot Spring 2009 Close the shutter switch by pulling it LOW CAM SHUTTER 0 delay32 1000000 Wait for delayed amount of time for camera to Pull the shutter switch back HIGH CAM_SHUTTER 1 __delay32 128000000 status powerOffCamera return status KKK kk Kk KKK KK K K I K K K K k k k k k k k k k k k k k k A KA k k k KK CK k k k k k k k k k k k k KKK camera h Authors Jeremy Til Project FlySpy ECE477 Te lman William Ehlhardt am 12 Spring 2009 KKK KKK KKK ske KKK Kk Ck X k kk k kk k k k k k k k k k Ck KA k k k k kk KKK KKK KKK void initCamera void int takePicture void S KKK KKK KKK kk kk Kk k k KK KK KK KK KK k k k k k k k k KK CK k k k k k KC k k k CK KA KA KC k k k k k k k k k k k Compiler h Authors Jeremy Til Project FlySpy ECE477 Te lman William Ehlhardt am 12 Spring 2009 KKK KKK KKK KKK K kA Ck X KX k k k k k k k k k k k k k Ck Ck Kk k k k k KKK KKK KKK KKK kk kk kk K kk k k kk k k k k Ck kA KA KA KA KA KA k k KA AXA KA KKK KKK KKK KKK k k Co mpiler and hardware specific definitions KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KE REE ET PNL RE GE Ne HO FileName Co Dependenc
24. lt 1 PitchAnglea atan2 Accel_x sqrt Accel_y Accel y Accel z Accel_z 180 PI RollAnglea atan2 Accel y sgrt Accel z Accel z Accel x Accel x 180 PI if Accel z lt 0 if Accel x gt 0 PitchAnglea 180 PitchAnglea else PitchAnglea 180 PitchAnglea if Accel y gt O RollAnglea 180 RollAnglea else RollAnglea 180 RollAnglea PitchAngle PitchAngle 9 PitchAnglea 1 RollAngle RollAngle 9 RollAnglea 1 if sensorInfo inuse sensorInfo MagnitudeVariance Variance sensorInfo Pitch PitchAngle sensorInfo Roll RollAngle sensorInfo GyroPitchVoltage CurrentPitchVolt sensorInfo GyroRollVoltage CurrentRollVolt sensorInfo Accelerometer X Accel x sensorInfo Accelerometer Y Accel y sensorInfo Accelerometer Z Accel z F 88 ECE 477 Final Report Spring 2009 return void updateClearing int lov int sample for lev 0 lev lt 10 levtt sample sampleADCPort RANGE_FINDER Clearing sample 3 3 3 96875 10240 if sensorInfo inuse sensorInfo Clearing Clearing KKK kk KA KKK KK K I K K K K k kk k k k k k k CK kA k k k k k k k CK k k k k k k KC k k k k k k ak k sensors h Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKK CK CK X A CK Ck K kA K K kA k k k k k k k k k k k k k k k
25. unsigned unsigned unsigned unsigned unsigned unsigned se se se See PRPRPP RR se S S Spring 2009 e LSB MSB Macros ify file header KKKKKKKKK k k kk k k kk kk k k k k k k k ke adopted by Peripheral lib H HO m Undefined size BOOL 0 Function attributes BYTI 8 bit WORD 16 bit unsigned DWORD 32 bit OWORD 64 bit unsigned CHAR SHORT 16 bit signed LONG LONGLONG 64 bit signed VOID CHAR8 UCHAR8 pendent size specific definitions the sizes on each compiler These pecific we should either move them r ifdef them for compiler type INT T8 T16 T32 T64 T I I T UINT UINT8 UINT16 UINT32 UINT64 other name for 32 bit integer F 17 ECE 477 Final Report Spring 2009 unsigned char b6 1 unsigned char b7 1 bits BYTE VAL BYTE BITS typedef union WORD VAL WORD Val BYTE v 2 struct BYTE LB BYTE HB byte struct unsigned char b0 1 unsigned char bl l unsigned char b2 1 unsigned char b3 1 unsigned char b4 1 unsigned char b5 1 unsigned char b6 1 unsigned char b7 1 unsigned char b8 1 unsigned char b9 1 unsigned char b10 1 unsigned char b11 1 unsigned char b12 1 unsigned char b13 1 unsigned char b14 1 unsigned char b15 1 bits WORD VAL WORD BITS typedef union DWORD VAL DWORD Val WORD w 2
26. void barometer read signed int temp long pressure E 10 ECE 477 Final Report Spring 2009 void barometer test void updateAltitude endif KKK RR Kk X Kk k k k kk kk k k k k k Ck k k k k k k k k k k KA KA KA k k k A KA CK k k k k k k IG k k k k camera c Authors Jeremy Tillman William Ehlhardt Project FlySpy k ECE477 Team 12 Spring 2009 KKK KKK KKK Ck Ck Ck Ck Kk k X kA k k A k k k k k k k k kA k KA I k kA k k k k k k ke Xo ke ke ke k k include FlySpy h void initCamera Pull both control outputs HIGH on bootup CAM_SHUTTER 1 CAM POWER 1 int changePowerMode int mode If the camera is not in the desired power stat if CAM_POW_FB mode Close the power switch by pulling LOW CAM_POWER 0 Keep it closed until the power state changes to the desired state as reported by the feedback if CAM_POW_FB mode delay32 1000000 Only wait for a specific amount of time so plane can control itself again We have reached the desired mode so flip that pin back on up to high CAM POWER 1 __delay32 1000000 if CAM_POW_FB mode return 0 return 1 int powerOnCamera return changePowerMode 1 int powerOffCamera return changePowerMode 0 int takePicture int status status powerOnCamera
27. void initializePID AXISPID float float float float adjustControl AXISPID float float float float float KKK kk kA KA A Kk k k k k k k k k k k k k k KK CK k k KA KA k k k KA k k KA k k k k k k k k k k k k k Timer c Authors Jeremy Tillman William Ehlhardt Project FlySpy i ECE477 Team 12 Spring 2009 KKK KKK KKK KKK K kA K K K K kk k k k k k k k k k k k k Ck kk k k k k k k kk KKK KKK KKK F 92 ECE 477 Final Report Spring 2009 include FlySpy h int SecondFlag 0 int TimerFlag 0 int p TimerCount i 0 int TimerCount 0 PRECONDITIONS Timerl polls the barometer so it must be init d already void initTimer TICON 0x20 Stops the Timerl and reset control reg Sets Prescaler to 1 64 TMR1 0x00 Clear contents of the timer register PR1 0x1388 Load the Period register with the value 0x0001 IPCObits T1IP 0x04 Setup Timerl interrupt for desired priority level This example assigns level 1 priority IFSObits T1IF 0 Clear the Timerl interrupt status flag IECObits T1IE 1 Enable Timerl interrupts T1CONbits TO instruction cycle 1 Start Timerl and clock source set to the internal T2CON 0x30 Stops Timer2 and Sets the prescaler to 1 256 TMR2 0x00 Clears the contents of the timer register PR2 0xF424 Loads the Period into the register for a 1 second interr
28. while 1 FSfprintf fptr Time Latitude Longitude Speed Heading Pitch Roll Altitude Clearing Throttle L Aileron R Aileron Elevator Rudder Gyro Pitch Volt Gyro Roll Volt AccelG X AccelG Y AccelG Z Variance r n FSfclose fptr while 1 val CTRL_SW if lastState val if val 0 fptr FSfopen LOG TXT a if fptr NULL printf Error in FSfopen of LOG TXT d r n FSerror while 1 else if length gt 0 length_check FSfwrite logBuffer 1 length fptr if length length check FSfclose fptr printf Error in FSfwrite d r n FSerror while 1 length G FSfclose fptr lastState val retrieveGpsData F 2 ECE 477 Final Report Spring 2009 if TimerFlag 1 if lastState read PWM IN amp man 1 ail amp man_r_ail amp man throttle amp man elev amp man rudder sensorInfo inuse 1 length sprintf amp logBuffer length 2d 2d 2d 3d ld 8 6f 59 6f 5 2f 6 3f 4 3f 54 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 4 3f 54 3f 4 3f r n CurrentGPS Hour CurrentGPS Minute CurrentGPS Second CurrentGPS Mils TimerCount CurrentGPS Latitude CurrentGPS Longitude CurrentGPS Heading CurrentGPS Speed sensorInfo Pitch sensorInfo Roll sensorInfo Altitude sensorInfo Clearing double man throttle double man 1 ail double man r ail double man e
29. will need enough power to handle this weight over the duration of time that we need to travel a reasonable flight path The battery itself will add weight to the plan and usually the more powerful it is the more it will weigh In choosing a battery we must be mindful of its weight flight time and size Size is also critical because it will be placed in the cockpit any space consumed by the battery is less space for the autopilot The battery must be able to source more than 5 V and 2 75 A The servos motor and receiver will run off of a 5 V rail the motor is expected to draw about 2 A and the servos 150 mA each The other components will run off a 3 3 V rail stepped down from the 5 V rail and are roughly estimated to draw 150 mA 3 7 Packaging Constraints The packaging on FlySpy is a major concern The aircraft that we have selected was made just to withhold the RC components for a manual pilot It is also molded on the inside so that pieces may have compartments to fit into without sliding Knowing this we have major constraints on space for items that will be placed on the interior of the aircraft We estimate ECE 477 Final Report Spring 2009 dimensions close to 1 5 in X 1 in X 5 in The pieces that will be placed internally also have to be placed in a way that they do not disturb the servos or servo rods that sit in the cockpit For the components that can be far away from the microcontroller may be placed on the exterior of t
30. 1 DE se F 71 else ECE 477 Final Report SPIOUTLAT 0 while clock SPICLOCKLAT clock MANUAL_SPI_CLOCK_VALU while cloc Bit 5 SPICLOCKLAT clock MANUAL_SPI_CLOCK_VALU if i amp 0x2 else while cloc SPICLOCKLAT clock MANUAL SPI CLOCK VALU while cloc Bit 4 SPICLOCKLAT clock lt MANUAL SPI CLOCK VALU if i amp 0x1 else while cloc SPICLOCKLAT clock MAN while cloc Bit 3 SPICLOCKLAT clock MAN if i amp 0x0 else while cloc SPICLOCKLAT clock MAN while cloc Pl Bit 2 SPICLOCKLAT clock MAN if i amp 0x0 SPIOUTL else SPIOUTL while cloc SPICLOCKLAT clock MAN while cloc Bit 1 SPICLOCKLAT clock MAN if i amp 0x0 SPIOUTL else SPIOUTL 1 k 7 0 0 SPIOUTLAT 1 SPIOUTLAT 0 k 1 JJ k 0 0 SPIOUTLAT 1 SPIOUTLAT 0 k 1 UAL SPI CLOCK VALU LJ se k 0 UAL_SPI_CLOCK_VALU 8 SPIOUTLAT 1 SPIOUTLAT 0 k 1 UAL SPI CLOCK VALU k Os UAL SPI CLOCK VALUE 4 AT 1 AT 0 k 1 JJ UAL SPI CLOCK VALUE k 0 ay UAL SPI CLOCK VALUE 2 AT 1 AT 0 F 72 Spring 2009 ECE 477 Final R
31. 1 1 16 primary prescale elif SYSCLK 32000000 MYSPICON1 PPRE 0 1 64 primary prescale else error Unsupported clock frequency endif MYSPICON1 SPRE 8 2 1 2 secondary prescale MYSPICON2 0 Don t use any framed mode stuff TODO config to monitor transmit receive status MYSPISTAT SPIEN 1 flip that bad boy back on while barometer startup running __delay32 8000000 printf BaroBoot r n V Order the barometer to commence acquisition in high speed continuous mode writereg8 0x03 0x09 baro status t barometer status void unsigned char status 0 baro_status_t res 0 0 0 Read in the device status status readreg8 0x07 printf 0x 02x int status Mash together the output structure res dataready status amp 05000100000 res error status amp 05000010000 res startup_running status amp 05000000001 return res ECE 477 Final Report Spring 2009 char barometer dataready void baro status t res barometer status return res dataready char barometer error void baro status t res barometer status return res error char barometer startup running void baro status t res barometer status return res startup running void barometer read signed int temp long pressure signed int _temp 0 long presh 0 presl 0 long _pressure 0 Pull in the reading
32. 1 ioMap Set micro pin directions and peripherals pin selects lockIO Locks port pin directions initgps Initializes communication to the GPS through UART and configures its message types initCamera Initializes Camera Outputs gpserial_init Initializes the communication to the RS 232 ifdef GPS_PASSTHROUGH warning Compiling for GPS passthrough mode printf GPS Passthrough mode go r n gps passthrough endif initio Initializes SD Communication and Reads in Flight Information initSensors Initializes the Sensor structure and zeros sensor algorithms initSurfaces initADC Initializes the Analog to digital module barometer init Intitia lizes and starts communication with the SPC 1000 initTimer Initializes and starts all Timer initpwm Initializes Input Capture of the Receiver PWM and Output Compare of PWM to Airplane Control Surfaces printf Please Wait to Aqui do retrieveGpsData while CurrentGPS Signal re GPS Signal r n ECE 477 Final Report printf GPS Signal Aquired r n ifdef MANUAL ONLY MODE printf Manual only modeXrin Spring 2009 FSFILE fptr int length 0 char logBuffer 2000 int lastState 1 int val int count 0 int length check Gdelay32 32000000 fptr FSfopen LOG TXT w if fptr NULL printf Error in Creating LOG TXT dNrMn FSerror
33. BYTE v 4 struct WORD LW WORD HW word struct BYTE LB BYTE HB BYTE UB BYTE MB byte struct WORD_VAL low WORD_VAL high wordUnion struct unsigned char b0 1 unsigned char b1 1 unsigned char b2 1 unsigned char b3 1 F 18 ECE 477 Final Report Spring 2009 unsigned char b4 1 unsigned char b5 1 unsigned char b6 1 unsigned char b7 1 unsigned char b8 1 unsigned char b9 1 unsigned char b10 1 unsigned char b11 1 unsigned char b12 1 unsigned char b13 1 unsigned char b14 1 unsigned char b15 1 unsigned char b16 1 unsigned char b17 1 unsigned char b18 1 unsigned char b19 1 unsigned char b20 1 unsigned char b21 1 unsigned char b22 1 unsigned char b23 1 unsigned char b24 1 unsigned char b25 1 unsigned char b26 1 unsigned char b27 1 unsigned char b28 1 unsigned char b29 1 unsigned char b30 1 unsigned char b31 1 i bits DWORD VAL typedef union OWORD VAL QWORD Val DWORD d 2 WORD w 4 BYTE v 8 struct DWORD LD DWORD HD dword struct WORD LW WORD HW WORD UW WORD MW word struct unsigned char b0 1 unsigned char b1 1 unsigned char b2 1 unsigned char b3 1 unsigned char b4 1 unsigned char b5 1 unsigned char b6 1 unsigned char b7 1 unsigned char b8 1 unsigned char b9 1 unsigned char b10 1 unsigned char b11 1 F 19 ECE 477 Final Report unsigned unsigned unsigned unsigned unsigned unsi
34. Command code byte li This structure allows bitwise access to elements of the command bytes struct BYTE END_BIT 1 Packet end bit BYTE CRC7 7 CRC value DWORD address Address BYTE CMD_INDEX 6 Command code BYTE TRANSMIT_BIT 1 Transmit bit BYTE START_BIT 1 Packet start bit l CMD PACKET Summary The format of an R1 type response Description This union represents different ways to access an SD card R1 type response packet typedef union BYTE _byte Byte wise access This structure allows bitwise access of the response struct unsigned IN IDLE STATE 1 Card is in idle state F 82 ECE 477 Final Report Spring 2009 unsigned ERASE RESET 1 Erase reset flag unsigned ILLEGAL CMD 1 Illegal command flag unsigned CRC ERR 1 CRC error flag unsigned ERASE SEQ ERR 1 Erase sequence error flag unsigned ADDRESS ERR 1 Address error flag unsigned PARAM ERR 1 Parameter flag unsigned B7 1 Unused bit 7 l RESPONSE 1 Summary The format of an R2 type response Description This union represents different ways to access an SD card R2 type response packet typedef union WORD word struct BYTE bytel BYTE _bytel i struct unsigned IN_IDLE_S unsigned ERASE RESI unsigned ILLEGAL CMD 1 1 Q unsigned CRC ERR unsigned ERASE SE unsigned ADDRESS E unsigned PARA
35. K K K Kk kA k kk k k kk k k k k k k k kA KKK KA KA k k KA KA KA k k k k k k k k k k k k k Re OC Authors Jeremy Tillman William Ehlhardt Project FlySpy k ECE477 Team 12 Spring 2009 KKK KKK KKK KKK KKK KK A k k k k k k k k k k k k k k k k k k k kA k k k k KKK KKK include FlySpy h char IOBuffer 100 WAYPOINT wayPoints MAXWAYPOINTS TAKEOFFLANDING StartEndPoint int wayPointCount 0 void initio void FSFILE fptr FSInit Initializes the FILE SYSTEM communication with the SD Card int index while FSInit Waiting for SD card to finish initialization if FSchdir Navigates to the root directory of the SD Card printf Error Could not move to root directory r n while 1 if FSchdir PROGRAMFOLDER Tries to change directory to that specified for this application printf Error Could not find the FLYSPY directory NrMn while 1 printf Found the FLYSPY directory r n Read in flight information fptr FSfopen INPUTFILE r if fptr NULL printf Error The input file was not found r n while 1 printf Found the input file s r n INPUTFILE wayPointCount 0 index 0 StartEndPoint TakeOff 0 StartEndPoint Landing 0 while FSfeof fptr index 0 F 39 ECE 477 Final Report Spring 2009 do FSfread amp
36. K k k k k k k k KA KA k k KA KA KA KA KK KA k k KA k k A k k ke ke k k k k k Function lockIO Preconditions None Overview This executes the necessary process to set the IOLOCK bit to lock I O mapping from being modified Input None Output None KCKCKCKCKCkCkCk KKK KKK KKK K K kk X k k k kk k k k k k k k k k k k k k k k kc k kc k KKK k k k k void lockIO asm volatile mov OSCCON wl Xn mov 40x46 w2 Nn mov 40x57 w3 Xn mov b w2 w1 Mn mov b w3 w1 Mn bset OSCCON 6 OK kk kk KKK KKK kk kk kk kk KKK kk k Ck k KA KK KA KA KA k k KA KA KA KA AXA KA AXA k k k k kk k k ke ke k k e k k eo E Function unlockIO Preconditions None Overview This executes the necessary process to clear the IOLOCK bit to F 46 ECE 477 Final Report Spring 2009 allow I O mapping to be modified Input None Output None KKK KKK KKK KKK KKK Ck kk kk kk Sk k k kk k k k k k Sk k k k k k k k k k KKK KKK k k k f void unlockIO asm volatile mov OSCCON wl Xn mov 40x46 w2 Nn mov 40x57 w3 Nn mov b w2 w1 Mn mov b w3 w1 Mn bclr OSCCON 6 else error This code is only for a PIC24FJ256GA110 endif KKK kk RR KK K KKK K I kk k k k k k k Kk k A CK k k k k k k KA k k KA KA KA k k k k k k k k k k k k k k iomapping h
37. KKK KKK KK KK KK KK KK KK KKK KKK k k KKK KKK KKK KKK KKK KKK KKK KKK uart2 h Authors Jeremy Tillman William Ehlhardt Project FlySpy X ECE477 Team 12 Spring 2009 KKK KK KKK KKK KK KKK K K K K K K K K K K K k k k k k k k k k k k k kk k k k k k k k k k k k k k kk k k kkk k kk UART2 Driver Header File for PIC24 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK FileName uart2 c Dependencies HardwareProfile h Processor PIC24 Compiler MPLAB C30 Linker MPLAB LINK30 Company Microchip Technology Incorporated Author Date Comment Anton Alkhimenok 18 Oct 2005 KO 11 Oct 2006 v1 0 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Software License Agreement Microchip Technology Inc Microchip licenses to you the right to use copy modify and distribute the software including source code only for use with Microchip microcontrollers or Microchip digital signal controllers provided that no open source or free software is incorporated into the Source Code without Microchip s prior written consent in each instance The software is owned by Microchip and its licensors and is protected under applicable copyright laws All rights reserved SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND EITHER EXPRESS OR IMPLIED INCLUDING WITHOUT LIMITATION ANY WARRANTY OF ERCHANTABILIT
38. Report E BYTI clear SPI INT SPIBUF OxFF while SPI_INTERRUPT_FLAG return SPIBUF clear SPIBUF ERRUPT FLAG 0 else SPIBUF OxFF while SPISTAT RBF return SPIBUF endif Spring 2009 Data Out Logic ones Wait until cycle complete Return with byte read S KKK KKK KKK KKK KKK KKK KK KK KK KKK KKK KKK CK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK Function void OpenSPIM Summary Initializes the SPI module Conditions None Input unsigned int sync mode sync mode Sets synchronization Return None Side Effects None Description The Remarks None OpenSPIM function will enable and configure the SPI module KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK ifdef 18CXX void OpenSPIM unsigned char sync mode else void OpenSPIM unsigned int sync_mode endif SPISTAT 0x0000 ifndef _ PIC32MX SPICON1 0x0000 SPICON1 sync mode endif ifdef 18CXX SPICON1 0x80 SPISTATbits CKE 1 else SPICONlbits CKP 1 SPICONlbits CKE 0 endif SPICLOCK 0 SPIOUT 0 SPIIN 1 SPIENABLE 1 power on state power on state select serial mode define SDOl as output master or slave define SDIl as input master or slave enable synchronous serial port F 70 ECE 477 Final Report Spring 2009 ifdef 18CXX dif GetSystemClock gt
39. Select the barometer spi_comm addr Send a read command ret spi comm 0x00 Read back the response BAROMETER_CS 1 Deselect the barometer return ret static unsigned int readregl6 unsigned char addr unsigned int high 0 low 0 Convert the address into the read from this address command to be sent over the SPI bus addr addr lt lt 2 amp 0b11111100 BAROMETER_CS 0 Select the barometer spi_comm addr Send a read command high spi_comm 0x00 Read back the high byte low spi comm 0x00 Read back the low byte BAROMETER_CS 1 Deselect the barometer return high lt lt 8 low ECE 477 Final Report Spring 2009 void barometer init void Set up the SPI interface BAROMETER_CS 1 deselect the barometer MYSPISTAT SPIEN 0 turn off the module MYSPICON1 DISSCK 0 enable PIC sourced clock MYSPICON1 DISSDO 0 SDO pin controlled by module MYSPICON1 MODE16 0 Byte width communications MYSP ICON1 SMP 0 Sample phase TODO check this MYSPICON1 CKE 1 Latch out new data on the FALLING clock edge the barometer latches it in on the RISING edge MYSPICON1 SSE 0 Don t use SS1 pin MYSPICON1 CKP 0 Clock idles on LOW MYSPICON1 MSTEN 1 Master mode Set the clock output to 125kHz dif SYSCLK 8000000 MYSPICON1 PPRE z
40. a lot we can do beyond incentivizing proper disposal 26 ECE 477 Final Report Spring 2009 7 0 Packaging Design Considerations Flyspy s packaging is going to be the plane called Easy Glider Pro and minimal modification to the plane is going to be done to avoid the drastic change in aerodynamic structure of the plane The weight of the circuit board will be light and therefore it would not change the balance of the system very much but the weight of the camera can ruin the balance of the air plane therefore it should be placed at very appropriate spot Since we expected that the additional weight would require more power of motor we ordered a motor with extra capacity Figure 1 Micro Pilot s Software ne E 4 MicroPilot_ Configuration Wizard 7 1 Commercial Product Packaging After searching online two competitors to our system were found One is Micro Pilot MP 2028 from Micropilot and another is Kestrel Autopilot from Procerus Technology They provide the circuit that can be installed to RC scale air plane to guide the plane to fly through pre programmed GPS coordinates Their packaging is amazing in terms of their size and weight of the circuit Those products which are similar to our system had every component on the board but our system will use cables to connect to many components and locate them on the better place They consist of similar components and the object of the system is the same therefore they are
41. appropriate examples to compare our system Figure 2 Micro Pilot s Circuit 7 1 1 Micro Pilot MP 2028 Micro Pilot provides a handy solution to turn any RC scale plane into unmanned aerial vehicle with single circuit installation The circuit only weighs 28 grams including 3 axis gyros accelerometers GPS pressure altimeter pressure and airspeed sensors 16 It also provides explanatory manuals and videos for installation and flight operation The circuit size is 4 x 1 5 x 0 6 27 ECE 477 Final Report Spring 2009 which is very small so that it can fit in our plane without any problem Micropilot s circuit seems much optimized since they could put all sensors on the board and still the size is very small It also provides flight management software and it costs about 2 000 7 1 2 Procerus Kestrel Autopilot The size of Kestrel Autopilot developed by Procerus Technology is 2 x 1 37 x 0 47 and the weight of Auto pilot is only 16 7 grams 17 Autopilot has a dual layer PCB and has most sensors on the board without GPS receiver Even though they did not include GPS receiver its cost is about 5 000 However it is smaller than Micro Pilot and it has wi fi connectivity to the ground station It has a very compact size and it was ERE developed with military purpose Since we are now going to use the dual layer PCB our design would be more similar to the Micro Pilot than Autopilot 7 2 Project P
42. be infeasible a low dropout voltage regulator will suffice the efficiency hit is tolerable as most of the current in the system will be drawn by the motor and servos 8 1 2 Analog Devices The gyro accelerometer and rangefinder are all analog devices that output simple voltages between 0 and 3 3V proportional to the angular rate acceleration and range detected respectively The gyro represents no rotation as a zero point voltage midway through its output range and reports both the direction and magnitude of rotation rate as voltage offsets from that zero point The overall rotation is calculated using integration in software We have not yet tested our gyro for this behavior Based on experience in FIRST robotics in most gyro chips the zero point is slightly temperature dependent or varies among individual units This is called gyro bias and can be compensated for by sampling the gyro for a second or two after bootup averaging its 31 ECE 477 Final Report Spring 2009 output and assuming that is the zero point Obviously the device must be as stationary as possible during this bias calculation The accelerometer s voltage output is very similar to that of the gyro except that it reports positive and negative acceleration instead of angular rate It responds to gravity which could be useful in determining which way is down We have not yet tested for temperature variant behavior or other irregularities but e
43. faster than 400kHz Initialize SPI port to slower than 400kHz dif defined C30 defined C32 ifdef _ PIC32MX SPIBRG SPICalutateBRG GetPeripheralClock 400000 F 75 ECE 477 Final Report Spring 2009 SPICONlbits MSTEN 1 OpenSPIM MASTER_ENABLE_ON else Calculate the prescaler needed for the clock timeout GetSystemClock 400000 if timeout is less than 400k and greater than 100k use a 1 1 prescaler if timeout 0 OpenSPIM MASTER ENABLE ON PRI PRESCAL 1 1 SEC_PRESCAL_1_1 while timeout 0 if timeout gt 8 spiconvalue round up if timeout 4 0 timeout 4 timeout 4 else timeout 0 OpenSPIM MASTER ENABLE ON spiconvalue timeout lt lt 2 amp 0x1C dendif let the card power on and initialize Delayms 1 Media requires 80 clock cycles to startup 8 clocks BYTE 10 us for timeout 0 timeout 10 timeout mSend8ClkCycles SD CS 0 Delayms 1 Send CMDO to reset the media response SendMMCCmd GO IDLE STATE 0x0 if response rl byte MMC BAD RESPONSE response rl byte amp 0xF7 0x01 status FALSE we have not got anything back from the card SD_CS 1 deselect the devices return status According to spec cmdl must be repeated until the card is fully initialized timeout OxFFF do response SendMMCCmd SEND OP
44. from 362 Due primarily to the voltage level issue and unit pricing we decided to buy the PIC For the airplane we stayed within the Multiplex brand of aircrafts This is because of the ELAPOR material that their products used which is popular for its durability and easy reconstruction after crashes When we narrowed our search down to two of their airframes we were torn between the Easy Star and the Easy Glider Pro When comparing the two we were concern about three main differences The Easy Star has a propeller that sits up in the middle of the plane which was appealing because if we crashed the plane the engine or propeller wouldn t be the first to hit The Easy Glider has its propeller and motor in the front but has a bigger motor to withstand more weight The size of the cockpit was another aspect we looked at closely as depicted below 11 ECE 477 Final Report Spring 2009 Easy Star in front and Easy Glider Pro in back 5 The Easy Star has a lot more cockpit space available to us so we may put our components in without worrying much about them brushing against the servos and receiver The Easy Glider Pro has significantly less space available to us The main determining factors were the wing spans and ailerons The wingspan of the Easy Glider Pro is much lengthier than the Easy Star The larger the wingspan the more stable our flight will be without our microcontroller having to give much correction Also t
45. k KKK KKK ke ke k k i i als i i i i i di i i i i i als i i i fndef define lude lude lude lude lude lude lude lude lude lude lude lude lude lude lude lude lude nc nc nc nc nc nc nc nc nc nc nc nc nc nc nc nc nc FLYSPY H FLYSPY H libpic30 h math h stdio h limits h p24fj256gall0 h ADC h gps h barometer h gpserial h Timer h iomapping h sensors h camera h pwm h iosh surfaces h MDD FILE SYSTEMNFSIO h define GPS PASSTHROUGH define MANUAL ONLY MODI er fifndef _ PIC24FJ256GA110 error endif FlySpy does not yet Explorer 16 Don t Main system clock frequency d d d Used in gpserial efine efine efine efine efine efine efine efine but makes more sense here SYSCLK 32000000 VREF 343 PI 3 141592653589793 MAX_PITCH 20 MAX_ROLL 30 ACCEL_X 5 ACCEL_Y 4 ACCEL Z 3 F 15 build for this target Are you trying to run it on ECE 477 Final Report efine RANGE FINDER 2 efine GYRO X 1 efine GYRO Y 0 efine MAX PITCH DEGREES 20 efine MAX ROLL DEGREES 20 efine ROLL ZERO 0 efine PITCH ZERO 12 enum SURFACETYPE E dendif x B Ab Ob RS GF EE EG MA MM FEE EG GE O IGHTAILERON EVATOR ER Ri Hoy
46. k k k k ke k k k k k Function MMC RESPONSE SendMMCCmd BYTE cmd DWORD address Summary Sends a command packet to the SD card Conditions None Input None Return Values MMC RESPONSE The response from the card Bit 0 Idle state Bit 1 Erase Reset Bit 2 Illegal Command Bit 3 Command CRC Error Bit 4 Erase Sequence Error Bit 5 Address Error Bit 6 Parameter Error Bit 7 Unused Always 0 Side Effects None Description SendMMCCmd prepares a command packet and sends it out over the SPI interface Response data of type Rl as indicated by the SD MMC product manual is returned Remarks F 59 ECE 477 Final Report Spring 2009 None KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK X MMC_RESPONSE SendMMCCmd BYTE cmd DWORD address WORD timeout 0x8 BYTE index MMC_RESPONSE response CMD PACKET CmdPacket SD CS 0 Card Select Copy over data CmdPacket cmd sdmmc_cmdtable cmd CmdCode CmdPacket address address CmdPacket crc sdmmc cmdtable cmd CRC Calc CRC here CmdPacket TRANSMIT BIT 1 Set Tranmission bit WriteSPIM CmdPacket cmd Send Command WriteSPIM CmdPacket addr3 Most Significant Byte WriteSPIM CmdPacket addr2 WriteSPIM CmdPacket addrl WriteSPIM CmdPacket addr0 Least Significant Byte WriteSPIM CmdPacket crc Send CRC see if
47. kk k k kk k k ke k k k k Function WORD MDD SDSPI InitIO void Summary Initializes the I O lines connected to the card Conditions DD MediaInitialize is complete The MDD InitIO function pointer is pointing to this function Input None Return None Side Effects None Description The MDD SDSPI InitIO function initializes the I O pins connected to the SD card Remarks None KKK KKK KKK k k kk X k XXX k k k kk k k k k k k k k KK KK k e k void MDD SDSPI InitIO void Turn off the card SD_CD_TRIS INPUT Card Detect input F 58 ECE 477 Final Report Spring 2009 SD CS Ty Initialize Chip Select line SD_CS_TRIS OUTPUT Card Select output SD_WE_TRIS INPUT Write Protect input k kk kk kok sk kk kk k kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk KKK k k e Function WORD MDD SDSPI ShutdownMedia void Summary Disables the SD card Conditions The MDD ShutdownMedia function pointer is pointing towards this function Input None Return None Side Effects None Description This function will disable the SPI port and deselect the SD card Remarks None KKK KKK KK KKK KKK KK KX k X k X k k kk kk k k kk kk k k k ke ke ke ke k e k void MDD SDSPI ShutdownMedia void close the spi bus CloseSPIM deselect the devic SD_CS 1 OK kok kk k kk k kk k I kk kk k kk RR CK KA k k KA KA KA KA AXA KA k k k k k k k
48. kk kk k k kk k k k k k k kA kA k k KA KA k k k k Ck k k KKK 8 Macros ED KR RR ske sk Kk k K K K k kk k k kk k k k k k k k k k k k k KA KA k k k k kk k k KA k k kkk k ke kk kk Description A macro to send clock cycles to dummy read the CRC define mReadCRC WriteSPIM OxFF WriteSPIM OxFF Description A macro to send clock cycles to dummy write the CRC define mSendCRC WriteSPIM OxFF WriteSPIM OxFF Description A macro to send 8 clock cycles for SD timing requirements define mSend8ClkCycles WriteSPIM OxFF KOK CK Ck k kk Ck Kk k k kk kk k kk k k k k k k k k k k k k k k k k k kk KKK ke ke kk f Prototypes KKK kk kk kA KX k KKK ck kk Sk k k k k k k k k k k k k k k Ck kk kk KKK KK ke ok ke ke kk J DWORD MDD SDSPI ReadCapacity void WORD MDD SDSPI ReadSectorSize void void MDD SDSPI InitIO void BYTE DD SDSPI MediaDetect void BYTE MDD SDSPI Medialnitialize void BYTE MDD SDSPI SectorRead DWORD sector addr BYTE buffer BYTE MDD SDSPI SectorWrite DWORD sector addr BYTE buffer BYTE allowWriteToZero BYTE MDD SDSPI WriteProtectState void void MDD SDSPI ShutdownMedia void dif defined C30 defined C32 extern BYTE ReadByte BYTE pBuffer WORD index extern WORD ReadWord BYTE pBuffer WORD index extern DWORD ReadDWord BYTE pBuffer WORD
49. kx BYTE MDD SDSPI MediaDetect void return SD_CD end MediaDetect ED KK RR KKK KKK K kk kk kk Sk kk kk kk kk kk kk kk kk kk k k k KKK k k e Function WORD MDD SDSPI ReadSectorSize void Summary Determines the current sector size on the SD card Conditions MDD MediaInitialize is complete Input None Return The size of the sectors for the physical media Side Effects None Description The MDD SDSPI ReadSectorSize function is used by the F 57 Spring 2009 ECE 477 Final Report Spring 2009 USB mass storage class to return the card s sector size to the PC on request Remarks None KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK k k KK KK k e k WORD MDD SDSPI ReadSectorSize void return MEDIA SECTOR SIZE se f KKK KKK KKK KK KKK KKK KKK KKK KKK KK KKK KKK kk kk KKK KKK KKK ke k ke ke e Function DWORD MDD SDSPI ReadCapacity void Summary Determines the current capacity of the SD card Conditions DD MediaInitialize is complete Input None Return The capacity of the device Side Effects None Description The MDD SDSPI ReadCapacity function is used by the USB mass storage class to return the total number of sectors on the card Remarks None KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK k k KK KK k e e kx DWORD MDD SDSPI ReadCapacity void return MDD_SDSPI_finalLBA KK KK k sk sk X Kk k kk I kk kk kk kk kk kk kk kk kk kk
50. p33Fxxxx dsPIC30F dsPIC30F processor p30fxxxx ECH C 18CXX e htc h include lt pl8cxxx h gt Microc h Microc h Microc h icroc n gt ford icroc Idefined C32 define endif include lt p32xxxx h gt include lt plib h gt include lt stdio h gt include lt stdlib h gt include lt string h gt C32 CH_C HI TI hip C30 hip C30 C30 hip hip C30 hip C32 error Unknown processor or compiler ECH PICC 18 compiler compil compil compil compil compil er er er er er Microchip C18 compiler See Compiler h Base RAM and ROM pointer types for given architecture dif defined __C32__ F 13 ECE 477 Final Report define PTR BAS define ROM PTR elif defined C30 9 define PTR BAS define ROM PTR elif defined 18CXX define PTR BASE define ROM PTR BAS LJ DWORD BASE DWORD LJ WORD BASE WORD WORD Lp endif Definitions that apply to all compilers if defined __18CXX defined HI TECH C define memcmppgm2ram a b c define strcmppgm2ram a b define memcpypgm2ram a b c define strcpypgm2ram a b define strncpypgm2ram a b c define strstrrampgm a b define strlenpgm a define strchrpgm a b define strcatpgm2ram a b dendif Spring 2009 unsigned short long except C18 strchr a b strcat a b
51. sharp fast spinning hard plastic propeller can both contribute to damage or injury The propeller deserves special consideration It can seriously injure a human who sticks a finger into its arc while it is spinning On top of being sharp fast and painful on impact it is also difficult to see while in operation Prop related injuries are a major hazard of all aircraft that involve spinning blades some of the potential mitigations of the risk are as follows 1 Brightly color the blade tips to make the arc s edge more visible Team 8 OCHO is doing exactly this Also color the nose cone so that it is easier to notice when it is spinning 2 Warnings in the user manual to keep one s fingers out of the blade arc as much as possible and to keep the propeller assembly detached from the motor until ready to fly 23 ECE 477 Final Report Spring 2009 3 Brightly colored warning sticker near the nose with a picture warning of the risk 4 After boot up the speed controller itself requires the throttle input to be set to 0 before it will arm and start spinning the motor in response to nonzero throttle inputs 5 We specifically selected a model plane with a prop mounted on the nose as opposed to in the rear of the plane This makes it easier to hand launch the plane without passing one s hand through the propeller arc 6 1 2 Loss of Plane Control FlySpy has a couple classes of loss of plane control conditions that coul
52. sprintf IOBuffer t t t lt Throttle gt f lt Throttle gt n double throt auto FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Throttle gt f lt Throttle gt n throt auto length sprintf IOBuffer t t t lt Elevator gt f lt Elevator gt n double ele_auto F 42 ECE 477 Final Report double rudder auto double left auto right auto right man if return TRUE FSfclose pointer FALSE FSfwrite IOBuffer 1 length pointer Spring 2009 FSfprintf pointer t t t lt Elevator gt f lt Elevator gt n ele auto length sprintf IOBuffer t t t lt Rudder gt f lt Rudder gt n FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Rudder gt f lt Rudder gt n rudder auto length sprintf IOBuffer t t t lt LeftAileron gt f lt LeftAileron gt n FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt LeftAileron gt f lt LeftAileron gt n left auto length sprintf IOBuffer t t t lt RightAileron gt f lt RightAileron gt n FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt RightAileron gt f lt RightAileron gt n right auto FSfprintf pointer t t lt SurfaceByAuto gt n FSfprintf pointer t t lt SurfaceByManual gt n length sp
53. title Restriction of Hazardous Substances Directive amp oldid 284259028HEffect on reliability 16 Micro Pilot MicroPilot Products MP2028g Online Document cited 1 November 2008 Online Available http www micropilot com products mp2028g htm 17 Procerus Technology Procerus Technology Kestrel Autopilot Online Document cited October 2008 http www procerusuav com productsKestrelAutopilot php 18 Microchip Technology Inc PIC24FJ256GA110 Family Data Sheet February 2008 Online Available http ww1 microchip com downloads en DeviceDoc 39905b pdf Accessed Feb 17 2009 19 Microchip Technology Inc Microchip ICD 2 datasheet 2005 Online Available http www farnell com datasheets 53561 pdf Accessed Feb 17 2009 20 Maxbotix Maxbotix LV MaxSonar EZ1 High Performance Sonar Rangefinder July 2007 Online Available http www maxbotix com uploads LV MaxSonar EZ 1 Datasheet pdf Accessed Feb 17 2009 21 M Glenewinkel Motorola App Note Online document 1995 cited 2009 Feb 27 Available HTTP https engineering purdue edu ece477 Homework CommonRefs AN1259 pdf 22 LTC1174 LTC1174 3 3 LTC1174 5 High Efficiency Step Down and Inverting DC DC Converter Online document 1994 Rev E cited 2009 Feb 27 Available HTTP http www linear com pc downloadDocument do navId HO0 C1 C1003 C1042 C1033 P139 22097 23 SparkFun Ele
54. traces needed to connect these analog components to the A D pins of the microcontroller and reduce analog noise The headers will probably be placed near respective signal traces to minimize the extra routing 9 1 5 Trace Sizing Because the 5 V supply supplied by the speed controller through its PWM cable will be brought out from the speed controller to headers on the board to power the servos the 5 V power trace under the headers must be capable of carrying about 600 mA A 60 mil trace is more than sufficient based on PCB trace width calculations The estimated current draw on the 3 3V rail however is a comparatively low 150 mA requiring only thin traces Traces of 60 mils should be sufficient to supply power from the step down converter to all components on the 3 3V rail The signal traces are to have a minimal size of around 12 mils because of the tight dimensional constraints on the PCB in the space critical application 9 1 6 EMI Reduction It is optimistically anticipated that RF interference from internal sources should not be a significant issue in the system Early in the component selection process a spread spectrum transmitter receiver pair was selected to minimize interference from the microcontroller The transmission band of the spread spectrum transmitter is in the 2 2 4 GHz range higher frequency than the GPS signals at 1 575 GHz and 1 228 GHz Although the GPS and micro could still interfere if the transmitter is a mul
55. we are going to get a response if sdmmc cmdtable cmd responsetype RI sdmmc cmdtable cmd responsetype R1b do response rl byte MDD SDSPI ReadMedia timeout Jwhile response rl byte MMC FLOATING BUS amp amp timeout 0 else if sdmmc_cmdtable cmd responsetype R2 MDD SDSPI ReadMedia response r2 bytel MDD SDSPI ReadMedia response r2 _byte0 MDD SDSPI ReadMedia if sdmmc cmdtable cmd responsetype R1b response rl _byte 0x00 for index 0 index lt OxFF amp amp response rl _byte 0x00 index timeout OxFFFF do response rl byte MDD SDSPI ReadMedia timeout Jwhile response rl byte 0x00 44 timeout 0 mSend8ClkCycles Required clocking see spec F 60 ECE 477 Final Report S if we ar xpecting data or not if sdmmc_cmdtable cmd moredataexpected SD CS SG return respons ifdef 18CXX dif GetSystemClock gt 25600000 Spring 2009 OK kk kk kk K kk k KK kk KK kk k KKK KKK KA KA KKK KKK KKK KA KA KA AXA KA k k k k k k k k k k ke ke k k k k k Function MMC RESPONSE Summary SendMMCCmdManual BYTE cmd DWORD address Sends a command packet to the SD card with bit bang SPI Conditions None Input None Return Values MMC RESPONSE The Bit Bit Bit Bit Bit Bit Bit Bit Side Effects None Description SendMMCCmd prepares a R
56. we did not observe any components that ran hot with a reasonable load Because of the relative irrelevance of these considerations mission critical components were chosen in additional to the microcontroller The PI3V512 multiplexor was chosen because it controls switching between manual and autonomous modes The LTC1174 buck converter was chosen because all components except the motor servos and receiver are powered on the 3 3V rail Microcontroller The microcontroller model from section 5 1 in the handbook was used 10 With this model p 7 C C 7 797 failures per 10 hours Parameter Description Value Comments regarding name choice of parameter value especially if you had to make assumptions C Die complexity 28 16 bit TT Temperature coeff 20 TJ 40 to 125 C from page 260 of datasheet 11 estimate 50 C C Package Failure Rate 053 SMT 128 pins 19 ECE 477 Final Report Spring 2009 Z Environment Factor 4 0 Assume ground mobile since the plane operates fairly close to the ground no typical stresses of airborne environments To Quality Factor 10 Commercial product T Learning Factor 1 0 gt 2 0 years in production Entire design Failures per million hours 2 032 Mean time to failure MTTF in years 38 908 Multiplexor The digital MOS model from section 5 1 in the handbook was used 10 With this model p 7 C7 C 7 67 fai
57. with the function of the PWM channels A D channels and SPI and SCI interfaces I was also heavily involved with the component selection and acquisition I was heavily involved in the PCB footprint creation planning component placement wiring and component verification of the PCB Documentation I put together the senior design report by myself worked with William on the final report and worked with Daeho on the user manual Construction I did some of the soldering on the PCB and soldered some connectors Miscellaneous I helped with top level planning in the early stages of the project A 2 Contributions of William Ehlhardt With respect to the design project itself I primarily worked on the hardware design I did a lot of the work in nailing down the overall structure of the hardware designing the flow of signals from system to system I worked out which microchip peripherals we were using and how they connected to the sensors and other hardware I selected the microcontroller based on our peripheral usage as well as other part selection I was the one who decided to change GPS modules instead of trying to get the GPS antenna signal routed I did the mapping of functions to pins on the microcontroller and the subsequent pin function changes required to make routing easier A 1 ECE 477 Final Report Spring 2009 I did the bulk of the work on the PCB layout and the subsequent schematic redesigns made to facilitate routing The PCB
58. 0 barometer over SPI 1 To use the barometer 1 Call barometer_init to set it up to acquire data 2 Don t read data until barometer_status reports that startup is complete 3 Poll barometer status every 10 20ms 1 to see if there is data ready to be bussed in 4 If so call barometer read to get that data 1 In high speed acquisition mode you have a 25ms window between the barometer having data ready and the time that it starts to acquire a new value and trashes its data buffer barometer_status reports when new data is ready R void barometer_init void typedef struct _baro_status_t Is there data ready to be read in unsigned dataready 1 Indicates whether the last data ready timed out before the micro serviced it Should this be the case the next value to be returned by barometer_read will be garbage however the read will clear the error unsigned error 1 Startup procedure running unsigned startup_running 1 baro_status_t baro status t barometer status void char barometer dataready void char barometer error void char barometer startup running void yee Returns the barometer s measured temperature in TENTHS of degC and the pressure in TENTHS of Pascals Notice that there is a chance this could return garbage see the error bit documentation above It would also be a poor plan to call this if the dataready status bit is not set bie
59. 0 floating point operations for every update at a 50 Hz interval 6 Assuming that we go with a very low end microcontroller without native floating point hardware such as Microchip s PIC line we conservatively estimate that each floating point operation will take 100 clock cycles This means that we need a processor of at least 500 kHz to sustain the updates Based on these estimates we concluded that an integer only processor of with a clock of IMHz or more would be sufficient to maintain the orientation calculations Once we have successfully done the navigation and orientation calculations we then will set the control surfaces so that the current orientation will approach the desired orientation We will also have to write the current data to the SD Card for flight logging These should not require much CPU power compared to the orientation calculations ECE 477 Final Report Spring 2009 We do not expect to need much RAM on the chip as there are no large data structures being manipulated in memory Program memory is not expected to be particularly constraining 3 3 General Purpose Digital I O Requirements In the design for FlySpy the camera will be the only device that will use the general purpose I O ports We assume that the camera will need to make use of only a few of these We will need to output control of the camera s on off switch and shutter pushbutton and we will need to relay back to our microcontroller a line which sig
60. 008 007 1431 March 20 2008 Douglas G Nelson Anti hijacking system operable in emergencies to deactivate on board flight controls and remotely pilot aircraft utilizing autopilot U S Patent Application No 2004 0079837 April 29 2004 MIL HDBK 217F Military Handbook Reliability Prediction of Electronic Equipment Online document 1991 Dec 2 cited 2009 Apr 9 Available HTTP https engineering purdue edu ece477 Homework CommonRefs Mil Hdbk 217F pdf PIC24FJ256GA110 Family Data Sheet Online document 2008 Jan 2 cited 2009 Apr 9 Available HTTP http ww 1 microchip com downloads en DeviceDoc 39905b pdf 45 ECE 477 Final Report Spring 2009 12 PI3V512 Low On Resistance 3 3V Wideband Video Switch 5 Port 2 1 Mux DeMux Online document 2004 Nov 1 cited 2009 Apr 9 Available HTTP http www pericom com pdf datasheets PI3V512 pdf 13 LTC1174 LTC1174 3 3 LTC1174 5 High Efficiency Step Down and Inverting DC DC Converter Online document 1994 Rev E cited 2009 Apr 9 Available HTTP http www linear com pc downloadDocument do navId HO C1 C1003 C1042 C1033 P139 2 D2997 14 Polystyrene Wikipedia 2009 Online Available http en wikipedia org w index php title Polystyrene amp oldid 28374088 14Disposal and e nvironmental issues 15 Restriction of Hazardous Substances Directive Wikipedia 2009 Online Available http en wikipedia org w index php
61. 1 Description SD SPI Write Protect Check TRIS bit define SD_WE_TRIS TRISFbits TRISF1 Registers for the SPI module you want to use Description The main SPI control register define SPICON1 SPI1CON Description The SPI status register define SPISTAT SPILSTAT Description The SPI Buffer define SPIBUF SPIIBUF Description The receive buffer full bit in the SPI status register define SPISTAT RBF SPI1STATbits SPIRBF Description The bitwise define for the SPI control register i e bits define SPICONlbits SPI1CONbits Description The bitwise define for the SPI status register i e bits define SPISTATbits SPI1STATbits Description The enable bit for the SPI module define SPIENABLE SPICON1bits ON Description The definition for the SPI baud rate generator register PIC32 define SPIBRG SPI1BRG Tris pins for SCK SDI SDO lines Description The TRIS bit for the SCK pin F 33 ECE 477 Final Report Spring 2009 define SPICLOCK TRISFbits TRISF6 Description The TRIS bit for the SDI pin define SPIIN TRISFbits TRISF7 Description The TRIS bit for the SDO pin define SPIOUT TRISFbits TRISF8 Will generate an error if the clock speed is too low to interface to the card dif GetSystemClock lt 100000 error Clock speed must exceed 100 kHz endif fendif fendif ifdef USE CF INTERFACE WITH PMP CompactFlash PMP card definitions change these to fit you
62. 25600000 Description Delay value for the manual SPI clock define MANUAL SPI CLOCK VALUE 1 KK kk KKK KKK K kk k kA kk kk k k k k k KKK KA KA KA k k KA KA KA KA AXA KA k k k k k k k k k k X ke k k ke k k Function unsigned char WriteSPIManual unsigned char data out Summary Write a character to the SD card with bit bang SPI Conditions None Input data out Data to send Return 0 Side Effects None Description Writes a character to the SD card Remarks The WriteSPIManual function is for use on a PIC18 when the clock speed is so high that the maximum SPI clock divider cannot reduce the SPI clock speed below the maximum SD card initialization speed kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk unsigned char WriteSPIManual unsigned char data out char i data_out unsigned char clock ADCON1 OxFF SPICLOCKLAT 0 SPIOUTLAT 1 SPICLOCK OUTPUT SPIOUT OUTPUT if SPIOUTPORT SPIOUTLAT return 1 SPICLOCKPORT SPICLOCKLAT Perform loop operation iteratively to reduce discrepancy JJ Bit 7 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUI if i amp 0x80 SPIOUTLAT lr D se else SPIOUTLAT 0 while clock SPICLOCKLAT 1 clock MANUAL_SPI_CLOCK_VALU while clock LJ se Bit 6 SPICLOCKLAT 0 clock MANUAL_SPI_CLOCK_VALU if i amp 0x40 SPIOUTLAT
63. 316 7 Filing Date November 27 2007 Abstract A system and method for providing autonomous control of unmanned aerial vehicles UAVs is disclosed The system includes a ground station in communication with an unmanned aerial vehicle The method for providing autonomous control of a UAV includes methods for processing communications between the ground station and UAV The method also includes process for estimating the attitude of the UAV and autonomously maintaining its altitude within a desired threshold process for autonomously orbiting about a specified point in space and process for an autonomous takeoff and landing of the UAV Claims for Possible Infringement Claim1 An autopilot control system for an unmanned aerial vehicle comprising a ground station and an on plane control system comprising a processor memory in electronic communication with the processor three accelerometers in electronic communication with the processor three rate gyroscopes in electronic communication with the processor an absolute pressure sensor in electronic communication with the processor a differential pressure sensor in electronic communication with the processor a global positioning system in electronic communication with the processor a transceiver in electronic communication with the processor to receive and transmit wireless signals and a power source that supplies power to both the on plane control system and to an actuator used
64. 95 SparkFun VIT Tech SCP1000 Mems Barometric Pressure Sensor 54 95 1 54 95 SparkFun Analog Devices ADXL330 Triple Axis Accelerometer 34 95 1 34 95 SparkFun Maxbotix LV EZ1 Ultrasonic Range Finder 24 95 1 24 95 Ublox Ublox Programmable GPS Module 99 99 1 99 99 LEA 4P Jeremy Tillman Nikon Coolpix s7 Camera 0 1 0 Jeremy Tillman Secure Digital IGBSD SD Card 0 1 0 TOTAL 878 54 E 1 ECE 477 Final Report Appendix F Software Listing KKK KKK KKK kk kk X k k k k k k k k k k k k k FlySpy vO c Spring 2009 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKKA KKK KKK K kA Ck kk Sk k k kk k k k k k k k k k Ck kk Ck k k k KKK KKK kk k k include FlySpy h _CONFIG1 JTAGEN OFF amp GCP OFF amp GWRP OFF amp CO OFF amp FWDTEN OFF amp ICS PGx2 CONFIG2 FCKSM CSDCMD amp OSCIOFNC OFF amp POSCMOD NONE amp FNOSC FRCPLL extern GPSINFO CurrentGPS extern WAYPOINT wayPoints MAXWAYPOINTS extern TAKEOFFLANDING StartEndPoint extern SENSORDATA sensorInfo extern int wayPointCount extern int SecondFlag extern int TimerFlag extern int TimerCount int main void float man 1 ail man r ail unlockIO CLKDIV 0x3000 Changes man throttle man elev man rudder Oscillator Postscalar to 1
65. A k kk k k k k A CK KA KK KA KA KA KKK KA k k k k k ke kk k k ke ke ke ke include FSIO h MDD File System FSIO h include FSDefs h MDD File System FSDefs h include SD SPI h MDD File System SD SPI h finclude string h include FSConfig h include HardwareProfile h S KKK KKK KKK KKK KK KKK KKK KK KK KK KK KKK KKK k k KKK KKK KKK KKK k k KKK KKK KKK KKK KKK Global Variables KKK KKK KK KKK KKK KKK KR KK KKK KKK k k k KKK KKK KA KA KA KA KA KKK KKK KKK KKK KKK Description Used for the mass storage library to determine capacity DWORD MDD_SDSPI_finalLBA ifdef 18CXX Summary Table of SD card commands and parameters Description The sdmmc_cmdtable contains an array of SD card commands the corresponding CRC code the response type that the card will return and a parameter indicating whether to expect additional data from the card const rom typMMC_CMD sdmmc_cmdtable else const typMMC_CMD sdmmc_cmdtable fendif cmd crc response cmdGO IDLE STATE 0x95 R1 ODATA cmdSEND OP COND OxF9 R1 ODATA cmdSEND CSD OxAF Rl OREDATA cmdSEND_CID Ox1B R1 OREDATA cmdSTOP TRANSMISSION OxC3 Rl ODATA cmdSEND_STATUS OxAF R2 ODATA cmdSET BLOCKLEN OxFF R1 ODATA cmdREAD SINGLE BLOCK OxFF R1 OREDATA F 55 ECE 477 Final Report Spring 2009 cmdREAD MUL
66. ATEREG2 SYSCLK 32 BAUDRATE2 1 if BAUDRATEREG2 gt 255 error Cannot set up UART2 for the SYSCLK and BAUDRATE Correct values in main h and uart2 h files endif LJ lt tr N define BAUDRATE MISTAKE 1000 BAUDRATE2 SYSCLK 32 BAUDRATEREG2 1 BAUDRATI if BAUDRATE MISTAKE gt 2 BAUDRATE MISTAKE lt 2 error UART2 baudrate mistake is too big for the SYSCLK and BAUDRATE2 Correct values in uart2 c file endif void gpserial init void Set up UART 2 for the spec d baud rate U2BRG BAUDRATEREG2 U2MODE 0 U2STA 0 U2MODEbits UARTEN 1 U2STAbits UTXEN 1 reset RX flag IFSlbits U2RXIF 0 Now set it up as STDIO C30 UART 2 KKK kk kA kk kk KX kA kA kk k k k k k k k k k k kA KKK KC Ck k k KA CK KA CK k k k k k k k k k k k gpserial h Authors Jeremy Tillman William Ehlhardt Project FlySpy Dj ECE477 Team 12 Spring 2009 KCKCKCKCKCK KKK ske skoke sk ske KKK X k ske K K kk A k k k k k k k k k Ck k k k k k kk k k k k k k k kk k k Xe KKK ifndef GPSERIAL H define __GPSERIAL_H F 27 ECE 477 Final Report Spring 2009 Baudrate define BAUDRATE2 19200 void gpserial_init void endif KKK kk RR KK KX K K K k kk kk k k k k k k k k k k k k k k KC KA k k k KA k k KA CK k k k k k k IG k k
67. Authors Jeremy Tillman William Ehlhardt Project FlySpy ki ECE477 Team 12 Spring 2009 KCKCKCKCKCKCKCkCKCk ske sk k KKK K K K K k k k k k k k k k k k k k k k ske k k k KKK sk ke k ke Xo ke k k k KKK kk kk Kk Kk kA kA kk kk kk k k k k k KA KA KA KA KA k k KA KA KA KA AXA AKA A A k k KKK k k k k kk KKK I O Mapping for Peripheral Pin Select devices Adapted from the Microchip Explorer 16 sample code William Ehlhardt 3 23 09 Set up for FlySpy project KKK KKK KK KKK KKK kA kA k k k k k k k k KKK KA KA KA KA KA KA KA KA KA KKK KKK KKK KKK KKK ifndef IOMAPPING H define IOMAPPING H TODO define TRIS LAT whatever stuff here I believe we need it for properly initializing the pins for output in particular See Fig 12 4 in the I O Ports reference define CAM POW FB _RA2 define CAM_SHUTTER _LATG2 define CAM_POWER _LATG3 define CTRL_SW _RD7 define GEAR_SW _RD6 Barometer Chip Select define BAROMETER_CS _LATB15 PPS Outputs from datasheet define NULL_IO 0 efine C1OUT IO 1 efine C20UT IO 2 efine U1TX TO 3 efine U1RTS_IO 4 Qs O 6 0 F 47 ECE 477 Final Report efine SS10U1 efine SS20U1 s Or Os OF Qi CQ DNG Or 00 0 A efine U2TX_IO efine U2RTS_ efine SDO1_IO efine SCK1OUT IO 8 r IO 9 efine SDO2 IO efine SCK20UT IO 11 r IO 12 efine OC1 IO efine OC2 IO
68. BF SPI2STATbits SPIRBF SPI1STATbits SPIRBF Description The bitwise define for the SPI control register i e s define SPICONlbits SPI2coNlbits SPI1CONlbits F 32 ECE 477 Final Report Spring 2009 Description The bitwise define for the SPI status register i e bits fidefine SPISTATbits SPI2STATbits SPI1STATbits Description The enable bit for the SPI module fidefine SPIENABLE SPI2STATbits SPIEN SPISTATbits SPIEN Tris pins for SCK SDI SDO lines Description The TRIS bit for the SCK pin define SPICLOCK TRISDbits TRISD15 TRISFbits TRISF6 Description The TRIS bit for the SDI pin define SPIIN TRISDbits TRISD14 TRISFbits TRISF7 Description The TRIS bit for the SDO pin define SPIOUT TRISFbits TRISF4 TRISFbits TRISF8 Will generate an error if the clock speed is too low to interface to the card if GetSystemClock lt 100000 error Clock speed must exceed 100 kHz endif elif defined PIC32MX Description SD SPI Chip Select Output bit define SD CS PORTBbits RB1 Description SD SPI Chip Select TRIS bit define SD CS TRIS TRISBbits TRISB1 Description SD SPI Card Detect Input bit define SD CD PORTFbits RFO Description SD SPI Card Detect TRIS bit define SD CD TRIS TRISFbits TRISFO Description SD SPI Write Protect Check Input bit define SD WE PORTFbits RF
69. COND 0x0 timeout Jwhile response rl byte 0x00 amp amp timeout 0 F 76 ECE 477 Final Report Spring 2009 see if it failed if timeout 0 status FALSE we have not got anything back from the card SD CS 1 deselect the devices else else let the card power on and initialize Delayms 1 if GetSystemClock 25600000 dif GetSystemClock lt 1600000 OpenSPIM SYNC MODE FAST BUS MODE SMP PHASE elif GetSystemClock lt 6400000 OpenSPIM SYNC MODE MED BUS MODE SMP PHASE else OpenSPIM SYNC_MODE_SLOW BUS_MODE SMP_PHASE dendif let the card power on and initialize Delayms 1 Media requires 80 clock cycles to startup 8 clocks BYTE 10 us for timeout 0 timeout lt 10 timeout mSend8ClkCycles SD_CS 0 Delayms 1 Send CMDO to reset the media response SendMMCCmd GO IDLE STATE 0x0 if response rl byte MMC BAD RESPONSE response rl byte amp 0xF7 0x01 status FALSE we have not got anything back from the card SD CS 1 deselect the devices return status According to spec cmdl must be repeated until the card is fully initialized timeout OxFFF do response SendMMCCmd SEND OP COND 0x0 timeout Jwhile response rl byte 0x00 amp amp timeout 0 felse Make sure the SPI module doesn t control the bus SPICON1 0x00
70. ECE 477 Final Report Spring 2009 Team 12 FlySpy Heather William Team Members 11 Jeremy Tillman Signature Date 2 Heather Barrett Signature Date 3 Daeho Hong Signature Date 4 William Ehlhardt Signature Date CRITERION SCORE 5 Technical content Design documentation Technical writing style Contributions Editing Comments ECE 477 Final Report TABLE OF CONTENTS Abstract 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 Project Overview and Block Diagram Team Success Criteria and Fulfillment Constraint Analysis and Component Selection Patent Liability Analysis Reliability and Safety Analysis Ethical and Environmental Impact Analysis Packaging Design Considerations Schematic Design Considerations PCB Layout Design Considerations Software Design Considerations Version 2 Changes Summary and Conclusions References Appendix A Individual Contributions Appendix B Packaging Appendix C Schematic Appendix D PCB Layout Top and Bottom Copper Appendix E Parts List Spreadsheet Appendix F Software Listing Appendix G FMECA Worksheet di Spring 2009 QN U N e 14 19 23 27 31 34 38 43 44 45 A 1 B 1 C 1 D 1 E 1 F 1 G 1 ECE 477 Final Report Spring 2009 Abstract FlySpy is a hobby aircraft modified to fly and take pictures under its own control It uses GPS for navigation flying along a path of waypoints defined on a
71. EVATORREG Percentage lt 0 msToClk ZERO ELEVATOR Percentage ZERO ELEVATOR MIN ELEVATOR msToClk ZERO ELEVATOR Percentage MAX ELEVATOR ZERO ELEVATOR break case RUDDER RUDDERREG Percentage 0 msToClk ZERO RUDDER MIN RUDDER msToClk ZERO RUDDER Percentage Percentage ZERO RUDD MAX RUDDER ZERO RUDD return void initializePID AXISPID pid float p_const float i_const float d_const pid gt Prev_Error 0 pid gt KP p_const pid gt KI i_const pid gt KD d_const float adjustControl AXISPID pid float target float actual float delta_t float max float min float derivative float error float output rror target actual pid gt Integral error delta_t derivative error pid gt Prev Error delta t pid gt Prev Error error output pid gt KP error pid gt KI pid gt Integral pid gt KD derivative if output gt max output max else if output lt min F 91 ECE 477 Final Report Spring 2009 output min return output KKK Kk kA KKK KKK KKK KK KK KK KK k KK k k k k k KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK surfaces h Authors Jeremy Tillman William Ehlhardt Project FlySpy i ECE477 Team 12 Spring 2009 KCKCKCKCKCK KKK KKK Kk k K K Sk kk k k
72. FEFTAILERON G rj 5g bo C pm UO ifndef FLYSPY H KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Generic Type Definitions KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK FileName GenericTypeDefs h Dependencies None Processor PIC18 PIC24 dsPIC PIC32 Compiler Microchip C18 C30 C32 Company Microchip Technology Inc Software License Agreement The software supplied herewith by Microchip Technology Incorporated the Company is intended and supplied to you the Company s customer for use solely and exclusively with products manufactured by the Company The software is owned by the Company and or its supplier and is protected under applicable copyright laws All rights are reserved Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws as well as to civil liability for the breach of the terms and conditions of this license THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION NO WARRANTIES WHETHER EXPRESS IMPLIED OR STATUTORY INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE THE COMPANY SHALL NOT IN ANY CIRCUMSTANCES BE LIABLE FOR SPECIAL INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER KKKKKKKKKKKKKKKKK
73. HIP BE LIABLE FOR ANY INCIDENTAL SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES LOST PROFITS OR LOST DATA COST OF PROCUREMENT OF SUBSTITUTE GOODS TECHNOLOGY OR SERVICES ANY CLAIMS BY THIRD PARTIES INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF ANY CLAIMS FOR INDEMNITY OR CONTRIBUTIO OR OTHER SIMILAR COSTS WHETHER ASSERTED ON THE BASIS OF CONTRACT TORT INCLUDING NEGLIGENCE BREACH OF WARRANTY OR OTHERWISE Author Date Comment E BG ERE O E RUE Na s RE De tke dm mig DGD Br DD Sid DSD ASA IG SAD FE LAG I SGK o BS bit AG ir PR De BANEN RARE RAR TG DRINA Ren RE ENE BGN Howard Schlunder 10 03 2006 Original copied from old Compiler h Howard Schlunder 11 07 2007 Reorganized and simplified KKK KKK KKK CK Ck Ck K kA KX K K k KK kk k k k k k k k k k k k k k KKK KK KR ifndef COMPI define COMPI Include proper devic if defined 18CXX Lif Lif Last Lif Lif else endif def def def def de ER H ER H header file fi defined HI TE All PIC18 processors if els ined inc ined HL B inc ined inc ined inc ned if endi P1 defined HI TI define includ e f PIC24F C24F lude PIC24H IC24H lude lt lude lt lude lt PIC32MX processor p24Fxxxx processor p24Hxxxx __dsPIC33F__ dsPIC33F processor
74. I k kk kk KKK ke k kk k typedef struct int inuse double Pitch double Roll double Altitude double Clearing double GyroPitchVoltage double GyroRollVoltage double Accelerometer_X double Accelerometer_Y double Accelerometer_Z double MagnitudeVariance SENSORDATA void initSensors void void updateOrientation void void updateClearing void float sampleToG float KKK kk RR K K K K KK K I ske ske K K k k k k k k k k k k k k k k k k KA KA KA k k KA k k KA k k k k k k k k k k k k k surfaces c Authors Jeremy Tillman William Ehlhardt Project FlySpy x ECE477 Team 12 Spring 2009 KCKCKCKCKCK KCk sk sk ske skok sk KKK K K k k k k k k k k k k k k k k k k k k k k k kk k k k k k k KKK KKK include FlySpy h extern float PitchAngle extern float RollAngle extern float Distance F 89 ECE 477 Final Report extern float Direction AXISPID rollPID AXISPID pitchPID float PitchRegister 0 float RollRegister 0 int Control_Enable 0 void initSurfaces void PitchRegister 0 RollRegister 0 initializePID amp rollPID 2 2 1 initializePID amp pitchPID 2 5 1 void directSurfaces void float RollPercent float PitchPercent if Control Enable 1 amp amp CTRL SW 1 RollPercent adjustControl amp rollPID 100 100 100 setSurface Roll
75. ILE H define HARDWAREPROFILE H Define your clock speed here Sample clock speed for PIC18 if defined 18CXX define GetSystemClock 40000000 System clock frequency Hz define GetPeripheralClock Get SystemClock Peripheral clock freq define GetInstructionClock GetSystemClock 4 Instruction clock freq Sample clock speed for a 16 bit processor elif defined __C30__ define GetSystemClock 32000000 define GetPeripheralClock GetSystemClock define GetInstructionClock GetSystemClock 2 Clock values define MILLISECONDS_PER_TICK 10 Definition for use with a tick timer define TIMER PRESCALER TIMER PRESCALER 8 Definition for use with a tick timer define TIMER PERIOD 20000 Definition for use with a tick timer Sample clock speed for a 32 bit processor elif defined PIC32MX F 29 ECE 477 Final Report Spring 2009 Indicates that the PIC32 clock is running at 48 MHz fidefine RUN AT 48MHZ Indicates that the PIC32 clock is running at 24 MHz fidefine RUN AT 24MHZ Indicates that the PIC32 clock is running at 60 MHz define RUN AT 60MHZ Various clock values if defined RUN AT 48MHZ define GetSystemClock freguency Hz define GetPeripheralClock clock frequency define GetInstructionClock clock frequency elif defined RUN_AT_24MHZ define GetSystemClock
76. IOBuffer index 1 1 fptr Reading one character into the buffer indextt while FSfeof fptr amp amp IOBuffer index 1 Nin Reading until I have reached the end of the file or the end of the line if index 2 Making sure I have atleast read in the instruction type continue IOBuffer index 0 Putting Null Terminator at the end of the string if IOBuffer 0 T amp amp IOBuffer 1 O Represents a TakeOff instruction sscanf IOBuffer TO 1f d n amp StartEndPoint TakeOff Altitude amp StartEndPoint Delay StartEndPoint TakeOff 1 else if IOBuffer 0 W amp amp IOBuffer 1 P Represents a waypoint instruction sscanf IOBuffer WP 1f 1f Sf din amp wayPoints wayPointCount Latitude amp wayPoints wayPointCount Longitude amp wayPoints wayPointCount Altitude amp wayPoints wayPointCount Picture wayPointCount else if IOBuffer 0 L amp amp IOBuffer 1 M Represents a Landing Mark Instruction sscanf IOBuffer LM 1f 1f 1f n amp StartEndPoint Landing Latitude amp StartEndPoint Landing Longitude amp StartEndPoint Landing Altitude StartEndPoint Landing 1 FSfclose fptr KKK kk kk k K kA K kk k k kk kk k k k k k k k k k k k k k KC k k k k k k k k k sk KG KKK Author Daeho Hong Function int logStart Summary Writing the very firs
77. ISD14 1 AKA RD14 RPOR2bits RP5R SCK20UT IO SCK2 output RP5 TRISD15 0 AKA RD15 RPOR5bits RP10R SDO2 IO SDO2 output RP10 _TRISF4 0 AKA RF4 RPOR8bits RP17R SS20UT IO 8512 output RP17 _TRISF5 0 AKA RF5 UART 1 GPS RPOR8bits RP16R U1TX IO U1TX output RP16 _TRISF3 0 AKA RF3 RPINR18bits U1RXR 30 U1RX input RP30 TRTSF2 ET AKA RF2 F 45 ECE 477 Final Report Spring 2009 UART 2 General serial RPOR7bits RP15R U2TX IO U2TX output RP15 _TRISF8 0 AKA RF8 RPINR19bits U2RXR 44 U2RX input RPI44 _TRISF7 1 AKA RF7 Input compare PWM in RPINR7bits IC1R 37 ICl THROT RPI37 _TRISC14 1 AKA RC14 RPINR7bits IC2R 11 IC2 L AIL RP11 _TRISDO 1 AKA RDO RPINR8bits IC3R 12 IC3 R AIL RP12 TRISD11 1 AKA RD11 RPINR8bits IC4R 3 IC4 ELEVATOR RP3 TRISD10 1 AKA RD10 RPINR9bits IC5R 4 IC5 RUDDER RP4 TRISD9 1 AKA RD9 Output compare PWM out RPOR10bits RP20R OC1 IO _TRISD5 0 AKA RD5 RPOR12bits RP25R OC2 10 _TRISD4 0 AKA RD4 RPORllbits RP22R OC3 IO _TRISD3 0 AKA RD3 RPORllbits RP23R OC4 IO _TRISD2 0 AKA RD2 RPOR12bits RP24R OC5 IO _TRISD1 0 AKA RD1 KKK kk RR ske sk K KK k k I kk k k k K K
78. KKKKKKKKKKKKKKKKKKKKKKKK ifndef SDMMC H define SDMMC H the Company s customer software is owned by the Company and or its supplier icrochip Technology Incorporated icrocontroller is intended and for use solely and icrocontroller products and is All rights are reserved The ht laws Any use in violation of the foregoing restrictions may subject the pplicable laws as well as to civil liability for the breach of the terms and conditions of this license THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION NO WARRANTIES WHETHER EXPRESS IMPLIED OR STATUTORY INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE THE COMPANY SHALL NOT IN ANY CIRCUMSTANCES BE LIABLE FOR SPECIAL INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER FAR A kc k k ck kc k kc k Ck k KA Ck ck k ck ck ck A A I kk kk F 79 ECE 477 Final Report Spring 2009 include GenericTypeDefs h include FSconfig h include FSDefs h MDD File System FSDefs h ifdef 18CXX Description prescale divider define SYNC MODE FAST 0x00 Description This macro is used to initialize a PIC18 SPI module with a 16x prescale divider define SYNC MODE MED 0x01 Description This macro is used to initialize a PIC18 SPI module with a 64x prescale divider define SYN elif defined PIC32MX o This macro is used to initial
79. KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK File Description Change History Rev Date Description gd 09 11 06 Add base signed types 1 2 02 28 07 Add QWORD LONGLONG QWORD VAL 143 02 06 08 Add def s for PIC32 F 16 Spring 2009 ECE 477 Final Report 1 4 08 08 08 Remov 15 08 14 08 Simpl KKKKKKKKKKKKKKKKKKKKKKKKKKK ifndef G define G z ERIC TYPE D ERIC TYPE D rj bj z typedef enum BOOL FALSI ifndef define endif NULL NULL 0 void PUBLIC PROTECTI PRIVATE aM define define define ED static typedef unsigned char unsigned typedef unsigned short int typedef unsigned long unsigned typedef unsigned long long typedef signed char 8 bit signed typedef signed short int typedef signed long 32 bit signed typedef signed long long Alternate definitions typedef void typedef char typedef unsigned char Processor amp Compiler inde To Do We need to verify may be compiler s to compiler h o typedef signed int typedef signed char typedef signed short int typedef signed long int typedef signed long long int char short int long int long long ypedef ypedef typedef typedef typedef unsigned unsigned unsigned unsigned unsigned typedef union BYTE VAL E BYTE Val struct b0 b1 b2 63 b4 bos char char char char char char
80. M ERR 1 unsigned B7 1 unsigned CARD IS LOCKED 1 unsigned WP ERASE SKIP LK FAIL 1 unsigned ERROR 1 unsigned CC ERROR 1 unsigned CARD ECC FAIL 1 unsigned WP VIOLATION 1 unsigned ERASE PARAM 1 unsigned OUTRANGE CSD OVERWRITE 1 l RESPONSE 2 Summary A union of responses from an SD card Description The MMC RESPONSE union represents any of the possible responses that an SD card can return after being issued a command typedef union ESPONSE 1 r1 ESPONSE 2 r2 MMC RESPONSE m F R R Summary A description of the card specific data register Description This union represents different ways to access information in a packet with SD card CSD informaiton For more information on the CSD register consult an SD card user s manual typedef union struct DWORD u320 DWORD u321 F 83 ECE 477 Final Report Spring 2009 DWORD _u322 DWORD _u323 li struct BYTE _byte 16 li struct unsigned NOT_USED unsigned CRC unsigned ECC unsigned FILE_FORMAT unsigned TMP_WRITE_PROTECT unsigned PERM_WRITE_PROTECT unsigned COPY unsigned FILE_FORMAT_GRP unsigned RESERVED_1 unsigned WRITE_BL_PARTIAL unsigned WRITE_BL_LEN_L unsigned WRITE_BL_LEN_H unsigned R2W_FACTOR unsigned DEFAULT_ECC unsigned WP_GRP_E unsigned WP_GRP_S unsigned ERASE_GRP_SIZE_L R S se se se se se se se
81. Media requires 80 clock cycles to startup 8 clocks BYTE 10 us F 77 ECE 477 Final Report Spring 2009 for timeout 0 timeout lt 10 timeout WriteSPIManual OxFF SD_CS 0 Delayms 1 Send CMDO to reset the media response SendMMCCmdManual GO IDLE STATE 0x0 if response rl byte MMC BAD RESPONSE response rl byte amp 0xF7 0x01 status FALSE we have not got anything back from the card SD_CS 1 deselect the devices return status According to the spec cmdl must be repeated until the card is fully initialized timeout OxFFF do response SendMMCCmdManual SEND OP COND 0x0 timeout Jwhile response rl byte 0x00 amp amp timeout 0 endif see if it failed if timeout 0 status FALSE we have not got anything back from the card SD CS 1 deselect the devices else fendif Delayms 2 ifdef PIC32MX if GetSystemClock lt 20000000 SPIBRG SPICalutateBRG GetPeripheralClock 10000 else SPIBRG SPICalutateBRG GetPeripheralClock 20000000 SPI Speed is 20MHz dendif SPICON1 0x0000C060 SPICON1bits MSTEN 1 else OpenSPIM SYNC MODE FAST dendif Turn off CRC7 if we can might be an invalid cmd on some cards CMD59 response SendMMCCmd CRC ON OFF 0x0 Now set the block length to media sector size I response SendMMCCmd SET BLOCKLEN MEDIA SECTOR SIZI shoul
82. Percent setSurface RollPercent JEFTAILERON RIGHTAILERON PitchPercent adjustControl amp pitchPID 02 100 100 100 setSurface PitchPercent void setPitch float Pitch PitchRegister Pitch void setRoll float Roll RollRegister Roll void enableControlSurfaces void Control Enable 1 void disableControlSurfaces void Control Enable 0 setSurface 0 THROTTLE setSurface 0 LEFTAILERON setSurface 0 RIGHTAILERON setSurface 0 ELEVATOR setSurface 0 RUDDER EI EVATOR F 90 RollRegister PitchRegister Spring 2009 RollAngle 02 PitchAngle ECE 477 Final Report Spring 2009 void setSurface float Percentage int Surface switch Surface case THROTTLE THROTTLEREG msToClk Percentage MAX THROTTLE MIN THROTTLE MIN THROTTLE break case LEFTAILERON AILERONREG Percentage lt 0 msToClk ZERO LAILERON Percentage ZERO LAILERON MIN LAILERON msToClk ZERO LAILERON Percentage MAX LAILERON ZERO LAILERON break case RIGHTAILERON RAILERONREG Percentage lt 0 msToClk ZERO RAILERON Percentage ZERO RAILERON MIN RAILERON msToClk ZERO RAILERON Percentage MAX RAILERON ZERO RAILERON break case ELEVATOR EL
83. Summary SD Description typedef struct his macro de his macro de his macro de ITE SINGLE his macro de fines fines fines fines fines cmdSTOP TRANSMISSION fines fines fines EAD SINGLE BLOCK fines EAD MULTI BLOCK fines BLOCK fines ITE MULTI BLOCK his macro de n his macro de n G SECTOR END his macro de ASE his macro de P CMD his macro the card de his macro de C ON OFF fines cmdTAG SECTOR START fines fines fines fines fines Rl type response Rib type response R2 type response R3 type response ne ne ne he 10 he 12 he 13 he 16 he T he 18 he 24 he 25 he 32 he 33 he 38 he 55 he 58 he 59 MMC FLOATING BUS command command command command command command command command command command command command command command command command command card command data structure The typMMC CMD structure is used to create a command table of information needed for each relevant SD command F 81 SD card Spring 2009 initialize the SD card get the Card Specific Data get the Card Information transmission during a information set the block length of the read one block from the card read multiple blocks from the address of the card ks to the the start of the end of erase all previous
84. TI BLOCK OxFF R1 OREDATA cmdWRITE SINGLE BLOCK OxFF R1 OREDATA cmaWRITE MULTI BLOCK OxFF R1 OREDATA cmdTAG SECTOR START OxFF R1 ODATA cmdTAG SECTOR END OxFF R1 ODATA cmdERASE OxDF R1b ODATA cmdAPP_CMD 0x73 R1 ODATA cmdREAD OCR 0x25 R3 ODATA cmdCRC ON OFF 0x25 R1 ODATA E KKK CK Ck k kk kk Kk k k KKK KKK k kk kk k kk k k k k k kA k k k k k k k k k k k k k k k k k k k k KG IG k k k k kk Prototypes KKK KKK KKK sk ske Ck KX k k X kA k k kk kk Sk k k k k KK KA KA KA KA KA KK k k KA KA AXA k k KA k kk k k k ek ke k k extern void Delayms BYTE milliseconds BYTE MDD SDSPI ReadMedia void BYTE MDD SDSPI MediaInitialize void MMC RESPONSE SendMMCCmd BYTE cmd DWORD address dif defined C30 defined C32 void OpenSPIM unsigned int sync mode void CloseSPIM void unsigned char WriteSPIM unsigned char data out elif defined o 18CXX void OpenSPIM unsigned char sync mode void CloseSPIM void unsigned char WriteSPIM unsigned char data out unsigned char WriteSPIManual unsigned char data out BYTE ReadMediaManual void MMC RESPONSE SendMMCCmdManual BYTE cmd DWORD address endif ifdef PIC32MX KOK kk k kk kk k kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk kk ke k k ke e Function static inline __attribute__ always_inline unsigned char SPICacutateBRG
85. TPUT INPUT SPIOUTPORT SPIOUTLAT SPICLOCKPORT SPICLOCKLAT eturn 1 rform loop operation iteratively to reduce discrepancy t 7 F 73 ECE 477 Final Report SPICLOCKLAT 0 clock MANUAL_SPI_CLOCK_VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x80 Bit 6 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x40 LB SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x20 Bit 4 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x10 Bit 3 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x08 Bit 2 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock SPICLOCKLAT 1 clock MANUAL SPI CLOCK VALUE while clock if SPIINPORT result 0x04 I Bit 1 SPICLOCKLAT 0 clock MANUAL SPI CLOCK VALUE while clock
86. Tail 0 Amount of characters that have been read in through a transmission int gpsSentenceStarted 0 Lets the module know if the stream was proceeded by the sentence starter GPS Data Circular Buffer char gpsBuffer GPSBUFFERSIZE 100 Buffer in which Transmission string is placed onces a full transmission has completed int gpsBufferLengths GPSBUFFERSIZE int gpsBufferHead lt 0 int gpsBufferTail lt 0 ifndef GPS PASSTHROUGH void initgps U1BRG BAUDRATEREGI IPC3bits UlTXIP 0x01 IPC2bits UIRXIP 0x05 U1STA 0x0000 UIMODE 0x8000 U1STAbits UTXEN 1 H ECObits U1RXIE 1 gpsSendMessage gpsOutputSetup 47 F 21 ECE 477 Final Report Spring 2009 gpsSendMessage gpsEnableSbas 15 gpsSendMessage gpsEnableWAAS 15 void __attribute__ interrupt no auto psv UIRXInterrupt void int length gpsReceiveBuffer gpsReceiveTail U1IRXREG if gpsReceiveBuffer gpsReceiveTail n 48 gpsSentenceStarted 1 48 gpsReceiveTail 0 amp amp gpsReceiveBuffer gpsReceiveTail 1 r If GPS Buffer not full add it into the buffer if gpsBufferTail 1 GPSBUFFERSIZE gpsBufferHead amp amp validateCheckSum 1 gpsBufferLengths gpsBufferTail gpsReceiveTail 1 gpsReceiveBuffer gpsReceiveTail 1 0 for length 0 length lt gpsBufferLengths gpsBufferTail length
87. ToZero WORD index BYTE data_response ifdef __18CXX BYTE clear endif MMC_RESPONSE response BYTE status TRUE if sector_addr 0 amp amp allowWriteToZero FALSE status FALSE else send the cmd response SendMMCCmd WRITE SINGLE BLOCK sector addr lt lt 9 see if it was accepted if response rl byte 0x00 status FALSE F 65 ECE 477 Final Report else WriteSPIM DATA START TOKEN for index 0 of data ifdef __18CXX clear SPIBUF SPI INTERRUPT FLAG 0 l SPIBUF buffer index while SPI INTERRUPT FLAG data response SPIBUF else SPIBUF buffer index while SPISTAT RBF data response SPIBUF endif calc cre mSendCRC data response MDD SDSPI ReadMedia if data response amp 0x0F status FALSE else index 0 do ifdef __18CXX clear SPIBUF SPI_INTERRUPT_FLAG 0 SPIBUF OxFF while SPI INTERRUPT FLAG data response SPIBUF else SPIBUF OxFF while SPISTAT_RBF data_response SPIBUF dendif indextt while data response 0x00 44 if index lt lt 0 status FALSE mSend8ClkCycles SD CS Ly Not writing to 0 sector return status end SectorWrite F 66 index lt MEDIA SECTOR SIZE DATA ACCEPTI Spring 2009 Send data start token Send 512 bytes index write byte to SSPIBUF register wait un
88. Y TITLE NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER F 94 ECE 477 Final Report Spring 2009 CONTRACT NEGLIGENCE STRICT LIABILITY CONTRIBUTION BREACH OF WARRANTY OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES LOST PROFITS OR LOST DATA COST OF PROCUREMENT OF SUBSTITUTE GOODS TECHNOLOGY SERVICES ANY CLAIMS BY THIRD PARTIES INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF OR OTHER SIMILAR COSTS KKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK EL S KRAKK KKK KK KKK K KKK KK KKK KK KK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK k k Function Prototypes S Ok kk kk K kk KK KK KKK KK KK KK KKK KKK k k KKK KKK KKK KA k k KKK KKK KKK KKK char UART2GetChar void UART2Init char UART2IsPressed void UART2PrintString char str void UART2PutChar char ch void UART2PutDec unsigned char dec void UART2PutHex int toPrint dif defined __C30__ defined __PIC32MX__ void UART2PutHexWord unsigned int toPrint endif KKK kk sk sk ske K KKK K X kA k kk kk k k k k k k
89. _ail float r ail float throttle float elev float rudder Throttle IECObits IC1IE 0 flip off the interrupt throttle MANUAL_THROTTLE_WIDTH safely read data IECObits IC1IE 1 interrupt back on Left Aileron IECObits IC2IE 0 flip off the interrupt x ail MANUAL LAILERON WIDTH safely read data IECObits IC2IE 1 interrupt back on Right Aileron IEC2bits IC3IE 0 L flip Off the interrupt r ail MANUAL RAILERON WIDTH safely read data IEC2bits IC3IE 1 interrupt back on Elevator IEC2bits ICAIE 0 flip off the interrupt elev MANUAL ELEVATOR WIDTH safely read data IEC2bits ICAIE 1 interrupt back on Rudder IEC2bits IC5IE 0 flip off the interrupt rudder MANUAL RUDDER WIDTH safely read data F 53 ECE 477 Final Report Spring 2009 IEC2bits IC5IE 1 interrupt back on void read_PWM_OUT float l_ail float r_ail float throttle float elev float rudder ail LAILERONREG PERIODMS PERIODCLK r ail RAILERONREG PERIODMS PERIODCLK throttle THROTTLEREG PERIODMS PERIODCLK elev ELEVATORREG PERIODMS PERIODCLK rudder RUDDERREG PERIODMS PERIODCLK JK KK KKK KKK K K Kk k k kk I K K K K k kk k k k k
90. ackaging Specifications The components that are going to be added to the plane to realize the unmanned system into our RC air plane are a single microcontroller gyro sensor pressure sensor ultrasonic range finder accelerometer camera and micro Figure 4 Autopilot s Circuit 2 SD card Every component except range finder and camera will be placed under the airplane since the range finder has to measure the distance between the plane and the ground and the camera has to take photos of the ground The circuit board which is going to be placed in fuselage will be smaller than 1 5 x 5 x 1 As depicted in Figure B 1 and B 1 in Appendix B the available area in the fuselage is enough for every component s arrangement and we do not have any concern on the available space 28 ECE 477 Final Report Spring 2009 Our biggest concern on the packaging is to prevent breaking the aerodynamic structure of the plane especially via the weight of camera Camera will weigh between 100 and 150 grams while PCB circuit will weigh less than 50 grams We already expected at least 300 grams of additional components and therefore ordered more powerful motor that can sustain the flight However we have not decided where to put the camera exactly since we do not have all components that we ordered yet This will be determined after designed PCB is obtained 7 3 PCB Footprint Layout In Figure 7 3 1 the drawing has the real size of every component on the b
91. aerial photograph of Purdue Memorial Mall I paid more attention on the graphic to make it interesting for the audience and revised it to make sure that it contains necessary information The size of the poster was limited and it was difficult to put everything in the poster A 4 Contributions of Jeremy Tillman As the team leader for FlySpy I was in charge of researching existing methods of controlling a RC Airplane autonomously Since no one on the team including myself had no previous experience of flying RC Airplanes I successfully sought out advice and experienced pilots to support the group with piloting and controls skills Once enough contacts and information were acquired I focused more on the components that the airplane would operate off of and its general logic of operation In doing so I selected the components that would be included in our design as well as the aircraft that we would modify I researched Inertial Measurement Units and what devices would be needed in building our own to given us adequate information about our airplane s orientation and position I acquired an unused camera from a personal friend Thereafter I disassembled it to gain access to pins that would enable the microcontroller to power on and off as well as take picture with I was very much involved in the hardware block diagram and loosely involved with the actual schematic only lending a hand where previous knowledge of interfacing or deep skills we
92. al IC4BUF Jwhile IC4CONlbits ICBNE if ELEVATOR_LAST_RISING 1 ELEVATOR_LAST_RISING val curr_width calculatePulseWidth ELEVATOR_LAST_RISING val if curr_width lt 3 amp amp curr_width gt 5 ANUAL ELEVATOR WIDTH curr width ELEVATOR LAST RISING 1 else ELEVATOR_LAST_RISING val Determined that I may get a falling edge first so if value is over max pulse width start timing over void __attribute__ __interrupt IFS2bits IC4IF 0 Clears and enables interrupts auto psv _IC5Interrupt void int val float curr width do val IC5BUF while IC5CoNlbits ICBNE if RUDDER LAST RISING 1 F 52 ECE 477 Final Report Spring 2009 RUDDER LAST RISING val else curr width calculatePulseWidth RUDDER LAST RISING val if curr width lt 3 amp amp curr width gt 5 MANUAL RUDDER WIDTH curr width RUDDER LAST RISING 1 else RUDDER_LAST_RISING val Determined that I may get a falling edge first so if value is over max pulse width start timing over IFS2bits IC5IF 0 Clears and enables interrupts float clkToMs int ClockTicks return ClockTicks PERIODMS PERIODCLK int msToClk float MilSecs return int MilSecs PERIODCLK PERIODMS void read PWM IN float l
93. assenger planes and the interaction between pilots and ground facility is very important part in the decision process as claimed in 1 and 2 of 9 Therefore there will be no infringement on 9 4 4 Summary As the demand on unmanned aerial vehicle was high there were a number of patents on UAV inventions Through this reports the closest three patents showed some similarities and differences Even if three patents work the same functions in UAV the design plan showed enough design dissimilarity to avoid from the infringement on existing patents 18 ECE 477 Final Report Spring 2009 5 0 Reliability and Safety Analysis Due to the range and potential for loss of control safety is an issue not only for the user but also for others who may be within flight range Software error is the primary concern because of the complexity of the software design software error is a far likelier culprit in erratic behavior or loss of control than hardware failure This analysis disregards the standard components on board the RC airplane servos motor receiver battery step down converter providing 5 V to power the servos motor and receiver off of the battery and only takes into account the components added in this design project 5 1 Reliability Analysis The most complex component in the design is the PIC24FJ256GA110 microcontroller Most of the other components except for the GPS receiver are fairly simple in comparison During testing
94. ator The software concerns with our design are how complex of instructions will be able to complete within a certain amount of time If they are too costly we will be forced to scale down to lesser accurate algorithms 10 1 Software Design Considerations In designing our software our most prominent concern is how complex our calculations can be within the certain time constraints of the individual components When using the term complex we are referring to the use of trigonometric functions which are highly costly with the math library provided to us by the microcontroller manufacturer If the precise algorithms are too costly with instruction cycles we will be forced to use less accurate algorithms which will affect our performance The table below shows the amount of cycles it takes to do each mathematical instruction Figure 10 1 1 Instruction Cost Breakdown 27 Function Group Function Performance cycles 1 2 3 4 Basic Floating Point addition 122 subtraction 124 multiplication 109 division 361 remainder 385 Trigonometric and Hyperbolic acos 478 asin 363 atan 696 atan2 3206 cos 3249 sin 2238 38 ECE 477 Final Report Spring 2009 tan 2460 cosh 1049 sinh 525 tanh 338 Logarithmic and Exponential exp 530 frexp 39 Idexp 44 log 2889 log10 3007 Power Function pow 2134 sqrt 493 Rounding Functions ceil 94 floor 51 Abs
95. ble by running both ailerons off the same PWM signal this choice would slightly limit the flexibility of the aircraft s control for example the ailerons could not be used as flaps for takeoff and landing This is not critical to fulfilling any PSSCs but a full 5 channels is a nice to have feature Input Compare 5 For reading the PWM control signals from the R C receiver ECE 477 Final Report Spring 2009 A D 8 The microcontroller will interface with a 3 axis accelerometer a 2 axis gyro and possibly some other analog devices such as a compass barometer or rangefinder SPI 1 Communicate with the SD card Digital I O 3 Spare change pins to control the camera SCI ports 2 One to communicate with the GPS module and one for general debugging PC interfacing Debug interface 1 JTAG ICD 2 or otherwise In addition voltage was a serious consideration as it determines which peripherals can be interfaced directly to the microcontroller and which ones require conversion logic Direct interfacing was preferred The SD card operates at 3 3v and uses signal levels in that range Similarly the GPS unit can use 3 3v signaling Bench testing of our airplane kit s hardware shows that the servos and speed controller should work fine with a 3 3v This made a 3 3v device a viable option conveniently reducing power consumption for the microcontroller itself The R C receiver gives 5
96. ct to an extent The most critical is that our microcontroller must have enough pulse width modulation channels to support the output to all the controls of the airplane In addition to the number of PWM channels we also need to make sure that the channels have a high enough resolution to smoothly control the plane s surfaces In order to calculate the orientation of the aircraft we have to have a lot of ATD channels that will convert data from accelerometers and gyroscopes in multiple axes Another big issue is the size and weight of the included components The Easy Glider Pro has a decent amount of space in the cockpit but a lot of this space is filled by the RC components This means that items that we want secured in the cockpit will have to be small but pieces that are not critical to be close to the microcontroller will have the option of being mounted to the outside shell of the airplane We must also be mindful of the weight of the components that we use because too much weight will not allow the plane to fly 3 2 Computation Requirements good amount of calculation will be needed to both calculate the current orientation of the aircraft based off accelerometer and gyroscope inputs and calculate the needed orientation of the aircraft from the GPS destination and current location In calculating the current orientation off of the accelerometer and gyro data we find ourselves needing quite a few floating point operations We approximate 10
97. ctronics Gyro Breakout Board Dual Axis IDG300 Online document cited 2009 Feb 27 Available HTTP http www sparkfun com commerce product info php products id 698 46 ECE 477 Final Report Spring 2009 24 25 26 27 28 ANTARIS 4 GPS Modules System Integration Manual SIM Online document Rev Al cited 2009 Feb 27 Available HTTP http www u blox com customersupport gps g4 ANTARIS4 Modules SIM GPS G4 MS4 05007 pdf Microchip PIC24FJ128GA106 Detail Page Online Available http www microchip com wwwproducts Devices aspx dDocName en532 133 Accessed February 06 09 Microchip PIC24 MCU dsPIC DSC Math Library Available http www microchip com stellent ideplg IdcService SS GET PAGE amp nodeld 2680 amp dD ocNam en022432 Accessed March 19 09 DIYDrones New ArduPilot Pocket Navigation Algorithm Available http diydrones com profiles blogs new ardupilot pocket Accessed March 24 09 Sparkfun FV M8 GPS Spec Available http www sparkfun com datasheets GPS FV M8_Spec pdf Accessed March 27 09 47 ECE 477 Final Report Spring 2009 Appendix A Individual Contributions A 1 Contributions of Heather Barrett Hardware Design I was heavily involved in the hardware design I did about 95 of the work on the first schematic revision assisted by Jeremy and William s research into the microcontroller peripheral pin select feature along
98. d lcv 48 Lovet commaPosition levtt while 1 if gpsBuffer gpsBufferHead lev break CurrentGPS Speed CurrentGPS Speed gpsBuffer gpsBufferHead lcv 48 float 10 lcv commaPosition lov gpsBufferHead gpsBufferHead 1 GPSBUFFERSIZE Finds the type of gps sentence from the head of the gps buffer 0 Unused Type I GPPGGA 2 GPVTG int gpsMessageType void if gpsBuffer gpsBufferHead 0 G amp amp gpsBuffer gpsBufferHead 1 P if gpsBuffer gpsBufferHead 2 G amp amp gpsBuffer gpsBufferHead 3 G amp amp gpsBuffer gpsBufferHead 4 A return GPGGA else if gpsBuffer gpsBufferHead 2 V amp amp gpsBuffer gpsBufferHead 3 T amp amp gpsBuffer gpsBufferHead 4 G return GPVTG return UNDEFINED Calculates the distance and bearing from staring coordinates to ending coordinates Coordinates must be sent in radians void calculatePath double startingLatitude double startingLongitude double endingLatitude double endingLongitude double distance double bearing double deltaLatitude endingLatitude startingLatitude double deltaLongitude endingLongitude startingLongitude double sinHalfDeltaLatitude sin deltaLatitude 2 double sinHalfDeltaLongitude sin deltaLongitude 2 double sinStartingLatitude sin startingLatitude
99. d be already Fl ct F 78 ECE 477 Final Report for timeout OxFF timeout gt timeout 5 see if we had an issue if timeout lt lt 0 status FALSE SD_CS 1 return status end MediaInitialize 8 RK kk kk kk kk kk k kk kk kk kk kk kk k k kk ke k k Spring 2009 0 amp amp MDD SDSPI SectorRead 0x0 NULL TRUE deselect the devices KKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Ehlhardt SD SPI h Authors Jeremy Tillman William Project FlySpy a ECE477 Team 12 Spring 2009 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK 8K KK k kk kk kk k kk kk kk kk kk kk kk k k k k k k Ck Ck CK Kk Ck CK Ck Ck CIS SC Ck Ck CI CSI SCC kk I I KK KA KK kk CKCkCkCkCkCkCkCkCkCkCk kc kCk ck k Ck kc k Ck k KA Ck ck k ck ck ck ck kk ck I kk ke KKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Microchip Memory Disk Drive File System KKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Inc FileName SD SPI h Dependencies GenericTypeDefs h FSconfig h FSDefs h Processor PIC18 PIC24 dsPIC30 dsPIC33 PIC32 Compiler C18 C30 C32 Company Microchip Technology Version 1 2 0 Software License Agreement The software supplied herewith by the Company for its PICmicroG supplied to you exclusively on Microchip PICmicro protected under applicable copyrig user to criminal sanctions under a KKKKKKKKKKK
100. d pose risks Under manual control it can easily be crashed by an inexperienced pilot as such the user manual should note that this plane is not trivial to operate and that the user should take lessons from a local hobby group before trying to fly the plane solo Under autonomous control the plane could fly off into the wild blue yonder out of range of the radio receiver This could result in a crash when the batteries run out or in total loss of the plane We designed the autopilot override such that the plane will maintain steady flight when out of radio range and be reliably and quickly switchable to manual control when in radio range 6 1 3 Privacy Risks FlySpy being an aerial photography reconnaissance device poses obvious privacy risks Users could easily misuse it to spy on their neighbors While we are not aware of the legality of aerial photography using FlySpy to spy on others against their will is certainly unethical Unfortunately we can think of no reliable way of preventing such use We can only add dire warnings in the user manual about legal consequences FlySpy could also be used by police forces to spy on private citizens which raises civil rights issues particularly in nations with poor human rights records Again we have no direct means of preventing abuse the best we could do is to refuse to sell to customers in countries that have records of civil rights abuse but we have little ability to prevent resale or
101. d successfully FALSE The sector could not be read Side Effects None Description Spring 2009 The MDD SDSPI SectorRead function reads 512 bytes of data from the SD card starting at the sector address and stores them in the location pointed to by buffer Remarks he card expects the address field in the command packet to b times multiplying by 512 a byte address he sector addr value is converted to a byte address by shifting it left nine KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK El BYTI E MDD SDSPI SectorRead DWORD sector_addr BYTE buffer WORD index WORD delay MC RESPONSE response BYTE data token E status TRUE DWORD new addr ifdef USB USE MSD DWORD firstSector DWORD numSectors dendif send the cmd new addr sector addr lt lt 9 response SendMMCCmd READ SINGLE BLOCK new addr Make sure the command was accepted if response rl byte 0x00 response SendMMCCmd READ SINGLE BLOCK new addr if response rl byte 0x00 return FALSE index Ox2FF Timing delay at least 8 clock cycles delay 0x40 while delay delay Now must wait for the start token of data block do data token MDD SDSPI ReadMedia index delay 0x40 while delay delay while data token MMC FLOATING BUS ss index 0 F 63 ECE 477 Final Re
102. d therefore it does not cause an infringement 4 2 3 Analysis of Liability involving Anti hijacking system operable in emergencies to deactivate on board flight controls and remotely pilot aircraft utilizing autopilot In Claim1 the patent explains the switching the control of the airplane by an emergency push button and this is very similar to the bypass module of FlySpy As supposed that the pilot is the autonomous flight control system and hijacking is the malfunction of the autopilot FlySpy should switch its control authority to the remote controller However FlySpy s module does not support the control from multiple stations and the patent s statement restricts the purpose of invention to the passenger planes 4 3 Action Recommended To avoid the infringement on 7 FlySpy has to develop the algorithm that can achieve the goals without following the sensor selections in the patent If FlySpy can accomplish the goal successfully with less number of components and the equal accuracy the technology can be patented as well To avoid the infringement on 8 FlySpy has to use the camera strictly and approach to the destination for photo taking by GPS guidance only as it is planned Although the 17 ECE 477 Final Report Spring 2009 similarity of the design is found in the patent and FlySpy s control bypassing module the targeting air plane is different and the patent 9 states the exclusive use in the hijacking circumstance of p
103. ddress bus bit 2 TRIS defini define ADRTRIS2 TRISG9 Description The CF address bus bit 3 TRIS defini define ADRTRIS3 _TRISG8 Data bus Description The Manual CF data bus port register define MDD_CFBT_DATABIN PORTE Description The Manual CF data bus output latch register define MDD_CFBT_DATABOUT PORTE Description The Manual CF data bus TRIS register define MDD_CFBT_DATADIR TRISE control bus lines IQ M M M M M IQ QI M QI M QI X OAN AN AXN AN AXN AN AN AN AN AN a o o o o o o oO o o o o Descrip Descrip Descrip Descrip Descrip Descrip Descrip Descrip Descrip Descrip Descrip Descrip fine CF fine CF fine CF fine CF fine CF fine CF fine CF_ fine CF fine CF fine CF fine CF tion The CF CE tion The CF CEDIR tion The CF OE tion The CF OEDIR tion The CF WE tion The CF WEDIR tion The CF BT RST tion The CF BT RESETDIR tion The CF BT RDY tion The CF BT READYDIR tion The CF BT CD1 tion The CF card card card card card card card card card card card card chip select output latch bit RD11 chip select TRIS bit _TRISD11 output enable strobe latch bit RDb5 output enable strobe TRIS bit _TRISD5 writ nable strobe latch bit _RD4 writ nable strobe TRIS bit _TRISD4
104. e SD card Remarks None F 68 ECE 477 Final Report Spring 2009 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK 4 unsigned char WriteSPIM unsigned char data out ifdef _ PIC32MX BYTE clear putcSPIl BYTE data out clear getcSPI1 return 0 return non negativeff elif defined C18XX BYTE clear clear SPIBUF SPI_INTERRUPT_FLAG 0 SPIBUF data_out if SPICON1 amp 0x80 return 1 else while SPI_INTERRUPT_FLAG return 0 else BYTE clear SPIBUF data_out write byte to SSPIBUF register while SPISTAT_RBF wait until bus cycle complete clear SPIBUF return 0 return non negative dendif OK kk kk KKK KKK KK KK KK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK Function BYTE MDD SDSPI ReadMedia void Summary Reads a byte of data from the SD card Conditions None Input None Return The byte read Side Effects None Description The MDD_SDSPI_ReadMedia function will read one byte from the SPI port Remarks This function replaces ReadSPI since some implementations of that function will initialize SSPBUF SPIBUF to 0x00 when reading The card expects OxFF ee ee k k sk k sk k kckckok k ok ske k sk k ee ee eee Kf BYTE MDD_SDSPI_ReadMedia void ifdef C32 putcSPI1 BYTE 0xFF return BYTE getcSPI1 elif defined C18XX F 69 ECE 477 Final
105. ear the interrupt status flag IEC2bits IC4IE 1 Enable Interrupts IC4CON1 0 IC4CON2 0 IC4CONlbits ICTSEL 0x0 Input Capture Timer is Timer 1 IC4CON2bits SYNCSEL 0x0D Synchronized by Timerl IC4CONlbits ICM 0x01 Edge Detect Capture mode IPC9bits IC5IP 0x05 IFS2bits IC5IF 0 Clear the interrupt status flag IEC2bits IC5IE 1 Enable Interrupts IC5CON1 0 IC5CON2 0 ICSCONlbits ICTSEL 0x0 Input Capture Timer is Timer 1 IC5CON2bits SYNCSEL 0x0D Synchronized by Timerl IC5CON1bits ICM 0x01 Edge Detect Capture mode float calculatePulseWidth int StartTime int StopTime int diff if StopTime lt StartTime diff PERIODCLK StartTime StopTime else diff StopTime StartTime return diff PERIODMS PERIODCLK void __attribute__ interrupt int val float curr width do val ICIBUF while if THROTTLE LAST RISIN T auto psv IClInterrupt void IC1coNlbits ICBNE 1 F 50 ECE 477 Final Report Spring 2009 THROTTLE LAST RISING val curr width calculatePulseWidth THROTTLE LAST RISING val if curr width 3 amp amp curr width 5 MANUAL THROTTLE WIDTH curr width THROTTLE LAST RISING 1 else THROTTLE_LAST_RISING val Determined that I may get a falling edge first so if value is over max pulse width start timing over IFSObits IClIF 0 Clears and enab
106. ecessary the digital only pins on the controller can tolerate up to 6V 18 The pins used are RPI38 RPI39 RPI40 RPI41 and RP21 8 2 2 Output Compare 32 ECE 477 Final Report Spring 2009 The output compare module will be used to generate the PWM control signals that are the final output of the flight control software There is a flexible PWM output mode supported on chip 18 The pins used are RP20 RP22 RP23 RP24 and RP25 and they will be connected directly to the control signal multiplexer 8 2 3 Analog to Digital Converter The A D system will be used to read the accelerometers gyros and rangefinders All those devices will connect directly to the microcontroller through ANxx pins as seen on our schematic 8 2 4 UART Module We will be using two UART interfaces One will communicate with the GPS module at 9600 baud 8 bits 1 stop bit no parity and will use pins RPI37 RP11 RP12 and RP3 The other interface on RPI44 RP15 RP16 and RP30 will be exposed via a 9 pin serial header for debugging via a computer 8 2 5 SPI Interface The barometer and SD card will both be connected directly to the microcontroller via SPI interfaces The barometer will be on RP31 RPI32 RP14 and RP29 and the SD card via RPI43 RP5 RP10 and RP17 8 2 6 ICD 2 Interface We will be using the Microchip ICD 2 module to program and debug our microcontroller This requires some pin allocations in order to interface with the module 19 We are expo
107. efine ADRTRIS3 TRISGbits TRISG8 Data bus Description The Manual CF data bus port register define MDD CFBT DATABIN PORTE Description The Manual CF data bus output latch register define MDD CFBT DATABOUT PORTE Description The Manual CF data bus TRIS register fidefine MDD CFBT DATADIR TRISE control bus lines Description The CF card chip select output latch bit define CF_CE PORTDbits RD11 Description The CF card chip select TRIS bit define CF CEDIR TRISDbits TRISD11 Description The CF card output enable strobe latch bit define CF OE PORTDbits RD5 Description The CF card output enable strobe TRIS bit define CF OEDIR TRISDbits TRISD5 Description The CF card write enable strobe latch bit define CF_WE PORTDbits RD4 Description The CF card writ nable strobe TRIS bit define CF_WEDIR TRISDbits TRISD4 Description The CF card reset signal latch bit define CF_BT_RST PORTDbits RDO Description The CF card reset signal TRIS bit define CF_BT_RESETDIR TRISDbits TRISDO Description The CF card ready signal port bit define CF_BT_RDY PORTDbits RD12 Description The CF card ready signal TRIS bit define CF_BT_READYDIR TRISDbits TRISD12 Description The CF card detect signal port bit define CF BT CD1 PORTCbits RC4 Description The CF card detect signal TRIS bit define CF BT CDIDIR TRISCbits TRISC4 fendif F 38 ECE 477 Final Report Spring 2009 endif include uart2 h dendif S KKK KKK KKK K
108. efine OC3 IO efine OC4 IO efine OC5 IO IO 6 extern void ioMap extern void unlockIO extern void lockIO dendif 10 18 19 20 24 22 Spring 2009 S KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK k k k k k KKK KKK KKK KKK KKK KKK KKK KKK pwm c Authors Jeremy Tillman William Project FlySpy ECE477 Team 12 include FlySpy h include util static volatile tatic volatile n static volatile tatic volatile n static volatile o static volatile tatic volatile o static volatile tatic volatile n void initpwm tatic volatile Ehlhardt Spring 2009 KCKCKCKCKCK KCk sk sk KKK sk K kA k A k k A k k k k k k k k Ck k k k k k k k k k k k k k k k kk KK KKK 2h float MANUAL_LAILERON_WIDTH 0 int LAILERON_LAST_RISING 1 float MANUAL_RAILERON_WIDTH 0 int RAILERON_LAST_RISING 1 float MANUAL_THROTTLE_WIDTH 0 int THROTTLE_LAST_RISING 1 float MANUAL_ELEVATOR_WIDTH 0 int ELEVATOR_LAST_RISING 1 float MANUAL_RUDDER_WIDTH 0 int RUDDER_LAST_RISING 1 initOutputCompare initInputCapture void initOutputCompare Clearing all Control bits OCICON1 OC1CON2 OC1R Throttle OC1RS msToClk MIN_THROTTL P OC1CON2bi 0 0 ts SYNCSI EL 0x0B E Setting 1 0ms Pu
109. eport Spring 2009 while SPICL clock while Bi SPICL clock ift S else S while SPICL Glocke OCKLAT 1 MANUAL SPI CLOCK VALUE clock t 0 OCKLAT 0 Bi se MANUAL SPI CLOCK VALUI amp 0x01 PIOUTLAT 1 PIOUTLAT 0 clock OCKLAT 1 clock while SPIC GT se MANUAL SPI CLOCK VALU clock OCKLAT 0 retur RK KKK KKK Functio BYTE Summary Reads Conditi None Input None Return The b Side Ef None Descrip This will This fac OG kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkka n ReadMediaManual void a byte of data from the SD card ons yte read fects tion The MDD SDSPI ReadMedia function will read one byte from the SPI port Remarks function replaces ReadSPI since some implementations of that function initialize SSPBUF SPIBUF to 0x00 when reading The card expects OxFF function is for use on a PIC18 when the clock speed is so high that the maximum SPI clock prescaler cannot reduce the SPI clock below the maximum SD card initi KKKKKKKKK x alization speed KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK BYTE ReadMediaManual void char unsig SPICL SPIOU SPICL SPIOU SPII if r Pe Bi i result 0x00 ned char clock OCKLAT 0 TLAT 1 OCK OUTPUT T OU
110. esponse data of type Remarks None response from the card I Oo U M UN F Oo Idle state Erase Reset Illegal Command Command CRC Error Erase Seguence Error Address Error Parameter Error Unused Always 0 command packet and sends it out over the SPI interface as indicated by the SD MMC product manual is returned This function is intended to be used when the clock speed of a PIC18 device is so high that the maximum SPI divider can t reduce the clock below the maximum SD card initialization sequence speed Rl KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKkKKKKKKKKkKkkkKKKKK K ko ko ko ko k MMC RESPONSE SendMMCCmdManual BYTE cmd DWORD address Card Select sdmmc_cmdtable cmd CmdCode WORD timeout 0x8 BYTE index MMC_RESPONSE response CMD PACKET CmdPacket SD CS 0 Copy over data CmdPacket cmd CmdPacket address address CmdPacket crc CmdPacket TRANSMIT BIT WriteSPI WriteSPI WriteSPI anual CmdPack anual CmdPack anual CmdPack sdmmc cmdtable cmd CRC et et et js Set Tranmission bit cmd Send Command addr3 Most Significant Byte addr2 F 61 Calc CRC here ECE 477 Final Report Spring 2009 WriteSPIManual CmdPacket addrl WriteSPIManual CmdPacket addr0 Least Significant Byte WriteSPIManual CmdPacket crc Send CRC see if we are going to get a resp
111. f a point on the surface that is disposed perpendicularly below the fixed point on the aircraft a computer for computing the position of the fixed point on the aircraft relative to the target point on the surface from the respective measurements of the camera and the navigation system and a controller for controlling the movement of the aircraft such that the fixed point on the aircraft is positioned at a selected azimuth angle elevation angle and slant range above the selected target point on the surface 8 Claim 4 The system of claim 1 wherein the navigation system comprises a Global Positioning Satellite GPS system an Inertial Navigation System INS or both a GPS and an INS 8 Claim 5 The system of claim 1 wherein the aircraft comprises a helicopter or an aerial vehicle 8 15 ECE 477 Final Report Spring 2009 4 1 3 Anti hijacking system operable in emergencies to deactivate on board flight controls and remotely pilot aircraft utilizing autopilot U S Patent Application No 2004 0079837 9 Filing Date April 29 2004 Abstract In an anti hijacking system for autopilot equipped aircraft a transceiver communicates with at least one remote guidance facility A panic button is activated by flight crew in case of hijacking A manager is coupled to the transceiver and the panic button as well as existing avionics including the aircraft s master computer and autopilot The manager recognizes predetermined override input
112. fine for the SPI control register i e bits define SPICONlbits SSP1CoNlbits Description The bitwise define for the SPI status register i e bits define SPISTATbits SSPISTATbits Description The interrupt flag for the SPI module define SPI INTERRUPT FLAG PIR1bits SSPIF Description The enable bit for the SPI module define SPIENABLE SPICONlbits SSPEN Defines for the FS USB demo board Tris pins for SCK SDI SDO lines define SPICLOCK TRISBbits TRISB1 define SPIIN TRISBbits TRISBO define SPIOUT TRISCbits TRISC7 Latch pins for SCK SDI SDO lines define SPICLOCKLAT LATBbits LATB1 define SPIINLAT LATBbits LATBO define SPIOUTLAT LATCbits LATC7 Port pins for SCK SDI SDO lines define SPICLOCKPORT PORTBbits RBl define SPIINPORT PORTBbits RBO F 31 ECE 477 Final Report card bit define SPIOUTPORT PORTCbits RC7 Description T fine SPICLOCK Description T fine SPIIN Description T fine SPIOUT Description T Description T fine SPIINLAT Description T fine SPIOUTLAT Description T Description T fine SPIINPORT Description T he TRIS bit for the he TRIS bit for the he TRIS bit for the he output latch for fine SPICLOCKLAT LATCbits he output latch for LATCbits he output latch for LATCbits he port for the SCK fine SPICLOCKPORT PORTCbits he port for the SDI PORTCbits he port for the SDO
113. gned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned bits O O ODO 0 0 OQ 07 QVO Q Q 0 QUO OMG AAR OO Q Q OQ OOO WA A A101 A0 A AA OWORD VAL endif GENERIC TYPE DI nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar nar b12 b13 b14 bl5 bl6 b17 b18 b19 b20 b21 b22 b23 b24 b25 b26 b27 b28 b29 b30 b31 b32 p33 b34 b35 b36 b37 b38 b39 b4 b4 b4 b4 b4 b4 b4 b4 b4 b4 b50 b51 b52 b53 b54 b55 b56 b57 b58 b59 b60 bel b62 b63 cC OJ OU BUN Oo Se Se Se Se Se Ne Ne Ne Ne Ne Ne Ne Ne Ne Ne Ne Ne Ne Ne NE SES 99 D Se Se Se Se Ne Ne Ne Ne Ne Ne Ne o Ne Se e lA p p pp B B pp pp pp Ep p pp pp pp pp pp Ep p ip pp pp p pp p pp pp pp p pp pp pp pp pp pp pp pp pp pp pp ip pp ip pp pp ipo i
114. gpsBuffer gpsBufferHead 10 48 10 gpsBuffer gpsBufferHead 11 48 CurrentGPS Mils gpsBuffer gpsBufferHead 13 48 100 gpsBuffer gpsBufferHead 14 48 10 gpsBuffer gpsBufferHead 15 48 CurrentGPS Latitude gpsBuffer gpsBufferHead 17 48 10 gpsBuffer gpsBufferHead 18 48 gpsBuffer gpsBufferHead 19 48 10 gpsBuffer gpsBufferHead 20 48 gpsBuffer gpsBufferHead 22 48 1 gpsBuffer gpsBufferHead 23 48 01 gpsBuffer gpsBufferHead 24 48 001 gpsBuffer gpsBufferHead 25 48 0001 60 if gpsBuffer gpsBufferHead 27 S CurrentGPS Latitude 1 CurrentGPS Longitude gpsBuffer gpsBufferHead 29 48 100 gpsBuffer gpsBufferHead 30 48 10 gpsBuffer gpsBufferHead 31 48 gpsBuffer gpsBufferHead 32 48 10 gpsBuffer gpsBufferHead 33 48 gpsBuffer gpsBufferHead 35 48 1 gpsBuffer gpsBufferHead 36 48 01 gpsBuffer gpsBufferHead 37 48 001 gpsBuffer gpsBufferHead 38 48 0001 60 if gpsBuffer gpsBufferHead 40 W CurrentGPS Longitude 1 CurrentGPS Signal gpsBuffer gpsBufferHead 42 48 lev 42 commaPosition 0 while commaPosition lt 1 if gpsBuffer gpsBufferHead lov commaPositiontt Lovet CurrentGPS SVs 0 F 24 ECE 477 Final Report Spring 2009 while 1 if gpsBuffer gpsBufferHead lcv lt
115. gyro data The basic operational logic of the autopilot unit is as flowcharted in Appendix A Although shown in a direct format some procedures will be done iteratively more than other portions All procedures of basic operation past initialization will be interrupt driven to assert that we have clean and up to date data The variables that hold the current GPS and orientation information will be stored as global variable therefore accessible to all functions This brings coherence into play but we will use timing to assert that there is not simultaneous use instead of using locks Since there will not be that much program code or memory storage in comparison to the 256Kb series of microcontrollers that we are using we will be fine using the default mapping of program memory for the stack heap and program memory This is displayed in detail in Appendix C The PIC24FJ256GA1 10 is an 100 pin device and we will use the following ports for interfacing to different devices as listed Device Ports Interface Type Accelerometer Axes ATD AN5 3 Range Finder ATD AN2 40 ECE 477 Final Report Spring 2009 Gyro Axes ATD AN1 0 Barometer SPIO SD Card SPI2 GPS Module SPI3 ICD DC Serial Port UART 10 2 Software Design Narrative File Name Description Main c written in pseudo code Used to initialize all micro controller ports and modules thereafter it start the timer on all in
116. hannel to an angle value Although this may take a lot of memory it may prove to be quite helpful in terms of 39 ECE 477 Final Report Spring 2009 timing if the atan function cannot execute within the about of time that we propose to refresh the accelerometer data The major algorithm that we are taking into consideration is the algorithms that we use to calculate distance and correct heading from the GPS data Given that the gps data is basically represented in degrees if we want to be precise with our calculations it will take several occurrences of trigonometric functions to derive a bearing and distances from two points that are very precise We have seen that there are scaled down versions of these algorithms but they do show that they affect accuracy largely over a certain amount of distance 28 Given the fact that we are using various devices we find ourselves having to model our software design in a fashion to accommodate for accurate up to date data from each of these components while they require different timing subroutines The GPS module that we are using the FV M8 4 works at 5 Hz On the other hand the IDG300 two axis gyro 5 will require us to sample its data faster around 50 Hz in order to retrieve accurate data We view these items as the two pacesetting products in our design Therefore we will have to use timer interrupts to update GPS data and also a faster timer interrupt to sum the change in rotation for the
117. he Easy Star does not have ailerons which is a major downfall Ailerons give us the capability to make direct and sharp turns but without them you may only turn with your rudder The rudder turn is not ideal and is a sluggish and slow rotation around the yaw axis For these reasons we choose the Easy Glider Pro Easy Glider Pro 3 Easy Star 4 Wing Length 72 in Wing Length 54 in Wing Area 645 Sq in Wing Area 372 sq in Wing Loading 6 25 oz sq ft glider Wing Loading 10 76 oz sg ft Fuselage Length 44 in Fuselage Length 34 in 12 ECE 477 Final Report Spring 2009 Weight English 34 oz Electric Weight Metric 29 oz Glider Weight English 24 oz 13 ECE 477 Final Report Spring 2009 4 0 Patent Liability Analysis The possible infringement could be occurred in the algorithm of controlling the airplane s position and orientation using appropriate sensors and GPS system controlling camera to take appropriate photo at the projected GPS coordinates and switching the control authority between FlySpy system and remote controller As the demand on the UAV technology has been high due to military purpose a number of related patents were researched and the following 3 patents were the most concerned ones in the each category 4 1 Results of Patent and Product Search 4 1 1 Programmable autopilot system for autonomous flight of unmanned aerial vehicles U S Patent No 7302
118. he aircraft This will be beneficial to use with use of the GPS receiver and the camera The GPS receiver may be placed on top of the fuselage and close to the rudder This unit can be used to counter balance the components that we insert internally therefore helping to retain a good aerodynamic center The camera itself will need to be mounted to the bottom of the aircraft It must be placed at the aerodynamic center because we do not want to add more weight to counter react it and adding to the total weight 3 8 Cost Constraints Currently there aren t any solutions that give you a airplane with built in autonomous abilities On the other hand they do commercially sell autopilot units that you may insert into your own plane MicroPilot markets themselves as the world leaders in miniature UAV autopilots so we will compare our design with their unit alone Their low end autopilot controller that they market as Disposable control is 2000 dollars per unit We are aiming for a total cost plane controller computing hardware of under 1000 3 9 Component Selection Rationale The microcontroller was one of the more difficult parts to select due to the bewildering number of choices available from various manufacturers The core requirements were as follows Type Comments PWM Outputs 5 One for each aircraft control signal two ailerons elevator rudder throttle While a controller with only 4 signals available would be doa
119. i b CID ifndef FALSE define FALSI endif ifndef TRUE define TRUE endif LJ o FALSI Ics define INPUT 1 define OUTPUT 0 Description define DELAY_PRESCALER A delay prescaler BYTE 8 Description define DELAY_OVERHEAD BYTE 5 Description the Delayms function define MILLISECDELAY WORD An approximation of the number of Spring 2009 cycles per delay loop of overhead GetInstructionClock DELAY_PRESCALER WORD 1000 Summary An enumeration of SD commands Description sdmmc_cmdtable sdmmc_cmdtable fel typedef enum array array Q o H O Fa E STATE D OP COND D CSD D CID P TRANSMISSION D STATUS T BLOCKLEN D SINGLE BLOCK D MULTI BLOCK WRITE SINGLE BLOCK Z Oz z ZI D n D O D Dd Dd Hj DH Ed NE Juuyudodouoouo F 85 D ELAY OVERH An approximate calculation of how many times to loop to delay 1 ms in EAD to retrieve command code information from This enumeration corresponds to the position of each command in the These macros indicate to the SendMMCCmd function which element of the ECE 477 Final Report Spring 2009 WRITE MULTI BLOCK TAG SECTOR START TAG SECTOR END ERASE APP CMD READ OCR CRC ON OFF sdmmc cmd rj tu KKK kk ske sk ske Kk k k k
120. ials ending up out in the woods somewhere is higher than that of most other consumer devices The airframe is constructed of a material called Elapor Elapor is extremely lightweight yet very robust However being essentially Styrofoam it is not really recyclable and so will end up in a landfill 14 This waste is somewhat mitigated by the fact that FlySpy is not a throw away product so each unit is expected to be used for years Also the choice of material both reduces the likelihood of damage as Elapor is much less brittle than balsa wood and makes damage to the airframe easy to repair using tape and glue reducing the number of units that will get thrown away due to damage In the event that the plane gets lost the Elapor will be a pollutant and will take a very long time to decompose To possibly mitigate this environmental hazard we could switch to something like a balsa wood airframe but that would make FlySpy more prone to damage or to a hard plastic airframe which would be heavier 25 ECE 477 Final Report Spring 2009 Like those of virtually all electronic devices FlySpy s circuit boards and electronic components are an environmental concern Most of the parts could be manufactured in an RoHS compliant way many of our components are already RoHS compliant However lead free parts particularly lead free solder are known to affect reliability so it may not be worth the tradeoff 15 The components themselves are all s
121. ies No Processor PI Compiler Mi Company Mi mpiler h ne C18 PIC24F PIC24H dsPIC30F dsPIC33F PIC32 crochip C32 v1 00 or higher Microchip C30 v3 01 or higher Microchip C18 v3 13 or higher HI TECH PICC 18 STD 9 50PL3 or higher crochip Technology Inc Software License Agreement Copyright C 2002 reserved Microchip licenses distribute 2008 Microchip Technology Inc All rights to you the right to use modify copy and i the Software when embedded on a Microchip microcontroller or digital signal controller product Device which is integrated into Licensee s product or ii ONLY the Software driver source files ENC28J60 c and ENC28J60 h ported to a non Microchip device used in conjunction with a Microchip ethernet controller for the sole purpose of interfacing with the ethernet controller You should refer to the license agreement accompanying this F 12 ECE 477 Final Report Spring 2009 Software for additional information regarding your rights and obligations THE SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND EITHER EXPRESS OR IMPLIED INCLUDING WITHOUT LIMITATION ANY WARRANTY OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE TITLE AND NON INFRINGEMENT IN NO EVENT SHALL MICROC
122. ileName HardwareProfile h Dependencies None Processor PIC18 PIC24 dsPIC30 dsPIC33 PIC32 Compiler C18 C30 C32 Company Microchip Technology Inc Software License Agreement The software supplied herewith by Microchip Technology Incorporated the Company for its PICmicro Microcontroller is intended and supplied to you the Company s customer for use solely and exclusively on Microchip PICmicro Microcontroller products The software is owned by the Company and or its supplier and is protected under applicable copyright laws All rights are reserved Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws as well as to civil liability for the breach of the terms and conditions of this license THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION NO WARRANTIES WHETHER EXPRESS IMPLIED OR STATUTORY INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE THE COMPANY SHALL NOT IN ANY CIRCUMSTANCES BE LIABLE FOR SPECIAL INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER KCKCKCKCKCkCKCk KKK KKK KKK X kk k k k k k k kA CK KA KA KA KK KA KIC CK k k k k KA AXA k k k k kk k k ke ke ke ke ifndef HARDWAREPROF
123. index fendif endif KKK kk skok sk KKK K K ske k k I A k k k k k K K k k k k k k k k k k k k k KA k k k k k k k k KA CK k k k k KA k k k k sensors c Authors Jeremy Tillman William Ehlhardt Project FlySpy ki ECE477 Team 12 Spring 2009 KCKCKCK skok ske sk ske sk ske sk k ske KKK K K kk k K K K k k k k k k k k k k Ck k k k k kA k k k k k k k KKK KKK include FlySpy h define VarianceLogLength 20 SENSORDATA sensorInfo float PitchAngle 0 Angle of pitch of the Airplane F 86 ECE 477 Final Report Spring 2009 float RollAngle 0 Angle of roll of the Airplane Right Roll is Positive float Clearing 0 The amount of clearing that we know we have from the bottom of the aircraft in meters 6 meters being the max float Variance 0 float magnitudes VarianceLogLength void initSensors int lov for lev 0 lev lt VarianceLogLength lcv magnitudes lev 0 sensorInfo inuse 0 sensorInfo Pitch 0 sensorInfo Roll 0 sensorInfo Altitude 0 sensorInfo Clearing 0 sensorInfo GyroPitchVoltage 0 sensorInfo GyroRollVoltage sensorInfo Accelerometer X sensorInfo Accelerometer Y sensorInfo Accelerometer Z sensorInfo MagnitudeVariance m6 65 6 lt se ae se float sampleToG float measure float G measure 98 042 5 222 return G void updateOrientation
124. ined not to ruin the balance of the plane and therefore our packaging is going to be successful 30 ECE 477 Final Report Spring 2009 8 0 Schematic Design Considerations The FlySpy will use inertial devices accelerometers and gyros and a barometer to maintain stable flight and GPS to do overall navigation photographs will be taken using a modified commercial digital camera The FlySpy is also equipped with a rangefinder to support autonomous landing if time permits 8 1 Theory of Operation 8 1 1 Power Supply In order to simplify the electrical design we selected parts with an eye towards minimizing the number of different DC power rails required The SD card accelerometer gyro GPS module and barometer all operate at 3 3V Thus we selected a microcontroller and rangefinder that also support 3 3V operation and verified in benchtop testing that our servos and speed controllers could accept a 3 3V PWM signal As such there will be two main power rails in the circuit at 3 3V and 5V The motor speed controller for the propeller connects directly to the 7 4V main battery and provides the 5V rail which will be used to power the R C receiver and the servos attached to the flight control surfaces The 3 3V rail will be provided by a high efficiency buck converter from the 5V rail A high estimate for the current draw on the 3 3V rail is 100mA which seems doable using a buck converter such as the LTC1174 If a buck converter turns out to
125. ize a PIC18 SPI module with a 4x ODE SLOW 0x02 I Description This macro is used to initialize a PIC32 SPI module define SYNC MODE FAST 0x3E Description This macro is used to initialize a PIC32 SPI module define SYNC MODE SLOW 0x3C else Description This macro indicates the SPI enable bit for 16 bit PICs define ASTER ENABLE ON 0x0020 Description This macro is used to initialize a 16 bit PIC SPI module define SYNC MODE FAST Ox3E Description This macro is used to initialize a 16 bit PIC SPI module define SYNC MODE SLOW 0x3C Description This macro is used to initialize a 16 bit PIC SPI module secondary prescaler define SEC PRESCAL 1 1 0x001c Description This macro is used to initialize a 16 bit PIC SPI module primary prescaler define PRI PRESCAL 1 1 0x0003 endif KKK kk RR ske sk ske sk ske k k kk k k k k k k k kk k k KA k k k k kk k k KA kk kk kkk ke kk ke Jeg Strcutures and defines ef KK KR RR RR K k kkk k kk kk kk Ck kA k KA k k k k k k k k kk k k KA ke ke ke k kk k ke ke k Description This macro represents an SD card start token define DATA START TOKEN OxFE Description This macro represents an SD card data accepted token define DATA ACCEPTED 0x05 Description This macro indicates that the SD card expects to transmit or receive more data define MOREDATA 10
126. k k k k k k k k k k Ck KA I k k k KKK KKK typedef struct float Prev_Error float Integral float KP float KI float KD JAXISPID define MAX THROTTLE 1 93 Percentage of MAX WIDTH as Throttle Maximum define MIN THROTTLE 1 05 Percentage of MIN WIDTH as Throttle Maximum define MAX ELEVATOR 1 93 Percentage of MAX WIDTH as Elevator Maximum define ZERO ELEVATOR 1 58 Pulse Width of the Alieron Zero point define MIN ELEVATOR 1 13 Percentage of MIN WIDTH as Elevator Maximum define MAX RUDDER 1 93 Percentage of MAX WIDTH as Rudder Maximum define ZERO RUDDER 1 47 Pulse Width of the Rudder Zero point define MIN RUDDER 1 13 Percentage of MIN WIDTH as Rudder Maximum define MAX LAILERON 1 8 Percentage of MAX WIDTH as Left Alieron Maximum define ZERO LAILERON 1 6 Pulse Width of the Left Aileron Zero point define MI AILERON 1 10 Percentage of MIN WIDTH as Left Alieron Maximum define MAX RAILERON 1 93 Percentage of MAX WIDTH as Right Alieron Maximum define ZERO RAILERON 1 65 Pulse Width of the Right Aileron Zero point define MIN RAILERON 1 22 Percentage of MIN WIDTH as Right Alieron Maximum void initSurfaces void void directSurfaces void void setSurface float int void disableControlSurfaces void void enableControlSurfaces void void setPitch float void setRoll float
127. k Drive File System KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKK FileName SD SPI Dependencies SD SPI h string h FSIO h FSDefs h F 54 ECE 477 Final Report Spring 2009 Processor PIC18 PIC24 dsPIC30 dsPIC33 PIC32 Compiler C18 C30 C32 Company Microchip Technology Inc Version 1 2 0 Software License Agreement The software supplied herewith by Microchip Technology Incorporated the Company for its PICmicro Microcontroller is intended and supplied to you the Company s customer for use solely and exclusively on Microchip PICmicro Microcontroller products The Software is owned by the Company and or its supplier and is protected under applicable copyright laws All rights are reserved Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws as well as to civil liability for the breach of the terms and conditions of this license THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION NO WARRANTIES WHETHER EXPRESS IMPLIED OR STATUTORY INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE THE COMPANY SHALL NOT IN ANY CIRCUMSTANCES BE LIABLE FOR SPECIAL INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER KCKCKCKCKCkCKCk KKK KA KKK KK
128. k k kk kk Sk kk k kk k k k k k KKK k k k KKK ke e e ke x KOR KK kok k k KKK KKK KKK Pin and Register Definitions KKK ck k ck KKK KK KK k ke x ke x F 30 ECE 477 Final Report KKK kk KKK KKK KKKKK KKK KK KK KK KK KKK KKK k k k k k k k k k k KKK ke ke e ke x SD Card definitions Change these to fit your application when using an SD card based physical layer x ifdef USE SD INTERFACE WITH SPI ifdef 18CXX Sample definition for PIC18 modify to fit your own project Description SD SPI Chip Select Output bit define SD CS PORTBbits RB3 Description SD SPI Chip Select TRIS bit define SD CS TRIS TRISBbits TRISB3 Description SD SPI Card Detect Input bit define SD CD PORTBbits RB4 Description SD SPI Card Detect TRIS bit define SD_CD_TRIS TRISBbits TRISB4 Description SD SPI Write Protect Check Input bit define SD_WE PORTAbits RA4 Description SD SPI Write Protect Check TRIS bit define SD_WE_TRIS TRISAbits TRISA4 Registers for the SPI module you want to use Spring 2009 Description The main SPI control register define SPICON1 SSP1CON1 Description The SPI status register define SPISTAT SSPISTAT Description The SPI buffer define SPIBUF SSPIBUF Description The receive buffer full bit in the SPI status register define SPISTAT RBF SSPISTATbits BF Description The bitwise de
129. l Report Spring 2009 13 0 References 1 2 3 4 5 6 7 8 9 10 11 Microchip PIC24FJ128GA106 Detail Page Online Available http www microchip com wwwproducts Devices aspx dDocName en532 133 Accessed February 06 09 Freescale S12HZ Product Summary Page Online Available http www freescale com webapp sps site prod summary jsp code S12HZ amp fsr ch 1 Accessed February 06 09 Multiplex Easy Star Model Kit 2007 Online Available http www multiplexusa com models kits easy star php Accessed January 9 09 Multiplex Easy Glider Pro Kit 2007 Online Available http www multiplexusa com models kits easy glider pro php Accessed January 9 09 Chris Anderson Review Multiplex EasyGlider Pro for UAV use December 4 2008 Online Available http www diydrones com profiles blogs review multiplex easyglider Accessed December 26 2006 Chris Parker Virtual Reality 3DOF Tracker August 13 2007 Online Available http www virtualreality net au 3DOF_ Tracker Accessed January 14 2009 Randal W Beard Walter H Johnson Reed Christiansen Joshua M Hintze Timothy W MeLain Programmable autopilot system for autonomous flight of unmanned aerial vehicles U S Patent No 7302316 November 27 2007 Gregory E Dockter Donald G Caldwell Jason Graham Precision Approach Control U S Patent Application No 2
130. lag 0 if StartEndPoint Landing Go to landing setPitch PITCH_ZERO setRoll ROLL ZERO setSurface 0 THROTTLE endif while 1 return 0 S KKK KKK Ck kA kk kk Kk KX k kk k k k k k k k k KKK KC CK KK KA KA k k k KA KA KA CK k k k k k k k k k k k ADC Authors Jeremy Tillman William Ehlhardt Project FlySpy X ECE477 Team 12 Spring 2009 KKK KKK KK KKK KKK KK K K K K K k k K K k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k kk k k k kk k k k include FlySpy h void initADC AD1PCFGH AD1PCFGL 0x0000 All Ports to analog inputs 0x0000 AD1CON1 0x00E0 SSRC lt 3 0 gt 111 implies internal counter ends sampling and starts converting in this example AN12 is the input AD1CSSL 0 AD1CON3 Ox1F02 Sample time 31Tad Tad 2 Tey AD1CON2 0 AD1CONlbits ADON 1 turning ADC ON return void setADCPort int portNumber AD1CHS portNumber Setting the ADC input as the appropriate pin int retrieveADCVal ECE 477 Final Report Spring 2009 int retVal AD1CoNlbits DONE 0 Assert that the DONE bit has been cleared from previous ADC Read AD1CON1bits SAMP into convert while AD1CONlbits DONE Wait for conversion to finish retVal ADCIBUFO return retVal 1 Starting to sample and then will automatically go int sampleADCPort int
131. les interrupts void __attribute__ __interrupt auto psv _IC2Interrupt void int val float curr width do val IC2BUF while IC2CON1bits ICBNE if LAILERON LAST RISING 1 LAILERON LAST RISING val else curr width calculatePulseWidth LAILERON LAST RISING val if curr width lt 3 amp amp curr width gt 5 MANUAL LAILERON WIDTH curr width LAILERON LAST RISING 1 else LAILERON_LAST_RISING val Determined that I may get a falling edge first so if value is over max pulse width start timing over IFSObits IC2IF 0 Clears and enables interrupts void __attribute__ __interrupt auto psv _IC3Interrupt void int val float curr width do val IC3BUF while IC3CONlbits ICBNE if RAILERON LAST RISING 1 F 51 void attribute interrupt ECE 477 Final Report Spring 2009 RAILERON LAST RISING val else curr width calculatePulseWidth RAILERON LAST RISING val if curr width 3 amp amp curr width 5 MANUAL RAILERON WIDTH curr width RAILERON LAST RISING 1 else RAILERON_LAST_RISING val Determined that I may get a falling edge first so if value is over max pulse width start timing over IFS2bits IC3IF 0 Clears and enables interrupts j auto psv _IC4Interrupt void int val float curr width do v
132. lev double man rudder sensorInfo GyroPitchVoltage sensorInfo GyroRollVoltage sensorInfo Accelerometer X sensorInfo Accelerometer Y sensorInfo Accelerometer Z sensorInfo MagnitudeVariance sensorInfo inuse 0 count if count gt 9 if length gt 0 length_check FSfwrite logBuffer 1 length fptr if length length check FSfclose fptr printf Error in FSfwrite d r n FSerror while 1 length 0 count 0 TimerFlag 0 else double targetBearing double targetDistance double bearingDifference double Pitch double Roll int wp_index Indexs the current waypoint that we are approaching in the wayPoints array int lov float auto 1 ail auto r ail auto throttle auto elev auto rudder enableControlSurfaces wp index 0 logStart if StartEndPoint TakeOff SecondFlag 0 lev 0 while lcv lt StartEndPoint Delay F 3 ECE 477 Final Report Spring 2009 __delay32 SYSCLK 2 lcv setSurface 5 THROTTLI setPitch 20 setRoll 0 while StartEndPoint TakeOff Altitude sensorInfo Altitude LJ s gt 20 setSurface 5 THROTTLE while wp index lt wayPointCount retrieveGpsData Retrieves Current GPS Data calculatePath CurrentGPS Latitude CurrentGPS Longitude wayPoints wp index Latitude wayPoints wp_index Longitude amp targetDistance amp targetBearing
133. lse Width Mininum for ERIODCLK Period of 20ms Synchronized by Timerl 50Hz F 48 ECE 477 Final Report Spring 2009 OC1coNlbits OCTSEL 0x04 Select Timerl as the clock source OC1CoNlbits OCM 6 Setting PWM Output in Edge Aligned Mode Clearing all Control bits OC2CON1 0 OC2CON2 0 OC2R msToClk ZERO LAILERON Setting 1 5ms Pulse Width Midpoint OC2RS PERIODCLK Period of 20ms OC2CON2bits SYNCSEL 0x0B Synchronized by Timerl 50Hz OC2CON1bits OCTSEL 0x04 Select Timerl as the clock source OC2CON1bits OCM 6 Setting PWM Output in Edge Aligned Mode Clearing all Control bits OC3CON1 0 OC3CON2 0 OC3R msToClk ZERO RAILERON Setting 1 5ms Pulse Width Midpoint OC3RS PERIODCLK Period of 20ms OC3CON2bits SYNCSEL 0x0B Synchronized by Timerl 50Hz OC3CON1bits OCTSEL 0x04 Select Timerl as the clock source OC3CON1bits OCM 6 Setting PWM Output in Edge Aligned Mode Clearing all Control bits OC4CON1 0 OC4CON2 0 OC4R msToClk ZERO_ELEVATOR Setting 1 5ms Pulse Width Midpoint OC4RS PERIODCLK Period of 20ms OC4CON2bits SYNCSEL 0x0B Synchronized by Timerl 50Hz OC4CON1bits OCTSEL 0x04 Select Timerl as the clock source OCACON1bits OCM 6 Setting PWM Output in Edge Aligned Mode Clearing all Control bits OC5CON1 0 OC5CON2 0 OC5R msToClk
134. lso researched on the SD card circuitry which was simple and it did not take a lot of time SD card breakout board was purchased and it helped a lot After our microcontroller was selected I found out that there were file I O library for PIC microcontroller on microchip com which is the vendor of our microcontroller It offered the most of the SD card interface and file I O functions and some optional functions could be enabled by our needs I enabled fprintf function which was initially disabled to save resources of the microchip I wrote flight logging functions to write the log in XML script so that it can be displayed with a certain scheme but it was not suitable for our situation so Jeremy changed to just text log After the flight logging is done I wanted to help Jeremy figuring out the flight controls but Jeremy was too ahead of me to catch up his pace and I decided to work on other A 2 ECE 477 Final Report Spring 2009 miscellaneous part that can help our team Therefore I spent time on preparing the user manual and poster For user manual the installation process user guide and trouble shooting were written It was very straight forward and I felt that the manual control mode and flight logging functions were the most important part that can help the user to solve the problem when they encounter any unfavorable circumstance For the poster I took the image of our plane and edited it with Photoshop so that it can get along with the
135. lt break CurrentGPS SVs CurrentGPS SVs 10 gpsBuffer gpsBufferHead lcv 48 Lagat lov commaPosition 0 gpsBuffer gpsBufferHead lcv 48 gpsBuffer gpsBufferHead lcv else if gpsBuffer gpsBufferHead lcv 48 gpsBuffer gpsBufferHead lcv while commaPosition 1 if gpsBuffer gpsBufferHead lcv commaPositiontt lov CurrentGPS Altitude 0 while gpsBuffer gpsBufferHead lev t hot CurrentGPS Altitude CurrentGPS Altitude 10 lov commaPosition lov while gpsBuffer gpsBufferHead lov pnt CurrentGPS Altitude CurrentGPS Altitude 48 10 lcv commaPosition Lev messageType GPVTG CurrentGPS Heading 0 lev 6 while 1 SSS Ve if gpsBuffer gpsBufferHead lev break CurrentGPS Heading CurrentGPS Heading 10 lov tr commaPosition levtt while 1 S if gpsBuffer gpsBufferHead lev break CurrentGPS Heading CurrentGPS Heading 48 float 10 lev commaPosition lov r commaPosition 0 lcvtt while commaPosition lt 5 Read 5 more commas if gpsBuffer gpsBufferHead lev commaPositiontt levrt CurrentGPS Speed 0 while 1 F 25 ECE 477 Final Report Spring 2009 if gpsBuffer gpsBufferHead lcv lt lt break CurrentGPS Speed CurrentGPS Speed 10 gpsBuffer gpsBufferHea
136. lures per 10 hours Parameter Description Value Comments regarding name choice of parameter value especially if you had to make assumptions C Die complexity 010 100 transistors each 2 1 mux 3 NAND gates 12 transistors x 5 60 each way because bidirectional TT Temperature coeff 5 6 TJ 150 C from page 2 of datasheet 12 e Package Failure Rate 0087 SMT 24 pins Z Environment Factor 4 0 Assume ground mobile since the plane operates fairly close to the ground no typical stresses of airborne environments To Quality Factor 10 Commercial product T Learning Factor 1 0 gt 2 0 years in production Entire design Failures per million hours 908 Mean time to failure MTTF in years 125 72 Buck Converter The linear MOS model from section 5 1 in the handbook was used 10 With this model p 7 C7 C H 67 failures per 10 hours Parameter Description Value Comments regarding 20 ECE 477 Final Report Spring 2009 name choice of parameter value especially if you had to make assumptions Cl Die complexity 010 lt 100 transistors Tr Temperature coeff 58 T T Pp 110 C W from page four of datasheet 13 C Package Failure Rate 0026 SMT 8 pins s Environment Factor 4 0 Assume ground mobile since the plane operates fairly close to the ground no typical stresses of airborne environments T
137. ly selected begin application specific code to reset th code to code to code to code to stop code to get the card status code to code to code to code to write one block to code to write multiple bloc code to set the address of code to set th code to code to code to get the OCR register code to disable CRC checking Enumeration of different SD response types ECE 477 Final Report Spring 2009 BYTE CmdCode The command code BYTE CRC The CRC value for that command RESP responsetype The response type BYTE moredataexpected Set to MOREDATA or NODATA depending on whether more data is expected or not typMMC CMD Summary An SD command packet Description This union represents different ways to access an SD card command packet typedef union This structure allows array style access of command bytes struct ifdef 18CXX BYTE field 6 BYTE array else BYTE field 7 endif bi This structure allows byte wise access of packet command bytes struct BYTE crc The CRC byte if defined C30 BYTE c30filler Filler space since bitwise declarations can t cross a WORD boundary elif defined C32 BYTE c32filler 3 Filler space since bitwise declarations can t cross a DWORD boundary endif BYTE addr0 Address byte 0 BYTE addrl Address byte 1 BYTE addr2 Address byte 2 BYTE addr3 Address byte 3 BYTE cmd
138. mReadCRC Read 2 bytes of CRC status mmcCardCRCError mSend8ClkCycles Required clocking see spec SD CS 1 return status end SectorRead OK kk kk k KK K K ske sk ske k k K K K K kk kk k k k KA KK KA KA KA k k KA KICK KA AXA KA k k k k k k k k k k ke ke ke I k k Function BYTE MDD SDSPI SectorWrite DWORD sector addr BYTE buffer BYTI allowWriteToZero ET Summary Writes a sector of data to an SD card Conditions The MDD SectorWrite function pointer must be pointing to this function Input sector addr The address of the sector on the card buffer The buffer with the data to write allowWriteToZero TRUE Writes to the 0 sector MBR are allowed FALSE Any write to the 0 sector will fail Return Values TRUE The sector was written successfully FALSE The sector could not be written Side Effects None Description The MDD SDSPI SectorWrite function writes 512 bytes of data from the location pointed to by buffer to the specified sector of the SD card Remarks The card expects the address field in the command packet to be a byte address The sector addr value is ocnverted to a byte address by shifting it left nine times multiplying by 512 KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK x BYTE MDD SDSPI SectorWrite DWORD sector addr BYTE buffer BYTE allowWrite
139. microSD card and triggering the onboard camera at defined points Autonomous flight control is achieved using inertial sensors accelerometers and gyros as feedback while a switch on the remote control allows manually controlled flight for takeoff and landing ECE 477 Final Report Spring 2009 1 0 Project Overview and Block Diagram The FlySpy as built by our team is a modification of the Easy Glider Pro hobby aircraft from Multiplex Modelsport The control system is primarily constructed on a printed circuit board PCB mounted within the plane s cockpit The pitch and roll of the plane are calculated using a three axis accelerometer and a two axis gyro which are used in the autopilot feedback loop to stabilize the aircraft Flight surface servos and the propeller throttle are controlled using PWM either from the microcontroller or from the RC receiver A consumer digital camera and ultrasonic rangefinder are mounted on the bottom of the fuselage The camera s on off switch and shutter are wired to pins on the microcontroller allowing the controller to take photographs automatically The rangefinder is to support fully autonomous landing although this is not implemented The guidance system uses an FV M8 GPS module to get a position heading and velocity measurement 5 times a second GPS waypoints are read in from files on a FAT formatted microSD card and flight data is written back out Essentially FlySpy is an aerial reconnais
140. ng 2009 flight and we aren t moving pointer FSfopen OUTPUTFILE a if pointer NULL return FALSE length sprintf IOBuffer t lt Coordinate Time d d d d gt n Gps gt Hour Gps gt Minute Gps gt Second Gps gt Mils FSfprintf pointer Nt lt Coordinate Time d d d d gt in Gps gt Hour Gps gt Minute Gps gt Second Gps gt Mils FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t lt Destination gt n length sprintf IOBuffer t t t lt Latitude gt f lt Latitude gt n wp gt Latitude FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Longitude gt f lt Longitude gt n wp gt Longitude FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t lt Destination gt n FSfprintf pointer t t lt POSITION gt n length sprintf IOBuffer t t t lt Latitude gt f lt Latitude gt n Gps gt Latitude FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Longitude gt f lt Longitude gt n Gps gt Longitude FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Longitude gt f lt Longitude gt n Gps gt Longitude length sprintf IOBuffer t t t lt Speed gt f lt Speed gt n Gps gt Speed FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Heading gt f lt Heading gt n Gps gt Heading FSfwrite IOBuffer 1 leng
141. ng sketch B 1 Spring 2009 IC an Schemat ECE 477 Final Report Appendix C g med z vidt zi ze zi Ll ORRE H ma Fh E il ES T i i83 EJ pupa PEL E I ETERS From AR6200 DSM2 Bx ammo 3 3V Power Supply Manual Override Signal Conditioning C 1 ECE 477 Final Report Spring 2009 Appendix D PCB Layout Top and Bottom Copper NOYITIV n 4 D Land m D o z IDG300 BN oaolaas FEE Fig D 1 PCB Top Layer ECE 477 Final Report Spring 2009 p p p II 000606 BOLLON Fig D 2 PCB Bottom Layer D 2 ECE 477 Final Report Spring 2009 Appendix E Parts List Spreadsheet Vendor Manufacturer Part No Description Unit Cost Qt Total Cost h MicroChip MicroChip PIC24FJ128GA106 16 bit Microcontroller 4 90 1 4 90 Advantage Hobby Multiplex MPU214226 Easy Glider Pro Kit 109 99 1 109 99 Advantage Hobby Multiplex MPUM998226 Easy Glider Pro Servo Pack 77 89 1 77 99 Advantage Hobby Multiplex MPUM993226 Easy Glider Pro Power Pack 145 89 1 145 89 Advantage Hobby Multiplex SPM6600 DX6i 6 Channel Spread Spectrum Rx Tx 199 99 1 199 99 Advantage Hobby Multiplex FPWEVOLITE250028 Li Po 7 4V 2500mAh Battery 49 99 1 49 99 SparkFun InvenSense SEN 00698 Dual Axis Gyro 74 95 1 74
142. nifies the on off status and the picture ready status of the camera We will also need an input pin to the microcontroller that will signify if the plane is being controlled from the manual pilot or by its own signals 3 4 Interfaces and On Chip Peripheral Requirements On chip peripherals are plenty in our design We will make use of 5 channels of Pulse Width Modulation We are requiring that these channels have 16 bit resolution because the control surface s servos can only tolerate a small range of pulse width and with 8 bit resolution we will not be able to make very accurate deflections In order to record the flight path of the manual pilot when in manual mode we will need to intercept the PWM signals coming from the receiver To do this we will need 5 input capture timer channels to record the pulse widths and write them to memory The GPS receiver module will communicate through SCI interface as well as another SCI interface for debugging purposes SPI interfaces will be needed to read and write to and from the SD Card and also to communicate with the barometer to receive altitude To interface with all of the sensors that will need to calculate the orientation of the aircraft we estimate making use of 6 channels of 10 bit ATD This includes 3 axes from the accelerometer chip 2 axes from the gyroscope chip and a range finder 3 5 Off Chip Peripheral Requirements In FlySpy a lot of off chip devices are required to provide important inf
143. nt Summary Writing a signle coordinate KCKCKCK sk sk ske sk ske sk ske sk ske sk A A k k k k k k k k k k k kk k k KA k k k k kk KA k kkk k kkk KA AXA kk kk A ke ek int logCoord WAYPOINT wp GPSINFO Gps double distance double bearing double altitude double pitch double roll float clearing float throt_auto float ele_auto float rudder_auto double left_auto double right_auto double throt_man double ele man double rudder_man double left man double right man KKK kk kk kA KKK KKK KKK KKK KKK k k k k k k KKK KKK KKK KKK KKK KKK KKK KKK KKK iomapping c Authors Jeremy Tillman William Ehlhardt Project FlySpy a ECE477 Team 12 Spring 2009 KKK KKK KKK KKK K kA K X kA k k k k k k k k k k k k k k k I k k k k k k k KKK KKK Ok kok kk k K KK k kk k k kk kk kk k k k kk k KA KA KA KA KA k k KA KA KA KA AXA KA AX k KA k k kk k k ke kk k k k k I O Mapping for Peripheral Pin Select devices Adapted from the Microchip Explorer 16 sample code be o Author Date Comment ep nohis dip AG BEE ie o REG FRA AIS SEO OLA FA r AG TA AR bi VG BE BORE HR VU FA HD PAD OO IAEA A Pah a tab the Tab tad Fb ng boji Vd esd oad Dips P ARA wie ee ROA ee Rd te Td te Ph William Ehlhardt 3 23 09 Set up for FlySpy project KKKKKKKK KKK KKK ske ske ske A kA k k K K K K k k I A k k k sk k k k k k k KA KA k k k k k kk k k k ek ke k k include FlySpy h
144. nt byte while U1STAbits UTXBF transmit ready UITXREG byte if U1STAbits URXDA enqueue U1RXREG if drdy amp amp U2STAbits UTXBF endif void gpsSendMessage char Message int Length int i for i 0 i lt Length i 1 while U1STAbits UTXBF U1TXREG Message i This function returns if the checksum valu int validateCheckSum F 23 Wait for UART to be send it on out U2TXREG dequeue in the buffertail is valid ECE 477 Final Report Spring 2009 int lov int CheckSum gpsReceiveBuffer 0 if gpsReceiveTail lt 6 Assert Sentence is at least proper length for a check return 0 for lev 1 lev lt gpsReceiveTail 4 levtt CheckSum gpsReceiveBuffer lcv if CheckSum amp 0xF gpsReceiveBuffer gpsReceiveTail 21 48 as CheckSum 4 0xF0 gt gt 4 gpsReceiveBuffer gpsReceiveTail 3 48 return 1 return 0 Reads all values in the gps buffer and updates the gps structure void retrieveGpsData void int lov int messageType int commaPosition while gpsBufferHead gpsBufferTail messageType gpsMessageType if messageType GPGGA CurrentGPS Hour gpsBuffer gpsBufferHead 6 48 10 gpsBuffer gpsBufferHead 7 48 CurrentGPS Minute gpsBuffer gpsBufferHead 8 48 10 gpsBuffer gpsBufferHead 9 48 CurrentGPS Second
145. o Quality Factor 10 Commercial product T Learning Factor 1 0 gt 2 0 years in production Entire design Failures per million hours 5 904 Mean time to failure MTTF in years 19 33 These conclusions appear reasonable The calculations suggest that the components are reliable as would be expected Based on this analysis one way to improve the reliability would be to select a microcontroller with fewer pins 5 2 Failure Mode Effects and Criticality Analysis FMECA Three criticality levels were defined based on in flight operation rather than benchtop testing In the High criticality level the plane either crashes or cannot be returned to manual control In the latter case the plane will simply fly autonomously until the battery runs down or it crashes Not only is a crash condition potentially injurious to the project but in addition it could present a danger to the user and any individuals within flight range The plane is made of foam but it is equipped with a front mounted plastic propeller Because of the danger to the user and the potential for destruction of the product a hardware failure rate A of 10 seems advisable In the Medium criticality level the plane loses its autonomous control functionality however it can still be flown manually The plane must be returned to manual control This category assumes that flight stability can be reachieved in the wake of autonomous control failure if it cannot any e
146. o ipo pp pp pp i S s se Spring 2009 f KKK KKK KKK kk kk Kk KKK KKK KKK KKK KKK KKK KKK k k KKK KKK KKK KKK KKK KKK KKK KKK gps c Authors Jeremy Tillman Project FlySpy ECE477 Team 12 William Ehlhardt Spring 2009 F 20 ECE 477 Final Report Spring 2009 KKK KKK KK KKK KKK KK KKK KKK KKK KKK k k k k k KKK KKK KKK KKK KKK include FlySpy h define BAUDRATEREG1 SYSCLK 32 BAUDRATE1 1 if BAUDRATEREGL gt 255 error Cannot set up UART1 for the SYSCLK and BAUDRATE Correct values in main h and uart2 h files endif LJ define BAUDRATE MISTAKE 1000 BAUDRATE1 SYSCLK 32 BAUDRATEREG1 1 BAUDRATI if BAUDRATE MISTAKE gt 2 BAUDRATE MISTAKE lt 2 error UART1 baudrate mistake is too big for the SYSCLK and BAUDRATE1 Correct values in uart2 c file endif LJ H enum MESSAGETYPE UNDEFINED GPGGA GPVTG l GPSINFO CurrentGPS char gpsEnableWAAS SPMTK301 2 2E r n API to enable WAAS char gpsEnableDGPS SPMTK301 1 2D r n API to enable RTCM char gpsEnableSbas SPMTK313 1 2E r n API to enable Sbas char gpsOutputSetup PMTK314 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 28 r n Setting Output frequency to GPGGA and GPVTG GPS Buffer for Receiving new sentence char gpsReceiveBuffer 100 String that GPS Transmission is read into int gpsReceive
147. oard The microcontroller will be surface mounted We do not have many components on the board since we connect to the microcontroller via cables We do have enough free space to avoid the acute angle on the board and the board itself will fit in the fuselage of the plane without any problem Our board size will be maximum 4 x 1 5 and will be finalized after all components arrive The size of connectors is drawn with some exaggeration and it will not be bigger than the size in the rough sketch of PCB Footprint in Figure 7 3 1 Figure 7 3 1 Micro SD Accelero Pressure Sensor ANDR pie Cableto Cable to Cable to Cable to Servos Cableto Camera GPS IRC Receiver Range Finder I I I u are i THE Qi uosa ye1 E Jojeha3 Jes Jep ny 74 Summary Our major concern on packaging is to minimize the modification to the original plane s structure As long as the plane flies without any in flight risk due to the imbalance of the body our packaging is successful Size of our circuit board is a little bigger than our competitors but our 29 ECE 477 Final Report Spring 2009 system s packaging fits in our plane and we think that the success of whole project is based on the algorithm of flying orientation control The position of camera will be determ
148. obtain the planes orientation Also it will retrieve and use data from the barometer and range finder setting the global variables for other modules to make uses Config c written and not tested Module simply sets the peripheral pin select and tri state i o of 100 pin microchip Transmitter c written in pseudo code Module uses input capture to clock manual users control signals from the receiver unit 10 3 Summary In designing the software for FlySpy timing is the most critical issue Besides the testing that we can do in to see if any algorithm has given us the correct response we still will have to alter our workflow to accommodate the response rate needed for a stabile flight We believe that we have come up with a solution that will yet and still pass the test of updating in a timely fashion with the required peripherals 42 ECE 477 Final Report Spring 2009 11 0 Version 2 Changes Put parts directly onto the PCB instead of on breakout boards examples SD card all of our sensors This would make our design more manufacturable and allow us to compact the PCB more m Find PCB space to include the ICD 2 debug header and RS 232 serial port instead of using external adapter boards m Instead of using the accelerometer which is affected by the plane s motion to estimate the direction of down we could use a non inertial device such as a magnetometer to correct for er
149. of components on the top layer Although the breakout boards for the gyro accelerometer and barometer are comparatively large for instance the gyro breakout board measures 0 7 x 0 7 23 it is possible to route signals in the space under the breakout boards This is because the breakout boards connected by standard 0 100 headers are to be mounted on top of the PCB with stand offs Analog signals should be routed away from digital signals as possible to avoid interference 9 1 4 Component Placement Bypass capacitors were placed for the micro MAX3222e mux and GPS receiver These bypass capacitors were chosen to be 0 01 uF as a typical value to avoid the inductive effects of larger capacitors 24 and to reduce high frequency emissions of the digital circuitry 24 They were placed physically near the components An attempt will be made in the course of the board layout to physically separate the digital analog and RF circuitry please refer to Appendix A for an approximate layout of the most significant components The clock circuitry of the microcontroller is anticipated to be the main source of noise and to produce wide band noise 21 Therefore the microcontroller will be 34 ECE 477 Final Report Spring 2009 placed near the middle of the board with analog circuitry gyro accelerometer and RF GPS on the far front and back of the board The microcontroller will be closer to the gyro and accelometer to reduce the length of
150. olute Value Function fabs 6 Modular Arithmetic Functions modf 151 fmod 129 1 Results are based on using the dsPIC30F MPLAB C30 Compiler SW006012 version 1 20 2 Maximum Memory Usage when all functions in the library are loaded Most applications will use less 3 All performance statistics represented here are for 32 bit IEEE754 floating point input and output data types 4 Performance in instruction cycles listed here represent an average number of instruction cycles required to perform the floating point operation There are two specific areas in FlySpy that we foresee having complex expensive code The accelerometer that we are reading on the ATD channels will give us the reading of acceleration over the x y and z axis Given just these individual components we will have to constantly calculate the magnitude of the axis to see if we are just reading gravitation pull This causes for costly the costly square root function which is not really a big concern On the other hand when calculating the actual pitch and roll values at that instantaneous moment with the accelerometer we will need to use the square root and the atan function As seen in the table the atan function will function cost about 696 performance cycles If clocking at 32 MHz we have 640 000 cycles available between samples An alternative to actually using the atan function would be to compose a look up table that references the actual values of the adc c
151. onnected to the processor The components used and how components are mapped is very similar to our design because the sensors are needed for specific measurement of in flight information Although our system utilizes single gyroscope 16 ECE 477 Final Report Spring 2009 accelerometer and pressure sensor the patent states that three of gyroscopes and accelerometer two of pressure sensors are used for the calculation of plane s altitude and orientation This would be a great reason that our system is different from theirs since we are utilizing less number of components for the system with the same objective which is to control airplane as unmanned The calculation algorithm will be different as we have different number of sensors and the main loop depicted in patent is also different 4 2 2 Analysis of Liability involving Precision Approach Control In Claiml the patent states that it utilizes the GPS navigation system to approach to the projected spot of photograph Although both system use GPS navigation system the difference between the patent and FlySpy is the algorithm to determine when to take the photo FlySpy solely depends on the GPS information and pressure sensor while the patent uses the laser rangefinder for more accurate measurement The laser rangefinder works with azimuth lens on camera to find the best angle and distance for photo shot FlySpy s photo taking system does not include laser range finder or azimuth lens an
152. onse if sdmmc_cmdtable cmd responsetype RI sdmmc cmdtable cmd responsetype R1b do response rl byte ReadMediaManual timeout Jwhile response rl byte MMC FLOATING BUS amp amp timeout 0 else if sdmmc_cmdtable cmd responsetype R2 ReadMediaManual response r2 _bytel ReadMediaManual response r2 _byte0 ReadMediaManual if sdmmc cmdtable cmd responsetype R1b response rl _byte 0x00 for index 0 index lt OxFF amp amp response rl _byte 0x00 index timeout OxFFFF do response rl byte ReadMediaManual timeout Jwhile response rl byte 0x00 amp amp timeout 0 WriteSPIManual OxFF Required clocking see spec S if we ar xpecting data or not if sdmmc_cmdtable cmd moredataexpected SD_CS 1 return response endif endif OK kk kk k kk K kk k k I kk k k RA k k k k k k CK KA AXA KA AXA k k k k k k k k ke ke k k e k k Function BYTE MDD SDSPI SectorRead DWORD sector addr BYTE buffer Summary Reads a sector of data from an SD card Conditions The MDD SectorRead function pointer must be pointing towards this function Input sector addr The address of the sector on the card byffer The buffer where the retrieved data will be stored If buffer is NULL do not store the data anywhere Return Values F 62 ECE 477 Final Report TRUE The sector was rea
153. ormation to the microcontroller so that it may compute and execute a flight path For to acquire this information we will need a GPS Receiver three axis accelerometer two axis gyroscope barometer and a rangefinder A GPS receiver is needed to provide position and heading information The receiver must have a minimum accuracy of about 5 6 meters so that we capture a picture of the ECE 477 Final Report Spring 2009 GPS coordinate within our picture The barometer will be used as an altimeter providing accurate measurements of pressure enough to stay within a 1m range of flight altitude The gyroscope will be used to sense angular rotation of the aircraft s pitch and roll The accelerometer will be used to correct the error of the gyroscope s accumulation of rotation data overtime The rangefinder will be used to sensor when the aircraft is close to the ground enabling it to land correctly Aside from the components that we will need for the autopilot we will also need the general components to the RC aircraft This includes the airframe servos receiver transmitter pair motor and speed controller 3 6 Power Constraints Battery power in FlySpy is critical so that we may have enough power to control the RC components and our autopilot devices Once all of these devices are added to the plane it will weigh more and need more power than the plane as it is out of the box The motor being the component with the most power consumption
154. ort Spring 2009 Description The output latch for the CF Reset signal define CF PMP RST PORTDbits RDO Description The TRIS bit for the CF Reset signal define CF_PMP_RESETDIR TRISDbits TRISDO Description The input port for the CF Ready signal define CF_PMP_RDY PORTDbits RD12 Description The TRIS bit for the CF Ready signal define CF_PMP_READYDIR TRISDbits TRISD12 Description The input port for the CF card detect signal define CF PMP CD1 PORTCbits RC4 Description The TRIS bit for the CF card detect signal define CF PMP CDIDIR TRISCbits TRISC4 fendif Description Defines the PMP data bus direction register define MDD CFPMP DATADIR TRISE endif ifdef USE_MANUAL_CF_INTERFACE Use these definitions with CF Bit transaction c and h This will manually perform parallel port transactions ifdef __18CXxX Address lines Description The CF address bus output latch register for PIC18 define ADDBL LATA Description The CF address bus TRIS register for PIC18 define ADDDIR TRISA Data bus Description The Manual CF data bus port register define MDD_CFBT_DATABIN PORTD Description The Manual CF data bus output latch register define MDD_CFBT_DATABOUT LATD Description The Manual CF data bus TRIS register define MDD_CFBT_DATADIR TRISD control bus lines Description
155. pecified number of milliseconds Used for SPI timing Remarks Depending on compiler revisions this function may delay for the exact time specified This shouldn t create a significant problem KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK x void Delayms BYTE milliseconds BYTE ms DWORD count ms milliseconds while ms F 67 ECE 477 Final Report Spring 2009 count MILLISECDELAY while count Nop return KKK RR RRR kk K K kk k kk k k k KA k k k k k k k k k KA KA KA KA AXA KA AXA k k k k k k k k ke ke k k ke k k Function void CloseSPIM void Summary Disables the SPI module Conditions None Input None Return None Side Effects None Description Disables the SPI module Remarks None KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK af void CloseSPIM void dif defined C30 defined __C32__ SPISTAT amp Ox7FFF elif defined C18XX SPICON1 amp OxDF endif OK kk kk k kk K kk k KK KK KK k k k k KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK ke ke k ke KK Function unsigned char WriteSPIM unsigned char data out Summary Writes data to the SD card Conditions None Input data out The data to write Return O Side Effects None Description The WriteSPIM function will write a byte of data from the microcontroller to th
156. port that zero is the datatoken 0 data token Hopefully if index status FALSE else ifdef USB_USE_MSD DATA START TOK ial Z Spring 2009 if sector addr 0 amp amp buffer NULL MDD SDSPI finalLBA 0x00000000 endif for index 0 index lt MEDIA SECTOR SIZE index Reads in 512 byte of data if buffer NULL ifdef 18CXX data token SPIBUF SPI INTERRUPT FLAG 0 SPIBUF OxFF while SPI INTERRUPT FLAG buffer index SPIBUF else SPIBUF OxFF while SPISTAT RBF buffer index SPIBUF endif else ifdef USB_USE_MSD if sector_addr 0 if index 0x1C6 index 0x1D6 index Ox1E6 index 0x1F6 firstSector MDD SDSPI ReadMedia firstSector DWORD MDD SDSPI ReadMedia lt lt 8 firstSector DWORD MDD SDSPI ReadMedia lt lt 16 firstSector DWORD MDD SDSPI ReadMedia lt lt 24 numSectors MDD SDSPI ReadMedia numSectors DWORD MDD SDSPI ReadMedia lt lt 8 numSectors DWORD MDD SDSPI ReadMedia lt lt 16 numSectors DWORD MDD SDSPI ReadMedia lt lt 24 index 8 if firstSector numSectors gt MDD SDSPI finalLBA MDD_SDSPI_finalLBA firstSector numSectors 1 else MDD SDSPI ReadMedia else MDD SDSPI ReadMedia else MDD SDSPI ReadMedia endif F 64 ECE 477 Final Report Spring 2009 Now ensure CRC
157. portNumber int retVal setADCPort portNumber Set the analog port to sample retVal retrieveADCVal Retrieve port value return retVal KKK kk RR K K K K ske K K K kk kk k k k k k k k k k k k k k k k KA KA k k k KA k k KA k k k k k k k k k k k k k k ADC h Authors Jeremy Tillman William Ehlhardt Project FlySpy ki ECE477 Team 12 Spring 2009 KCKCKCKCKCKCKCk ske sk ske skok sk KKK K K K K k k K K K K k k k k k k k k k k k k k k k kA k k k k k k sk ke k ke X KKK void initADC void setADCPort int int retrieveADCVal int sampleADCPort int KKK RR KK K ske K K K K K k K K kk k k k k k k k k k k kA k KA KA k k k ske KA k k k k k k k k k k k k k k k barometer c Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKK KKK Ck Ck Ck Ck K kk K K K K K k k k k k k k k k k Ck k Ck k k k k k KKK KKK KKK include FlySpy h extern SENSORDATA sensorInfo define MYSPISTAT SPI1STATbits define MYSPICON1 SPI1CONlbits define MYSPICON2 SPI1CON2 define MYSPIBUF SPIIBUF Signed int temp 0 long pressure O0 float Altitude 0 Static unsigned char spi comm unsigned char send unsigned char reply 0 MYSPISTAT SPIROV 0 clear Mr Overflow Bit MYSPIBUF send Initiate the transfer while MYSPISTAT SPITBF
158. r application when using the PMP module to interface with CF cards cards ifdef 18CXX error The PIC18 architecture does not currently support PMP interface to CF felif defined __dsPIC30F__ Sample dsPIC30 defines Description The output latch for the CF Reset signal define CF_PMP_RST _RDO Description The TRIS bit for the CF Reset signal define CF_PMP_RESETDIR _TRISDO Description The input port for the CF Ready signal define CF_PMP_RDY _RD12 Description The TRIS bit for the CF Ready signal define CF_PMP_READYDIR _TRISD12 Description The input port for the CF card detect signal define CF PMP CD1 _RC4 Description The TRIS bit for the CF card detect signal define CF PMP CD1DIR _TRISC4 felif defined __dsPIC33F__ feli Sample dsPIC33 defines Description The output latch for the CF Reset signal define CF PMP RST RDO Description The TRIS bit for the CF Reset signal define CF PMP RESETDIR TRISDO Description The input port for the CF Ready signal define CF PMP RDY RD12 Description The TRIS bit for the CF Ready signal define CF PMP READYDIR TRISD12 Description The input port for the CF card detect signal define CF PMP CD1 _RC4 Description The TRIS bit for the CF card detect signal define CF PMP CD1DIR _TRISC4 f defined _ PIC24F__ Default case for PIC24F F 34 ECE 477 Final Rep
159. re not needed Once the plane was purchase I assembled it to its stock entirety I also setup flight dates with our experienced pilot to flight test the plane noting the power of the engine and flight traits of the airframe Once the devices were purchased for the PCB I learned to solder small port appropriately as our microcontroller had a small pitch and a large amount of pins I used a soldered a practice microcontroller to the breakout board and started developing a small amount A 3 ECE 477 Final Report Spring 2009 of code before the actual board had arrived I also soldered the microcontroller and multiple breakout devices to the PCB Thereafter I made cables that interfaced with the PC and off board peripherals I was in charge of the entire autopilot program aside from bare level microcontroller device interfacing I asserted that the plane was retrieving correct information from the off chip devices and use them to determine the control of the planes surfaces as well as throttle Once a reasonable amount of the program was written I found material and methods to package the PCB board into the cockpit as well as mount the camera and range finder to the bottom When the packaging was complete I setup times with experienced pilots to test the autopilot algorithm A 4 ECE 477 Final Report Spring 2009 Appendix B Packaging Figure B 1 Approximate placement of PCB within fuselage top view Figure B 2 Overall packagi
160. reset signal latch bit _RDO reset signal TRIS bit _TRISDO ready signal port bit _RD12 ready signal TRIS bit _TRISD12 detect signal port bit _RC4 detect signal TRIS bit F 37 Spring 2009 h definition for h definition for h definition for h definition for tion for PIC24 30 33 32 tion for PIC24 30 33 32 tion for PIC24 30 33 32 tion for PIC24 30 33 32 ECE 477 Final Report Spring 2009 define CF BT CDIDIR _TRISC4 elif defined PIC24F Address lines Description The CF address bus bit 0 output latch definition for PIC24 30 33 32 define ADDRO LATBbits LATB15 Description The CF address bus bit 1 output latch definition for PIC24 30 33 32 define ADDR1 LATBbits LATB14 Description The CF address bus bit 2 output latch definition for PIC24 30 33 32 define ADDR2 LATGbits LATG9 Description The CF address bus bit 3 output latch definition for PIC24 30 33 32 define ADDR3 LATGbits LATG8 Description The CF address bus bit 0 TRIS definition for PIC24 30 33 32 define ADRTRISO TRISBbits TRISB15 Description The CF address bus bit 1 TRIS definition for PIC24 30 33 32 define ADRTRIS1 TRISBbits TRISB14 Description The CF address bus bit 2 TRIS definition for PIC24 30 33 32 define ADRTRIS2 TRISGbits TRISG9 Description The CF address bus bit 3 TRIS definition for PIC24 30 33 32 d
161. rintf IOBuffer t t t lt Throttle gt f lt Throttle gt n throt man FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Throttle gt f lt Throttle gt n throt man length sprintf IOBuffer t t t lt Elevator gt f lt Elevator gt n ele man FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Elevator gt f lt Elevator gt n ele man length sprintf IOBuffer t t t lt Rudder gt f lt Rudder gt n rudder man FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Rudder gt f lt Rudder gt n rudder man length sprintf IOBuffer t t t lt LeftAileron gt f lt LeftAileron gt n left man FSfwrite IOBuffer length pointer FSfprintf pointer t t t lt LeftAileron gt f lt LeftAileron gt n left man length sprintf IOBuffer t t t lt RightAileron gt f lt RightAileron gt n FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt RightAileron gt f lt RightAileron gt n right man FSfprintf pointer t t lt SurfaceByManual gt n FSfprintf pointer t lt Coordinate gt n return FALSE se S KKK KKK KKK KKKKKK KKK KK KK KK KK KK KK KKK KKK k k KKK KK KKK KKK KKK KKK KKK KKK KKK io h Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKK KKK Ck Ck Ck Ck KKK K K Sk k k k k k k k k k k k k
162. rors in the inertial system s orientation estimates m Power the multiplexer directly off the SV power rail which eliminates its dependence on the proper operation of the 3 3V buck converter Incorporate two way wireless communication 43 ECE 477 Final Report Spring 2009 12 0 Summary and Conclusions As far as electrical engineering work goes the FlySpy project has been a success There were no hardware problems and there are no known logic bugs in the software As of the writing of this report the software only lacks proper parameter tuning and if that can be completed all five PSSCs will be completed by the end of the semester The project has been very educational providing an opportunity to work with all manner of interesting hardware inertial sensors GPS microcontrollers in a real world application setting The team gained significant real world design and engineering skills particularly with respect to navigating the jungle of parts available and in doing research to get a problem solved expediently The team also learned to work independently the TAs while nearly always helpful did not have all the answers and the team had to learn to deal with this FlySpy was certainly the something cool that we went into engineering to create Although we didn t quite complete it we have made great strides in our understanding of the engineering process in the real world as a result of working on it 44 ECE 477 Fina
163. s such as activation of the panic button or receipt of override signals from the remote guidance facility Responsive to the override input the manager deactivates on board control of selected aircraft flight systems and the autopilot system and directs the autopilot to fly the aircraft to a safe landing Claims for Possible Infringement Claiml A method for preventing hijacking of an aircraft comprising operations of providing a hijacking intervention module aboard an aircraft having an autopilot system the module sensing a predetermined override input responsive to the sensing of the predetermined override input the module performing operations comprising deactivating on board control of predetermined aircraft flight systems deactivating on board control of the autopilot system directing the autopilot system to fly the aircraft to a landing 9 Claim2 The method of claim 1 the operations responsive to the sensing of the predetermined override input further comprising receiving manual commands from at least one remote guidance facility the manual commands comprising instructions to manually manipulate specified aircraft flight systems 9 4 2 Analysis of Patent Liability 4 2 1 Analysis of Liability involving Programmable autopilot system for autonomous flight of unmanned aerial vehicles In Claiml it states that components such as gyroscope accelerometer memory pressure sensor GPS receiver and bypass module are all c
164. s from the barometer temp readregl6 0x21 presh readreg8 0x1F s 0blll presl readregl6 0x20 pressure presh lt lt 16 presl Convert units temp temp 2 pressure pressure gt gt 2 void barometer test unsigned char addr 0x07 unsigned char cmd addr lt lt 2 s 0b11111100 BAROMETER_CS 0 Select the barometer Spi comm cmd Call printf 02xNXrWMn int spi comm 0x00 and response BAROMETER CS 1 Deselect the barometer if MYSPISTAT SPIRBF printf 02xNrNMn MYSPIBUF if MYSPISTAT SPIROV printf LOLOVERFLOW r n void updateAltitude baro status t stat barometer status if stat dataready amp amp stat startup running barometer read amp temp amp pressure Altitude 44 33 4 9465 pow pressure 190263 if sensorInfo inuse F 9 ECE 477 Final Report Spring 2009 sensorInfo Altitude Altitude J KKK KKK KKK kk kk kk KKK KK KK KKK KK kk k k k k k KKK KK KKK KKK KKK KKK KKK KKK KKK barometer h Authors Jeremy Tillman William Ehlhardt Project FlySpy Gi ECE477 Team 12 Spring 2009 KCKCKCKCKCK skok ske sk ske KK sk K KKK K K K k k k k k k k k k k k k k k k k ske k k k k k k k KK RH R ifndef BARO define BARO T T td p td pi kk API OVERVIEW wR KKK fF This file is a driver for the SCP100
165. sance platform It allows a user to take pictures of ground locations given only their GPS coordinates making it easy to survey areas that the user cannot travel to himself ECE 477 Final Report Spring 2009 Bs ud NN Speed Controle m Rig Ad x dder ul U E jes oft Alero p m Elefator Servo E m Len fons dt Shutter Fig 1 1 Block Diagram ECE 477 Final Report Spring 2009 Fig 1 2 The FlySpy ECE 477 Final Report Spring 2009 2 0 Team Success Criteria and Fulfillment 1 Ability to control airplane s control surfaces and throttle Status Completed 2 Ability to read write flight information to non volatile memory Status Completed Reading from and writing to files on a FAT filesystem on the microSD card is supported and used extensively in our project 3 Ability to take pictures with onboard camera Status Completed The camera is completely mounted on the plane which bears the load and stays in the air 4 Ability to autonomously navigate to GPS coordinates Status Incomplete We have not had sufficient time to tune the control algorithms to get the plane airborne under its own control 5 Ability to calculate orientation of the vehicle Status Completed ECE 477 Final Report Spring 2009 3 0 Constraint Analysis and Component Selection 3 1 Design Constraint Analysis In designing the full layout for FlySpy we observe various constraints that limit our proje
166. sing the PGEC1 PGED1 and MCLR pins via an RJ 12 jack that the ICD 2 will plug into The ICD 2 can also provide Vss and Vpp for the microcontroller to operate on however we are currently unsure how this should be integrated with the plane s on board power if at all 8 3 Summary The hardware choices are currently almost complete We still have some details to nail down but at this point the major issues should be software ones 33 ECE 477 Final Report Spring 2009 9 0 PCB Layout Design Considerations The dimensions in the cavity of the fuselage permitted PCB dimensions of 1 5 wide x 5 long A double sided board is currently planned however after cost analysis a ground plane and or a power plane might be integrated into the design 9 1 1 PCB Layout Design Considerations Overall 9 1 2 Headers Headers for important signals on surface mount pins are necessary to provide probe points The surface mount components used are the PIC 24FJ256GA110 microcontroller the MAX3222e RS232 translator the PI3V512 5 port 2 1 mux and the LEA 4P GPS receiver The critical signals generated by or input to these devices that might be probed in debugging and bench testing are thus included on the headers Headers are also provided for off board connections such as the rangefinder receiver motor servos and 5V supply input to the 3 3V regulator 9 1 3 Signal Routing Signal routing will primarily be on the second layer due to the density
167. t in lab However in flight operation introduces a risk of injury to the users and others in the vicinity as well as damage to the body of the plane The best safety precaution is probably to keep the potential flight area as clear of people as possible and to stay alert 22 ECE 477 Final Report Spring 2009 6 0 Ethical and Environmental Impact Analysis Ethically the FlySpy presents some hazards to the user as it is an airborne vehicle with a fast spinning prop the risks are exacerbated by its autonomy FlySpy also has obvious civil privacy implications There may also be military uses for FlySpy however since it is unarmed we do not think the ethical implications are overly pressing The drone has environmental concerns similar to most electronic consumer devices However as FlySpy is modified from a commercially available hobby model aircraft FlySpy s airframe provides a disposal concern beyond that already posed by the onboard electronics Due to the risk of loss the risk of improper disposal is somewhat greater than that of say an iPod 6 1 Ethical Impact Analysis 6 1 1 Consumer Safety Hazards FlySpy is A airborne B autonomous and C propeller powered As such it poses a significant risk of physical harm to a careless user Being airborne and highly mobile FlySpy could collide with an object and potentially cause damage Possible objects include cars windows pets and humans The momentum of the plane and the
168. t part of the log which is xml initialization KKK KKK KKK X KKK KKK k k kk k k k k k CK k KA KA KA KA KA CK KA KA KA k k kk KKK A ke int logStart Create a file FSFILE pointer pointer FSfopen OUTPUTFILE w if pointer NULL return FALSE FSfprintf pointer lt xml version 1 0 encoding UTF 8 gt n FSfprintf pointer xml stylesheet type text xsl href W xsl3 xslW gt in FSfprintf pointer lt FLYSPY gt n if FSfclose pointer FALSE Ley F 40 ECE 477 Final Report Spring 2009 return FALSE return TRUE J KKK KKK KKK KK KKK KKK KK KKK KK KK KK KK KK k k k KKK KKK KKK KKK k k k k k k k k kk Author Daeho Hong Function int logEnd Summary Writing the very last part of the log which is xml closer KKK KKK KKK KKK KKK KKK KK KKK KKK k k KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK int logEnd Create a file FSFILE pointer pointer FSfopen OUTPUTFILE a if pointer NULL return FALSE FSfprintf pointer lt FLYSPY gt n if FSfclose pointer FALSE return FALSE return TRUE se void logPicturePoint GPSINFO Gps int length FSFILE pointer Assert that we are not in manual flight and we aren t moving if Gps gt Speed lt 88 amp amp CTRL SW 0 return pointer FSfopen OUTPUTFILE a leng
169. tandard electronic parts there is nothing particularly unusual about any of the electronics so any standard electronics recycler could process them As with the airframe there is a decent risk that the electronic parts could end up in the environment due to plane loss The lithium polymer LiPo battery used in FlySpy could be a major environmental problem particularly if it is damaged and or lost during a crash The user should be encouraged to safely dispose of the battery at a battery drop perhaps the user could get a new battery at a discount if he trades in the old one in the process In short the environmental concerns of FlySpy are fairly large and primarily relate to safe disposal 6 2 2 Wildlife Interaction Bird strikes are a fairly common problem in aviation so FlySpy could have the same issue As a bird is yet another object with which the propeller does not get along well serious injury to wild fowl could result from a collision There is little that we can do to mitigate this risk in our design and documentation fortunately such collisions are relatively rare to start with 6 3 Summary FlySpy has nontrivial safety hazards but they are not so great as to be dangerous to your average careful user It is however certainly not a product for children There are some ethical issues relating to how FlySpy is used but they are not overwhelming The environmental impact is potentially very serious however there is not
170. terrupts and remain in an empty infinite loop throughout the rest of the operation ADC c ADC h written and tested This module consists of functions to operate all analog to digital functions This reduces t has control of all the channels has multiple functions and can read all channels base on the channel number Timer c written and not tested Initializes all time interrupts for all general operation Has multiple clocks for different timers Ex 5 Hz for GPS 50Hz for orientation calculations GPS c written in pseudo code This module consists of functions to retrieve GPS data from the GPS receiver Also functions to calculate difference in baring and distance Camera c written in pseudo code Module consists of simple functions that control the operations of a camera Simply turning the camera on flash a picture signal and placing the camera back to the off state Filesystem c written in pseudo code Module consists formatting for i o into the auto pilot programs Uses microchips filesystem library to read and write from the non volatile memory Control c Has functions which set the PMW control signals to the aircraft control 41 ECE 477 Final Report Spring 2009 written in pseudo code surfaces Sensors c written in pseudo code Module consists of algorithm that will be used to fuse the accelerometer and gyro data to successful
171. th sprintf IOBuffer Nt lt Picture Time d d d d gt n Gps gt Hour Gps gt Minute Gps gt Second Gps gt Mils FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Latitude gt f lt Latitude gt n Gps gt Latitude FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Longitude gt f lt Longitude gt n Gps gt Longitude FSfwrite IOBuffer 1 length pointer FSfprintf pointer t lt Picture gt n FSfclose pointer e e KKK KKK KKK KK KKK KKK KK KK KKK KKK KKK KKK KKK k k k k KKK KKK k k k k k k k k KKK Author Daeho Hong Function int logCoord int int Summary Writing a signle coordinate KCKCKCKCKCK RA ske sk ske sk ske ske ske k kA k K k k k k k ske k k k k k k k k k KA KA k k k k KICK Ck k k k kkk kkk kk kkk Zk int logCoord WAYPOINT wp GPSINFO Gps double distance double bearing double altitude double pitch double roll float clearing float throt_auto float ele_auto float rudder_auto double left_auto double right_auto double throt_man double ele_man double rudder_man double left_man double right_man int length FSFILE pointer F 41 ECE 477 Final Report Assert that we are not in manual if return 0 Create a file Gps gt Speed lt 88 amp amp CTRL SW Spri
172. th pointer length sprintf IOBuffer t t t lt Distance gt f lt Distance gt n distance FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Latitude gt f lt Latitude gt n Gps gt Latitude length sprintf IOBuffer t t t lt Altitude gt f lt Altitude gt n altitude FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Altitude gt f lt Altitude gt n altitude length sprintf IOBuffer t t t lt Distance gt f lt Distance gt n distance FSfwrite IOBuffer 1 length pointer length sprintf IOBuffer t t t lt Bearing gt f lt Bearing gt n bearing FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t lt POSITION gt n FSfprintf pointer t t lt Orientation gt n length sprintf IOBuffer t t t lt Pitch gt Se lt Pitch gt n pitch FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Pitch gt e lt Pitch gt n pitch length sprintf IOBuffer t t t lt Roll gt e lt Roll gt n roll FSfwrite IOBuffer length pointer FSfprintf pointer t t t lt Roll gt e lt Roll gt n roll length sprintf IOBuffer t t t lt Clearing gt f lt Clearing gt n double clearing FSfwrite IOBuffer 1 length pointer FSfprintf pointer t t t lt Clearing gt f lt Clearing gt n clearing FSfprintf pointer t t lt Orientation gt n FSfprintf pointer t t lt SurfaceByAuto gt n length
173. til bus cycle complete Clear the SPIBUF Send 2 bytes of CRC Read response ti O using i as a timeout counter Wait for write completion index 0 if timeout first ECE 477 Final Report Spring 2009 OK kk kk k kk KK KKK KK KK KKK KKK kk k KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK Function BYTE MDD SDSPI WriteProtectState Summary Indicates whether the card is write protected Conditions The MDD WriteProtectState function pointer must be pointing to this function Input None Return Values TRUE The card is write protected FALSE The card is not write protected Side Effects None Description The MDD SDSPI WriteProtectState function will determine if the SD card is write protected by checking the electrical signal that corresponds to the physical write protect switch Remarks None KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK En BYTE MDD SDSPI WriteProtectState void return 0 Since we don t have a write protect pin so we always return 0 meaning not write protected SD_WE KKK RR KK KKK KKK K k kk kk kk k kk RR k k k k k KA KA CK KA KK AKA k k k k k k k k k k k ke kk k KK Function void Delayms BYTE milliseconds Summary Delay Conditions None Input BYTE milliseconds Number of ms to delay Return None Side Effects None Description The Delayms function will delay a s
174. tiple of the frequency the interference is minimized by the use of the spread spectrum transmitter Therefore because of the limited analog circuitry on the board digital circuitry primarily the clock circuitry of the microcontroller is the primary noise concern The use of a ground plane to protect against this noise is being investigated Analog noise can be reduced by using the shortest traces possible between the gyro and accelerometer and the microcontroller A D pins The use of several small bypass capacitors 0 1 uF will reduce high frequency emissions 9 1 7 Manufacturing Concerns This is a standard PCB with no especially difficult or minimal manufacturing specifications 35 ECE 477 Final Report Spring 2009 9 2 PCB Layout Design Considerations Microcontroller 9 2 1 Oscillator Circuit Layout At the present time the team does not understand how to integrate an external oscillator into the system and has not decided on a clocking speed 9 2 2 Decoupling All of the power pins Vpp Vss on the microcontroller have 0 1uF bypass capacitors which will be located as close to the relevant pins as possible probably on the underside of the PCB The Motorola PCB application note 21 suggests using an RC filter circuit to reduce noise on the analog to digital converter reference pins The note does not specify the precise topology of the filter required but it does suggest routing the reference voltages directly from the 3 3V power s
175. to propel the unmanned aerial vehicle 7 14 ECE 477 Final Report Spring 2009 Claim4 The autopilot control system as defined in claim 3 wherein the on plane control system further comprises a bypass circuit that allows the unmanned aerial vehicle to be controlled by the RC controller instead of the on plane control system 7 4 1 2 Precision Approach Control U S Patent Application No 2008 0071431 8 Filing Date March 20 2008 Abstract An aircraft control system for operations close to the ground includes a camera having a rangefinder for measuring the azimuth elevation and slant range from a fixed point on the aircraft relative to a selected target point on a surface below the aircraft a navigation system for measuring the latitude and longitude of the aircraft on the surface a computer for computing the position of the fixed point on the aircraft relative to the target point from the respective measurements of the camera and the navigation system and a controller for controlling the movement of the aircraft Claims for Possible Infringement Claiml An aircraft command and control system comprising a camera including a rangefinder disposed aboard the aircraft for measuring an azimuth angle an elevation angle and a slant range from a fixed point on the aircraft relative to a selected target point on a surface located below the aircraft a navigation system disposed aboard the aircraft for measuring a latitude and a longitude o
176. ts Method of Criticality Remarks Detection Al No output Software bug or chip Loss of autonomous Observation Medium failure control and non essential features A2 Some pins are Exceeded voltage or Cannot power on Observation Low stuck atO or 1 current ratings fried camera or cannot trigger affecting non pin software bug shutter Camera will not essential respond with power on peripherals feedback signal if it camera does not receive rangefinder particular pulse to power on No known damage to camera Rangefinder unaffected A3 Some pins are Exceeded voltage or Loss of autonomous Observation Medium stuck at 0 or 1 affecting essential peripherals GPS analog sensors etc current ratings fried pin software bug control ECE 477 Final Report Fall 2008 Control Mode Switching Failure Failure Mode Possible Causes Failure Effects Method of Criticality Remarks No Detection Bl No output Mux failure Total loss of Observation High control B2 Stuck in CTRL_SW shorted Loss of manual Observation Medium or autonomous high due to control high mode comparator failure or filter failure B3 Stuck in CTRL_SW shorted to Loss of Observation Medium manual mode ground low due to autonomous filter failure capability
177. upply The same design will be used for the barometer which while providing digital output is an analog sensor and thus likely sensitive to supply voltage fluctuations 9 4 Summary The primary design constraints are space and noise immunity Given the space critical application and tight constraints on the PCB size surface mount components were chosen for those devices not on breakout boards or brought out to headers from off board Minimal trace widths will be used and most routing is expected to be on the second layer of the board The space under the breakout boards will be utilized for routing as well Noise immunity will be designed through separation of the analog digital and RF circuitry and may be increased with the inclusion of a ground plane in the design 37 ECE 477 Final Report Spring 2009 10 0 Software Design Considerations Since we need to interface with a wide variety of devices we will have to program to accommodate for different data rates from these different devices This makes our device time critical meaning that some things will need to have precise timing in order for us to make correct calculations in guiding the aircraft Examples of this would be the gyros which depend on the change in voltage over time to correctly calculate the change in pitch and roll Our software will be written for the Microchip PIC24FJ256GA110 26 This is capable of having a maximum clock speed of 32 MHz with its own internal oscill
178. upply which is planned 9 3 PCB Layout Design Considerations Power Supply The system runs on two power supply rails 5V and 3 3V derived from a 7 4V Li Po 2500mAh battery The 5V rail is provided by the speed controller through its PWM cable The physical presence of the 5V rail on the PCB is fairly limited it connects to the 5V pins of all the PWM connector headers which are clustered close together and it provides the input to a high efficiency DC DC step down converter The 3 3V rail is generated by the LTC1174 DC DC step down converter 22 and provides power to all of the devices in the system besides the servos and receiver It is designed in line with the application note in the LTC1174 data sheet 22 according to the High Efficiency 3 3V Regulator circuit on page 13 The Schottky catch diode will be located close to its GND and SW connections the Cin capacitors will be closely connected to the Vin and GND pins and the decoupling capacitor will be placed close to the Vin pin Shutdown and IPGM are pulled up An appropriate bulk capacitor will be placed immediately at the terminals of the supply There will be two major sections of the PCB the analog gyro and accelerometer are clustered at one end of the board and the rest is devoted to digital devices To reduce noise independent traces will be run directly to the power and ground terminals of the analog devices 36 ECE 477 Final Report Spring 2009 from the 3 3V s
179. upt IPClbits T2IP 0x03 Setup a priority level of 3 IFSObits T2IF 0 Clear the Timer2 interrupt status flag IECObits T2IE 1 Enables Timer2 interupts T2CONbits TON 1 T3CON 0x20 TMR3 0x00 PR3 0x1388 IPC2bits T3IP 0x5 IFSObits T3IF 0 IECObits T3IE 0 T3CONbits TON 1 void __attribute__ __interrupt__ auto psv TlInterrupt void 50Hz Timer updateOrientation updateClearing updateAltitude directSurfaces p TimerCounttt if p TimerCount ll ll CI imerFlag 1 p_TimerCount 0 TimerCount if TimerCount gt 9 TimerCount 0 IFSObits TlIF 0 Reset Timerl interrupt flag and Return from ISR F 93 ECE 477 Final Report Spring 2009 void __attribute__ __interrupt__ auto psv _T2Interrupt void Second Timer SecondFlag 1 IFSObits T2IF 0 void __attribute__ __interrupt__ auto_psv _T3Interrupt void 50hz Input Capture Timer IFSObits T3IF 0 KKK kk RR K K KK K kk kk kk kk kk k k k k k k k k k k k k k k KA KA k k KA k k KA k k k k k k k k k k k k k k Timer h Authors Jeremy Tillman William Ehlhardt Project FlySpy ECE477 Team 12 Spring 2009 KKK KKK KKK KKK KK KKK K K K K K K K k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k kk k k k kk kkk void initTimer KKK kk kk KKK
180. v PWM signals which could require some signal conditioning PIC24FJ128GA106 1 MC9S12HZ128CA 2 5 16 bit PWM channels via Output Compare 4 16 bit PWM channels 9 Input Compare channels 8 Input Compare channels Internal Oscillator Internal Oscillator 16 A D channels at 10bits 16 A D channels at 10bits ICD debugging interface BDM debugging interface Current draw up to 24mA Current draw 65 mA with everything enabled 2 2v to 3 6v operating voltage means that it can be run at 3 3v and thus interfaced directly to all of the peripherals Operates at 5v This certainly means that signal conditioning would be required on the SPI interface and probably the SCI interface to ECE 477 Final Report Spring 2009 the GPS unit A 3 3v rail is still necessary to power the various peripherals but the analog inputs can measure 0 3 3v perfectly fine with the consequence that the resolution will be worse Can tolerate up to 6V on digital inputs This will allow the receiver s PWM signals to be fed directly to the input pins on the microcontroller Can tolerate 5v digital inputs due to its operating voltage Unit cost is around 5 Unit cost is around 10 William is already familiar with the Microchip development environment Group has decent familiarity with 9S12 processors and peripherals
181. vent in this category would need to be upgraded to High criticality level The selection of an appropriate failure rate is somewhat arbitrary however a failure rate of A 10 per million hours would result in an MTTF of about 11 4 years longer than the expected use of the product 21 ECE 477 Final Report Spring 2009 In the Low criticality level the project experiences some loss of non critical functionality For example the plane could not take photos A failure rate of A 35 per million hours is fairly generous for low criticality failures and would result in an MTTF of about 3 3 years Most point and shoot cameras probably have a lifetime of about 3 5 years As an aside intelligent engineering would have dictated using a multiplexer with a 5 V supply the current multiplexer is powered on the 3 3 V rail If the 3 3 V power supply circuit fails the plane will necessarily crash because no PWM signals can be switched However had the mux been powered on the 5 V rail along with the servos motor and receiver manual control could have been maintained 5 3 Summary In summary software error is the biggest threat to the safety and reliability of the project Physical reliability of the hardware is a secondary focus Aside from the microcontroller and GPS module few components would be considered complex and none of the components run very hot under testing with a reasonable load The plane is comparatively safe to a user testing i
182. was my single most significant functional contribution to the project and took me the better part of two weeks Once the PCB came back I helped with the hardware assembly although I had others do some of the harder soldering work I assembled the 3 3V power supply and babysat it through several hours of burn in under load I validated the signal conditioning for the gear switch autopilot manual control catching a capacitor value mistake in the process I then validated the whole autopilot manual multiplexing system and confirmed its correct operation While Jeremy did the bulk of the software development I helped significantly on it I wrote the SPI based driver for the barometer myself I also did the tedious work of creating the peripheral pin select code that assigns the microcontroller peripherals to physical pins although I later discovered that there was an automation tool to do all that easily I managed to track down several minor and a few major bugs that were tripping Jeremy up Heather and I did the compilation of the homeworks into the final report submission materials along with a lot of the editing thereof A 3 Contributions of Daeho Hong My major part in this project was to implement SD card interface and flight logging functions First I spent a few weeks to research on how SD card works and FAT file system works because I expected that I have to write the entire file header and generate control signals for the SD card I a
183. xpect that the device will require some tuning The rangefinder s output voltage is proportional to the range detected Every 50ms the device sends out an ultrasonic pulse and listens for the response Based on the response time it drives an analog voltage to correspond to the range 20 The components selected were the IDG300 gyroscope ADXL330 accelerometer and the Maxbotix LV EZ1 8 1 3 SPI Devices Both the SD card and barometer use SPI to communicate with the microcontroller The barometer reports a simple pressure value and the SD card has a standard block level SPI interface 8 1 4 GPS Module The GPS module communicates using RS 232 serial signals It reports a latitude and longitude over the serial link in the form of NMEA sentences a standardized ASCII based interchange format 8 1 5 Camera The camera is an off the shelf commercial digital camera We have disassembled it and will use digital outputs possibly with additional signal conditioning to control its shutter and focus 8 2 Hardware Design Narrative 8 2 1 Input Capture The input capture system will be used to time the pulse width of the 5 PWM control signals coming from the RC receiver This allows the on board software to record the human pilot s commands which will be useful during flight testing with the autopilot disabled The relevant pins on the microcontroller will be connected directly to the PWM signal pins on the receiver No voltage level translation is n

Download Pdf Manuals

image

Related Search

Related Contents

Audio Pro SONO 61 Electronic Keyboard User Manual  建設業年度末労働災害防止強調月間  CAPILLARYS PROTEIN(E) 6  in a world of infinite possibilities, find your own.    

Copyright © All rights reserved.
Failed to retrieve file