Вы находитесь на странице: 1из 28

PD/PID Control Quadcopters Control

PID Control for Quadcopter Stabilization


Andrew Gibiansky andrew.gibiansky@gmail.com

November 30, 2012

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

System

Suppose we have some system with the transfer function G (s ) = a0 s2 1 . + a1 s

We would like this system to follow some desired trajectory . However, we have a disturbance (due to modeling error or external factors) summarized by a term D (s ). In addition, this system is clearly not asymptotically stable.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

PD Control
We can drive the difference between the true trajectory and the desired trajectory to zero. The open loop system would be: t (s ) = (s )G (s ). In order to drive the error to zero, we introduce a PD compensator: F (s ) = Kp + Kd s. The new input is given by U (s ) = F (s )(t (s ) (s )). Then, the output is t (s ) = (F (s )(t (s ) (s )) + D (s ))G (s ) = t (s ) = Kp (s ) D (s ) + Kd (s )s Kp + Kd s a1 s a0 s2
PID Control for Quadcopter Stabilization

Andrew Gibiansky andrew.gibiansky@gmail.com

PD/PID Control Quadcopters Control

PD Control PID Control General Case

Final Value Theorem

Theorem: Suppose F (s ) is the unilateral Laplace transform of f (t ), and f (t ) converges to some value as t . Then,
t

lim f (t ) = lim sF (s ).
s 0

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

PD Control Results
Suppose we have a step trajectory (s ) = L {T } = T s

and a similar constant disturbance term D (s ) = L {D } = Then, the tracking error is E (s ) = (s ) t (s ) D s

a0 Ts2 + Ta1 s D s (Kp + Kd s a1 s a0 s2 )


PID Control for Quadcopter Stabilization

Andrew Gibiansky andrew.gibiansky@gmail.com

PD/PID Control Quadcopters Control

PD Control PID Control General Case

Steady State Error


By the nal value theorem:
t

lim e (t ) = lim sE (s ) =
s 0

D . Kp

Steady state error! In physical systems, we cannot make the gain Kp arbitrarily large, so this becomes a real problem. A PD controller cannot accurately track a trajectory with a step in it. (The error comes from the fact that eventually the system has zero derivative error, so Kd is ineffective, and the constant disturbance balances out the proportional gain Kp .)

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

PID Control
Add an integral term: F (s ) = Kp + Kd s + Ki /s. This integral term ensures that if we remain in a steady state error for long enough, the build-up will overcome any constant disturbance. The error becomes: E (s ) = Ta0 s2 + Ta1 s D Ki + Kp s + Kd s2 a0 s3 a1 s2

Final value theorem:


t

lim e (t ) = lim sE (s ) = 0.
s 0

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

General Case: PD Control


Suppose we have a system with transfer function H (s )/s, such that H (0) = 0. Then, using a PD controller where F (s ) = Kp + Kd s we have E (s ) = (F (s )E (s ) + D (s ))H (s )/s (s ) E (s ) = F (s )H (s ) /s + D (s )H (s ) /s (s ) 1 F (s )H (s ) /s F (s )H (s ) + D (s )H (s ) s (s ) s F (s )H (s )

lim e (t ) = lim sE (s ) = lim s


s 0 s 0

= lim

sF (s )H (s ) + s (D /s )H (s ) s2 (s ) D = s 0 s F (s )H (s ) Kp

We have the steady state error shown before.


Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control General Case

General Case: PID Control


With a PID control with F (s ) = Kp + Kd s + Ki /s, we obtain the same form of the result:
t

lim e (t ) = lim

sF (s )H (s ) + s (D /s )H (s ) s2 (s ) s 0 s F (s )H (s ) D = lim =0 s 0 Kp + Kd s + Ki /s

Thus, the result we found before generalize for any transfer function of the form H (s )/s where H (0) = 0.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Quadcopters

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Quadcopter Thrusts

Degrees of freedom provided by extra motors.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Coordinate Systems

Figure: Quadcopter Body Frame and Inertial Frame

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Forces and Torques


Thrust force: 0 TB = Ti = k 0 . i =1 i 2
4

Drag force: kd x FD = kd y kd z Motor torques: Lk (1 2 3 2 ) B = Lk (2 2 4 2 ) 2 2 2 2 b 1 2 + 3 4


Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Equations of Motion: Linear


Inertial Frame: 0 = 0 + RTB + FD mx mg Body Frame: 0 = R 1 0 + TB + R 1 FD (mx ) mx mg

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Equations of Motion: Rotational


