Sensor Fusion, MCUXPresso

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sensor Fusion, MCUXPresso

1,963 Views
a8Chcx
Contributor V

Hi,

I am using FRDM-K64F and FRDM-FXS-MULTI2-B to do sensor fusion.

I am using MCUXpresso 11.5.0 and SDK 2.10.0.

I can see all library and project "main_baremetal" are there...

When I try to use "import SDK sample project", I can't find it?

Can anybody tell me how to import this project in MCUXpresso and I can test it with Fusion tool box?

Thanks,

Christie

0 Kudos
17 Replies

1,951 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

Could you help me check the SDK builder here: Select Board | MCUXpresso SDK Builder (nxp.com), and search for the board you are using (K64F), then click on build SDK.

In the next menu, you can select all the middleware available, or just make sure you have the sensing IoT checked:

Julin_AragnM_0-1659973740414.png

After this, install it in MCUXpresso and you should have the project examples available under "frdmk64f mult2b" and under "sensors".

Hope you find this helpful!

Best regards, Julián. 

0 Kudos

1,948 Views
a8Chcx
Contributor V

Hi Julian,

 

Yes. I put SDK 2.10.0 into MCUXPresso and I can see the project under ...\SDK_2_10_0_FRDM-K64F\boards\frdmk64f_mult2b\issdk_examples\algorithms\sensorfusion\baremetal_mult2b

But, when I use "import SDK Example(s)", I can't see this project?

Can you tell me how to import it because I want to copy all related files and this project becomes independent?

Thanks,

Christie

0 Kudos

1,944 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx

If you have installed the SDK into MCUXpresso already, you should follow these steps below:

Julin_AragnM_0-1659974979678.png

Click "Import SDK example(s)..."

Julin_AragnM_1-1659975098770.png

Select the kit "frdmk64f_mult2b"

Julin_AragnM_2-1659975151241.png

Under "issdk" and "algorithms" is the project "sensorfusion_bm_mult2b"

Julin_AragnM_3-1659975389661.png

After these steps, you should have the project imported and ready to use.

If, by any chance, you still can't seem to import it, please update the SDK to version 2.11 and try again.

Best regards, Julián

0 Kudos

1,942 Views
a8Chcx
Contributor V

Hi Julian,

Thanks. I have to select K64F+Multi...

Another question:

Based on NED definition:

ACC is +1g when axis is down, -1g when axis is UP.

GYRO: Increase when in clockwise.

MAG: What is definition for MAG? I can't find in document...

Why need to apply the following for NED? 

Thanks,

Christie

 

void ApplyAccelHAL(struct AccelSensor *Accel)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Accel->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Accel->iGsFIFO[i][CHX];
Accel->iGsFIFO[i][CHX] = Accel->iGsFIFO[i][CHY];
Accel->iGsFIFO[i][CHY] = itmp16;
#endif // NED
#if THISCOORDSYSTEM == ANDROID
Accel->iGsFIFO[i][CHX] = -Accel->iGsFIFO[i][CHX];
Accel->iGsFIFO[i][CHY] = -Accel->iGsFIFO[i][CHY];
#endif // Android
#if (THISCOORDSYSTEM == WIN8)
Accel->iGsFIFO[i][CHZ] = -Accel->iGsFIFO[i][CHZ];
#endif // Win8

} // end of loop over FIFO count

return;
}

// function applies the hardware abstraction layer to the magnetometer readings
void ApplyMagHAL(struct MagSensor *Mag)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Mag->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Mag->iBsFIFO[i][CHX];
Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHY];
Mag->iBsFIFO[i][CHY] = -itmp16;
Mag->iBsFIFO[i][CHZ] = -Mag->iBsFIFO[i][CHZ];
#endif // NED
#if THISCOORDSYSTEM == ANDROID
Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
#endif // Android
#if THISCOORDSYSTEM == WIN8
Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
#endif
} // end of loop over FIFO count

return;
}

// function applies the hardware abstraction layer to the gyro readings
void ApplyGyroHAL(struct GyroSensor *Gyro)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Gyro->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Gyro->iYsFIFO[i][CHX];
Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHY];
Gyro->iYsFIFO[i][CHY] = -itmp16;
Gyro->iYsFIFO[i][CHZ] = -Gyro->iYsFIFO[i][CHZ];
#endif // NED
#if THISCOORDSYSTEM == ANDROID
Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
#endif // Android
#if THISCOORDSYSTEM == WIN8
Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
#endif // Win8

} // end of loop over FIFO count

return;
}

 

0 Kudos

1,938 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

MAG refers to the Magnetometer included in the board:

It can be used in conjunction with a 3-axis accelerometer so that orientation-independent accurate compass heading information may be achieved.

Best regards, Julián

0 Kudos

1,934 Views
a8Chcx
Contributor V

Hi Julian,

Based on ACC definition for NED:

Do you think that X_acc=(-1)*Y_acc, Y_acc=(-1)*X_acc, and Z_acc=(-1)*Z_acc?

For MAG, it matches the definition because when X up, X-mag is MAX and X down, X_mag is MAX...

Thanks,

 

Christie

 

0 Kudos

1,931 Views
a8Chcx
Contributor V

Hi Julian,

 

I can compile and download the project to the board.

Can you tell me how to connect to Sensor Fusion toolbox on Windows?

I just have P&E USB multilink cable and do not have BlueTooth. Do I need to use another cable to connect to the board?

Thanks,

Christie

0 Kudos

1,910 Views
a8Chcx
Contributor V

Hi Julian,

It works fine after I put J27, J28 jumper to 2&3 instaed of 1&2.

Now, the 9-axes fusion is based on FXO8700 and FXAS21002 with NED frame.

Can you explain to me why need to use the above applyXXXHAL for NED?

