Hey all, I’m currently using simconnect to show where my plane is and what it’s doing on a webpage, but figured why not try my hand at implementing a rudimentary autopilot?
Implementing a LVL button was basically a one liner (just set the aileron trim to a sllightly dampened opposite of whatever our current bank angle is) but that’s where things stop being easy =D
I figured I’d try HDG mode first, but I tried both a DFA approach and a PID approach, and the former sort of works, but not great, and the second works so poorly that no amount of parameter tweaking is going to save what it does. Are there any tutorials or posts that cover this topic concretely rather than abstractly? (I can find lots of articles that explain “how an autopilot works” but none actually about implementing that. What polling rate you need, what parameters control what other parameters, etc).
As DFA I had a four state machine,
- banking
- coasting
- correcting
- level flight
where any time a new heading gets set, we set the aileron trim to 0.03 (with the sign based on whether we need to bank left or right), and then once we hit a bank angle of 20, setting it to 0 so that we can coast until we get near the target heading, then switch to correcting which sets the trim to 0.03 in the opposite direction to decrease the bank, until we get to the desired heading at which point we switch to level flight.
(With some shortcuts to go from banking to correcting if the diffrence between current/target is too low, and from banking to level flight if our rate of turn is low and we’re almost at the target)
That works (sort of… well enough to pretend it works at least) but only for large heading changes.
I also tried a PID with two controllers: an outer controller based on getting the difference between current and target heading to zero, used to control the rate of turn. That, in turn, uses an inner controller that sets trim values. The problem with this is that the PIDs have no idea how to “slow down before we get there”, they just overshoot by a wild amount, and no amount of parameter tweaking yields a curve that doesn’t first grossly overshoots the target (way more than the DFA does) and then oscillates around the target heading in a way that would make both passengers and pilot quite sick.
Any tips for someone getting into the more serious parts flightsim coding?