C code for ICM-20948 9DOF IMU
Spent way too much time on this...
Was intrigued by this IMU because it has a built in FPGA that does the work of sensor fusion and generating a game rotation vector.
The attached is working for the most part over SPI interface.
The output looks like this when you start it up:
{"quat_w":0.997885, "quat_x":-0.061911, "quat_y":0.013995, "quat_z":-0.013535}
The one thing I haven't been able to fix is that the quat_x value isn't as close to zero as it should be...
The original code is here:
https://github.com/ZaneL/Teensy-ICM-20948/tree/master
And it works with his web viewer here:
https://github.com/ZaneL/quaternion_sensor_3d_nodejs
Here's what it looks like before you move it (attached).
Annoyingly that -.06 offset causes there to be a slight initial x axis rotation that I haven't figured out how to get rid of.
Anyway, after a lot of time put into this, I'm not sure it's worth it...
I thought it might be able to track x,y,z position. Seems to be cabable of it, but the FPGA data provided here doesn't seem to do it. That would make it worth it if it worked...
So, this seems like a lot of code and used up memory for not much help for my robot project.
But, we'll see, maybe I'm wrong about that...
Comments
There's an error mode that had to get around... I this mode the initial error is much worse than described above and the movement is sorta right but way off.
Interestlingly, the Sparkfun version of the code also shows this mode when used with the Teensy 4.1.
Anyway, the solution for P2 seems to need two things, for reasons I don't really understand.
First, you need an initial delay of around a second before talking to the chip.
Then, the code tries to program the FPGA twice, but the second attempt is ignored. I had to override that so it is programmed twice. No idea why these are needed, but seem to here.
ah yes, I looked at this unit in January just to see if was any good.
I wrote a driver for it and then seen that the FPGA code was only given in binary and to load it was a pain.
I finally gave up on it as it was too cryptic and there are two other units that work so much better than this one does.
It's fine if you just want to read each of the IMU's and create your own fusion.
Mike
There's a lot of potential there, but most of it doesn't seem to be supported by the FPGA code we're given.
I don't even think it uses the magnetic field sensor at all...
Guess it is using the gyros, it is pretty good at that.
I seem to have a problem with the initial calibration. I think the FPGA code is doing that and have no idea why it's slightly off in X axis rotation...
Here's my little breadboard setup. Started with the Teensy 4.1 to have a working example.
Tried to share SPI bus with Teensy, but couldn't get that going...
Seems like should be able to configure with Teensy and then hand off to P2 for testing, but didn't work for some reason...
One thing that is useful is ZaneL viewer. Very simple interface.
I'm going to have to try that with the quaternion code we have for another 9DOF chip...