My Flight Data Recorder

by Octapoo

Saturday, October 10, 2020 at 21:45:00 UTC

Return to the Summary in Ecstatic Lyrics Blog

So I made this thing...

The idea here is to record GPS and Gyroscope data while the plane is flying, and video too, so that I can bring it home, write some code to take the gyroscope and GPS data and calculate where the plane is and how it is oriented, and then compare the output of that code to the video of the flight to see if they agree, and thus test how the code performs in-flight without actually putting the code on a plane. I've already flown it so tomorrow (I'm about to go to sleep now) I'll begin working on processing the data.

At first I was just going to buy a flight controller because there are cheap clones on eBay, but I was doing research (watching YouTube) and one video that came up was about an error message in the software that says the board is "retired." Apparently they stopped supporting that board and switched to a more expensive one. ...and apparently they're thinking about no longer supporting that one too. Meanwhile the first one apparently did what people wanted just fine, and you can still use it, just not with the latest version of the software.

I just thought that was kind of dumb, and that led me to thinking about other things, like how in all of the rctestflight videos I watched where he used it, he always had one problem or another with it. In particular, it was never happy with his compass calibration, but perhaps worse, he'd often try to switch the plane into "return to home" mode or some other automated mode only to have it refuse to do so and he never seemed to really know why it was refusing the command. So that got me to thinking that maybe I should just write my own software.

So then I considered buying one of those cheap flight controllers just for the hardware, but I looked it up and it's an ATmega2560 with seemingly nothing else to help it along, it's just a single CPU. ...and that seems like the wrong approach to me. I've always said that the best thing about small microcontrollers like the ATmega328 is that they're small and cheap so you can use several if you need to, and though I've never actually done that, I think this might be the time to do it.

What I need to do is receive control data from the radio receiver, which is serial, probably I'll want to send sensor data back to the transmitter, which is also done over serial. Then the GPS is serial. There's also these "telemetry radios" you can get so that the flight controller can communicate with a laptop on the ground, and they also use serial. So do I buy a more expensive microcontroller so that I have four serial ports, and deal with it being a surface-mount chip and all of the hassle that comes with that, or do I just use four ATmega328 and have them communicate with each other over SPI, which costs less and gives me a combined 80 MHz of CPU power? It seems like an easy choice to me.

So my plan is to use one ATmega328 to receive the data from the radio receiver, another to receive GPS and Gyroscope data and calculate the plane position and orientation, another to read data from both of those chips and do the actual flight controlling and communication over the "telemetry radio," and a fourth which receives data from that third chip and outputs the many PWM signals that control the servo motors. I think I can just make them all communicate over SPI. One advantage of this approach is that I can use either the Arduino library or just avr-gcc alone to write the code on one chip and then use assembly code on another if I think it's appropriate. To get the best timing I'll probably want assembly on the PWM output chip, but for writing a flight controller, floating point math would be very useful and trying to do that in assembly would be a nightmare.

For testing, I plan to modify the source for the flight simulator I've been using so that it outputs fake GPS and gyroscope data, feed that into the actual hardware I plan to use, let it do it's thing, and then whatever it says to do, give that input to the flight simulator, and see what happens. In that way I can crash a thousand planes if I have to, and do some testing where I mess with the controls for a couple of seconds just to make sure it's able to recover when I stop, or just constantly mess with it's control to simulate bad flying conditions, and thus make sure I don't just have code that works when everything is perfect but fails the moment anything goes wrong.


If you were logged in, there would be a comment submission form here.
Creating an account is easy. You literally just type in a name and a password.
I don't want your email address, so there won't be any links in any emails to click.

Return to the Summary in Ecstatic Lyrics Blog