UAVX Multicopter Flight Controller.

Dependencies:   mbed

Committer:
gke
Date:
Tue Apr 26 12:12:29 2011 +0000
Revision:
2:90292f8bd179
Parent:
1:1e3318a30ddd
Not flightworthy. Posted for others to make use of the I2C SW code.

Who changed what in which revision?

UserRevisionLine numberNew 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 2:90292f8bd179 5 // = http://code.google.com/p/uavp-mods/ =
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 2:90292f8bd179 28 const uint8 mbed1768Pins[32] = { // Maping of mbed pins to LPC 1768 "port" pins
gke 2:90292f8bd179 29 255,255,255,255,255,9,8,7,6,0,
gke 2:90292f8bd179 30 1,18,17,15,16,23,24,25,26,62,
gke 2:90292f8bd179 31 63,69,68,67,66,65,64,11,10,5,
gke 2:90292f8bd179 32 4,255
gke 2:90292f8bd179 33 };
gke 2:90292f8bd179 34
gke 2:90292f8bd179 35 /*
gke 2:90292f8bd179 36 const uint32 mbed1768Ports[8] = {
gke 2:90292f8bd179 37 LPC_GPIO0_BASE,
gke 2:90292f8bd179 38 LPC_GPIO1_BASE,
gke 2:90292f8bd179 39 LPC_GPIO2_BASE,
gke 2:90292f8bd179 40 LPC_GPIO3_BASE,
gke 2:90292f8bd179 41 LPC_GPIO4_BASE
gke 2:90292f8bd179 42 };
gke 2:90292f8bd179 43 */
gke 2:90292f8bd179 44
gke 0:62a1c91a859a 45 // connections to ARM
gke 1:1e3318a30ddd 46 // 1 GND
gke 1:1e3318a30ddd 47 // 2 4.5-9V
gke 1:1e3318a30ddd 48 // 3 VBat
gke 1:1e3318a30ddd 49 // 4 NReset
gke 1:1e3318a30ddd 50
gke 0:62a1c91a859a 51 //SPI SPI0(p5, p6, p7); // 5 SPI MOSI, 6 SPI MOSO, 7 SPI CLK
gke 0:62a1c91a859a 52 //DigitalOut SPICS(p8); // 8
gke 0:62a1c91a859a 53 SDFileSystem SDCard(p5, p6, p7, p8, "SDCard");
gke 1:1e3318a30ddd 54
gke 0:62a1c91a859a 55 //I2C I2C1(p9, p10); // 9 Tx / I2C SDA, 10 Rx / I2C SCL
gke 0:62a1c91a859a 56 SerialBuffered TelemetrySerial(p9, p10);
gke 0:62a1c91a859a 57 DigitalIn Armed(p11); // 11 SPI MOSI
gke 0:62a1c91a859a 58 DigitalOut PWMCamPitch(p12); // 12 SPI MOSO
gke 1:1e3318a30ddd 59
gke 0:62a1c91a859a 60 Serial GPSSerial(p13, p14); // 13 Tx1 / SPI CLK, 14 Rx1
gke 0:62a1c91a859a 61
gke 0:62a1c91a859a 62 AnalogIn PitchADC(p15); // 15 AN0
gke 0:62a1c91a859a 63 AnalogIn RollADC(p16); // 16 AN1
gke 0:62a1c91a859a 64 AnalogIn YawADC(p18); // 17 AN2 (has DAC capability)
gke 0:62a1c91a859a 65
gke 0:62a1c91a859a 66 AnalogIn RangefinderADC(p17); // 18 AN3
gke 0:62a1c91a859a 67 AnalogIn BatteryCurrentADC(p19); // 19 AN4
gke 1:1e3318a30ddd 68 AnalogIn BatteryVoltsADC(p20); // 20 AN5
gke 0:62a1c91a859a 69
gke 0:62a1c91a859a 70 PwmOut Out0(p21); // 21
gke 0:62a1c91a859a 71 PwmOut Out1(p22); // 22
gke 0:62a1c91a859a 72 PwmOut Out2(p23); // 23
gke 0:62a1c91a859a 73 PwmOut Out3(p24); // 24
gke 0:62a1c91a859a 74
gke 0:62a1c91a859a 75 //PwmOut Out4(p25); // 25
gke 0:62a1c91a859a 76 //PwmOut Out5(p26); // 26
gke 0:62a1c91a859a 77
gke 0:62a1c91a859a 78 DigitalOut DebugPin(p25); // 25
gke 0:62a1c91a859a 79
gke 1:1e3318a30ddd 80 #ifdef SW_I2C
gke 2:90292f8bd179 81
gke 1:1e3318a30ddd 82 MyI2C I2C0;
gke 2:90292f8bd179 83
gke 2:90292f8bd179 84 #define I2C0SDASet (1<<mbed1768Pins[28&0x1f]) // 10
gke 2:90292f8bd179 85 #define I2C0SDAPort (mbed1768Pins[28&0x0f]>>5)
gke 2:90292f8bd179 86 PortInOut I2C0SDA(Port0, I2C0SDASet );
gke 2:90292f8bd179 87
gke 2:90292f8bd179 88 #define I2C0SCLSet (1<<mbed1768Pins[27&0x1f]) // 11
gke 2:90292f8bd179 89 #define I2C0SCLPort (mbed1768Pins[27&0x0f]>>5)
gke 2:90292f8bd179 90 PortInOut I2C0SCL(Port0, I2C0SCLSet );
gke 2:90292f8bd179 91
gke 1:1e3318a30ddd 92 #else
gke 2:90292f8bd179 93
gke 0:62a1c91a859a 94 I2C I2C0(p28, p27); // 27, 28
gke 2:90292f8bd179 95
gke 1:1e3318a30ddd 96 #endif // SW_I2C
gke 2:90292f8bd179 97
gke 0:62a1c91a859a 98 DigitalIn RCIn(p29); // 29 CAN
gke 1:1e3318a30ddd 99 DigitalOut PWMCamRoll(p30); // 30 CAN
gke 0:62a1c91a859a 100
gke 1:1e3318a30ddd 101 //Serial TelemetrySerial(USBTX, USBRX);
gke 1:1e3318a30ddd 102 // 31 USB +, 32 USB -
gke 1:1e3318a30ddd 103 // 34 -37 Ethernet
gke 1:1e3318a30ddd 104 // 38 IF +
gke 1:1e3318a30ddd 105 // 39 IF -
gke 1:1e3318a30ddd 106 // 40 3.3V Out
gke 1:1e3318a30ddd 107
gke 1:1e3318a30ddd 108 // order L-R end of card
gke 0:62a1c91a859a 109 DigitalOut BlueLED(LED1);
gke 0:62a1c91a859a 110 DigitalOut GreenLED(LED2);
gke 0:62a1c91a859a 111 DigitalOut RedLED(LED3);
gke 0:62a1c91a859a 112 DigitalOut YellowLED(LED4);
gke 0:62a1c91a859a 113
gke 0:62a1c91a859a 114 InterruptIn RCInterrupt(p29);
gke 0:62a1c91a859a 115
gke 0:62a1c91a859a 116 char RTCString[32], RTCLogfile[32];
gke 0:62a1c91a859a 117 struct tm* RTCTime;
gke 0:62a1c91a859a 118
gke 1:1e3318a30ddd 119 void UpdateRTC(void) {
gke 0:62a1c91a859a 120 time_t s = time(NULL);
gke 0:62a1c91a859a 121 RTCTime = localtime(&s);
gke 1:1e3318a30ddd 122 strftime(RTCString, 32, "%a %b %d %H:%M:%S %Y", RTCTime );
gke 0:62a1c91a859a 123 } // UpdateRTCString
gke 0:62a1c91a859a 124
gke 1:1e3318a30ddd 125 void InitHarness(void) {
gke 0:62a1c91a859a 126
gke 0:62a1c91a859a 127 I2C0.frequency(I2C_MAX_RATE_HZ);
gke 1:1e3318a30ddd 128
gke 0:62a1c91a859a 129 TelemetrySerial.baud(115200);
gke 1:1e3318a30ddd 130 TelemetrySerial.set_tx_buffer_size(512);
gke 0:62a1c91a859a 131
gke 0:62a1c91a859a 132 GPSSerial.baud(115200); // reduce baud rate to lighten interrupt traffic?
gke 1:1e3318a30ddd 133
gke 0:62a1c91a859a 134 PWMCamRoll.write(false);
gke 0:62a1c91a859a 135 PWMCamPitch.write(false);
gke 1:1e3318a30ddd 136
gke 0:62a1c91a859a 137 Armed.mode(PullUp);
gke 0:62a1c91a859a 138
gke 0:62a1c91a859a 139 CheckSDCardValid();
gke 1:1e3318a30ddd 140
gke 0:62a1c91a859a 141 UpdateRTC();
gke 0:62a1c91a859a 142
gke 0:62a1c91a859a 143 } // InitHarness