| Arduino Forum ::  Members :: mamette
 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.htmlThere 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..
 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.htmlAnd 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.inoI 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 Quote from: michinyon on March 11, 2013, 03:14:40 amYeah, 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.inoI 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 declarationextern float q0, q1, q2, q3; // quaternion elements representing the estimated orientation//---------------------------------------------------------------------------------------------------// Function declarationvoid 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 //----------------------------------------------------------------------------------------------------// 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 definitionsfloat q0 = 1, q1 = 0, q2 = 0, q3 = 0; // quaternion elements representing the estimated orientationfloat 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 periodWahat 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 QuoteYeah, 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 QuoteThe direction of the magnetism is flat at the equator, and pointing down at the poles.http://geokov.com/education/magnetic-declination-inclination.aspxhttp://en.wikipedia.org/wiki/Magnetic_dipThis 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..QuoteThats 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-libraryTo 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 QuoteI 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 aroundthe yaw axis.   It's nothing to do with tilting the yaw axis.Sorry, i mean "tilt compensation for magnetometer"QuoteIf 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-tutorialhttp://diy.powet.eu/2011/03/19/tilt-compensation-azimuth-pitch-le-roll/?lang=enhttps://gist.github.com/timtrueman/322555http://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.