This action might not be possible to undo. Are you sure you want to continue?

# 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 ( ) ) ) ) )

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.6) Transfer function system: .1.4) We define a Differential equations system from the equations above: (2.1.: Motor shaft angular speed ( : Motor shaft angular position ( Numerical values of the parameters: ) ) (2.

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 .7) Identification based on the current measurement In this section.1.(2. First. we will identify the transfer function of the DC Motor based on input/output data measurements.

The parameters of this command specify a transfer function with a first order numerator and a second order denominator.001 (2.2. Number of iterations: 96 Relative convergence: 0.Output: current measurement 1 0 1 2 3 4 5 The sample time of the data measurements is: 0.035616 (2.000992 Relative error: 0. We get as a result the identified parameters of this transfer function.2. the covariance matrix of these parameters and the identified system.1) We use now the Control[Identify] command to identify the system.2) .

In particular.(2. 1 Output 0 1 2 3 Time [s] 4 5 measurement Transfer function between the voltage and the torque: simulation (2.4) . defining this structure in the identification command helps this identification. We can see that when the structure of the model is well-known.3) We can compare the result of the identification with the measured data. the definition of a second order system filters the noise.2.2.

(2.2.2.8) (2.9) Open loop analysis Open-loop simulation (unit step response on at ) .5) Continuous system: (2.7) (2.6) (2.2.2.2.

y1 0 0 Bode diagram: 1 2 t 3 4 5 .

] .Freq [rad/s] Freq [rad/s] Magnitude [dB] Automatic PID design We design a PID controller to control the torque . Since we want a proper controller. We want a settling time of about (see Control[PID]). although we could get Phase [deg. we use the option in order to get a controller with a filtered derivative.

Warning. Replace the option Tf = true by Tf = a small value chosen in the following range. degree(num) > degree (den) Warning. Using ResponsePlot may require Digits:=50. (2.infinity) (2. improper transfer-function. Using ResponsePlot may require Digits:=50.1) In this case. is not computed automatically but the function lets you choose the best value for it: Warning.). Warning.2) Now we can plot the result of the closed-loop simulation: . assuring stability of the closed loop: RealRange(Open(0.also a result without this derivative term. Tf cannot be computed automatically.4.4.

1) (3.1 y1 0 0 1 t 2 Interactive PID design Warning. (3. Using ResponsePlot may require Digits:=50.2) Equations of the inverted pendulum without actuator .

2) .1.Non linear equations Here are the non linear equations of the system: (4.1) (4.1.

3) (4.4) Linearization In order to design a controller.1.1. and (small movements) . we need to linearize the system.(4. . We linearize around .

2.(4.1) .

We define the numerical values: (4.4) There is positive eigenvalues: the system is unstable. We can also see it by computing the eigenvalues of the state matrix A: (4.2.3) Open-loop simulation 0 1 t As we can see. .2. the system is unstable.

1) (5.3) Open-loop simulation .1.Control of the full system Equations We associate the 2 systems (the inverted pendulum and the controlled DC motor) in serie: (5.1.1.2) (5.

2) Now we can plot the result of the closed-loop simulation: .0 1 t Internal Model control We want a settling time of about . (5.2. Warning. Using ResponsePlot may require Digits:=50.

1.1) .3.1.1 0 2 4 t 6 8 10 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.

1.3.1.2.2) 1 0 2 4 t 6 8 10 Automatic design We want a settling time of about (5.3.(5.1.1) .

Here.2.(5.2) 1 0 2 4 t 6 8 10 Observer Since we are not able to measure any component of the state vector. we measure only the cart position to compute the observer gain: .1.3. we need to estimate this state vector from the measurements.

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 t 6 8 10 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 .

2) .1.1.1.4.1) The closed-loop system is computed with the Control[StateFeedbackClosedLoop] command: (5.(5.1.4.

2.4.2.1 0 5 10 t 15 20 25 Automatic design We want the weighting matrices to be computed automatically.2) .4.1.1) The closed-loop system is computed with the Control[StateFeedbackClosedLoop] command: (5.1. so we define only the desired settling time in the Control[LQR] command: (5.

Here.1 0 2 4 t 6 8 10 Kalman filter Since we are not able to measure any component of the state vector. We compute a Kalman filter in order to estimate the states of the system. we measure the cart position and the angle of the pendulum. we need to estimate this state vector from the measurements. The state weighting matrix is defined as below: .

(5.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: .4.2.

Using ResponsePlot may require Digits:=50. 1 0 2 4 t 6 8 10 .Warning.