Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Softiron calibration #1

Open
altineller opened this issue Oct 25, 2024 · 0 comments
Open

Softiron calibration #1

altineller opened this issue Oct 25, 2024 · 0 comments

Comments

@altineller
Copy link

altineller commented Oct 25, 2024

Hello,

First of all thank you for your work.

I have some questions namely:

I could not reach the raw values from my sensor, which outputs microTeslas for x,y,z as floats. I created the same csv file, but with floats, and the software did indeed work. The generated offsets are in par with previous software, so would providing microteslas as float be ok and if not, could we derive an int like 100x the microteslas? Is scale a problem.

Secondly:

Does this software calibrate for soft iron errors? It generates offsets, and scale values, but I did not see it generate a matrix for softiron calibration. Or would we need another kind of data such as accel and gyro outputs as well to get soft iron calibration.

How could we apply these values to correct the magnetometer values.

In my code I have a:

float mag_offsets[3] = { 11.88f, 10.51f, -4.02f };

float mag_softiron_matrix[3][3] = {{ 0.986f, 0.003f, -0.005f },
{ -0.001f, 1.021f, -0.006f },
{ -0.005f, -0.006f, 0.966f }};

and to correct I do:

float c_mx = magData.float_x - mag_offsets[0];
float c_my = magData.float_y - mag_offsets[1];
float c_mz = magData.float_z - mag_offsets[2];

mx = c_mx * mag_softiron_matrix[0][0] + c_my * mag_softiron_matrix[0][1] + c_mz * mag_softiron_matrix[0][2];
my = c_mx * mag_softiron_matrix[1][0] + c_my * mag_softiron_matrix[1][1] + c_mz * mag_softiron_matrix[1][2];
mz = c_mx * mag_softiron_matrix[2][0] + c_my * mag_softiron_matrix[2][1] + c_mz * mag_softiron_matrix[2][2];

I understand from generic_implementation.h the following code does the scale correction, but I have not fully understood how it does it.
Does it simply multiply each value by the scale factor?

void apply_scale_correction(std::vector& x, std::vector& y, std::vector& z,
float& scale_x, float& scale_y, float& scale_z)
{
long avg_delta_x = (*std::max_element(x.begin(), x.end()) - *std::min_element(x.begin(), x.end())) / 2;
long avg_delta_y = (*std::max_element(y.begin(), y.end()) - *std::min_element(y.begin(), y.end())) / 2;
long avg_delta_z = (*std::max_element(z.begin(), z.end()) - *std::min_element(z.begin(), z.end())) / 2;
long avg_delta = (avg_delta_x + avg_delta_y + avg_delta_z) / 3;
scale_x = (float)avg_delta / avg_delta_x;
scale_y = (float)avg_delta / avg_delta_y;
scale_z = (float)avg_delta / avg_delta_z;
for (size_t i = 0; i < x.size(); ++i)
{
x[i] *= scale_x;
y[i] *= scale_y;
z[i] *= scale_z;
}
}

Best Regards,
Can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant