Original Concept
- I have a MiniMag RC plane that I have been flying around for the past year.
- I have a microstrain 6 DOF IMU that Piwai gave me for my birthday to attach to my airplane.
- I have an XMos XC-2 test board that I got to evaluate as a candidate for making a microphone array for the robot at work. It looked pretty cool in theory: a quad-core processor, with plenty of RAM (64k per core). Eight hardware threads per core, making it easy to implement UARTS, ethernet MACs and other IO devices in software. Dev tools that looked easy to use and complete. What better way to test it than to use it in a cool project.
After a suprisingly short 4 evenings of development, the plane was ready to fly upside-down in auto-pilot mode mode: flick a switch, and the plane will servo roll and pitch to be level and
upside-down. By this time, I was also sold on the X-core. Good dev tools and lots of ressources unlike a PIC. Near-instant compiling, and ability to do complex IO like an FPGA. The .xc language tries a bit too hard to prevent you from running into locking and pointer problems, but you can work in C/C++ too. (And it looks like they are coming out with a single-core version in a LQFP/TQFP package, for those who like to do their own soldering.)
Saturday
Went out to the field with the autopilot programmed for inverted flight, and all the electronics in a large hunk of foam in place of the cockpit.
We had quite a crowd (9 including Jonathan) along for the test so everything went about as badly as it could. There was a tremendous wind. Not usually a problem, but in this case it was apparently accompanied by a down-draft just above the flying field, which made it pretty much impossible to gain any altitude for testing the autopilot, and which made flying really difficult because of turbulent air. The plane was flying so slow I couldn't even get it inverted to try out the autopilot. After a crash landing, we stopped to replace the propeller and to glue up cracks in the foam around the motor. Piwai and Francois-Marie cut off excess foam from around the electronics to try to reduce drag (and greatly improve appearance). I also did some in-field reprogramming (literally) with the laptop, so that the plane would servo to an upside-right position instead of upside down.
Subsequent flights went a bit better. The plane flew better with a LiPo battery (more power, less mass), but the battery only being partially charged, I had to land before any testing could be done. Under NiMh power, I found that flying was much better a bit up-wind from where were standing, where there seemed to be an up-draft rather than a down-draft. The plane finally reached a safe height for the test. I flicked the switch, and the plane promptly entered a fast downward spin. I flicked the switch back to manual, and recovered the plane, but by now the battery was starting to die, and I had to land. The spin was probably due to the low battery voltage causing the IMU to shut down (in which case the autopilot currently continues to trust the last reading it got which is bound to cause a spin).
Conclusion
- Remember to plug in the charger when you want to charge your LiPos.
- Don't try to fly in a down-draft.
- Wind isn't always irrelevant.
- Fly upside-right before you fly upside-down. (I have been bit by this before, right Jim?)
- Power the IMU straight from the battery, not from the 5V servo supply (good advice from Piwai).
- 110g of extra electronics and foam makes this the heaviest I have ever flown the plane (by about 50g). Always weigh what you put on the plane to know what to expect.
Sunday Morning
Saturday evening, and Sunday morning I made various changes to the plane:
- I changed the IMU's power supply to be directly from the battery.
- I moved the IMU to the back of the plane where it is easy to slide in and snugly attach, to reduce bulk at the front of the plane.
- I decided to do away with the protective foam around the electronics. That isn't the part of the plane that is going to touch the ground first unless Jim O'keeffe is flying it, and I wanted to have as little stuff behind the propeller as possible.
- I changed the code so that in auto mode the aileron/elevator stick can be used to set the target attitude for the plane: the position of the stick directly maps to a target attitude).
- I programmed the buttons on the X-Core board so that one button selects upside-right mode, and the other selects upside-down mode.
computer as it was already late for lunch. Things went better this time,
all with NiMH batteries, except with a few problems with a faulty
connection on the throttle control line (not a major flight-safety issue as
you can still glide to the ground).
There wasn't a breath of wind. The plane flew just fine (despite the extra weight). I flicked the switch, and the plane started dancing side to side and up and down in a rather crazy pattern. Clearly the gains were set too high. I tried adjusting the set-point with the control stick, but the plane was dancing too wildly to make out any differenc. Around this point, the motor started causing large resonances. I landed, re-tightened the propellor, selected upside-down mode,
and took off again. The resonance was still pretty bad, but I decided to test anyways. I rolled the plane onto its back and flicked the switch. This time the plane spiraled down right away. After landing, I got the impression from the plane's behavior that it had somehow switched back to upside-right mode. Perhaps a power supply glitch reset the XCore.
Back at the parking lot, a guy who had been flying his helicopter on the same field asked what the crazy dance the plane had been doing was. I guess it was pretty obvious that it wasn't a human flying the plane when it was in auto mode.
Sunday Afternoon
Back home, I divided the gains in the controller by 5, and changed the IMU settings so that if it loses power, it automatically re-starts broadcasting attitude when it regains power.
After some canoeing at Shoreline, we made a final stop at the park to test out the new gains. There was a lot more wind than in the morning, but less than Saturday. As soon as I started the pre-flight check, I realized we had a problem. I had forgotten to turn off debug mode before programming the firmware, and the computer was at home.
In debug mode, the auto/manual switch is disabled, and always set to auto. This is so that I can test the plane while the controller is charging. If I hadn't added the ability to set the target attitude, this would have been a show-stopper, as the plane would have been un-controllable in auto-mode. With the ability to set the target attitude, the plane should be flyable in auto mode. In fact, it should be easier to fly than usual: set the attude you want, and watch the plane servo to that attitude. However, if the IMU stops sending data, things could get bad. If the last IMU
reading was way off-target the ailerons and elevators could be in an extreme position that could not be compensated for by setting the attitude set-point. Also, with the gain settings I had in the morning, the plane would have been un-controlable in auto-mode.
I decided to do a quick low-altitude test flight despite the risk, to see how things would go. If things didn't look good, I would cut power and hope for a soft crash...
I threw the plane and throttled up. It started diving a bit, so I pulled back on the stick. It obeyed and started gaining altitude. There was still a bit too much gain on the roll axis, and the plane tended to oscillate a bit in roll. But overall, things were looking good! By this time of course, it was no longer a small low-altitude test flight. The plane was flying upwind fast, and I wanted to bring it around to land while the going was good. I tried to adjust the roll set-point. It had some effect, but not much. I though I had given myself a lot of range on the roll set point when I was testing in the living room, but in the air, the amount of roll I could request seemed pretty pathetic. I could steer the plane, but a lot less that I would want for comfort, even with help from the rudder (which is always in manual mode). I managed to steer the plane to a cross-wind orientation, and it drifted back towards us, then I steered it back to face the wind ready to land. Throughout the maneuver, the plane would sometimes oscillate a bit in roll, and at other times it would be nice and steady, possibly because of varying aileron authority with airspeed. I throttled down to land, and the plane started diving a lot more than seemed comfortable. I throttled up again, and the plane, very low now, appeared to ricochet off the ground. I cut the throttle, and it landed softly a few meters later.
We ran to the plane fearing damage from the ricochet, but it turned out that the plane must have regained enough airspeed to recover just before it hit the ground (before that it may have been in control inversion, where, at slow airspeeds, the elevators have the opposite of their normal effect). It was intact, and potentially ready to go, with 2 and a half batteries remaining.
At this point I decided not to try my luck. I was pretty thrilled. The roll gain was still set too high, but we had managed to do a full flight with the autopilot in the loop. The overall setup was proven, and it was now time to keep improving the software, and think about adding the GPS module...
Thanks for everybody who came to watch this week-end, and especially to Piwai who forced me into this by giving me the most expensive pice of the setup (even if he does say it has been taken apart and is probably poorly calibrated). And thanks to Chiu-Ki for the pictures. I hope you don't mind that I stole a couple of them for this post.
I'm curious, can you tell us more about the autopilot software you're using? Since the X-Core is an uncommon hardware platform I assume you wrote it yourself. How do you filter the IMU output to get an attitude reading? How do you combine that with a set-point to drive the control surfaces? Is it as simple as static filtering on accelerometers and a simple proportional gain?
ReplyDeleteThe IMU is pretty fancy. It has a three-axis gyro for the high frequency attitude response, and a three-axis accelerometer to cancel drift. The filtering is done on the IMU, and I am currently getting nice filtered Euler angles directly from it. Currently the control loop is just simple proportional control, but as I am reducing the gain, it will be nice to add an integrator term. I could also add a derivative term to try to keep the roll rate down, which would also stabilize things.
ReplyDeleteThat is pretty sexy, where do I get a pre-filtered IMU like that? I spent several weeks trying to reimplement the filtering logic on top of an unfiltered 6DoF IMU. Of course it would have been easier if I had a faster processor on board...
ReplyDeleteThe XC-2 looks physically kind of bulky on XCore's site, I'm surprised it fits in a plane like that. Maybe the photos are misleading? Did you have to cut it down at all?
I'm curious why powering the logic from the 5V ESC output was glitchy. Simply not enough current to handle peak load?
This is the type of IMU I am using. Definitely sexy, and I had forgotten to mention the magnetometer, so that it automatically removes yaw drift also using the Earth's magnetic field.
ReplyDeletehttp://www.microstrain.com/3dm-gx1.aspx
I did not have to cut down the XC-2 at all. In the end I just have it strapped in the cockpit of the plane, and did away with all the foam you can see in the picture. It is just a bit smaller than the opening.
As for the last question, the microstrain IMU is supposed to have a power supply above 5.2V. I was running it around 4.9, and probably dipping slightly lower when the batteries were low causing it to reset. I had originally done things that way to try to better isolate it from the battery line that would have a lot of noise from the motor. Piwai told me that they have really good filtering on the IMU, so I shouldn't worry about the motor noise, but that by powering it below 5.2 V, I am effectively guaranteeing that all noise from the servo supply will end up on the IMU sensors. To make things worse, if I have the ESC's voltage regulator on the supply to the IMU, I'm losing whatever headroom the ESC's regulator needs. When the battery is at 5.2V, the ESC will be lower, so powering from the ESC means that I will drop below the IMU's minimal operating voltage sooner.
I see on your blog that you are doing some similar testing, and was curious why you are testing near the ground rather than gaining altitude where you are less likely to hit the ground and cause damage (assuming you can flip between auto and manual mode).
How well are you controlling airspeed? I expect that optimal control parameters will totally depend on airspeed.
IMU: Nice. $1500! Good thing you got a sample. Still, looks like a dream part.
ReplyDeleteI had no manual override! I didn't have a standard RC receiver at all in fact. Direct manual control of a quadrotor is pretty much impossible anyway -- everything flyable is stabilized and interpreted to some degree. Hence low altitude testing. My final step before returning from leave had been to write a simulator so I could tweak my PID parameters in silico to at least get a decent starting point. I wrote the sim but never got around to the tweaking.
I was mainly interested in slow speed flight and hovering, so differences at high airspeed didn't really concern me.