After I soldered the board together, it was time for me to test all of the sensors and implement an IMU (inertial measurement unit). The gyro and accelerometer both use I2C communication, so I had to get familiar with the Wire library for the Arduino. I quickly wrote up some test programs for the Arduino to make sure that the communication worked and sure enough it did! The only unintuitive thing I had to do was call endTransmission(false) because the communication didn't want a stop message after querying for the data registers when reading the measurements.
After proving that the sensors worked, I wanted to test my algorithm for measuring orientation. I decided to implement it in Processing for the time being so that I could tweak it without having to reprogram the board. So I wrote a program that simply would send the readings over Serial to the computer to be processed.
For my orientation detection, I use a Kalman filter to integrate the readings from the gyro and accelerometer together to get a better approximation of the board's orientation. For those who don't know, a Kalman filter is a very powerful tool that can be used to combine two different sensors and get a better approximation of your position or orientation than either could do individually. Because of this, Kalman filters are used extensively in localization. Essentially, Kalman filters work by combining two sensors, one that directly measures the information and another that indirectly can be used to correct for errors. So in the case of a quadcopter, where I want to measure the roll, pitch, and yaw of the board, I use the gyroscope to directly measure the angular acceleration. Then through basic kinematics, it is easy to convert these accelerations to angles accurately. However, a problem with the gyroscope is that it drifts making it inaccurate over long periods. Meanwhile, the accelerometer can be used to measure the tilt of the board using the gravitational acceleration. While it doesn't drift over time, it is very noisy because it is sensitive to any other linear motion the board is subjected to. By combining the two, you get the best of both worlds. They gyro provides the immediate, precise readings while the accelerometer corrects for its drift over time.
In my Processing sketch, I query the Arduino for sensor readings and then pass them through a Kalman filter and display the results on my computer. This allows me to test the filter's functionality and tweak the filter parameters. I based my code off of the examples from this forum. I also have attached all of my code below. Enjoy!
Check out my code at: https://sourceforge.net/projects/nanoquad/?source=directory
Post a Comment