Show Posts
Pages: 1 2 3 [4] 5
46  Using Arduino / Sensors / HMC5883L Calibration? on: March 23, 2013, 07:03:25 am
Hi, i have HMC5883L 3 axis magnetometer. I heard that magnetometer must be calibrated first before it can used properly. And the method is depending from the area where we live.

I find out the magnetic field on my area through this website:
http://www.geomag.bgs.ac.uk/data_service/models_compass/wmm_calc.html

There is many variable, like Declination, Inclination, North Intensity, East Intensity, Horizontal Intensity, Vertical Intensity, and total Intensity.

The question is, are those variables used in magnetometer calibration? Or which variables that used in magnetometer calibration? And how to do a magnetometer calibration?

Thank you..
47  Using Arduino / Programming Questions / Re: Need Help about Quaternion Algorithm Code on: March 19, 2013, 07:41:41 am
Code:
byte readAccel()
{
  Wire.beginTransmission(BMA180);
  Wire.write(0x02);
  if(Wire.endTransmission()){return(1);}
  if(Wire.requestFrom(BMA180,7) != 7){return(2);}

...

  z >>= 2;
  temp = Wire.read();
}

First, since you are returning non-zero for errors, you should return zero at the very end (success).

You mean like this:
Code:
...

  z >>= 2;
  temp = Wire.read();
return 0;

Next:

