need help to explain of: Vector norm = compass.readNormalize();

Hi,
I saw this "Vector norm = compass.readNormalize();" in many code of HMC5883L, I didn't find an explanation about, need help please.
Thanks
Adam

Vector is a type declaration for a vector, in this case with three components (x, y, z).

Normalized means should mean that the vector has length = sqrt(x2 + y2 + z2) equal to 1.

It's probably an over load of the 'operator=' function. Post a link to the library's GitHub.

EDIT:
Actually, it looks like it's simpler than I thought. No overload required. Google search found this, guess it's the library that you didn't specify: GitHub - jarzebski/Arduino-HMC5883L: HMC5883L Triple Axis Digital Compass Arduino Library

VECTOR is just a struct:

struct Vector
{
    float XAxis;
    float YAxis;
    float ZAxis;
};

And, readNormalize() returns a VECTOR:

Vector HMC5883L::readNormalize(void)
{
    v.XAxis = ((float)readRegister16(HMC5883L_REG_OUT_X_M) - xOffset) * mgPerDigit;
    v.YAxis = ((float)readRegister16(HMC5883L_REG_OUT_Y_M) - yOffset) * mgPerDigit;
    v.ZAxis = (float)readRegister16(HMC5883L_REG_OUT_Z_M) * mgPerDigit;

    return v;
}

'v' is a private member of type VECTOR.

I see. Contrary to what most sensible people would assume, the function named readNormalize() does NOT normalize the returned vector. How clever!

The function is also wrong, because it does not provide for subtracting a Z offset.

Find a better library.

jremington:
Vector is a type declaration for a vector, in this case with three components (x, y, z).

Normalized means should mean that the vector has length = sqrt(x2 + y2 + z2) equal to 1.

gfvalvo:
It’s probably an over load of the ‘operator=’ function. Post a link to the library’s GitHub.

EDIT:
Actually, it looks like it’s simpler than I thought. No overload required. Google search found this, guess it’s the library that you didn’t specify: https://github.com/jarzebski/Arduino-HMC5883L

VECTOR is just a struct:

struct Vector

{
   float XAxis;
   float YAxis;
   float ZAxis;
};




And, readNormalize() returns a VECTOR:


Vector HMC5883L::readNormalize(void)
{
   v.XAxis = ((float)readRegister16(HMC5883L_REG_OUT_X_M) - xOffset) * mgPerDigit;
   v.YAxis = ((float)readRegister16(HMC5883L_REG_OUT_Y_M) - yOffset) * mgPerDigit;
   v.ZAxis = (float)readRegister16(HMC5883L_REG_OUT_Z_M) * mgPerDigit;

return v;
}




'v' is a private member of type VECTOR.

Thank you.
Solved my quandary。
Best.

jremington:
I see. Contrary to what most sensible people would assume, the function named readNormalize() does NOT normalize the returned vector. How clever!

The function is also wrong, because it does not provide for subtracting a Z offset.

Find a better library.

Thanks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.