Caros,
Estou com uma dúvida (se calhar é porque não percebo nada disto)
Ando a fazer experiencias com uma bússula e o programa de teste tem uma função definida antes do setup() e todas as outras estão depois do loop().
Existe alguma razão para isto?
Aqui vai o código:
/code
#include "Wire.h"
#include "HMC5883L.h"
HMC5883L compass; //Copy the folder "HMC5883L" in the folder "C:\Program Files\Arduino\libraries" and restart the arduino IDE.
float xv, yv, zv;
//calibrated_values[3] is the global array where the calibrated data will be placed
//calibrated_values[3]: [0]=Xc, [1]=Yc, [2]=Zc
float calibrated_values[3];
//transformation(float uncalibrated_values[3]) is the function of the magnetometer data correction
//uncalibrated_values[3] is the array of the non calibrated magnetometer data
//uncalibrated_values[3]: [0]=Xnc, [1]=Ync, [2]=Znc
void transformation(float uncalibrated_values[3])
{
//calibration_matrix[3][3] is the transformation matrix
//replace M11, M12,..,M33 with your transformation matrix data
double calibration_matrix[3][3] =
{
{1.454, 0.102, -13.718},
{-0.094, 1.106, -121.059},
{0.081, 0.076, 54.453}
};
//bias[3] is the bias
//replace Bx, By, Bz with your bias data
double bias[3] =
{
69.825,
295.451,
-184.34
};
//calculation
for (int i=0; i<3; ++i) uncalibrated_values = uncalibrated_values - bias*;*
* float result[3] = {0, 0, 0};*
* for (int i=0; i<3; ++i)*
* for (int j=0; j<3; ++j)*
result += calibration_matrix[j] * uncalibrated_values[j];
for (int i=0; i<3; ++i) calibrated_values = result*;*
}
void setup()
*{ *
* Serial.begin(9600);*
* Wire.begin(); *
* compass = HMC5883L(); *
* setupHMC5883L(); *
}
void loop()
{
* float values_from_magnetometer[3];*
* getHeading();*
* values_from_magnetometer[0] = xv;
values_from_magnetometer[1] = yv;
values_from_magnetometer[2] = zv;
transformation(values_from_magnetometer);
_ Serial.flush();_
Serial.print(calibrated_values[0]);
_ Serial.print(",");_
Serial.print(calibrated_values[1]);
_ Serial.print(",");_
Serial.print(calibrated_values[2]);
_ Serial.println();
delay(100);
}
void setupHMC5883L()
{
compass.SetScale(0.88);_
compass.SetMeasurementMode(Measurement_Continuous);
_}*_
void getHeading()
{
* MagnetometerRaw raw = compass.ReadRawAxis();*
* xv = (float)raw.XAxis;*
* yv = (float)raw.YAxis;*
* zv = (float)raw.ZAxis;*
}
code/
Obrigado por qualquer explicação.