Code:
void loop() {
 
  timer = millis(); //get a start value to determine the time the loop takes
 
  readCompass();
  getGyroscopeReadings(gyroResult);
  readAccel();

You aren't checking the return value. You may have had a transmission error. How about:

Code:
  if (readAccel() != 0)
    return;

So, it will become like this?
Code:
void loop() {
 
  timer = millis(); //get a start value to determine the time the loop takes
 
  readCompass();
  getGyroscopeReadings(gyroResult);
  readAccel();
if (readAccel() != 0)
    return;

48  Using Arduino / Programming Questions / Need Help about Quaternion Algorithm Code on: March 18, 2013, 12:07:04 am
Hi, everyone! I want to make 3D positioning (Pitch, roll, and yaw) using this board:
https://www.hobbyking.com/hobbyking/store/__27033__MultiWii_328P_Flight_Controller_w_FTDI_DSM2_Port.html
And then i will use the positioning data to my 3 axis gimbal.

From the results of my search on the internet. I get the hint that one of the best methods for 3D positioning is quaternion.

And I found the Quaternion based algorithm from here:
http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/

It's open source, and i tried to use that algorithm on my code. This is my coomplete Code:
https://github.com/mamette/quaternion/blob/master/AHRS.ino

I got the Pitch, Roll and Yaw value, but they are irregularly. Is anything wrong with my code?

And i have some question:
1. When we insert the Accelerometer value to Quaternion, the Accelerometer value must be in "g" scale or just raw value on each axis?
2. When we insert the Gyroscope value to Quaternion, the Gyroscope value must be in rad/s, it is right?
3. When we insert the Magnetometer value to Quaternion, just insert Magnetometer raw value on each axis, it is right?

Thank You..
49  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 17, 2013, 11:43:55 pm
Yeah, quaternions are the way to go.

The problem starts,  when you assume that you can calculate the direction of the magnetic field simply by taking the arctan of the Y axis and X ais readings of the magnetometer.    That assumption is misguided.  And once you have made that assumption,   you have all kinds of work-arounds to "compensate" for the fact that you have made a poor assumption.

If you assume that your vehicle has very small actual real acceleration,   then you can estimate the orientation of your device by observing the apparent direction of the gravitational "down" direction using your accelerometer.

You can then estimate the rotation matrix which transforms the actual orientation of your device into a reference frame which is parallel to the ground.   You can then transform the apparent magnetic field vector into the reference frame.   You can compare that to the assumed actual magnetic field vector,  to estimate the discrepancy between the reference direction in the horizontal direction of your calculated reference frame,  and the actual "true" reference horizontal direction of the reference frame.

This is conceptually quite simple.   Further complications emerge because different people use different conventions for which way the reference axes run.


Hi, michinyon. I found Quaternion based algorithm from here:
http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/

It's open source, and i tried to use that algorithm on my code. This is my coomplete Code:
https://github.com/mamette/quaternion/blob/master/AHRS.ino

I got the Pitch, Roll and Yaw value, but they are irregularly. Is anything wrong with my code?

And i have some question:
1. When we insert the Accelerometer value to Quaternion, the Accelerometer value must be in "g" scale or just raw value on each axis?
2. When we insert the Gyroscope value to Quaternion, the Gyroscope value must be in rad/s, it is right?
3. When we insert the Magnetometer value to Quaternion, just insert Magnetometer raw value on each axis, it is right?

Thank You..
50  Using Arduino / Programming Questions / How to Implements Quaternion in Attitude and heading reference system (AHRS)? on: March 12, 2013, 11:17:57 am
Hi, i want to make  Attitude and heading reference system (AHRS) using quaternion algorithm. And I found this code on the internet:

This is header file code (AHRS.h):
Code:
//=====================================================================================================
// AHRS.h
// S.O.H. Madgwick
// 25th August 2010
//=====================================================================================================
//
// See AHRS.c file for description.
//
//=====================================================================================================
#ifndef AHRS_h
#define AHRS_h

//----------------------------------------------------------------------------------------------------
// Variable declaration

extern float q0, q1, q2, q3; // quaternion elements representing the estimated orientation

//---------------------------------------------------------------------------------------------------
// Function declaration

void AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);

#endif
//=====================================================================================================
// End of file
//=====================================================================================================

and this is the main code:
Code:
//=====================================================================================================
// AHRS.c
// S.O.H. Madgwick
// 25th August 2010
//=====================================================================================================
// Description:
//
// Quaternion implementation of the 'DCM filter' [Mayhony et al].  Incorporates the magnetic distortion
// compensation algorithms from my filter [Madgwick] which eliminates the need for a reference
// direction of flux (bx bz) to be predefined and limits the effect of magnetic distortions to yaw
// axis only.
//
// User must define 'halfT' as the (sample period / 2), and the filter gains 'Kp' and 'Ki'.
//
// Global variables 'q0', 'q1', 'q2', 'q3' are the quaternion elements representing the estimated
// orientation.  See my report for an overview of the use of quaternions in this application.
//
// User must call 'AHRSupdate()' every sample period and parse calibrated gyroscope ('gx', 'gy', 'gz'),
// accelerometer ('ax', 'ay', 'ay') and magnetometer ('mx', 'my', 'mz') data.  Gyroscope units are
// radians/second, accelerometer and magnetometer units are irrelevant as the vector is normalised.
//
//=====================================================================================================

//----------------------------------------------------------------------------------------------------
// Header files

#include "AHRS.h"
#include <math.h>

//----------------------------------------------------------------------------------------------------
// Definitions

#define Kp 2.0f // proportional gain governs rate of convergence to accelerometer/magnetometer
#define Ki 0.005f // integral gain governs rate of convergence of gyroscope biases
#define halfT 0.5f // half the sample period

//---------------------------------------------------------------------------------------------------
// Variable definitions

float q0 = 1, q1 = 0, q2 = 0, q3 = 0; // quaternion elements representing the estimated orientation
float exInt = 0, eyInt = 0, ezInt = 0; // scaled integral error

//====================================================================================================
// Function
//====================================================================================================

void AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) {
float norm;
float hx, hy, hz, bx, bz;
float vx, vy, vz, wx, wy, wz;
float ex, ey, ez;

// auxiliary variables to reduce number of repeated operations
float q0q0 = q0*q0;
float q0q1 = q0*q1;
float q0q2 = q0*q2;
float q0q3 = q0*q3;
float q1q1 = q1*q1;
float q1q2 = q1*q2;
float q1q3 = q1*q3;
float q2q2 = q2*q2;  
float q2q3 = q2*q3;
float q3q3 = q3*q3;          

// normalise the measurements
norm = sqrt(ax*ax + ay*ay + az*az);      
ax = ax / norm;
ay = ay / norm;
az = az / norm;
norm = sqrt(mx*mx + my*my + mz*mz);          
mx = mx / norm;
my = my / norm;
mz = mz / norm;        

// compute reference direction of flux
hx = 2*mx*(0.5 - q2q2 - q3q3) + 2*my*(q1q2 - q0q3) + 2*mz*(q1q3 + q0q2);
hy = 2*mx*(q1q2 + q0q3) + 2*my*(0.5 - q1q1 - q3q3) + 2*mz*(q2q3 - q0q1);
hz = 2*mx*(q1q3 - q0q2) + 2*my*(q2q3 + q0q1) + 2*mz*(0.5 - q1q1 - q2q2);        
bx = sqrt((hx*hx) + (hy*hy));
bz = hz;        

// estimated direction of gravity and flux (v and w)
vx = 2*(q1q3 - q0q2);
vy = 2*(q0q1 + q2q3);
vz = q0q0 - q1q1 - q2q2 + q3q3;
wx = 2*bx*(0.5 - q2q2 - q3q3) + 2*bz*(q1q3 - q0q2);
wy = 2*bx*(q1q2 - q0q3) + 2*bz*(q0q1 + q2q3);
wz = 2*bx*(q0q2 + q1q3) + 2*bz*(0.5 - q1q1 - q2q2);  

// error is sum of cross product between reference direction of fields and direction measured by sensors
ex = (ay*vz - az*vy) + (my*wz - mz*wy);
ey = (az*vx - ax*vz) + (mz*wx - mx*wz);
ez = (ax*vy - ay*vx) + (mx*wy - my*wx);

// integral error scaled integral gain
exInt = exInt + ex*Ki;
eyInt = eyInt + ey*Ki;
ezInt = ezInt + ez*Ki;

// adjusted gyroscope measurements
gx = gx + Kp*ex + exInt;
gy = gy + Kp*ey + eyInt;
gz = gz + Kp*ez + ezInt;

// integrate quaternion rate and normalise
q0 = q0 + (-q1*gx - q2*gy - q3*gz)*halfT;
q1 = q1 + (q0*gx + q2*gz - q3*gy)*halfT;
q2 = q2 + (q0*gy - q1*gz + q3*gx)*halfT;
q3 = q3 + (q0*gz + q1*gy - q2*gx)*halfT;  

// normalise quaternion
norm = sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
q0 = q0 / norm;
q1 = q1 / norm;
q2 = q2 / norm;
q3 = q3 / norm;
}

