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.
Diff: Sensors/Comp/HMC5883.cpp
- Revision:
- 14:cf260677ecde
- Parent:
- 13:4737ee9ebfee
- Child:
- 15:753c5d6a63b3
--- a/Sensors/Comp/HMC5883.cpp Thu Oct 25 19:27:56 2012 +0000 +++ b/Sensors/Comp/HMC5883.cpp Sat Oct 27 10:53:43 2012 +0000 @@ -1,9 +1,9 @@ #include "mbed.h" #include "HMC5883.h" -HMC5883::HMC5883(PinName sda, PinName scl) : local("local"), i2c(sda, scl) +HMC5883::HMC5883(PinName sda, PinName scl) : i2c(sda, scl), local("local") { - i2c.frequency(400000); // zu testen!! + i2c.frequency(400000); // TODO: zu testen!! // load calibration values FILE *fp = fopen("/local/compass.txt", "r"); @@ -18,8 +18,8 @@ writeReg(HMC5883_CONF_REG_B, 0x20); // Gain for +- 1.3 gauss (earth compass ~0.6 gauss) writeReg(HMC5883_MODE_REG, 0x00); // continuous measurement-mode - /* - // Scaling with testmode (not important, just from data sheet) + /* (not important, just from data sheet) + // Scaling with testmode for(int j = 0; j < 3; j++) // set all scales to 1 first so the measurement for scaling is not already scaled scale[j] = 1; @@ -105,18 +105,16 @@ float Heading; Heading = Rad2Deg * atan2(data[0],data[1]); - Heading += 1.367; //bei Ost-Deklination += DecAngle, bei West-Deklination -= DecAngle //Missweisung = Winkel zwischen geographischer und magnetischer Nordrichtung //Bern ca. 1.367 Grad Ost //http://www.swisstopo.admin.ch/internet/swisstopo/de/home/apps/calc/declination.html - if(Heading < 0) Heading += 360; // minimum 0 degree if(Heading > 360) Heading -= 360; // maximum 360 degree - + return Heading; }