A flight controller is a special harware component that is typically purchased and installed to fly a UAV. Many projects use flight controllers – this is not one of them!
This is an experiment to fly a quadcopter in .NET and to demonstrate the eloquence of Functional Reactive Programming (FRP) for processing sensory input to control the output in a system.
Watch the all-C# autopilot in action!
- Windows IoT Extensions for the UWP
- Reactive Extensions
Controlling rotary-wing aircraft requires an understanding of how their rotor speeds must be continually adjusted to balance and steer them through the air.
In quadcopter flight dynamics the proportions of speeds between the front-side and back-side rotors are varied to control pitch. Similarly, the proportions of speeds between the left-side and right-side rotors are varied to control roll.
Because two rotors turn in a clockwise direction and the other two rotors in a counter-clockwise direction, yaw is controlled by varying the proportions of speeds between those that turn in one direction and those that turn in the other direction.
Be sure to check out my blog entry that describes this in more detail.
The quadcopter is steered with a USB game controller where thumbstick inputs are interpreted for flight control commanded to the rotors.
In control theory feedback is required to modify the behavior of a system and, without sensory input, autonomous flight would be impossible.
These sensory inputs ultimately determine the process variable (PV) for a proportional-integral-derivative controller (PID controller) that is used to calculate an error value (e) for a desired setpoint (SP). The purpose of the controller is to return a manipulated variable (MV) that continually adjusts the state of the system to minimize error over time.
Controller thumbstick inputs are interpreted for the desired setpoint (SP) and the manipulated variable (MV) determines the flight control commanded to the rotors.
The orientation of the quadcopter is relative to the ground, for which an accelerometer can be used to sense the direction of Earth's gravity. A value of 1g is sensed in the downward direction – at least when the body is stationary. When the quadcopter experiences motion, these readings would become entirely misleading.
A gyroscope can be used to sense the angular velocity of the quadcopter. From this, the total angular displacement can be accumulated over time and, assuming we have a firm initial estimate of the direction of Earth's gravity (accelerometer), the sensor readings can be combined to provide an accurate estimate of the orientation.
However, gyroscopes are imperfect instruments and experience gyroscopic drift. Accumulating rotations in this way would very soon, perhaps in just a few seconds, become entirely misleading. The optimal solution involves striking a balance – the accelerometer provides meaningful readings only in the long run whereas the gyroscope only provides meaningful readings in the short run.
For as long as the latest estimate for orientation that is continually applied with the new rotation further gets corrected by rotating very slightly towards the direction of the latest accelerometer reading – barely enough to cancel out perhaps only a tiny bit of drift – orientation estimates remain responsive and true over time.
Because Earth's magnetic field extends outward into space, it is necessary to further consider the estimate for orientation to determine the direction of North along the surface of the ground (in the direction perpendicular to gravity).
However, magnetometers are rather slow and faster heading estimates can be provided. By sensing and accumulating gyroscopic rotations that occur in the meantime, between magnetometer readings, the latest heading estimate could be combined to provide more frequent estimates of the heading.
As with combining gyroscopic readings to estimate orientation, gyroscopic drift would again need to be compensated for.
However, large fluctuations of up to 1 meter were observed between estimates. While a proximity sensor is within operating range it may be used to measure the distance above ground. A ground-level altitude estimate can be calculated and referenced as a fixed point from which finer distance measurements may be combined for more consistent altitude estimates during this time.
This method of combining readings from the proximity sensor would be misleading if the quadcopter's orientation weren't near-level with the ground.
Another concept yet to be trialed involves accumulating changes in acceleration in the vertical direction (perpendicular to the ground) to estimate displacement over time. These changes could be combined with other estimates for altitude.
u-blox PAM-7Q GPS antenna module sponsored by Derrick Herbst.