flowchart TB subgraph Outer loop: position control direction TB POS_SP["Position Setpoint (X, Y, Z)"] --> POS_ERR["Position Error"]; POS_ERR --> P_pos["P-Control (Position Error → Velocity Setpoint)"]; P_pos --> VEL_SP["Velocity Setpoint (X, Y, Z)"]; VEL_SP --> VEL_ERR["Velocity Error"]; VEL_ERR --> PID_vel["PID-Control (Velocity Error → Acceleration/Thrust)"]; PID_vel --> THR_VEC["Desired Thrust Vector (Acceleration Setpoint)"]; end THR_VEC --> ATT_SP["Attitude Setpoint (orientation to align with thrust vector and desired yaw)"]; THR_VEC --> THR_CMD["Thrust Command (magnitude)"]; subgraph Middle loop: attitude control direction TB ATT_SP --> ATT_ERR["Attitude Error"]; ATT_ERR --> P_att["P-Control (Attitude Error → Rate Setpoint)"]; P_att --> RATE_SP["Angular Rate Setpoint (p, q, r)"]; end RATE_SP --> RATE_ERR["Rate Error"]; RATE_ERR --> PID_rate["PID-Control (Rate Error → Torque Commands)"]; PID_rate --> TORQUES["Body Torque Commands (roll, pitch, yaw)"]; TORQUES --> MIXER["Mixer"]; THR_CMD --> MIXER; MIXER --> MOTORS["Motor Outputs"];