A Nonlinear Observer for the Inverted Pendulum

8 downloads 0 Views 187KB Size Report
Abstract. This paper deals with the design of a nonlinear ob- server for the inverted pendulum. The observer uses the standard structure of the linear observer ...
The 8th IEEE Conference on Control Application, Dearborn, USA, September 15-18, 1996.

A Nonlinear Observer for the Inverted Pendulum J. Eker and K. J. Åström Department of Automatic Control Lund Institute of Technology Box 118, S-221 00 Lund, Sweden Fax +46 46 138118, email [email protected] Abstract This paper deals with the design of a nonlinear observer for the inverted pendulum. The observer uses the standard structure of the linear observer with the linear model replaced by a nonlinear model. Nominal observer gains are determined from a linearized model. This model is also used to find a compromise between robustness and performance. The stability of the observer is then discussed and conditions for the stability of the observer are given. The results are illustrated by simulation and experiments on a real pendulum. 1. Introduction When controlling a process it is useful to incorporate its physical behavior into the controller. This appears naturally in the state space approach where the controller is based on feedback from measured or estimated states. The process model is then an essential ingredient of the observer. In spite of many efforts there is no general theory for design of observers for nonlinear systems, and instead observers are designed in an ad hoc fashion. Extended Kalman filters are commonly used, even if they often perform well it is not common that any guarantees can be given. In this paper we consider control of an inverted pendulum. An observer is an essential element of many control schemes for pendulums. The need for an nonlinear observer for the inverted pendulum becomes evident when implementing other control schemes than just stabilization. For example the implementation of a swing-up strategy involves estimation of the angle and the angular velocity at all positions, and hence one linear observer cannot be used to accomplish this task. The pendulum can make a complete revolution which makes the system highly nonlinear. A nonlinear observer is proposed. It has the same structure as a linear observer but with the linear

model replaced by a nonlinear model. The observer has two parameters which are determined based on linearized analysis. Conditions for stability of the nonlinear observer are also given, both for the pure observer and for situation when there is a feedback from the observed states. The stability conditions imposes some conditions on the estimator gains. The results are illustrated by simulations and by experiments on a laboratory process.

2. Preliminaries The equation of motion of an inverted pendulum is given by d2 θ  ω 20 sin θ + uω 20 cos θ dt2 where ω 0 is the natural frequency for small oscillations around the stable equilibrium and u is the normalized acceleration of the pivot. Introduce the state variables x1  θ x2 

1 dθ ω 0 dt

The equation of motion can then be written as dx1  ω 0 x2 dt dx2  ω 0 sin x1 + uω 0 cos x1 dt

(1)

Since ω 0 is a scaling factor, which can be removed by a proper choice of time scale we will consider the case ω 0  1. We can transform back later when the result is obtained. It is assumed that the angle θ is measured with noise and that it is desired to filter

the noisy signal and to generate an estimate of the velocity dθ / dt. Let the output be y  x1 + n where n is measurement noise. A reasonable structure of a nonlinear observer which accomplishes these tasks is d xˆ 1  xˆ 2 + k1 ( x1 − xˆ 1 + n) dt d xˆ 2  sin xˆ 1 + u cos xˆ 1 + k2 ( x1 − xˆ 1 + n) dt

(2)

Robustness We will first consider the sensitivity to parameter variations. To do this we will investigate the roots of the characteristic equation of the filter and investigate how much it changes over the range of operating conditions. The characteristic equation of the filter becomes s2 + k1 s + k2 + α  0 Assume that we design to obtain the characteristic equation s2 + 2ζ 0ω n s + ω 2n  0

Notice that the observer has a very simple structure. It combines a model for the nonlinear dynamics with a simple feedback from the measured angle.

in the nominal case α  0. The characteristic equations for the extreme cases are s2 + k 1 s + k 2 + 1  0

Introducing the estimation error x˜  xˆ − x we find that

With a relative damping ζ 0 in the nominal case we obtain

d x˜ 1  −k1 x˜ 1 + x˜ 2 + k1 n dt d x˜ 2  sin xˆ 1 − sin x1 + u(cos xˆ 1 − cos x1 ) dt − k2 x˜ 1 + k2 n

ωn ζ  ζ0 p ω 2n ± 1

This can be written as d x˜ 1  −k1 x˜ 1 + x˜ 2 + k1 n dt d x˜ 2  −k2 x˜ 1 + v + k2 n dt

(3)

x˜ 1  x˜ 1 x˜ 1  cos ( x1 + ) − u sin( x1 + ) 2 2 2

