Prof Greg Egan
/
UAVXArm-GKE
UAVX Multicopter Flight Controller.
harness.c@1:1e3318a30ddd, 2011-02-25 (annotated)
- Committer:
- gke
- Date:
- Fri Feb 25 01:35:24 2011 +0000
- Revision:
- 1:1e3318a30ddd
- Parent:
- 0:62a1c91a859a
- Child:
- 2:90292f8bd179
This version has broken I2C - posted for debugging involvement of Simon et al.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gke | 0:62a1c91a859a | 1 | // =============================================================================================== |
gke | 0:62a1c91a859a | 2 | // = UAVXArm Quadrocopter Controller = |
gke | 0:62a1c91a859a | 3 | // = Copyright (c) 2008 by Prof. Greg Egan = |
gke | 0:62a1c91a859a | 4 | // = Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer = |
gke | 0:62a1c91a859a | 5 | // = http://code.google.com/p/uavp-mods/ http://uavp.ch = |
gke | 0:62a1c91a859a | 6 | // =============================================================================================== |
gke | 0:62a1c91a859a | 7 | |
gke | 0:62a1c91a859a | 8 | // This is part of UAVXArm. |
gke | 0:62a1c91a859a | 9 | |
gke | 0:62a1c91a859a | 10 | // UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU |
gke | 0:62a1c91a859a | 11 | // General Public License as published by the Free Software Foundation, either version 3 of the |
gke | 0:62a1c91a859a | 12 | // License, or (at your option) any later version. |
gke | 0:62a1c91a859a | 13 | |
gke | 0:62a1c91a859a | 14 | // UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without |
gke | 0:62a1c91a859a | 15 | // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
gke | 0:62a1c91a859a | 16 | // See the GNU General Public License for more details. |
gke | 0:62a1c91a859a | 17 | |
gke | 0:62a1c91a859a | 18 | // You should have received a copy of the GNU General Public License along with this program. |
gke | 0:62a1c91a859a | 19 | // If not, see http://www.gnu.org/licenses/ |
gke | 0:62a1c91a859a | 20 | |
gke | 0:62a1c91a859a | 21 | #include "UAVXArm.h" |
gke | 0:62a1c91a859a | 22 | |
gke | 0:62a1c91a859a | 23 | void UpdateRTC(void); |
gke | 0:62a1c91a859a | 24 | void InitHarness(void); |
gke | 0:62a1c91a859a | 25 | |
gke | 0:62a1c91a859a | 26 | LocalFileSystem Flash("local"); |
gke | 0:62a1c91a859a | 27 | |
gke | 0:62a1c91a859a | 28 | // connections to ARM |
gke | 1:1e3318a30ddd | 29 | // 1 GND |
gke | 1:1e3318a30ddd | 30 | // 2 4.5-9V |
gke | 1:1e3318a30ddd | 31 | // 3 VBat |
gke | 1:1e3318a30ddd | 32 | // 4 NReset |
gke | 1:1e3318a30ddd | 33 | |
gke | 0:62a1c91a859a | 34 | //SPI SPI0(p5, p6, p7); // 5 SPI MOSI, 6 SPI MOSO, 7 SPI CLK |
gke | 0:62a1c91a859a | 35 | //DigitalOut SPICS(p8); // 8 |
gke | 0:62a1c91a859a | 36 | SDFileSystem SDCard(p5, p6, p7, p8, "SDCard"); |
gke | 1:1e3318a30ddd | 37 | |
gke | 0:62a1c91a859a | 38 | //I2C I2C1(p9, p10); // 9 Tx / I2C SDA, 10 Rx / I2C SCL |
gke | 0:62a1c91a859a | 39 | SerialBuffered TelemetrySerial(p9, p10); |
gke | 0:62a1c91a859a | 40 | DigitalIn Armed(p11); // 11 SPI MOSI |
gke | 0:62a1c91a859a | 41 | DigitalOut PWMCamPitch(p12); // 12 SPI MOSO |
gke | 1:1e3318a30ddd | 42 | |
gke | 0:62a1c91a859a | 43 | Serial GPSSerial(p13, p14); // 13 Tx1 / SPI CLK, 14 Rx1 |
gke | 0:62a1c91a859a | 44 | |
gke | 0:62a1c91a859a | 45 | AnalogIn PitchADC(p15); // 15 AN0 |
gke | 0:62a1c91a859a | 46 | AnalogIn RollADC(p16); // 16 AN1 |
gke | 0:62a1c91a859a | 47 | AnalogIn YawADC(p18); // 17 AN2 (has DAC capability) |
gke | 0:62a1c91a859a | 48 | |
gke | 0:62a1c91a859a | 49 | AnalogIn RangefinderADC(p17); // 18 AN3 |
gke | 0:62a1c91a859a | 50 | AnalogIn BatteryCurrentADC(p19); // 19 AN4 |
gke | 1:1e3318a30ddd | 51 | AnalogIn BatteryVoltsADC(p20); // 20 AN5 |
gke | 0:62a1c91a859a | 52 | |
gke | 0:62a1c91a859a | 53 | PwmOut Out0(p21); // 21 |
gke | 0:62a1c91a859a | 54 | PwmOut Out1(p22); // 22 |
gke | 0:62a1c91a859a | 55 | PwmOut Out2(p23); // 23 |
gke | 0:62a1c91a859a | 56 | PwmOut Out3(p24); // 24 |
gke | 0:62a1c91a859a | 57 | |
gke | 0:62a1c91a859a | 58 | //PwmOut Out4(p25); // 25 |
gke | 0:62a1c91a859a | 59 | //PwmOut Out5(p26); // 26 |
gke | 0:62a1c91a859a | 60 | |
gke | 0:62a1c91a859a | 61 | DigitalOut DebugPin(p25); // 25 |
gke | 0:62a1c91a859a | 62 | |
gke | 1:1e3318a30ddd | 63 | #ifdef SW_I2C |
gke | 1:1e3318a30ddd | 64 | MyI2C I2C0; |
gke | 1:1e3318a30ddd | 65 | DigitalInOut I2C0SCL(p27); |
gke | 1:1e3318a30ddd | 66 | DigitalInOut I2C0SDA(p28); |
gke | 1:1e3318a30ddd | 67 | #else |
gke | 0:62a1c91a859a | 68 | I2C I2C0(p28, p27); // 27, 28 |
gke | 1:1e3318a30ddd | 69 | #endif // SW_I2C |
gke | 0:62a1c91a859a | 70 | DigitalIn RCIn(p29); // 29 CAN |
gke | 1:1e3318a30ddd | 71 | DigitalOut PWMCamRoll(p30); // 30 CAN |
gke | 0:62a1c91a859a | 72 | |
gke | 1:1e3318a30ddd | 73 | //Serial TelemetrySerial(USBTX, USBRX); |
gke | 1:1e3318a30ddd | 74 | // 31 USB +, 32 USB - |
gke | 1:1e3318a30ddd | 75 | // 34 -37 Ethernet |
gke | 1:1e3318a30ddd | 76 | // 38 IF + |
gke | 1:1e3318a30ddd | 77 | // 39 IF - |
gke | 1:1e3318a30ddd | 78 | // 40 3.3V Out |
gke | 1:1e3318a30ddd | 79 | |
gke | 1:1e3318a30ddd | 80 | // order L-R end of card |
gke | 0:62a1c91a859a | 81 | DigitalOut BlueLED(LED1); |
gke | 0:62a1c91a859a | 82 | DigitalOut GreenLED(LED2); |
gke | 0:62a1c91a859a | 83 | DigitalOut RedLED(LED3); |
gke | 0:62a1c91a859a | 84 | DigitalOut YellowLED(LED4); |
gke | 0:62a1c91a859a | 85 | |
gke | 0:62a1c91a859a | 86 | InterruptIn RCInterrupt(p29); |
gke | 0:62a1c91a859a | 87 | |
gke | 0:62a1c91a859a | 88 | char RTCString[32], RTCLogfile[32]; |
gke | 0:62a1c91a859a | 89 | struct tm* RTCTime; |
gke | 0:62a1c91a859a | 90 | |
gke | 1:1e3318a30ddd | 91 | void UpdateRTC(void) { |
gke | 0:62a1c91a859a | 92 | time_t s = time(NULL); |
gke | 0:62a1c91a859a | 93 | RTCTime = localtime(&s); |
gke | 1:1e3318a30ddd | 94 | strftime(RTCString, 32, "%a %b %d %H:%M:%S %Y", RTCTime ); |
gke | 0:62a1c91a859a | 95 | } // UpdateRTCString |
gke | 0:62a1c91a859a | 96 | |
gke | 1:1e3318a30ddd | 97 | void InitHarness(void) { |
gke | 0:62a1c91a859a | 98 | |
gke | 0:62a1c91a859a | 99 | I2C0.frequency(I2C_MAX_RATE_HZ); |
gke | 1:1e3318a30ddd | 100 | |
gke | 0:62a1c91a859a | 101 | TelemetrySerial.baud(115200); |
gke | 1:1e3318a30ddd | 102 | TelemetrySerial.set_tx_buffer_size(512); |
gke | 0:62a1c91a859a | 103 | |
gke | 0:62a1c91a859a | 104 | GPSSerial.baud(115200); // reduce baud rate to lighten interrupt traffic? |
gke | 1:1e3318a30ddd | 105 | |
gke | 0:62a1c91a859a | 106 | PWMCamRoll.write(false); |
gke | 0:62a1c91a859a | 107 | PWMCamPitch.write(false); |
gke | 1:1e3318a30ddd | 108 | |
gke | 0:62a1c91a859a | 109 | Armed.mode(PullUp); |
gke | 0:62a1c91a859a | 110 | |
gke | 0:62a1c91a859a | 111 | CheckSDCardValid(); |
gke | 1:1e3318a30ddd | 112 | |
gke | 0:62a1c91a859a | 113 | UpdateRTC(); |
gke | 0:62a1c91a859a | 114 | |
gke | 0:62a1c91a859a | 115 | } // InitHarness |