ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 4224

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

PID Control

Naive approach

Proper PI implementation

The naive way of implementing the I controller part is to transform the integration into a sum of a fixed number (for example 10) of previous error values. These 10 values would then have to be stored in an array and added for every iteration.

The proper way of implementing a PI controller starts with discretization, replacing the integral with a sum, using the trapezoidal rule:

R

= K

· e

+

Q

· t

·

n

ei ei 1

P

¦

-------------------

n

n

I

delta

2

i 1

Now we can get rid of the sum by using Rn–1, the output value preceding Rn:

Limit controller output values!

Rn – Rn–1 = KP · (en – en–1) + QI · tdelta · (en + en–1)/2 Therefore (substituting KI for QI · tdelta):

Rn = Rn–1 + KP · (en – en–1) + KI · (en + en–1)/2

So we only need to store the previous control value and the previous error value to calculate the PI output in a much simpler formula. Here it is important to limit the controller output to the correct value range (for example -100 .. +100 in RoBIOS) and also store the limited value for the subsequent iteration. Otherwise, if a desired speed value cannot be reached, both controller output and error values can become arbitrarily large and invalidate the whole control process [Kasper 2001].

Program 4.5 shows the program fragment for the PI controller, to be inserted into the framework of Program 4.1.

Program 4.5: PI controller code

1

static

int r_old=0, e_old=0;

2 ...

= v_des -

v_act;

3

e_func

4

r_mot

= r_old +

Kp*(e_func-e_old) + Ki*(e_func+e_old)/2;

5

r_mot = min(r_mot, +100);

/* limit output */

6

r_mot = max(r_mot, -100);

/* limit output */

7

r_old

= r_mot;

8

e_old

= e_func;

4.2.3 Derivative Controller

Similar to the I controller, the D controller (derivative controller) is rarely used by itself, but mostly in combination with the P or PI controller. The idea for adding a derivative term is to speed up the P controller’s response to a change of input. Figure 4.10 shows the measured differences of a step response between the P and PD controller (left), and the PD and PID controller (right). The PD controller reaches equilibrium faster than the P controller, but still has

59


4 Control

a steady-state error. The full PID controller combines the advantages of PI and PD. It has a fast response and suffers no steady-state error.

4500

4500

4000

4000

3500

3500

[ticks/sec]

3000

[ticks/sec]

3000

2500

2500

2000

2000

velocity

1500

Vdesired

velocity

1500

1000

1000

P control only (Kp

=0.2)

500

500

PD control (KP=0.2 KD=0.3)

0

0

0.0

0.1

0.2

0.3

0.4

0.5

Vdesired

PD control (Kp=0.2 KD=0.3)

PID control (Kp=0.2 KI=0.05 KD=0.3)

0.0

0.1

0.2

0.3

0.4

0.5

time [sec]

time [sec]

Figure 4.10: Step response for derivative controller and PID controller

When using e(t) as the error function, the formula for a combined PD controller is:

R(t) = KP · [ e(t) + TD · de(t)/dt]

The formula for the full PID controller is:

R(t) = KP · [ e(t) + 1/TI · 0³t e(t)dt + TD · de(t)/dt ]

Again, we rewrite this by substituting TD and TI, so we receive independent additive terms for P, I, and D. This is important, in order to experimentally adjust the relative gains of the three terms.

R(t) = KP · e(t) + QI · 0³t e(t)dt + QD · de(t)/dt

Using the same discretization as for the PI controller, we will get:

R

= K

· e

+

Q

· t

·

n

ei ei 1

+ Q

/ t

· (e – e

)

P

n

delta

¦

-------------------

n–1

n

I

2

D

delta

n

i 1

Again, using the difference between subsequent controller outputs, this results in:

Rn – Rn–1 = KP · (en – en–1) + QI · tdelta · (en + en–1)/2

+ QD / tdelta · (en – 2·en–1 + en–2) Finally (substituting KI for QI · tdelta and KD for QD / tdelta):

Complete Rn = Rn–1 + KP · (en – en–1) + KI · (en + en–1)/2 + KD · (en - 2·en–1 + en–2)

PID formula

Program 4.6 shows the program fragment for the PD controller, while Program 4.7 shows the full PID controller. Both are to be inserted into the framework of Program 4.1.

