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 19:40c252b4a792, committed 2012-11-03
- Comitter:
- maetugr
- Date:
- Sat Nov 03 10:48:18 2012 +0000
- Parent:
- 18:c8c09a3913ba
- Child:
- 20:e116e596e540
- Commit message:
- trotz i2c adress?nderung funktionieren sensoren nicht!
Changed in this revision
--- a/InterruptControl/IntCtrl.cpp Sat Nov 03 07:44:07 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -// Funktionen zur Interruptkontrolle bei IO-Ports -//--------------------------------------------------------------------------------------------------------------------------------------- -#include "mbed.h" //muss immer geladen werden -#include "IntCtrl.h" - - - -// Enable GPIO Interrupt (nur fuer P0.0..P0.30 und P2.0..P2.13) -// PortNumber = 0 oder 2, BitPosition = 0..31, RiseFall: 0 = rise, 1 = fall, 2 = rise and fall -//------------------------------------------------------------------------------- -void GPIO_IntEnable(char PortNumber, char BitPosition, char RiseFall) - { - switch ( PortNumber ) - case 0: - { - switch ( RiseFall ) - { - case 0: - LPC_GPIOINT->IO0IntEnR |= (0x1<<BitPosition); - break; - - case 1: - LPC_GPIOINT->IO0IntEnF |= (0x1<<BitPosition); - break; - - case 2: - LPC_GPIOINT->IO0IntEnR |= (0x1<<BitPosition); - LPC_GPIOINT->IO0IntEnF |= (0x1<<BitPosition); - break; - - default: - break; - } - - case 2: - { - switch ( RiseFall ) - { - case 0: - LPC_GPIOINT->IO2IntEnR |= (0x1<<BitPosition); - break; - - case 1: - LPC_GPIOINT->IO2IntEnF |= (0x1<<BitPosition); - break; - - case 2: - LPC_GPIOINT->IO2IntEnR |= (0x1<<BitPosition); - LPC_GPIOINT->IO2IntEnF |= (0x1<<BitPosition); - break; - - default: - break; - } - } - } - } - - -// Disable GPIO Interrupt (nur fuer P0.0..P0.30 und P2.0..P2.13) -// PortNumber = 0 oder 2, BitPosition = 0..31, RiseFall: 0 = rise, 1 = fall, 2 = rise and fall -//------------------------------------------------------------------------------- -void GPIO_IntDisable(char PortNumber, char BitPosition, char RiseFall) - { - switch ( PortNumber ) - case 0: - { - switch ( RiseFall ) - { - case 0: - LPC_GPIOINT->IO0IntEnR &= ~(0x1<<BitPosition); - break; - - case 1: - LPC_GPIOINT->IO0IntEnF &= ~(0x1<<BitPosition); - break; - - case 2: - LPC_GPIOINT->IO0IntEnR &= ~(0x1<<BitPosition); - LPC_GPIOINT->IO0IntEnF &= ~(0x1<<BitPosition); - break; - - default: - break; - } - - case 2: - { - switch ( RiseFall ) - { - case 0: - LPC_GPIOINT->IO2IntEnR &= ~(0x1<<BitPosition); - break; - - case 1: - LPC_GPIOINT->IO2IntEnF &= ~(0x1<<BitPosition); - break; - - case 2: - LPC_GPIOINT->IO2IntEnR &= ~(0x1<<BitPosition); - LPC_GPIOINT->IO2IntEnF &= ~(0x1<<BitPosition); - break; - - default: - break; - } - } - } - } - \ No newline at end of file
--- a/InterruptControl/IntCtrl.h Sat Nov 03 07:44:07 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#ifndef __INTCTRL_H -#define __INTCTRL_H - -extern void GPIO_IntEnable(char PortNumber, char BitPosition, char RiseFall); -extern void GPIO_IntDisable(char PortNumber, char BitPosition, char RiseFall); - - -/* mbed DIP Pin LPC1768 Pin - p5 = P0_9 - p6 = P0_8 - p7 = P0_7 - p8 = P0_6 - p9 = P0_0 - p10 = P0_1 - p11 = P0_18 - p12 = P0_17 - p13 = P0_15 - p14 = P0_16 - p15 = P0_23 - p16 = P0_24 - p17 = P0_25 - p18 = P0_26 - p21 = P2_5 - p22 = P2_4 - p23 = P2_3 - p24 = P2_2 - p25 = P2_1 - p26 = P2_0 - p27 = P0_11 - p28 = P0_10 - p29 = P0_5 - p30 = P0_4 -*/ - - -#endif \ No newline at end of file
--- a/InterruptControl/IntCtrl.lib Sat Nov 03 07:44:07 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -IntCtrl#000000000000
--- a/Sensors/Acc/ADXL345.cpp Sat Nov 03 07:44:07 2012 +0000 +++ b/Sensors/Acc/ADXL345.cpp Sat Nov 03 10:48:18 2012 +0000 @@ -25,9 +25,9 @@ readMultiRegister(ADXL345_DATAX0_REG, buffer, 6); // read axis registers using I2C - data[0] = (short) (buffer[1] << 8 | buffer[0]); // join 8-Bit pieces to 16-bit short integers - data[1] = (short) (buffer[3] << 8 | buffer[2]); - data[2] = (short) (buffer[5] << 8 | buffer[4]); + data[0] = (float)(short) (buffer[1] << 8 | buffer[0]); // join 8-Bit pieces to 16-bit short integers + data[1] = (float)(short) (buffer[3] << 8 | buffer[2]); + data[2] = (float)(short) (buffer[5] << 8 | buffer[4]); // calculate the angles for roll and pitch (0,1) float R = sqrt(pow((float)data[0],2) + pow((float)data[1],2) + pow((float)data[2],2)); // calculate the absolute of the magnetic field vector
--- a/Sensors/Acc/ADXL345.h Sat Nov 03 07:44:07 2012 +0000 +++ b/Sensors/Acc/ADXL345.h Sat Nov 03 10:48:18 2012 +0000 @@ -6,7 +6,7 @@ #include "mbed.h" #include "I2C_Sensor.h" -#define ADXL345_I2C_ADDRESS 0 +#define ADXL345_I2C_ADDRESS 0xA6 // read or write bytes //#define ADXL345_READ 0xA7 //#define ADXL345_WRITE 0xA6
--- a/Sensors/Comp/HMC5883.cpp Sat Nov 03 07:44:07 2012 +0000 +++ b/Sensors/Comp/HMC5883.cpp Sat Nov 03 10:48:18 2012 +0000 @@ -3,8 +3,8 @@ HMC5883::HMC5883(PinName sda, PinName scl) : I2C_Sensor(sda, scl, HMC5883_I2C_ADDRESS) { // load calibration values - loadCalibrationValues(scale, 3, "COMPASS_SCALE.txt"); - loadCalibrationValues(offset, 3, "COMPASS_OFFSET.txt"); + //loadCalibrationValues(scale, 3, "COMPASS_SCALE.txt"); + //loadCalibrationValues(offset, 3, "COMPASS_OFFSET.txt"); // initialize HMC5883 writeRegister(HMC5883_CONF_REG_A, 0x78); // 8 samples, 75Hz output, normal mode
--- a/Sensors/Comp/HMC5883.h Sat Nov 03 07:44:07 2012 +0000 +++ b/Sensors/Comp/HMC5883.h Sat Nov 03 10:48:18 2012 +0000 @@ -6,7 +6,7 @@ #include "mbed.h" #include "I2C_Sensor.h" -#define HMC5883_I2C_ADDRESS 0x1E +#define HMC5883_I2C_ADDRESS 0x3C #define HMC5883_CONF_REG_A 0x00 #define HMC5883_CONF_REG_B 0x01
--- a/Sensors/I2C_Sensor.cpp Sat Nov 03 07:44:07 2012 +0000 +++ b/Sensors/I2C_Sensor.cpp Sat Nov 03 10:48:18 2012 +0000 @@ -35,8 +35,8 @@ { char value = 0; - i2c.write(GET_I2C_WRITE_ADDRESS(i2c_address), ®, 1, true); - i2c.read(GET_I2C_READ_ADDRESS(i2c_address), &value, 1, true); + i2c.write(i2c_address, ®, 1, true); + i2c.read(i2c_address, &value, 1, true); return value; } @@ -44,11 +44,11 @@ void I2C_Sensor::writeRegister(char reg, char data) { char buffer[2] = {reg, data}; - i2c.write(GET_I2C_WRITE_ADDRESS(i2c_address), buffer, 2, true); + i2c.write(i2c_address, buffer, 2, true); } void I2C_Sensor::readMultiRegister(char reg, char* output, int size) { - i2c.write (GET_I2C_WRITE_ADDRESS(i2c_address), ®, 1, true); // tell register address of the MSB get the sensor to do slave-transmit subaddress updating. - i2c.read (GET_I2C_READ_ADDRESS(i2c_address), output, size, true); // tell it where to store the data read + i2c.write (i2c_address, ®, 1, true); // tell register address of the MSB get the sensor to do slave-transmit subaddress updating. + i2c.read (i2c_address, output, size, true); // tell it where to store the data read } \ No newline at end of file
--- a/main.cpp Sat Nov 03 07:44:07 2012 +0000 +++ b/main.cpp Sat Nov 03 10:48:18 2012 +0000 @@ -8,7 +8,6 @@ #include "RC_Channel.h" // RemoteControl Chnnels with PPM #include "Servo_PWM.h" // Motor PPM using PwmOut #include "PID.h" // PID Library by Aaron Berk -#include "IntCtrl.h" // Interrupt Control by Roland Elmiger #define PI 3.1415926535897932384626433832795 // ratio of a circle's circumference to its diameter #define RAD2DEG 57.295779513082320876798154814105 // ratio between radians and degree (360/2Pi) @@ -25,7 +24,7 @@ // initialisation of hardware (see includes for more info) LED LEDs; -PC pc(USBTX, USBRX, 57600); // TODO: Testen ?!!! 115.200 +PC pc(USBTX, USBRX, 115200); L3G4200D Gyro(p28, p27); ADXL345 Acc(p28, p27); HMC5883 Comp(p28, p27); @@ -132,6 +131,12 @@ //pc.printf("Comp_scale: %6.4f %6.4f %6.4f ", Comp.scale[0], Comp.scale[1], Comp.scale[2]); no more accessible its private pc.locate(10,15); pc.printf("PID Test: %6.1f", co); + pc.locate(10,16); + pc.printf("Gyro_data: X:%6.1f Y:%6.1f Z:%6.1f", Gyro.data[0], Gyro.data[1], Gyro.data[2]); + pc.locate(10,17); + pc.printf("Acc_data: X:%6.1f Y:%6.1f Z:%6.1f", Acc.data[0], Acc.data[1], Acc.data[2]); + pc.locate(10,18); + pc.printf("Comp_data: %6.1f %6.1f %6.1f |||| %6.1f ", Comp.data[0], Comp.data[1], Comp.data[2], Comp.get_angle()); pc.locate(10,19); pc.printf("RC0: %4d :[", RC[0].read());