in the extreme cases. To have a system whose behavior is invariant over the operating range it is apparently advantageous to choose the parameter ω n as large as possible. With ω n  2, i.e. the filter twice as fast as the nominal system we get ζ  0.89ζ 0 and ζ  1.15ζ 0 respectively. Performance

where v  2 sin

s2 + k 1 s + k 2 − 1  0

(4)

A key issue is how efficient the filter is in reducing the noise from the angle sensor. To explore this we will calculate the transfer function from the measurement noise to the errors in the estimates of the angle and the angular velocity. It follows from Equation (5) that the transfer functions are k1 s + k2 + k1 s + k2 + α k2 s − α k1 Gv ( s)  2 s + k1 s + k2 + α

Gθ ( s) 

3. Linearization To get some insight into the properties of the system the error equation (3) will be linearized around the operating condition θ 0 . This gives d x˜ 1  −k1 x˜ 1 + x˜ 2 + k1 n dt d x˜ 2  −( k2 + α ) x˜ 1 + k2 n dt

(5)

where α  − cos θ 0 . Notice that α  −1 when the pendulum is standing up and that α  1 when it is hanging down.

s2

For α  0 these transfer functions become Gθ ( s)  Gv ( s) 

s2

k1 s + k2 2ζ ω n s + ω 2n  2 + k1 s + k2 s + 2ζ ω n s + ω 2n

k2 s ω 2n s  2 2 s + k1 s + k2 s + 2ζ ω n s + ω 2n

(6)

It follows from these equations that there is a roll-off of high frequency measurement noise with a slope of -1 for both transfer functions. The frequency where

1

1

10

Magnitude

Magnitude

10

0

10

−1

10

0

10

−1

−1

10

0

10 Frequency [rad/s]

1

10

10

−1

10

0

1

10 Frequency [rad/s]

10

Figure 1 Bode diagrams for the transfer functions Gθ (s) (left) and Gv (s) (right) in Equation (6), which describe how measurement noise propagates to the estimates of the angle and the angular velocity. The values of the design parameters are ζ  0.707 and ω n  2. The transfer function eGv (s)e has a resonance peak of 1.414 at ω  ω n .

the roll-off begins is essentially determined by the parameter ω n . The transfer function Gθ has low pass character and Gv has band pass character. The transfer function Gv has a resonance peak at ω  ω n which is given by

e Gv ( iω n )e 

ωn 2ζ

This shows that too high a value of ω n gives a high noise level in the velocity estimate. A comparison with the analysis of robustness shows that we have the traditional trade off. To make a specific design it is highly desirable to determine the spectrum of the measurement noise. Bode diagrams of the transfer functions are shown in Figure 1. The figure indicates that the observer gives a good estimate of the derivative for frequencies up to ω 0  1. The angle is typically measured by a potentiometer or an encoder. Additional noise is also generated from slip-rings that are often used. Figure 2 shows a realization of the angle measurement from a laboratory process with a potentiometer. The signal is filtered with an analog anti-aliasing filter and sampled with 200 Hz. A spectrum analysis shows that the measurement noise is white over a wide range.

4. Stability Although the linearized analysis gives insight it does not guarantee stability of the nonlinear system (3). To analyze the stability of the nonlinear system we will apply the theory of input-output stability of nonlinear systems, see [1] and [2]. Pure Filtering We will first discuss the pure filtering problem, i.e. when there is no control signal. The signals x1 and x2

Radians 0.025

Angle Measurement Signal

0.02 0.015 0.01 0.005 0 −0.005 −0.01 −0.015 0

1

2

3

4

5 s

Figure 2 A sequence of the measurement noise taken from a laboratory pendulum where the angle is measured with a potentiometer.

can be considered as time functions and the function v in Equation (4) becomes v  2 sin

x˜ 1 x˜ 1 cos ( x1 ( t) + ) 2 2

(7)

The system described by Equations (3) and (4) can be regarded as an interconnection of a linear system with the transfer function G ( s) 

1 s2 + k 1 s + k 2

and the nonlinear time-varying function v( x˜ 1 , t) given by Equation (7). See Figure 3. We can now establish the following result. THEOREM 1 Assume that the signal space is L2e , and that the control signal is zero, then the system (3) is inputoutput stable if  √ 2 2  k− if k1 < 2, 1 + k 1 /4 (8) k2 > √ 1 if k1 ≥ 2

If k21 ≥ 2k2 the maximum is obtained for ω  0, hence

G(s)

max G ( iω ) 

x~ 1

v

1 k2

and the condition that the gain of the linear block is less than one becomes k2 > 1 which completes the proof.