60


PID Control

Program 4.6: PD controller code

1

static

int e_old=0;

2 ...

= v_des - v_act;

/*

error

function */

3

e_func

4

deriv

= e_old - e_func;

/*

diff.

of error fct. */

5

e_old

= e_func;

/*

store

error function */

6

r_mot

= Kp*e_func + Kd*deriv; /*

motor

output */

7

r_mot

= min(r_mot, +100);

/*

limit

output */

8

r_mot

= max(r_mot, -100);

/*

limit

output */

Program 4.7: PID controller code

1

static

int r_old=0, e_old=0, e_old2=0;

2 ...

= v_des - v_act;

3

e_func

+ Ki*(e_func+e_old)/2

4

r_mot

= r_old + Kp*(e_func-e_old)

5

+ Kd*(e_func - 2* e_old +

e_old2);

6

r_mot = min(r_mot, +100);

/* limit output */

7

r_mot = max(r_mot, -100);

/* limit output */

8

r_old

= r_mot;

9

e_old2

= e_old;

10

e_old

= e_func;

4.2.4 PID Parameter Tuning

Find parameters experimentally

The tuning of the three PID parameters KP, KI, and KD is an important issue. The following guidelines can be used for experimentally finding suitable values (adapted after [Williams 2006]):

1.Select a typical operating setting for the desired speed, turn off integral

and derivative parts, then increase KP to maximum or until oscillation occurs.

2.If system oscillates, divide KP by 2.

3.Increase KD and observe behavior when increasing/decreasing the desired speed by about 5%. Choose a value of KD which gives a damped response.

4.Slowly increase KI until oscillation starts. Then divide KI by 2 or 3.

5.Check whether overall controller performance is satisfactorily under typical system conditions.

Further details on digital control can be found in [Åström, Hägglund 1995] and [Bolton 1995].

61


4 Control

4.3 Velocity Control and Position Control

What about starting and stopping?

So far, we are able to control a single motor at a certain speed, but we are not yet able to drive a motor at a given speed for a number of revolutions and then come to a stop at exactly the right motor position. The former, maintaining a certain speed, is generally called velocity control, while the latter, reaching a specified position, is generally called position control.

a

t

v

vmax

t s

s1

s0

t

Figure 4.11: Position control

Position control requires an additional controller on top of the previously discussed velocity controller. The position controller sets the desired velocities in all driving phases, especially during the acceleration and deceleration phases (starting and stopping).

Speed ramp Let us assume a single motor is driving a robot vehicle that is initially at rest and which we would like to stop at a specified position. Figure 4.11 demonstrates the “speed ramp” for the starting phase, constant speed phase, and stopping phase. When ignoring friction, we only need to apply a certain force (here constant) during the starting phase, which will translate into an acceleration of the vehicle. The constant acceleration will linearly increase the vehicle’s speed v (integral of a) from 0 to the desired value vmax, while the vehicle’s position s (integral of v) will increase quadratically.

When the force (acceleration) stops, the vehicle’s velocity will remain constant, assuming there is no friction, and its position will increase linearly.

62

Multiple Motors – Driving Straight

During the stopping phase (deceleration, breaking), a negative force (negative acceleration) is applied to the vehicle. Its speed will be linearly reduced to zero (or may even become negative – the vehicle now driving backwards – if the negative acceleration is applied for too long a time). The vehicle’s position will increase slowly, following the square root function.

a

t

v

s

t

s1

s0

t

ts

Figure 4.12: Breaking adaptation

The tricky bit now is to control the amount of acceleration in such a way that the vehicle:

a.Comes to rest

(not moving slowly forward to backward).

b.Comes to rest at exactly the specified position

(for example we want the vehicle to drive exactly 1 meter and stop within r1mm).

Figure 4.12 shows a way of achieving this by controlling (continuously updating) the breaking acceleration applied. This control procedure has to take into account not only the current speed as a feedback value, but also the current position, since previous speed changes or inaccuracies may have had already an effect on the vehicle’s position.

4.4 Multiple Motors – Driving Straight

Still more tasks to come

Unfortunately, this is still not the last of the motor control problems. So far, we have only looked at a single isolated motor with velocity control – and very briefly at position control. The way that a robot vehicle is constructed, how-

63