unclejacko Posted March 2, 2016 Posted March 2, 2016 So I'm working on a small little plane to learn things and I got her flying..somewhat. What I want to try next is create a simple autopilot that keeps the aircraft level and at speed. From all my attemps so far, I've just gotten the plane to basically purpose like a fish up and down the whole time....not really staying level. I think my math is off a bit. So my question is - are there any guides out there on how to program a autopilot system? Searching the net I found mostly stuff for drones, but no code. Wondered if anyone here ever created one they could push me in the right direction.
tombeckett2285 Posted March 2, 2016 Posted March 2, 2016 You need a PID controller to prevent porpoising when under autopilot control - the actual numbers required will vary on the aerodynamic and inherent stability characteristics of your particular model. You 'could' go a slightly different route, by constantly taking a reading of your actual altitude/airspeed/roll angle etc and use that to create a delta term; then effect the relevant trim control on a variable basis dependent on how large the delta is; i.e as the altitude delta decreases then slowly reduce the nose up trim until your vertical speed is zero and delta is also zero. You will also still need to damp the altitude hold to prevent the aircraft 'hunting' the selected altitude. Sent from my iPhone using Tapatalk "The only replacement for a Buccaneer is a Buccaneer".
SilentEagle Posted March 6, 2016 Posted March 6, 2016 (edited) For autopilots, an altitude hold is more complex than an attitude hold. The altitude hold AP mode mode I wrote for my F-16 EFM uses a PID controller with the following influencing data: Altitude influence: altitude difference between current and setpoint altitude (using meters, this gain was low ~0.001 and clamped between -2000 and +2000 m difference) Attitude influence: to prevent too high/low pitch angle when climbing and descending to reach the target altitude, this uses the difference between the current pitch angle and the max pitch angle (using degrees, this gain was ~1.0 and kicked in when above +20 deg or below -20 deg) Vertical velocity influence: to prevent overshooting the target by climbing or descending too quickly, this uses the difference between the current vertical velocity and the max vertical velocity (using ft/min, this gain was ~0.001 and kicked in when above 15000 ft/min or below -15000 ft/min) Leveling influence: this was added to get the correct direction of pitch and also to help the AP actually reach the target and not get stuck short of the target. I calculated this by dividing the current vertical velocity by the current altitude difference (with handling for low altitude difference values, <20m) and using a variable gain that changed depending on whether I was above or below the target and whether I was currently climbing or descending. Add all the influences together and send it into the PID as the current error to be eliminated. Windup prevention: a flag that when true resets the integrator on the PID to zero so the AP doesn't continue increasing the commanded output when the limits of the AP or flight control system have been reached in an attempt to reach the setpoint. Finally, make sure to add an upper and lower bound on the output before it goes to the flight control system (in my case 0.5G to 2.0G). Keep in mind, many real autopilots vary in complexity, and this was a bit of a mess, but I found this combination to work pretty well. My flight controls system is G command, so your gains may be quite different depending on the required output. Here is one reference that explains the basics of the different AP modes. Edited March 6, 2016 by SilentEagle
unclejacko Posted March 6, 2016 Author Posted March 6, 2016 Thanks for the rest info...will keep testing things out.
Recommended Posts