I’ve spent two days and around 12+ hours writing and rewriting code for this infernal gyroscope and I’m still not happy with what I have. I want to use a gyroscope to calculate orientation based off the measured angular velocities.
Im building a multirotor. All the code is ready to be tested, and the hardware purchased. I just need to get this stupid gyroscope to give me good values, then i’ll be ready to begin flight testing.
Things I know, that you dont need to tell me:
“orientation is usually calculated with an accelerometer too (accel + gyro = IMU).”
I know. But with rotation matrices, high precision gyroscopes and 1000 samples a second, you should be able to get a pretty dang good reading from just a gyro. Then I can combine that with some controller tuning to get it hovering at least.
“Gyroscopes are temperature sensitive”
I’m aware of this too, and if youve noticed I added a function to read the temperature value. Unfortunately I havent been able to map the offset drift to the temperature, or find information online for the ITG-3200’s tendencies. Now if you tell me how to make the adjustments THEN youre really being helpful.
I have checked http://www.arduino-projects4u.com/itg3200/ and while their library/code is alot neater than mine, I actually feel like my program’s output is more filtered than theirs.
Contains a two moving average filters (recent values are stored into constantly updated arrays to be averaged, and the length of those arrays are easily adjustable. Mine are set to the last 5 values).
Calculates the variance of the data in the moving average filter arrays and sets it as a dynamic tolerance/sensitivity, but deactivates variance calculation when the gyro is in motion.
Contains (un-debugged) code for 3x3 rotation matrix conversions to actually calculate 3D rotations (Though it is currently commented out) and a simple linear integration function has been used in the mean time for debugging.
Time delay. can be remedied by playing with the timing and length of the Moving Average Filters (MAF) at the cost of sensitivity.
Not measuring sudden rotations well.
I went pretty deep with the rotation matrices and MAFs and variance calculations but I’m not a very good programmer. Most of what I know is self taught and adapted from other people’s code. On top of that, I’m messy in real life too.
So I apologize in advance for the logical mess that is my thoughts expressed into a computer program.
Any helpful help would be greatly appreciated. But if you’re unsure about this yourself please dont screw me over by giving me guesswork/bad advice. I’m confused and aggravated enough already.
The code is attached.
adapted from Sparkfun ITG-3200 sample code for setup and read commands
adapted from www.euclideanspace.com for rotation matices
Gyroscope_Right_Handed.zip (6.14 KB)