v(x~ 1 ,t) Figure 3 Block diagram of the observer. The upper block represent the linear part of the observer and the lower block represents the nonlinear part.

PROOF 1 The system in Figure 3 is a standard configuration where the small gain theorem can be used, see [1] and [2]. For this purpose we calculate the gains of the linear and the nonlinear subsystems. Since the cosine function is bounded by one it follows from Equation (7) that

The values of the observer gains which give a stable closed loop system are shown in Figure 4. Notice that the stability conditions for the linearized case are k1 > 0, k2 > 1. This shows that the stability conditions for the nonlinear observer are not very conservative and that there is considerable freedom for the designer. This verifies the intuitive insight that it is easy to obtain a low gain of the nonlinear system simply by choosing high values of the observer gains. The linearized analysis in Section 3 does however indicate that there are disadvantages in using too high gains. k2 15

x˜ 1 ev( x˜ 1 , t)e ≤ 2e sin e ≤ e x˜ 1 e 2 The gain of the nonlinear block is thus at most one. The small gain theorem, [2], then implies that the closed loop system is stable if the gain of the linear system is less than one.

Stable k−region f1

f2

10

5

To calculate the gain of the linear block we observe that 1  k2 − ω 2 + ik1ω G ( iω )

(9)

Hence

e

1 e2  ω 4 + ( k21 − 2k2 )ω 2 + k22 G ( iω )

 (ω 2 − k2 + k21 /2)2 − k41 /4 + k21 k2 If

k21 q
1

So far we have discussed a free observer where the control signal u was zero. When a feedback is introduced the control u becomes a function of the state. It is straight forward to extend the analysis to this case. The results will in general depend on the nature of the feedback. It is highly desirable to obtain conditions that do not depend on the detailed structure of the control law. Such results can be obtained if we make the reasonable assumption that the acceleration of the pivot is bounded. This leads us to the following theorem

k2 > k1−2 + k21 /4

THEOREM 2 Assume that thepsignal space is L2e , and that eue ≤ u max . Let β  1 + u2max , then the system (3) is

hence

max G ( iω )  q

1 k21 k2 − k41 /4

Requiring that the gain of the linear block is less than one gives.

or

k2 15

Angle and its estimate

Stable k−region f1

f2

4 0 0

10

5

10

15

5

10

15

5

10

15

2 Angular velocity and its estimate 0 −2 0

5

1 Estimation errors

f3

0

k1 0 0

1

2

3

4

5

−1 0

6

Figure 5 The shaded area marks the k-values, for which the resulting observer becomes stable. The area is bounded by the following three curves: f1 (k1 )  β 2 / k21 + k12 /4, f2 (k1 )  k21 /2, and f3 (k1 )  β . β is equal to two in the figure.

input-output stable if  β 2 k1−2 + k21 /4 k2 > β ,

if k1 < if k1 ≥

p p

2β , 2β

(10)

PROOF 2 When the control signal is different from zero it follows from Equation (4) that the nonlinear block is characterized by v  2 sin

x˜ 1  x˜ 1 x˜ 1  cos ( x1 ( t) + ) − u sin ( x1 ( t) + ) 2 2 2

Since

e cos φ + u sin φ e ≤

q

1 + u2max  β

it follows that the p gain of the nonlinear block is bounded by β  1 + u2max . The calculation of the gain of the linear block given in the proof of Theorem 1 now leads to the results and completes the proof. The observer parameters that give a stable closed loop system are illustrated in Figure 5. A comparison with Figure 4 shows the additional restrictions on the observer gains that are introduced because of the feedback.

5. Simulation and Experiments The results have been illustrated by simulations and experiments on laboratory processes.

Figure 6 A simulation of the observer with ω 0  2. This choice of ω 0 will as expected give a stable system.

Simulation of the Observer To illustrate the result we first present two simulations of the system. The normalized system has been used in the simulations. We choose ζ  0.707 for the nominal case α  0. To have guaranteed stability with ζ  0.707 we must choose ω 0 > 1. To have some margin we choose ω 0  2 which means that the observer is about twice as fast at the natural period of the pendulum. The filter gains are k1  2.818 and k2  4. Figure 6 shows a simulation where the pendulum performs an oscillatory motion starting from an almost upright position. Measurement noise has been simulated by a sinusoid with frequency ω  ω 0 , which is the most sensitive case. The amplitude of the measurement noise in the simulation is one degree. A sample of the real measurement noise is shown in Figure 2. The assumption that the noise is approximately one degree is thus reasonable. Notice that the estimates of the angle and the angular velocity settle quickly and that the system is not very sensitive to the noise. If we instead choose ω 0  0.5, which violates the condition in Theorem 1, the resulting observer will become much more sensitive to the nonlinearities. A simulation of this case shows that the estimator does not converge. Experiments with Pure Filtering A number of experiments have been performed on a laboratory process. The system used is a version of the Furuta pendulum. In this pendulum the pivot is rotated in the horizontal plane, see [3]. The position of the pendulum was measured with a potentiometer and the signals were transmitted through slip rings. An anti-aliasing filter was used before the signals were sampled. The pendulum has a natural frequency ω 0  6.3 rad/s. The observer was implemented by approximating the differential equations

