Hello,
I am trying to use the FRDM-SFUSION kit with the k64f MCU to do some motion sensing. However, I am having a little trouble understanding exactly how to implement the functions that are provided. What I want to do is grab linear acceleration data in NED coordinates. I think I need to use the fRun_9DOF_GBY_KALMAN function on line 1090 of the fusion.c file. In this function (lines 1519-1513) is see this
// gravity positive NED
pthisSV->faGlPl[X] = -pthisSV->faGlPl[X];
pthisSV->faGlPl[Y] = -pthisSV->faGlPl[Y];
pthisSV->faGlPl[Z] = -(pthisSV->faGlPl[Z] - 1.0F);
break;
With a comment above saying:
// compute the linear acceleration in the global frame from the accelerometer measurement (sensor frame).
// de-rotate the accelerometer measurement from the sensor to global frame using the inverse (transpose)
// of the a posteriori rotation matrix
It seems to me that this is the code that I am looking for. My problem is that there are a lot of inputs to this function, and I am not sure what all of them mean. Here is the entire function that I am trying to call.
void fRun_9DOF_GBY_KALMAN(struct SV_9DOF_GBY_KALMAN *pthisSV, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, struct GyroSensor *pthisGyro,
struct MagCalibration *pthisMagCal, int16 ithisCoordSystem, int16 iOverSampleRatio)
I am wondering if someone could just give me an example of how to call this function. Again, I am using the NED coordinates, and don't care about over sampling.
Also, once I have called this function, would assigning the values look something like this?
accx = SV_9DOF_GBY_KALMAN.faGlPl[X]
已解决! 转到解答。
In user_tasks.c just add these lines to tell your file about the 9 axis sensor fusion structure:
#include "build.h"
#include "types.h"
before the line:
#include "mqx_tasks.h"
I did find the change to CHX, CHY and CHZ. I made those changes that that fixed part of the problem. But I am still getting an error that says "invalid use of undefined type 'struct SV_9DOF_GBY_KALMAN'" I am not sure what I need to do to fix this. I have looked at the other sources and it seems like they call this structure the same way, but I am only getting this error for the code I have written in the user_tasks.c
Again, my code looks like this.
// PUT YOUR CODE HERE
accx = thisSV_9DOF_GBY_KALMAN.fAccGl[CHX];
accy = thisSV_9DOF_GBY_KALMAN.fAccGl[CHY];
Description Resource Path Location Typeinvalid use of undefined type 'struct SV_9DOF_GBY_KALMAN' user_tasks.c /FSFK_K64F/Sources line 146 C/C++ Problem
Thanks this got it working!
Although this doesn't worry me too much, for some reason after awhile all of the blue led files are not being built. This is not essential to what I am trying to do, but seems strange. The red and green files are still being built, just not the blue. Any ideas why?
We never used the Blue LED in the V4 code so we deleted it in Processor Expert for V5. You've got some legacy files from V4 in the your Generated_Code folder. Delete that folder and then re-generate all files from Processor Expert and you'll see the Blue LED files have gone.
First, may I suggest you download the Version 5.00 library from freescale.com/sensorfusion? We like it a lot more than the 4.22 library, which is what you are using. The new version has better convergence properties.
Next, I think you are overthinking it. Since you are using the K64F board, you can use the prebuilt project and simply read the values you want out of the global data structures after the fusion call. You are going to want to read it like this:
float accx = thisSV_9DOF_GBY_KAL.fAccGl[X];
Put that call at the bottom of UserMediumFrequencyTaskRun() inside user_tasks.c and you should be good to go.
If you want to see how the Kalman function is called, look at Fusion_task() in mqx_tasks.c.
I downloaded the KDS 5.0 as you suggested. I am curious though because the library says FSFK K64F, but this board is the FRDM K64F. This doesn't seem to be a problem though. I am getting an error during building.
I did manage to get rid of X and Y being undeclared by changing the to 1 and 2. But I couldn't find this anywhere else in the code. Do you know if these correspond? Also, here is the code that I dropped into the UserMediumFrequencyTaskRun()
// PUT YOUR CODE HERE
accx = thisSV_9DOF_GBY_KALMAN.fAccGl[X];
accy = thisSV_9DOF_GBY_KALMAN.fAccGl[Y];
The FRDM*** projects are simplified versions that run on the Freedom boards using the sensors available on that Freedom board. The FSFK*** are the full versions that require the MQX-Lite RTOS and require the gyroscope sensor available on shield boards to run the most sophisticated algorithms.
We changed the compile time constants X, Y, X to CHX, CHY, CHZ (with the same values 0, 1, 2) to avoid conflict with Processor Expert which was also using those same names. So just change your previous references in your code to X, Y, Z to CHX, CHY, CHZ.