//====================================================================================================
// END OF CODE
//====================================================================================================

But, i really confusing to implements that algorith. Am i must change all variables with some value? I know for variables gx, gy,  gz, ax, ay, az, mx,  my, and mz i must change the value with accelerometer, Gyroscope and magnetometer value. But how with other variables like q0, q1, q2, q2, halfT, and others? What value that i must put?

Or, there is another way?

Thank You..
51  Using Arduino / Programming Questions / What's the mean of "f" in this Code on: March 12, 2013, 10:34:49 am
Hi, i found this code on the internet:

Code:
#define Kp 2.0f // proportional gain governs rate of convergence to accelerometer/magnetometer
#define Ki 0.005f // integral gain governs rate of convergence of gyroscope biases
#define halfT 0.5f // half the sample period

Wahat the mean of "f" at 2.0f, 0.005f, and 0.5f?
52  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 11, 2013, 08:55:00 am
Quote
Yeah, quaternions are the way to go.

The problem starts,  when you assume that you can calculate the direction of the magnetic field simply by taking the arctan of the Y axis and X ais readings of the magnetometer.    That assumption is misguided.  And once you have made that assumption,   you have all kinds of work-arounds to "compensate" for the fact that you have made a poor assumption.

If you assume that your vehicle has very small actual real acceleration,   then you can estimate the orientation of your device by observing the apparent direction of the gravitational "down" direction using your accelerometer.

