The "position controller" is not really one good encapsulated thing. It maintains a desired internal position, stored in the global
navigation.c. In waypoint mode, this would be the waypoint coordinates, velocity, and heading. It then delegates to an altitude controller, which does some funky stuff with accelerations to get to the desired altitude, and the actual position controller. The position controller uses multiple layers of PID controllers to calculate a desired x/y acceleration (
src/main/navigation/navigation_multicopter.c:605), converts it to roll/yaw angles with some simple trig, and then saves the roll angle to
posControl.rcAdjustment. It later sends that calculated output roll angle to the attitude controller on line 658.
The position controller is (probably) only used in "navigation", or autonomous flight. This means that the possible inputs (that we care about) are:
- IMU measurements
- GPS coordinates
- Barometer values (altitude)
- Possibly magnetometer readings (from IMU)
- Waypoints (list of position, velocity, and heading values)
The only thing that should really matter for our purposes are the waypoints. We should be able to treat the rest of the system as a black box, and only really care about the code from the point where it calculates a desired x/y acceleration.
Important to note here is that raw RC controller values are only processed either as adjustments to the current course or as an emergency passthrough. The position controller gets its target x/y ONLY from waypoints or other autonomous internal inputs.
On line 658, the controller writes out desired roll values to the RC command global. This value makes its way to the "Attitude Controller" (
src/main/flight/pid.c:978), which runs even more PID on it to end up with actual roll, pitch, and yaw power values. This goes into the mixer, which uses a linear combination of parameters to map the roll, pitch, and yaw power values to individual motor power values. These motor power values are then output via PWM to the ESC, which drives the motors at the requested power.