5
$\begingroup$

I'm programming a flight controller on an Arduino. I've researched how other people have written theirs but without notes it's often so obfuscated that I've decided it will be easier and better to write my own.

This is my pseudocode thus far, will this work?

all of this will happen inside the constant Arduino loop

  • Read RX signal
  • Calculate desired pitch, roll, and yaw angles from RX input
  • Signal ESCs using PWM in order to match desired pitch, roll, and yaw from RX input
  • Gather IMU values (using Kalman filter to reduce noise)
  • Compare filtered IMU values vs. RX input to find errors in desired outcome vs. actual outcome
  • Use PID algo to settle errors between IMU vs. RX
  • Rinse and repeat

Suggestions are greatly appreciated

$\endgroup$
5
$\begingroup$

The signals to the ESC's using PWM should be sent after the PID algo is done processing the errors. The output calculated from the PID is the PWM value to be sent to the ESC's to actuate the motors in such a way that they move to reduce the error thus obtaining the desired orientation

So the right order is:

  • Read RX signal
  • Calculate desired pitch, roll, and yaw angles from RX input
  • Gather IMU values (using Kalman filter to reduce noise)
  • Compare filtered IMU values vs. RX input to find errors in desired outcome vs. actual outcome (Get error (Target - Measured) for PID algorithm input)
  • Use PID algo to settle errors between IMU vs. RX
  • Use output of PID controller (assuming gains are already tuned properly) as PWM signal to the ESC's
  • Rinse and repeat

These resources might be of help in the future:

  1. Quadcopter PID Algorithm
  2. Different PID Architectures
  3. Cascaded PID Controller Explained
  4. PID output does not reach setpoint precisely enough
  5. Is it possible to stabilize a quadcopter considering only angle measurements?
$\endgroup$
  • $\begingroup$ Awesome info. I didn't know "Cascaded PID" or "Control Splitting" existed until you posted this answer. That definitely opened my mind up to some new possibilities and as far as I'm concerned that's the ultimate goal as far as SE answers go. You are certainly a gentleman and a scholar! $\endgroup$ – Jacksonkr Aug 8 '16 at 15:31
  • $\begingroup$ Glad to be of help :) Good luck :) $\endgroup$ – user123456098 Aug 10 '16 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.