I can understand that need to switch X and Y. But, sign is confused for me...

Thanks,

Christie

0 Kudos

1,879 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

I'm sorry for the confusion, but I don't really understand the question, could you explain into further detail?

If you have any doubts or questions about the Sensor Fusion Kit, you can check the User Guide attached to the page below:

NXP® Sensor Fusion | NXP Semiconductors

There is every explanation, from vocabulary, 3-axis tilt/rotation, etc in chapter 2 of this User Guide (Sensor Fusion topics and options).

Hope you find this helpful!

Best regards, Julian
  

0 Kudos

1,875 Views
a8Chcx
Contributor V

Hi Julian,

Based on FRDM-K64+FXS_MULT2-B with latest fusion, in demo project, did the following conversions for NED:

void ApplyAccelHAL(struct AccelSensor *Accel)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Accel->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Accel->iGsFIFO[i][CHX];
Accel->iGsFIFO[i][CHX] = Accel->iGsFIFO[i][CHY];
Accel->iGsFIFO[i][CHY] = itmp16;
#endif // NED

} // end of loop over FIFO count

return;
}

// function applies the hardware abstraction layer to the magnetometer readings
void ApplyMagHAL(struct MagSensor *Mag)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Mag->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Mag->iBsFIFO[i][CHX];
Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHY];
Mag->iBsFIFO[i][CHY] = -itmp16;
Mag->iBsFIFO[i][CHZ] = -Mag->iBsFIFO[i][CHZ];
#endif // NED

} // end of loop over FIFO count

return;
}

// function applies the hardware abstraction layer to the gyro readings
void ApplyGyroHAL(struct GyroSensor *Gyro)
{
int8 i; // loop counter

// apply HAL to all measurements read from FIFO buffer
for (i = 0; i < Gyro->iFIFOCount; i++)
{
// apply HAL mapping to coordinate system used
#if THISCOORDSYSTEM == NED
int16 itmp16 = Gyro->iYsFIFO[i][CHX];
Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHY];
Gyro->iYsFIFO[i][CHY] = -itmp16;
Gyro->iYsFIFO[i][CHZ] = -Gyro->iYsFIFO[i][CHZ];
#endif // NED
} // end of loop over FIFO count

return;
}

 

My questions:

1) Switch X and Y for NED. I understand this. I check sensor reading, when axis is UP, it 1g, when axis down, it is -1g. Why do not switch X,Y, Z to (-1) because NED down is positive?

2) For Gyro, check the sensor reading, it is positive if I follow right-hand. It switches to (-1) on X,Y,X because right-hand rule is opposite to clockwise definition?

3) For MAG, I check sensor reading, when axis is UP, it is MIN, when axis down, it is MAX. It did switch X,Y, Z to (-1) because NED down is positive for MAG?

 

Thanks,

Christie

0 Kudos

1,869 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx

Please refer to chapter 5.3 (Frames of reference and the HAL), as it explains the behaviour you are having doubts about. 

Julin_AragnM_0-1660237296063.png

Julin_AragnM_1-1660237368307.png

You can find the User Guide here: NXP Sensor Fusion - NXP Sensor Fusion for Kinetis MCUs. Hope you find this useful, if you have any other doubts, please feel free to ask.

Best regards, Julian

 

0 Kudos

1,867 Views
a8Chcx
Contributor V

Hi Julian,

I read this many times and still not sure:

Based on NED, when axis point down, ACC reading should be positive, right? NXP fusion definition is opposite to NED definition?

But for MAG, when axis point down, MAG reading should be MAX, right?

There is no MAG definition in document...Can you tell me where I can find it?

Thanks,

Christie

 

0 Kudos

1,852 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

Yes, when axis is pointing down, acc should be positive. Only the MAG3110 sensor is inverted in it's z axis, that is why in the drivers, sample CHZ is negative, to compensate this behaviour.

Yes, you are correct: When pointing the axis down, the reading should be maximum.

Best regards, Julian

0 Kudos

1,850 Views
a8Chcx
Contributor V

Hi Julian,

I think MAG is *(-1) for FX8700 MAG, not for MAG3110.

For MAG3110, it should keep as it is because Z axis is opposite already.

I am confused with ACC because ACC points down, it always read -1g, not 1g.

EX. when flat, ACC on Z is 1g. Why not to do (-1) conversion that it is the same as MAG?

 

Thanks,

Christie

 

0 Kudos

1,847 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

A sensor flat should read +1g, as it is only reading Earth's gravity, and the other two axes should read 0;

Julin_AragnM_1-1660322350113.png

You can also refer to this note (Implementing a Tilt-Compensated eCompass using Accelerometer and Magnetometer Sensors (nxp.com)), at chapter 2, where it is showing the final revisions while implementing an accelerometer and magnetometer in a PCB:

"The z-axis accelerometer should read +1g and the x and y axes
negligible values. Invert the PCB so that the z-axis points upwards and verify that the z-axis
accelerometer now indicates -1g."

If your application needs the contrary behaviour, you can implement that yourself in code, by just negating the axis.

Hope you find this useful!

Best regards, Julian

0 Kudos

1,844 Views
a8Chcx
Contributor V

HI Julian,

That is what confused to me.

When flat, Z is pointing UP and reading is 1g. The same for X and Y because I tested the raw data reading.

But, in fusion project, it didn't do *(-1), why?

Based on NED definition, pointing DOWN, it should positive, right?

Thanks,

Christie

0 Kudos

1,827 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @a8Chcx,

When flat, the z-axis is pointing downwards, which is why the board or the value is +1g. When inverting the board, or any other PCB, the z-axis will point upwards, which will indicate a -1g.

Best regards, Julian

0 Kudos