Eulers Equations (Rigid Body Dynamics): + (I ) = I Body Frame Dynamics: Ixx I=0 0 0 Iyy 0 0 0 . Izz

Iyy Izz y z Ixx 1 I xxIxx = Iyy 1 IzzI x z yy 1 I I xx yy Izz x y


Izz
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Simulation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 % Simulation times, in seconds. start_time = 0; end_time = 10; dt = 0.005; times = start_time:dt:end_time; N = numel(times); % Initial simulation state. x = [0; 0; 10]; xdot = zeros(3, 1); theta = zeros(3, 1); % Simulate some disturbance in the angular velocity. % The magnitude of the deviation is in radians / second. deviation = 100; thetadot = deg2rad(2 * deviation * rand(3, 1) - deviation); % Step through the simulation, updating the state. for t = times i = input(t); % Get controller input , , ) omega = thetadot2omega(thetadot, theta); % Convert ( a = acceleration(i, theta, xdot, m, g, k, kd); % Compute linear acceleration omegadot = angular_acceleration(i, omega, I, L, b, k); % Compute angular acceleration omega = omega + dt * omegadot; % = + dt , , ) thetadot = omega2thetadot(omega, theta); % Convert ( , , ) theta = theta + dt * thetadot; % = + dt ( = x + dt a xdot = xdot + dt * a; % x x = x + dt * xdot; % x = x + dt x end

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

Mechanical View Kinematics Equations of Motion

Visualization

YouTube Movie
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

PD Control
Control signal should be turned into a torque: = Iu (t ) = I We can set torques: + Kp I Kd xx + Kp = Iyy Kd + Kp Izz Kd

T 0 T 0 T 0

dt

dt dt

Our electronic gyro outputs angular velocities, so we integrate them to get the angle. This integral is multiplied by the proportional gain.
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Motor Angular Velocities


We do not actually set torques, we set voltages over the motors. These correspond directly to the motor angular velocities i . We can solve for the inputs i = i 2 : + Kp I Kd Lk (1 3 ) xx + Kp = Lk (2 4 ) B = Iyy Kd b (1 2 + 3 4 ) + Kp Izz Kd

T 0 T 0 T 0

dt

dt dt

For the last constraint, choose one to keep the quadcopter aloft: mg T = cos cos
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

PD Control

Figure: Left: Angular velocities. Right: angular displacements (, , ). Note that there is some small steady-state error (approximately 0.3 ).
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

We can do better by adding an integral term to make this a PID controller. + Kp e = Kd + Kp e = Kd + Kp e = Kd


T 0 T 0 T 0

dt + Ki dt + Ki dt + Ki

T 0 T 0 T 0

T 0 T 0

dt dt dt dt dt dt

T 0

To avoid integral wind-up, only start integrating the double-integral once the angle deviation is relatively small.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Integral Windup

Figure: In some cases, integral wind-up can cause lengthy oscillations instead of settling. In other cases, wind-up may actually cause the system to become unstable, instead of taking longer to reach a steady state.
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

PID Control

Figure: With a properly implemented PID, we achieve an error of approximately 0.06 after 10 seconds.
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Automatic Gain Tuning

Tuning the PID gains (Ki , Kp , and Kd ) can be difcult. Quality of results depends on gain values and the ratios of the different gain values. Best gains might be different for different modes of operation. Requires expert intuition and a lot of time to tune them. We would like to do this automatically.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Extremum Seeking
Dene a cost function, dening the quality of a set of parameters: J ( ) = 1 tf to
tf t0

e ( t , ) 2 dt

Use gradient descent to minimize this cost function in parameter-space: (k + 1) = (k ) J ( ) Approximate gradient numerically:

J ( ) =

J ( ), J ( ) . J ( ), Kp Ki Kd

K ) J ( u K ) J ( + u J ( ) K 2
Andrew Gibiansky andrew.gibiansky@gmail.com PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Gradient Descent Tricks

Adjust step size as we go along, to become more precise as time goes on. Computing e (t , ) means running a simulation with some random initial disturbance. Use many simulations, take the average. As we go along, average more simulations. Repeat many times to produce many local minima, then choose the best one and call it the global minimum. Automatically choose a time to stop iterating (when were no longer improving our average cost).

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Manual Gains vs. Automatically Tuned Gains

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

PD/PID Control Quadcopters Control

PD Control PID Control Automatic Gain Tuning

Questions?

Thank you to Professors Donatello Materassi and Rob Wood for their help.

Andrew Gibiansky andrew.gibiansky@gmail.com

PID Control for Quadcopter Stabilization

Вам также может понравиться