by finite differences. The sampling period used was 5 ms. The Furuta pendulum can be approximated by Equation (1) provided that the rotation of the pivot in the horizontal plane is not too large. Figure 7 shows estimates of the angular velocity in an experiment when the pendulum swings freely after it is released from the upper position. The dashed line shows the output of the nonlinear filter and the full line shows the estimate obtained by filtering the position signal with the filter G ( s)  s/(1 + s/ N ). The filter shows clearly the advantage of using the nonlinear observer. As seen in the figure the low-pass filtered derivative is more sensitive to noise, has longer delay and has a gain that is less than one. The attenuation of the filtered derivative p is approximately 1 + (6.3/10)2  1.2.

Control signal

4 0 −4 0

2

4

6

8

10

4

6

8

10

4

6

8

10

Angle estimate 4

0 0

2 Estimated angular velocity

0 −10 0

2

Figure 8 A simulation of swinging-up and stabilizing the pendulum using the non-linear observer. The simulation starts with the pendulum in the downward position. The observer is initiated to start in this position.

Filter (N=10) & Observer 5

Control Signal

Radians/Second

5

0

0

−5 0

1

2

3

1

2

3

1

2

3

4

5 6 Angle estimate

7

8

9

10

7

8

9

10

7

8

9

10

4

−5 0

1

2 Seconds

3

4

2 0

Figure 7 Two curves taken from the real process; the dashed line is the angular velocity from the filter described in this paper, and the solid line is the theta measurement fed through the filter G(s)  s/(1 + s/ N ), with N  10.

0

0 −5 −10 −15 0

Experiments with Feedback Control Finally we will show results from experiments where the observer is used for feedback control. Figure 8 shows a simulation and Figure 9 shows real data from a swing-up experiment. The pendulum is started in the downward position. A swing-up controller is used to move the pendulum to its upward equilibrium, where a linear feedback controller is used to stabilize the pendulum. In both the simulation and the real case the observer was initiated to start in the downward position. In the simulations measurement noise is approximated with a high frequency sinusoid. Notice the good agreement between experiment and simulation and the good performance of the nonlinear observer.

4 5 6 Estimated angular velocity

4

5

6

Figure 9 Plots from the swing-up and stabilization of a real pendulum process. The pendulum starts in the downward position.

6. Conclusions In this paper we have designed a nonlinear observer for the inverted pendulum in the form of an extended Kalman filter. Stability conditions have been derived using the small gain theorem. This gives mild restriction on the observer gains. Conditions are presented both for a free observer and for the case where the observer output is used for feedback. It turns out that conditions that are independent of the details of the control law can be obtained. In this case the conditions contain the maximum value of the control sig-

nal. Specific choices of observer gains that satisfy the stability conditions are then obtained by linearized analysis. The results have been investigated both by simulation and by experiments with laboratory processes. The key properties which makes it possible to derive the stability results are that the nonlinearities in the model are bounded functions and that the control signal also is bounded.

7. Acknowledgment This project was supported by the National Swedish Board of Technical Development under contract 9204014P.

8. References

[1] C. A. Desoer and M. Vidyasagar. Feedback Systems: Input-Output Properties. Academic Press, New York, 1975. [2] H. K. Khalil. Nonlinear Systems. MacMillan, New York, 1992. [3] K. Furuta, S. Kobayashi, and M. Nishimura. A new inverted pendulum apparatus for eduction. Prepeints IFAC Conference on Advances in Control Educations, pages 191–196, 1991. [4] J. F. Schaefer. On the bounded control of some unstable mechanical systems. Thesis, Stanford University, 1965. [5] J. F. Schaefer and R. H. Cannon. On the control of unstable mechanical systems. In Automat. Remote Contr. III, Proc. 3rd Int. Fed. Automat. Contr. (IFAC), volume 1, 6C.1-6C.13, 1967. [6] Karl Johan Åström and Björn Wittenmark. Computer Controlled Systems—Theory and Design. Prentice-Hall, Englewood Cliffs, New Jersey, second edition, 1990.