You can then estimate the rotation matrix which transforms the actual orientation of your device into a reference frame which is parallel to the ground.   You can then transform the apparent magnetic field vector into the reference frame.   You can compare that to the assumed actual magnetic field vector,  to estimate the discrepancy between the reference direction in the horizontal direction of your calculated reference frame,  and the actual "true" reference horizontal direction of the reference frame.

This is conceptually quite simple.   Further complications emerge because different people use different conventions for which way the reference axes run.

Well, thank you about the Explanation michinyon, but i little bit confusing, can you explain it again with some mathematical form,    formulation or algorithm?
53  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 10, 2013, 06:07:19 am
Quote
The direction of the magnetism is flat at the equator, and pointing down at the poles.
http://geokov.com/education/magnetic-declination-inclination.aspx
http://en.wikipedia.org/wiki/Magnetic_dip
This site tells how much the inclination is, http://magnetic-declination.com/  (if you type your location, click on the location marker).
This site tells even more, http://www.geomag.bgs.ac.uk/data_service/models_compass/wmm_calc.html  (click on the map to place the marker).

Ok thanks Erdin..

Quote
Thats not really correct.   That is spurious wooly thinking which comes from the days of 2-axis magnetometers, maybe.   A 3-axis magnetometer DOES NOT need to be held flat to function properly.   It is always going to correctly show you the direction of the geomagnetic field ( or any other magnetic field which is present ),  relative to its own current orientation.   Apart from scaling and offset calibration for the different axial directions ( which will be an issue whether you are holding it flat and level, or not ),  the assertion that the reading will be more inaccurate the further the compass is tilted,  is simply not correct.

If you know the orientation of the device,  you can always determine the projection of the magnetic field vector into a plane parallel to the ground.  If you don't know the orientation of the device,  you can compare the measured magnetic field vector to the expected magnetic field vector in your region,  to determine the correct which needs to be made to the modelled orientation of the device.

Ok, so the 3 axis magnetometer give us magnetic field in three axis, X, Y and Z. From my program that i have posted before, I successfully get magnetic field value in all 3 axis vector. Then, i want to know where we are heading (degree from north pole) by using this data . And    
according to this site:
https://www.loveelectronics.co.uk/Tutorials/8/hmc5883l-tutorial-and-arduino-library

To Calculate heading of magnetometer, we can use this formulation:
heading = arc tan (magnetic filed on Y Axis/magnetic filed on X Axis)

And finally i get the heading degrees, pretty nice when magnetometer keep flat. But, when i tilt the magnetometer (Pitch or Roll), the degrees value is change. And so far,  I still not found a way to maintain the value of degree when the magnetometer tilted. Is there something wrong with my calculations?

Oh, and i found this video:


i look up for his code and he use something called Quaternion..
54  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 09, 2013, 07:19:38 am
Quote
I am not even sure what you think this sentence means.

A magnetic device is going to clarify the orientation of your device in relation to rotating around
the yaw axis.   It's nothing to do with tilting the yaw axis.

Sorry, i mean "tilt compensation for magnetometer"

Quote
If you literally intend to use it as a compass ( for orienteering or something ),   then you need to "compensate" for the fact that you are not holding your compass flat, steady, and parallel to the ground.

If you intend to use it as an aid to orientation calculation for some moving device,   that's a rather different question.   The best method comes down to what sort of device you are trying to orient (  a car ?  a robot on the ground ?  a copter ?  An acrobatic aircraft ? ),    and what other devices you are using it with.

That's it, i am going to use this magnetometer for Multicopter to know where we are heading, so the magnetometer is not always flat, steady, and parallel to the ground. And the problem is the magnetometer need to be held flat to function properly. If we tilt it (pitch or roll) to certain angle (for example to 45 degrees) the reading will be more inaccurate the further the compass is tilted. So I need to keep the accuracy of magnetometer even we tilt it.

I am looking for some references on the internet and found some useful sites like this (Maybe it will help explain my problem more clearly):
https://www.loveelectronics.co.uk/Tutorials/13/tilt-compensated-compass-arduino-tutorial
http://diy.powet.eu/2011/03/19/tilt-compensation-azimuth-pitch-le-roll/?lang=en
https://gist.github.com/timtrueman/322555
http://n0m1.com/2012/02/27/6dof-arduino-compass-accelerometer/

