Pid Tuning Questions

I'm working on tuning a PID for a quadcopter using the PID Library Arduino Playground - PIDLibrary

It's coming along slowly... but making bits of progress. But I've got a few questions that I can't seem to find the answer to.

My motors fire up when sent a signal of 55 and max out when sent a signal of 133. So my questions are:

  1. When the PID is tuned, does it work at any throttle level? I have been setting it to 20% throttle while tuning and it was somewhat stable, I started increasing the throttle and it got kind of wild.

  2. Should I be capping any of the outputs? I have SetOutputLimits(-133, 133) so can send max power to the motors, should I be capping this at less than max?

  3. What should i set SetSampleTime() to? I have it set to 5 milliseconds now. And it's almost reasonable. When i set it to 50, it gets very sluggish, when I set it to 1 it gets crazy. I've checked and my loop takes around 100 milliseconds to execute.

  4. Here's my code Quadcopter/quadcopter.ino at master · GerHarte/Quadcopter · GitHub. Anyone have any tips/suggestions?

Here's my setup in case it matters, so I'm just tuning pitch at the moment. Will have to put an opposite propeller on one of the motors once all 4 are working.

The more throttle you're using the more authority your feedback algorithm will have and the greater the risk of instability.

I suggest you read up on the theory of PID if you haven't already do that, so you can understand how to go about tuning PID for a new system. In crude terms it's a matter of ramping up P until you get a system that will settle or oscillate around the set point, and then ramp up I as far as necessary to produce critical damping, and then increasing I to eliminate steady state errors. But these factors all affect each other, so you can expect to have to approach this iteratively.

There is PID tuning library that might be helpful with the legwork and fine tuning, but I'd recommend that you get the hang of the basics manually before trying to automate it.

PeterH:
ramp up I as far as necessary to produce critical damping,

typo: "I" should be "D"

Thanks guys.

I've been working away and I'm pretty sure I understand the PID theory and what each element does. I'm just wondering how overall throttle plays into it.

The way I have it set up is as follows:

Motor1 = throttle + PitchPIDOutput
Motor3 = throttle - PitchPIDOutput

I've been tuning it while the throttle is pretty low, and its somewhat steady, expecting to throttle up when it's level. Now when I turn throttle up it gets unstable. Should I be tuning it while it's at a hover throttle level?

I don't really want to use the autotune library.

gerry87:
I'm just wondering how overall throttle plays into it.

It depends how you have combined the throttle with the PID, but most likely throttle is going to increase the control authority of all modes. You should start by tuning in the easiest case (low throttle) to make life as easy as possible while you get the kinks out of your algorithm, but eventually you should also tune for the worst case (full throttle).