Quadcopter on a rig to test control algorithm and gain
Quadcopter
The airframe of my VTOL dream. It was never complete. Perhaps one day.
I've always had a fascination for flight, so when I was in sophomore year of college and wanted to get my hands dirty with something other than problem sets, I decided to pick up a cool project on my own. But I wanted to make it really, really cool - so made a ambitious plan of making a vertical lift-off and landing (VTOL) RC plane with thrust vectoring and no control surfaces. I'd never even flown a RC plane or quadcopter before then, and had only heard of the name "Arduino", but this seemed like a good challenge at the time.
I chugged along and made the airframe for a tilt-rotor quadcopter with wings. I read some books and figured out how to make an airfoil with a laser cutter and some balsa. I got the propellers spinning, servos moving to the motors, but I still hadn't figured out one thing: How will this craft fly stably as a quadcopter? I had no idea. This is where my journey to program a quadcopter truly began.
Things I needed to Learn
- How to use an Arduino
- How hobby RC electronics talk to each other
- How to make an attitude-heading reference system (AHRS)
- How to reach stable flight
It seems like a short list, but given that I had just started taking engineering classes, I had a long way to go. #1 and #2 were relatively easy - there were tutorials and forums online, so it wasn't too difficult. Just a lot of online research trial and error got me a good enough understanding of how things work.
#3 and #4 of the list were the difficult parts. And because they're difficult, nobody does tried to do it on their own, which made it even more difficult. Hobbyists typically bought flight controllers that are pre-programmed to do these tasks. But I was interested in learning how navigation and controls work, so I went ahead and decided to reinvent the wheel.
Attitude-Heading Reference System
The AHRS is used to compute out the quadcopter's yaw, pitch, and roll in real-time. The most difficult part of the AHRS was the sensor fusion of the gyro and accelerometer to maintain a fast time-response and eliminate long-term drift. Gyros have great time-response, but the it slowly drifts over time. On the other hand, accelerometers can sense the acceleration due gravity, but it also senses acceleration due to motion, so it is not very reliable unless it is averaged over a long period of time. And all of this sensor fusion happens in 3 dimensional rotation, so it was not easy for me to wrap my head around everything.
Thankfully, there was a paper that spelled out everything for me so that I could understand and code it. The paper Direction Cosine Matrix IMU: Theory by Premerlani and Bizard explained how to implement the complementary filter using 3D rotation matrices. Basically, the algorithm uses the angular velocity data from the gyro to update the angle at every time-step, but also incorporates a fictitious angular velocity that tries to align the z-axis to the direction of the acceleration (which is usually gravity).
Stable Flight
At the point in my engineering studies, I had not taken a controls class so I had very little idea how controls worked. My intuition told me I should do a proportional controller, and I did one, but the quadcopter came crashing down every time it took off. I read more, and I tried doing a PID controller. it turns out that a PID controller works if you are trying to control the roll rate or pitch rate, but not the roll angle or the pitch angle. After lots of trial and error I "cheated" by looking at the code for a established flight controller. I added second derivative term, and it started flying stably!