They are says we need both accelerometer and magnetometer to solve magnetometer inaccurate problem when it tilted, and use an algorithm. But, i still not yet success to solve this problem.
55  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 08, 2013, 10:16:08 am
Quote
I don't use that concept at all,   and I think the logic and methodology for it is spurious.

The basic feature of the geomagnetic field is that it isn't parallel to the ground,  as you would
think when you have a magnetic compass sitting on a map on a table.

It is a vector field shooting down into the ground at a diagonal angle,   which is more or less
constant over short distances and which you can easily find out what it is for your region.

The 3-axis magnetometer is going to give you a vector in 3D which is going to show you the
direction of that field.    Since you already know the direction of the field,   you can determine
the orientation of the magnetometer,  with the exception of rotation about the vector direction.

If you also have an accelerometer,  and you assume your device is stationary or moving at a constant
velocity ( so it has no actual acceleration ),   you can fully determine the orientation of your device.

So, how i can solve tilt compensation for yaw Axis? By the way, this is my complete code:
Code:
// Reference the I2C Library
#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>

// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;

int accelResult[3];
float timeStep = 0.02;          //20ms. Need a time step value for integration of gyro angle from angle/sec
float biasAccelX, biasAccelY, biasAccelZ;
float pitchAccel = 0;
float rollAccel = 0;

float Xh;
float Yh;
float realHeading;
float pitchAccelXh;
float rollAccelYh;
float XM;
float YM;
float ZM;

unsigned long timer;

//Penjabaran fungsi writeTo sebagai Fungsi untuk writing byte ke alamat device pada I2C
void writeTo(byte device, byte toAddress, byte val) {
  Wire.beginTransmission(device); 
  Wire.write(toAddress);       
  Wire.write(val);       
  Wire.endTransmission();
}

//Penjabaran fungsi readFrom sebagai Fungsi untuk membaca num bytes dari alamat pada device I2C
void readFrom(byte device, byte fromAddress, int num, byte result[]) {
  Wire.beginTransmission(device);
  Wire.write(fromAddress);
  Wire.endTransmission();
  Wire.requestFrom((int)device, num);
  int i = 0;
  while(Wire.available()) {
    result[i] = Wire.read();
    i++;
  }
}


//Fungsi untuk mmebaca nilai Accelerometer
void getAccelerometerReadings(int accelResult[]) {
  byte buffer[6];
  readFrom(0x40,0x02,6,buffer);
  accelResult[0] = (((int)buffer[1]) << 8 ) | buffer[0]; //Yes, byte order different from gyros'
  accelResult[1] = (((int)buffer[3]) << 8 ) | buffer[2];
  accelResult[2] = (((int)buffer[5]) << 8 ) | buffer[4];
}


// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
 
  int totalAccelXValues = 0;
  int totalAccelYValues = 0;
  int totalAccelZValues = 0;
  int i;
 
  // Initialize the serial port.
  Serial.begin(115200);

  Serial.println("Starting the I2C interface.");
  Wire.begin(); // Start the I2C interface.

  Serial.println("Constructing new HMC5883L");
  compass = HMC5883L(); // Construct a new HMC5883 compass.
   
  Serial.println("Setting scale to +/- 1.3 Ga");
  error = compass.SetScale(1.3); // Set the scale of the compass.
  if(error != 0) // If there is an error, print it out.
    Serial.println(compass.GetErrorText(error));
 
  Serial.println("Setting measurement mode to continous.");
  error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
  if(error != 0) // If there is an error, print it out.
    Serial.println(compass.GetErrorText(error));
 
  writeTo(0x40,0x10,0xB6); //Soft_reset accelerometer BMA180
  writeTo(0x40,0x0D,0x10); //set fungsi ee_w
 
  // Determine zero bias for all axes of both sensors by averaging 50 measurements
  delay(100); //wait for gyro to "spin" up
  for (i = 0; i < 50; i += 1) {
    getAccelerometerReadings(accelResult);
    totalAccelXValues += accelResult[0];
    totalAccelYValues += accelResult[1];
    totalAccelZValues += accelResult[2];
    delay(50);
   }
   
  biasAccelX = totalAccelXValues / 50;
  biasAccelY = totalAccelYValues / 50;
  biasAccelZ = (totalAccelZValues / 50) - 256; //Don't compensate gravity away! We would all (float)!
   
}

