You are on page 1of 27

Control Toolbox Demo

Inverted Pendulum on a Cart with a DC Motor Actuator

Description of the system: inverted pendulum on a cart with a


DC motor actuator
We want to control the position of the cart.
The pendulum must stay vertical.
The actuator of the cart is a DC motor

We will first control the torque of the DC motor. Then, we will integrate this actuator (controlled DC
motor) into the cart + pendulum system and we will control the full system.

Torque control of the DC motor

Equations

The equations of the system are:

(2.1.1)

(2.1.2)

(2.1.3)
Parameters:
: Moment of inertia of the motor ( )
: Damping of the mechanical system ( )
: Electromotive force constant ( )
: Motor coil resistance ( )
: Motor coil inductance ( )

Inputs:
: Applied voltage ( )

Outputs:
: Motor current ( )
: Motor shaft angular speed ( )
: Motor shaft angular position ( )

Numerical values of the parameters:

(2.1.4)
We define a Differential equations system from the equations above:

(2.1.5)

Conversions to a state-space form or a transfer function are easy with the new DynamicSystems
package of Maple 12:
State-space system:

(2.1.6)

Transfer function system:


(2.1.7)

Identification based on the current measurement


In this section, we will identify the transfer function of the DC Motor based on input/output data
measurements.
First, we get the data from a file:

Then we plot the input and the output versus time

Voltage Input
1

0
0 1 2 3 4 5
Output: current measurement
1

0
1 2 3 4 5
The sample time of the data measurements is:

0.001 (2.2.1)
We use now the Control[Identify] command to identify the system. The parameters of this
command specify a transfer function with a first order numerator and a second order denominator.
We get as a result the identified parameters of this transfer function, the covariance matrix of
these parameters and the identified system.

Number of iterations: 96
Relative convergence: 0.000992
Relative error: 0.035616

(2.2.2)
(2.2.3)

We can compare the result of the identification with the measured data. We can see that when the
structure of the model is well-known, defining this structure in the identification command helps
this identification. In particular, the definition of a second order system filters the noise.

1
Output

0
1 2 3 4 5
Time [s]
measurement simulation

Transfer function between the voltage and the torque:

(2.2.4)
(2.2.5)

Continuous system:

(2.2.6)

(2.2.7)
(2.2.8)
(2.2.9)

Open loop analysis


Open-loop simulation (unit step response on at )
y1

0
0 1 2 3 4 5
t
Bode diagram:
Freq [rad/s] Freq [rad/s]

Magnitude [dB]

Phase [deg.]

Automatic PID design


We design a PID controller to control the torque .

We want a settling time of about (see Control[PID]). Since we want a proper controller, we use
the option in order to get a controller with a filtered derivative, although we could get
also a result without this derivative term.

Warning, improper transfer-function, degree(num) > degree


(den)
Warning, Using ResponsePlot may require Digits:=50.
Warning, Tf cannot be computed automatically. Replace the
option Tf = true by Tf = a small value chosen in the
following range, assuring stability of the closed loop:
RealRange(Open(0.),infinity)

(2.4.1)

In this case, is not computed automatically but the function lets you choose the best value for it:

Warning, Using ResponsePlot may require Digits:=50.

(2.4.2)

Now we can plot the result of the closed-loop simulation:


1

y1

0
0 1 2
t

Interactive PID design

Warning, Using ResponsePlot may require Digits:=50.

(3.1)

(3.2)

Equations of the inverted pendulum without actuator


Non linear equations
Here are the non linear equations of the system:

(4.1.1)

(4.1.2)
(4.1.3)

(4.1.4)

Linearization
In order to design a controller, we need to linearize the system.
We linearize around , , and (small movements)
(4.2.1)
We define the numerical values:

(4.2.3)
Open-loop simulation

0
1
t

As we can see, the system is unstable. We can also see it by computing the eigenvalues of the
state matrix A:

(4.2.4)

There is positive eigenvalues: the system is unstable.


Control of the full system

Equations
We associate the 2 systems (the inverted pendulum and the controlled DC motor) in serie:

(5.1.1)

(5.1.2)

(5.1.3)

Open-loop simulation
0
1
t

Internal Model control


We want a settling time of about .

Warning, Using ResponsePlot may require Digits:=50.

(5.2.2)
Now we can plot the result of the closed-loop simulation:
1

0
2 4 6 8 10
t

Control design by pole placement

State feedback with pole placement


First step: we compute a state feedback controller with a pole placement strategy:

Custom design

(5.3.1.1.1)
(5.3.1.1.2)

0
2 4 6 8 10
t

Automatic design
We want a settling time of about

(5.3.1.2.1)
(5.3.1.2.2)

0
2 4 6 8 10
t

Observer
Since we are not able to measure any component of the state vector, we need to estimate this
state vector from the measurements.
Here, we measure only the cart position to compute the observer gain:
Association of the state feedback controller and the observer
The final controller is the association of the state feedback controller and the observer:

Warning, Using ResponsePlot may require Digits:=50.


1

0
2 4 6 8 10
t

Multi-variable LQG control design

State feedback with Linear Quadratic Regulator


First step: we compute a state feedback controller with a Linear Quadratic Regulator:

Custom design
(5.4.1.1.1)

The closed-loop system is computed with the Control[StateFeedbackClosedLoop]


command:

(5.4.1.1.2)
1

0
5 10 15 20 25
t

Automatic design
We want the weighting matrices to be computed automatically, so we define only the
desired settling time in the Control[LQR] command:

(5.4.1.2.1)

The closed-loop system is computed with the Control[StateFeedbackClosedLoop]


command:

(5.4.1.2.2)
1

0
2 4 6 8 10
t

Kalman filter
Since we are not able to measure any component of the state vector, we need to estimate this
state vector from the measurements.
Here, we measure the cart position and the angle of the pendulum. We compute a Kalman
filter in order to estimate the states of the system.

The state weighting matrix is defined as below:


(5.4.2.1)

The measurement weighting matrix is defined as below:

We use the Control[Kalman] command in order to compute the Kalman filter gain :

Association of the LQ controller and the Kalman filter: LQG regulator


Finally we compute the closed loop with the state feedback controller and the Kalman filter,
according to the following structure:
Warning, Using ResponsePlot may require Digits:=50.

0
2 4 6 8 10
t

You might also like