It's been a long time since my last post. After becoming a father, it has been increasingly difficult to find the time to continue with my RC hobby. In fact, I've gone flying only a perhaps half a dozen times after my last post.
Plane lost
In my last post I talked about the possibility of implementing an autopilot in my receiver using the AHRS I've been working on. I implemented the autopilot as described in the last post, and tried it out for the first time in December. It didn't seem to work, as the plane would always just turn away and fly west when the autopilot was engaged. I was almost coming in for a landing, when disaster struck. I guess the melting snow shorted out the SPI lines, through which the processor and radio talk. This left me without control, which in turn caused the receiver to go into fail-safe. In this case it meant activating the autopilot. So the plane turned west, flew over a small forest and crashed somewhere. We searched for a couple of hours, but couldn't find the plane.
It wasn't until April this year, after the snow had melted, that some people walking in the woods found my plane and contacted me. The plane was in surprisingly good shape, considering it spent most of the winter outdoors. All the larger mechanical parts were intact, even the propeller wasn't damaged. Two servos were dead, both showing signs of overheating with melted plastic gears inside. I suspect the control surfaces got stuck against something, and the servos were stalling until the battery ran dry. Damage was also caused to the small 808 #11 keychain camera I had on board. It had its USB port ripped out, perhaps due a yank on the power cable as the plane hit a tree. The memory card in the camera was undamaged though. The only other casualty in the end was the flight battery.
I carefully washed and dehumidified all the electronics I had on board, and to my surprise all of them came back to life. In the future, I plan to put a
conformal coating on all of my electronics. This should not only protect against glitches due to water seeping in, but also prevent corrosion in the case the electronics do have to spend some time exposed to the elements.
I put the video from the camera on YouTube:
two last minutes of the flight and
whole flight with telemetry.
Air crash investigation
So the primary cause of the crash was the lost radio connection, and I could deduce that the problem was at the plane end. But why didn't the autopilot work? Why did the plane fly west? I suspected a programming error, so I started going through the autopilot code. However, I couldn't find any problems there. I soon realized that the telemetry I had recorded on my laptop before the radio failure, contained most of the parameters the autopilot based its decisions on. The only parameters it didn't include were the home coordinates the plane was flying toward.
I set up a simulation. I took a guess that the home coordinates were the first coordinates the telemetry contained. This is how the code should have worked. The first valid GPS fix after power on was supposed to be set as the home location. In the simulation it turned out, that the recorded roll angles were completely different from the target roll angles the simulated autopilot was producing. This was initially very strange.
When flying, I had noticed the autopilot caused the plane always to head west. So I tried simulating the autopilot output using home coordinates that were set a kilometer west from the flying site. This time the output matched the recorded values very well, and it became clear that the autopilot was working correctly, but it just didn't know where home was. I still didn't understand how the home coordinates could have been wrong. The code that set them seemed trivial, and it didn't seem very likely that the problem was there.
Since I didn't have a second set of hardware, it wasn't until I got the plane back, that I could connect a debugger to the system to figure out what was wrong with setting the home coordinates. It turned out that the problem was indeed not with the autopilot, but with the AHRS board. Due to a small bug, invalid GPS data was fed to the autopilot and labeled as valid. The autopilot would then sometimes take the invalid data and set it as the home coordinates. The plane would then of course try to fly to the fictional coordinates of something like one million degrees northern latitude and one billion degrees western longitude.
Now what?
The problems above are now all taken care of, and yesterday I finally flew the first quasi-successful test flight. It seems the autopilot still requires some tweaking of the controller parameters, as it sometimes goes into a catastrophic oscillation.
I'm also in the process of developing a new receiver. There are mainly two reasons for this:
- Currently used software-only servo updates are inaccurate (3us resolution at best) and prone to jitter. The new version will have support for 8 hardware PWM channels at 0.13us resolution and (hopefully) negligible jitter. This will come at the expense of a multiplexer IC.
- The current board is designed for DIY PCB manufacturing, which makes it quite large at 5cm x 2.5cm, and is a two-board design. The new version will be a small single board design, which I will order professionally made from ITead Studio.
I hope to write more on this new receiver quite soon.