NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.
Revision 1:5a64632b1eb9, committed 2012-09-28
- Comitter:
- maetugr
- Date:
- Fri Sep 28 13:24:03 2012 +0000
- Parent:
- 0:0c4fafa398b4
- Child:
- 2:93f703d2c4d7
- Commit message:
- bevor anpassung/vorschl?ge f?r ADXL345 library
Changed in this revision
--- a/LED/LED.cpp Wed Sep 26 12:15:00 2012 +0000 +++ b/LED/LED.cpp Fri Sep 28 13:24:03 2012 +0000 @@ -1,21 +1,49 @@ #include "LED.h" #include "mbed.h" -LED::LED() : Led(LED1, LED2, LED3, LED4){ } +LED::LED() : Led(LED1, LED2, LED3, LED4){ + roller = 0; +} void LED::shownumber(int number) { Led = number; } -void LED::roll(int times = 1) { +void LED::ride(int times = 1) { + Led = 0; for (int j = 0; j < times; j++) { - for(int i=0; i<4; i++) { + for(int i=0; i < 4; i++) { Led = 1 << i; - wait(0.25); + wait(0.2); } } + Led = 0; +} + +void LED::roll(int times = 1) { + Led = 0; + for (int j = 0; j < (times*2); j++) { + for(int roller = 1; roller <= 4; roller++) { + tilt(roller); + wait(0.1); + } + } + roller = 0; + Led = 0; +} + +void LED::rollnext() { + if (roller >= 4) + roller = 0; + else + roller++; + tilt(roller); } void LED::tilt(int index) { Led = Led^(1 << (index-1)); +} + +void LED::operator=(int value) { + Led = value; } \ No newline at end of file
--- a/LED/LED.h Wed Sep 26 12:15:00 2012 +0000 +++ b/LED/LED.h Fri Sep 28 13:24:03 2012 +0000 @@ -7,14 +7,18 @@ class LED { -public: - LED(); - void shownumber(int number); - void roll(int times); - void tilt(int index); - -private: - BusOut Led; + public: + LED(); + void shownumber(int number); + void ride(int times); + void roll(int times); + void rollnext(); + void tilt(int index); + void operator=(int value); + + private: + BusOut Led; + int roller; }; #endif \ No newline at end of file
--- a/Sensors/Acc/ADXL345.cpp Wed Sep 26 12:15:00 2012 +0000 +++ b/Sensors/Acc/ADXL345.cpp Fri Sep 28 13:24:03 2012 +0000 @@ -1,57 +1,5 @@ -/** - * @author Peter Swanson - * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because - * today, religion is thought of as something that you do or believe and has about as - * little impact on a person as their political stance. But for me, God gives me daily - * strength and has filled my life with the satisfaction that I could never find in any - * of the other things that I once looked for it in. - * If your interested, heres verse that changed my life: - * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus, - * because through Christ Jesus, the law of the Spirit who gives life has set - * me free from the law of sin (which brings...) and death. For what the law - * was powerless to do in that it was weakened by the flesh, God did by sending - * His own Son in the likeness of sinful flesh to be a sin offering. And so He - * condemned sin in the flesh in order that the righteous requirements of the - * (God's) law might be fully met in us, who live not according to the flesh - * but according to the Spirit." - * - * A special thanks to Ewout van Bekkum for all his patient help in developing this library! - * - * @section LICENSE - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @section DESCRIPTION - * - * ADXL345, triple axis, I2C interface, accelerometer. - * - * Datasheet: - * - * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf - */ - -/** - * Includes - */ #include "ADXL345.h" - -//#include "mbed.h" +#include "mbed.h" ADXL345::ADXL345(PinName sda, PinName scl) : i2c_(sda, scl) { @@ -85,6 +33,13 @@ z[0] = ADXL345_OFSZ_REG ; z[1] = 0xFE; i2c_.write( ADXL345_WRITE , z, 2); + + // MY INITIALISATION ------------------------------------------------------- + + setPowerControl(0x00); + setDataFormatControl(0x0B); + setDataRate(ADXL345_3200HZ); + setPowerControl(MeasurementMode); }
--- a/Sensors/Gyro/L3G4200D.cpp Wed Sep 26 12:15:00 2012 +0000 +++ b/Sensors/Gyro/L3G4200D.cpp Fri Sep 28 13:24:03 2012 +0000 @@ -5,7 +5,7 @@ #define L3G4200D_I2C_ADDRESS 0xD0 -Gyro::Gyro(PinName sda, PinName scl): +L3G4200D::L3G4200D(PinName sda, PinName scl): i2c(sda, scl) { i2c.frequency(400000); @@ -32,7 +32,7 @@ } // Writes a gyro register -void Gyro::writeReg(byte reg, byte value) +void L3G4200D::writeReg(byte reg, byte value) { data[0] = reg; data[1] = value; @@ -41,7 +41,7 @@ } // Reads a gyro register -byte Gyro::readReg(byte reg) +byte L3G4200D::readReg(byte reg) { byte value = 0; @@ -52,7 +52,7 @@ } // Reads the 3 gyro channels and stores them in vector g -void Gyro::read(int g[3]) +void L3G4200D::read(int g[3]) { // assert the MSB of the address to get the gyro // to do slave-transmit subaddress updating. @@ -77,7 +77,7 @@ } // Reads the gyros Temperature -int Gyro::readTemp() +int L3G4200D::readTemp() { return (short) readReg(L3G4200D_OUT_TEMP); } \ No newline at end of file
--- a/Sensors/Gyro/L3G4200D.h Wed Sep 26 12:15:00 2012 +0000 +++ b/Sensors/Gyro/L3G4200D.h Fri Sep 28 13:24:03 2012 +0000 @@ -39,10 +39,10 @@ typedef char byte; -class Gyro +class L3G4200D { public: - Gyro(PinName sda, PinName scl); // constructor, uses i2c + L3G4200D(PinName sda, PinName scl); // constructor, uses i2c void read(int g[3]); // read all axis to array int readTemp(); // read temperature from sensor
--- a/Servo/Servo.cpp Wed Sep 26 12:15:00 2012 +0000 +++ b/Servo/Servo.cpp Fri Sep 28 13:24:03 2012 +0000 @@ -2,9 +2,12 @@ #include "mbed.h" Servo::Servo(PinName Pin) : ServoPin(Pin) { +} + +void Servo::initialize() { // initialize ESC Enable(2000,20000); // full throttle - wait(2); // for 2 secs + wait(0.01); // for 2 secs SetPosition(1000); // low throttle }
--- a/Servo/Servo.h Wed Sep 26 12:15:00 2012 +0000 +++ b/Servo/Servo.h Fri Sep 28 13:24:03 2012 +0000 @@ -57,6 +57,9 @@ //operator for confortable positioning void operator=(int position); + + // initialize ESC + void initialize(); private: void StartPulse();
--- a/main.cpp Wed Sep 26 12:15:00 2012 +0000 +++ b/main.cpp Fri Sep 28 13:24:03 2012 +0000 @@ -1,48 +1,43 @@ -#include "mbed.h" +#include "mbed.h" // Standar Library #include "LCD.h" // Display #include "LED.h" // LEDs #include "L3G4200D.h" // Gyro #include "ADXL345.h" // Acc +#include "Servo.h" // Motor -PinName kl[4] = {LED1, LED2, LED3, LED4}; -LED Led(); +// initialisation +LED LEDs; TextLCD LCD(p5, p6, p7, p8, p9, p10, p11, TextLCD::LCD16x2); // RS, RW, E, D0, D1, D2, D3, Typ - -// Sensor initialisation -Gyro Gyro(p28, p27); +L3G4200D Gyro(p28, p27); ADXL345 Acc(p28, p27); +Servo Motor(p12); int main() { - + // LCD/LED init + LCD.cls(); // Display löschen LCD.printf("FlyBed v0.1"); + LEDs.roll(2); + //LEDs = 15; - wait(2); - int j = -1; int Gyro_data[3]; int Acc_data[3]; - Acc.setPowerControl(0x00); - Acc.setDataFormatControl(0x0B); - Acc.setDataRate(ADXL345_3200HZ); - Acc.setPowerControl(MeasurementMode); - while(1) { Gyro.read(Gyro_data); Acc.getOutput(Acc_data); - //LCD.cls(); // Display löschen LCD.locate(0,0); LCD.printf("%d %d %d |%d ", Gyro_data[0],Gyro_data[1],Gyro_data[2],Gyro.readTemp()); //roll(x) pitch(y) yaw(z) LCD.locate(1,0); - //LCD.printf("%d|%d|%d %d", gmitt[0]/j,gmitt[1]/j,gmitt[2]/j,gyro.readTemp()); //roll pitch yaw - LCD.locate(1,0); - LCD.printf("%d %d %d ", (int16_t)Acc_data[0],(int16_t)Acc_data[1],(int16_t)Acc_data[2]); + LCD.printf("%d %d %d %d ", (int16_t)Acc_data[0],(int16_t)Acc_data[1],(int16_t)Acc_data[2], 1000 + abs((int16_t)Acc_data[1])); - j++; + if(abs((int16_t)Acc_data[0]) > 200) + Motor.initialize(); - //Led[j%4] = !Led[j%4]; + Motor = 1000 + abs((int16_t)Acc_data[1]); // Motorwert anpassen + LEDs.rollnext(); wait(0.1); }