I’m stupid, I did too many changes in attempts to abstract skateboard logic from the IMU without being able to test it out. Having bare electronics with LEDs on it that blink while being 2 miles in the air around “normies” isn’t a good idea.
After 2 hours of debugging, I got this:
That’s right, 200 cycles a second! One interesting thing also is how the gyro data is coming back, it appears to be “reversed” with how I’d imagine it would be.
So what did I do?
The IMU logic is now 100% independent of the skateboard which is where you’d want it. I’ve removed unused / needed members from the ImuData class,
I also reduced the amount of object creation since now I use the ImuData object to process the byte array. Why did I move this you may ask yourself? Other than I wanted to make my life hard by refactoring tons of code, the Imu deals with the gyro, why should the Imu class deal with assigning the bytes to the ImuData class? I can see why someone may disagree with me here, but I think it makes sense so deal with it. hehe
So now I think I’m officially ready to post the Imu classes for the 6DoF v2 IMU in c#. I still want to add in a “loader” that will initialize the IMU. I had something semi working but the new IMU I have has a different style of doing this which instantly broke how I was doing pulling this off. I also want to create a small project with a similar to the Skateboard UI that gives you all the data back from the IMU.
Also by checking if I have to process something, at the worst case scenario, I’ll only gain a few extra ticks for the if statements.
public ImuData GetImuData(double maxX, double maxY, double maxZ)
{
if (!isImuPrimed)
StartImu();
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//41 |01 F0 02 03 02 18 |01 C1 02 07 02 18 |02 00 02 03 02 18 |01 4F |01 63 |01 F0 |02 03 |5A
//A |240 515 530 |449 263 530 |512 515 530 |335 |355 |496 |515 |Z
// |pitch |roll |yaw |X |Y |Z |Bat |
com.DiscardInBuffer();
do
{
while (imuDataArray[imuDataArray.Length - 1] != 0x5A)
{
imuDataArray[0] = 0;
while (imuDataArray[0] != 0x41)
imuDataArray[0] = (byte)com.ReadByte();
while (com.BytesToRead < imuDataArray.Length)
{
}
com.Read(imuDataArray, 1, imuDataArray.Length - 1);
}
data.ProcessData(imuDataArray);
} while (!checkData());
// reverting data
imuDataArray[0] = imuDataArray[imuDataArray.Length - 1] = 0x00;
now = DateTime.Now;
data.ChangeInTime = now.Subtract(lastRead);
lastRead = now;
applyCorrections(maxX, maxY, maxZ);
return data;
}
Checking in now before my brain dies.