// Our main program loop.
void loop()
{
  // Retrive the raw values from the compass (not scaled).
  MagnetometerRaw raw = compass.ReadRawAxis();
  // Retrived the scaled values from the compass (scaled to the configured scale).
  MagnetometerScaled scaled = compass.ReadScaledAxis();
 
  // Values are accessed like so:
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2(scaled.YAxis, scaled.XAxis);
 
  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
  // Find yours here: http://www.magnetic-declination.com/
  // Mine is: 2� 37' W, which is 2.617 Degrees, or (which we need) 0.0456752665 radians, I will use 0.0457
  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
  float declinationAngle = 0.55;
  heading += declinationAngle;
 
  // Correct for when signs are reversed.
  if(heading < 0)
    heading += 2*PI;
   
  // Check for wrap due to addition of declination.
  if(heading > 2*PI)
    heading -= 2*PI;
   
  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180/M_PI;

  // Output the data via the serial port.
  //Output(raw, scaled, heading, headingDegrees);

  // Normally we would delay the application by 66ms to allow the loop
  // to run at 15Hz (default bandwidth for the HMC5883L).
  // However since we have a long serial out (104ms at 9600) we will let
  // it run at its natural speed.
  // delay(66);
 
  timer = millis(); //get a start value to determine the time the loop takes
  getAccelerometerReadings(accelResult);
 
  pitchAccel = atan2((accelResult[1] - biasAccelY) / 1024, (accelResult[2] - biasAccelZ) / 1024) * 360.0 / (2*PI);
  rollAccel = atan2((accelResult[0] - biasAccelX) / 1024, (accelResult[2] - biasAccelZ) / 1024) * 360.0 / (2*PI);
 
  //---------------Tilt Compensated Begin----------------------------------------
 
  pitchAccelXh = atan2((accelResult[1] - biasAccelY) / 1024, (accelResult[2] - biasAccelZ) / 1024);
  rollAccelYh = atan2((accelResult[0] - biasAccelX) / 1024, (accelResult[2] - biasAccelZ) / 1024);
 
  //pitchAccelXh = constrain(pitchAccelXh, -1.57, 1.57);
  //pitchAccelXh = map(pitchAccelXh, -3.14, 3.14, 0, 6.28);
 
  //rollAccelYh = constrain(rollAccelYh, -1.57, 1.57);
  //rollAccelYh = map(rollAccelYh, -3.14, 3.14, 0, 6.28);
 
  float cos_roll= cos(rollAccelYh);
  float sin_roll = sin(rollAccelYh);
  float cos_pitch = cos(pitchAccelXh);
  float sin_pitch = sin(pitchAccelXh);
 
  XM = scaled.XAxis;
  YM = scaled.YAxis;
  ZM = scaled.ZAxis;
 
  // The tilt compensation algorithem.
  Yh = YM * cos_roll - ZM * sin_roll;
  Xh = XM * cos_pitch + YM * sin_roll * sin_pitch + ZM * cos_roll * sin_pitch;
 
  realHeading = atan2(-Yh, Xh) * 360.0 / (2*PI);
 
  //--------------------Tilt Compensated End--------------------------------------
 
   Serial.print(pitchAccel);
   Serial.print("  pitch \t");   
   Serial.print(rollAccel);
   Serial.print("  roll \t");
   
   //Serial.print(pitchAccelXh);
   //Serial.print("  pitchXH ");   
   //Serial.print(rollAccelYh);
   //Serial.print("  rollYH");
   
   //Serial.print(raw.XAxis);
   //Serial.print("RawX:\t");
   //Serial.print("   ");   
   //Serial.print(raw.YAxis);
   //Serial.print("   ");   
   //Serial.print(raw.ZAxis);
   //Serial.print("   \tScaled:\t");
   
   //Serial.print(scaled.XAxis);
   //Serial.print("  X ");   
   //Serial.print(scaled.YAxis);
   //Serial.print("  Y ");   
   //Serial.print(scaled.ZAxis);
   //Serial.print("  Z ");

   Serial.print(realHeading);
   Serial.print(" DegreeReal  \t");
   
   Serial.print(headingDegrees);
   Serial.println(" Degrees   \t");
   
   delay(200);
   
  //timer = millis() - timer;          //how long did the loop take?
  //timer = (timeStep * 1000) - timer; //how much time to add to the loop to make it last time step msec
  //delay(timer);                                    //make one loop last time step msec
 
}



56  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 08, 2013, 07:46:18 am
Any Idea?
57  Using Arduino / Sensors / Re: Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 06, 2013, 06:54:26 am
I have try those one, but not working. It is working for you?
58  Using Arduino / Sensors / Magnetometer Tilt Compensation for Yaw Axis Using HMC5883L and BMA180 on: March 06, 2013, 05:54:17 am
Hi, i want to make yaw Axis for my 3 Axis Gimbal project, but i really confused to solve the magnetometer tilt compensation. I use HMC5883L magnetometer and BMA 180 Accelerometer. From the reference that i found on the internet, i need magnetometer and accelerometer to solve Magnetometer Tilt Compensation. Anda i found this algorithm from https://code.google.com/p/sf9domahrs/:

CMx = mag_x*cos(pitch) + mag_y*sin(roll)sin(pitch) + mag_z*cos(roll)sin(pitch)
CMy = mag_y*cos(roll) - mag_z*sin(roll)

MAG_Heading = Atan(CMy/CMx)

So, i applying the algorithm to my sketch:

Code:
pitchAccelXh = atan2((accelResult[1] - biasAccelY) / 1024, (accelResult[2] - biasAccelZ) / 1024); //Accelerometer Pitch Degrees in radian
  rollAccelYh = atan2((accelResult[0] - biasAccelX) / 1024, (accelResult[2] - biasAccelZ) / 1024); //Accelerometer Roll Degrees in radian
  
  float cos_roll= cos(pitchAccelXh);
  float sin_roll = sin(pitchAccelXh);
  float cos_pitch = cos(rollAccelYh);
  float sin_pitch = sin(rollAccelYh);
  
  float mag_X = scaled.XAxis;  //magnetometer X Axis
  float mag_Y = scaled.YAxis;  //magnetometer Y Axis
  float mag_Z = scaled.ZAxis;  //magnetometer Z Axis
  
  // The tilt compensation algorithem.
  Yh = mag_Y * cos_roll - mag_Z * sin_roll;
  Xh = mag_X * cos_pitch + mag_Y * sin_roll * sin_pitch + mag_Z * cos_roll * sin_pitch;
  
  realHeading = atan2(Yh, Xh) * (360.0 / (2*PI));

But it didn't works, it is still like just use magnetometer without accelerometer, but different in data value.
Anybody know about the right algorithm for Magnetometer Tilt Compensation?

Thank You..
59  Using Arduino / Programming Questions / Interrupt Program on: March 03, 2013, 12:53:23 pm
Hi, i want to make 3 axis gimbal using arduino. I use 3 servo motor and multiwii board to control the stabilization. So far i success to stabilized all of three axis. But, i want to make additional feature to this system, the manual control. So, when the stabilized system active, i can interrupt the program with the manual control of servo too, and the system can detect the last position of manual control of servo, then stabilized the last position.

How can i do that?

Thank you..
60  Using Arduino / Sensors / How to Read Yaw Axis with IMU? on: February 27, 2013, 01:31:20 am
Hi, how to make 3 axis gimbal, but i have a proble in yaw Axis. How to read yaw Axis from IMU? I can read it from Gyro, but not with accelerometer. Am i must use Magnetometer to read yaw axis?

Thank You..
Pages: 1 2 3 [4] 5