documentation for the bytronic pendulum control systeminconsy/lab/frames/experiments/... · 2007....

63
Documentation for the Bytronic Pendulum Control System Version 3.0 The Courtyard Reddicap Trading Estate Sutton Coldfield West Midlands B75 7BU ENGLAND Tel : +44 (0121) 378 0613 Fax : +44 (0121) 311 1774 Email : [email protected] Website : http://www.bytronic.net

Upload: others

Post on 02-Oct-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Documentation for the Bytronic

Pendulum Control System

Version 3.0

The Courtyard

Reddicap Trading Estate Sutton Coldfield West Midlands

B75 7BU ENGLAND

Tel : +44 (0121) 378 0613 Fax : +44 (0121) 311 1774

Email : [email protected] Website : http://www.bytronic.net

Page 2: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing
Page 3: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Copyright © 2001 Bytronic International Ltd. All Rights Reserved. Documentation for the Bytronic Pendulum Control System. This manual, as well as the software described within, is furnished under license and may only be used or copied in accordance with the terms of such license. The content of this manual is furnished for information use only, is subject to change without notice and should not be construed as a commitment by Bytronic International Ltd. Bytronic International Ltd. assumes no responsibility or liability for any errors or inaccuracies that may appear in this manual. Except as permitted by such license, no part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, recording or otherwise, without prior written permission of Bytronic International Ltd. Bytronic acknowledges all copyrights and trademarks.

Page 4: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Table of Contents

© Bytronic International Ltd Pendulum Control System

Table of Contents Getting Started ......................................................... 1.1

Using the PCS1 as an Analogue Control System ........................1.2

Using the PCS1 as a Digital Control System ..............................1.4 Overview: The Pendulum Control Problem .......... 2.1

Fundamentals...............................................................................2.1

Two modes: swinging crane and inverted pendulum ..................2.2

Calculation and instability of y for inverted pendulum ...............2.3

Analogue and digital modelling ..................................................2.4 Labworks .................................................................. 3.1

Labwork 1: Static and Dynamic Characteristics of the Pendulum Control System ........................................3.3 Apparatus..............................................................................3.3 Introduction ..........................................................................3.3 Carriage Servo ......................................................................3.3 Effect of Servo Gain on Hysteresis ......................................3.4 Transient Response of the Servo Subsystem........................3.4 Dynamic Model of the Pendulum.........................................3.5 Modelling of the Carriage Servo ..........................................3.7

Labwork 2: Analogue Control of an Inverted Pendulum ............3.8 Apparatus..............................................................................3.8 Introduction ..........................................................................3.8 Measurement of the Mass Position.......................................3.8 Setting up the Pendulum.......................................................3.9 Software Linear Control of the Pendulum............................3.9 Software Harmonic Control of the Pendulum......................3.10 Transfer Function for the Inverted Pendulum ......................3.10 Stabilisation using Phase Lead Compensation .....................3.12 The Effect of Hysteresis in the Servo Sub-System...............3.14

Page 5: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Table of Contents

© Bytronic International Ltd Pendulum Control System

Labwork 3: Fuzzy Control of the Inverted Pendulum .................3.15 Apparatus..............................................................................3.15 Introduction ..........................................................................3.15 Description of the Fuzzy Controller .....................................3.15 Fuzzification..................................................................3.16 Rules..............................................................................3.17 Defuzzification ..............................................................3.18 Use of the Fuzzy Controller..................................................3.19

Labwork 4: Direct Digital Controller Design and Implementation: Inverted Pendulum .......................3.20 Apparatus..............................................................................3.20 Introduction ..........................................................................3.20 Design of a DD Controller using a Simplified Model..........3.21 Design Criteria and Sample Rate Selection...................3.21 Pole Placement ..............................................................3.23 Implementing the Controller using the PCS software ..........3.24 Further work .........................................................................3.25

Labwork 5: Direct Digital Controller Design and Implementation: Swinging Crane ............................3.26 Apparatus..............................................................................3.26 Introduction ..........................................................................3.26 Sample Time and Design Objectives ...................................3.27 Dead-Beat Controller Design using Simplified Plant Model ..........................................................................3.28 Use of Dead-Beat Controller ................................................3.29 Frequency Response of Plant and Compensator ..................3.29 Dead-Beat Controller using Plant Model with Damping .....3.29 Ringing Pole Problem ...................................................3.30 Correct Design Approach to Avoid Ringing Pole Problem .........................................................................3.30

Page 6: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Table of Contents

© Bytronic International Ltd Pendulum Control System

Appendices............................................................... 4.1

Appendix 1: Recalibrating the Angle θ Servo Potentiometer ................................................4.1 Adjusting the Servo Potentiometer................................4.1 Appendix 2: Resetting the X Position Potentiometer...........4.2 Appendix 3: Derivation of Plant Controller .........................4.4 Appendix 4: Technical Specification ...................................4.6 Appendix 5: Header Pin-out Details.....................................4.7 Connector 1: 26 Way IDC Microcomputer Header.......4.7 Appendix 6: Recommended Texts for Block Diagrams,......4.8 Laplace and Z Transforms Appendix 7: MATLAB Solutions for DDC Controllers ......4.9 Inverted Pendulum.........................................................4.9 Crane .............................................................................4.11 Tables and Diagrams

Table 1 – PCS1 Analogue Channels ....................................1.5

Figure 1 – Linear Pendulum Controller Connections...........1.2

Figure 2 – Inverted Pendulum Compensator ........................1.3, 3.12

Figure 3 – Determination of Mass Position..........................2.1

Figure 4 – The Pendulum Control Module...........................3.2

Figure 5 – Mounting of the X Position Potentiometer .........4.2

Page 7: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Getting Started

© Bytronic International Ltd Pendulum Control System

1.1

Getting Started

The PCS1 consists of two separate modules linked by a connecting cable: the Carriage Module and the Control Module. The Carriage Module consists of a carriage that carries a pivoted rod and mass. These are driven along a 500mm track by a dc servo motor and toothed belt. The motor has an integral tachometer. When standing upright the carriage unit behaves as an inverted pendulum. When turned upside down, the rod and mass represent the lifting block of an overhead crane. In both modes the overall behaviour of the pendulum is a combination of linear and oscillatory behaviour. When the pendulum is upright these two modes are coupled, and the behaviour of the pendulum is best described by the position of the pendulum bob. When the pendulum is turned upside down these two modes are decoupled, and the behaviour of the pendulum is best described by the position of the carriage and the angle of the pendulum. The carriage position and the attitude of the rod/mass assembly are measured by potentiometers. The position of the pendulum bob is calculated in hardware. The Control Module includes a clear mimic diagram of the overall system and connection to the control/measurement signals are via easily accessible 4mm colour coded sockets. The colour coding is as follows:

Red terminals are analogue inputs and outputs. Blue terminals are monitoring points for feedback signals. Yellow terminals are the compensator connection points. Green terminals are ground.

The Pendulum Control System has two modes of operation, namely stand-alone in analogue mode or linked to a computer in digital mode, as discussed in the remainder of this manual. These control modes are quite distinct. To begin, we recommend you start with the simpler analogue mode so as to gain understanding of the control problem.

Page 8: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Getting Started

© Bytronic International Ltd Pendulum Control System

1.2

Using the PCS1 as an Analogue Control System The following procedure will allow a quick set-up of the PCS1 as first a linear positioning control system and then an inverted pendulum balancing system. 1. Position the equipment on a desk with the carriage module in the

inverted pendulum position (the carriage to the bottom of the unit and the motor to your right).

2. Position the set point potentiometer to the middle (0V). 3. With one of the 4mm leads supplied, connect the set point to the

servo amplifier input terminal as shown in Figure 1.

Figure 1: Linear Position Controller Connections

4. Turn on the power. 5. The system is now configured as a linear position controller. The

position of the set point potentiometer will determine the position of the carriage assembly along the x axis.

6. To achieve optimum position control, the servo amplifier gain and

velocity feedback must be calibrated on the control panel. This procedure is covered in detail in Labwork 1. Approximate values to get the system working are maximum for the servo gain and three quarters maximum setting for velocity feedback.

7. Now the servo system is set-up we may begin to balance the

pendulum. Disconnect the servo input from the set point and temporarily connect the servo input to GND to prevent noise pick-up.

Page 9: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Getting Started

© Bytronic International Ltd Pendulum Control System

1.3

8. To balance the pendulum the variables “a”, “gain” and the compensator all need to be designed and calculated. The procedure to do this is discussed in Labwork 1. Approximate values to get the system going are:

a) Mass positioned at the top of the rod. b) Set “a” to 2.7. c) Set “gain” to 1.2. d) Switch the gain to negative. e) To allow quick set-up, preset compensator components

are supplied with the PCS1. Carefully plug these modules into the compensator yellow 4mm terminals as shown in Figure 2.

Figure 2: Inverted Pendulum Compensator

9. Hold the pendulum upright in the centre of the track. Connect the

controller output to the servo input using the 4mm connecting lead. Now, gently let go of the pendulum, and the pendulum should balance in the centre of the track.

10 a) Nudge the balancing weight and see the controller compensate

and regain balance. b) Try adjusting the gain value from zero to 3.0 and find out its

effect on the balancing operation. If the pendulum will not balance with the suggested values, gently move the rod to the upright position and the controller should take over. If not, check all connections and settings, especially the compensator as shown in Figure 2.

Page 10: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Getting Started

© Bytronic International Ltd Pendulum Control System

1.4

This section has been a simple introduction into the operation of the PCS1 in its analogue control mode. Many of the subtleties of this control problem have been left out. To fully investigate the set-up values and compensator design, please refer to the Labworks.

Using the PCS1 as a Digital Control System

The PCS1 control module signals are available for use with any external controller via the 4mm connectors. To facilitate PC digital control of the PCS1, a socket at the rear of the control module allows the measurement signals to be transmitted directly to a Bytronic AD/DA Interface Board (MPIBM3) located in a PC expansion slot. In addition, the control signal from the PC is also routed via this cable to drive the input of the carriage servo amplifier that in turn controls the motor. To achieve digital control of the PCS1 please follow the procedure outlined below- 1. Ensure the power to the microcomputer system and the PCS1 are both

off. 2. Install the MPIBM3 card into a spare PC expansion slot and set both

the ADC and DAC channels to operate on a ±10V bipolar operation, as described in the MPIBM3 manual.

3. Remove all 4mm cables that may be connected to the control panel. 4. The MPIBM3 card may be connected to the pendulum unit by either: a) Direct connection using the MPIBM3 26 way ribbon cable into

the rear of the control console; or b) The MPIBM3 26-way cable may be connected to the MPIBM3A

screw terminal board. This will allow more flexible connection of the analogue channels to the Control Module 4mm terminals.

Note – The MPIBM3A screw terminal board must be purchased

separately. 5. Power-up the PCS1 and then the microcomputer system. The carriage

assembly should position itself in the centre of the track and the

Page 11: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Getting Started

© Bytronic International Ltd Pendulum Control System

1.5

microcomputer power-up as normal. If not, power down immediately and check all the connections.

6. Run the PCS software. When using the Bytronic MPIBM3 card with the PCS1 the analogue

channel usage is given in Table 1.

MPIBM3 ANALOGUE Function INPUT CHANNEL

0 Position Y 1 Position X 2 Slider Position 3 Angle theta 4 Tachometer Feedback (dX/dt)

MPIBM3 ANALOGUE Function OUTPUT CHANNEL

0 Carriage Servo Input

Table 1: PCS1 Analogue Channels

When connected to the MPIBM3 card these ADC input channels and DAC output channels can be viewed directly using the Internal Interface Cards software. Please refer to the manual supplied with the MPIBM3 interface card.

Page 12: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.1

Overview: The Pendulum Control Problem Fundamentals

The position of the pendulum bob, y , the position of the carriage, x , and the angle of the pendulum, θ , are related by the equation:

θsinLxy += (equation 1)

where L is the effective length of the pendulum, the distance between the pivot and the centre of mass of the combined pendulum and bob.

Figure 3: Determination of Mass Position

Page 13: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.2

This tells us that in any mode the dynamics of the position of the pendulum bob, y , is a combination of linear dynamics, x , and oscillatory dynamics, θsinL .

Linear and oscillatory quantities possess quite different dynamic properties. Linear behaviour with error reduction requires feedback. In feedback, oscillatory behaviour will either be amplified or damped. To analyse this response needs a frequency response test. As such the pendulum is a very difficult control problem.

Two modes: swinging crane and inverted pendulum

The pendulum provides two control problems: inverted pendulum (upright, base on ground), and swinging crane (turned over, pendulum hanging). The stable behaviour of the pendulum in the two cases is fundamentally different. Consider the two variables x and θ . In the case of the inverted crane x and θ can be varied independently and the crane is still stable: move x , and θ will return to zero, change θ and x will not be affected. By contrast, with the pendulum inverted and stable, any small change

θ∆ in θ requires a adjustment x∆ in x , as x has to be adjusted to keep the pendulum upright. Variations in x are dependent on θ . However, the reverse is also true: variations in θ are dependent entirely on x . Any adjustment x∆ in x requires a small change θ∆ in θ . This means that for the inverted pendulum it is not meaningful to talk about x and θ as independent variables. This has the consequence that the description and dimension of the control problem of the pendulum are different in the two modes. In the crane mode x and θ are independent variables and so the position of the pendulum is described by ),( θx . This is two-dimensional. By contrast in the inverted pendulum mode x and θ are not independent variables. Any attempt to balance the inverted pendulum in terms of x and θ will have to take into account all the modes of interaction between x and θ as well as the values of x and θ themselves. However, we only consider the stable control problem. So long as the pendulum is in balance we can talk about a single independent variable, the position of the pendulum bob or y . Thus the appropriate variable for control for the inverted pendulum is y alone. This is one-dimensional.

Page 14: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.3

Calculation and instability of y for inverted pendulum We shall now consider the inverted pendulum mode alone for a moment. In the inverted pendulum mode, so long as the pendulum is balanced, the behaviour of θ is small angle (θ smaller than about 15° or so) and we can apply the “small angle” approximation:

θθ ≈sin

(with θ measured in radians). Substituting into equation 1 we obtain:

θLxy +≈ (equation 2).

As L is fixed in any one control application, this means we can quickly calculate y in terms of x and θ , which are measurable. Hardware analogue control requires that this calculation is performed in analogue terms, and in fact the Control Module performs this calculation in analogue voltages. If xV is a voltage representing x , and θV a voltage representing θ , then θV can be scaled by a factor a (using an op-amp with a variable resistor to change the multiplication factor) and then summed with xV using a summing junction to give a voltage yV representing y on the same scale as xV . Thus:

θaVVV xy += ,

a voltage implementation of equation 2, with the factor a scaled to represent the value of L (see Figure 4 on page 3.2). This is the method used to give the voltage representing y which is available from junction L on the Control Module. Note that though this voltage sum is exact, the value yV is an approximated representation of y , because equation 2 is an approximation. In the inverted pendulum mode, the pendulum is fundamentally unstable. This can be seen with a simple gain model. Suppose we simply amplify the error yr − of displacement from the set-point by a gain g as the control signal for the position of the pendulum carriage, x , ensuring that the signal is 180° out of phase. A block diagram can represent the system as follows:

Page 15: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.4

With gGC −= . (Y is the measured value, R the set point, YRE −= the error, CG is the controller gain, pG the plant gain and X the output). Thus )( YRGX c −= . Substituting our gain function into this equation we obtain )( yrgx −−= . (Here capital letters represent functions in the block diagram; lower case letters represent real variables).

Taking r as zero for simplicity, we see x will move in the same direction as y (negative gain; positive feedback – a minus times a minus equals a plus), amplified by an amount g . Thinking linearly, for the pendulum to balance, clearly we require 1≥g : the carriage must move at least as far as the bob or the pendulum will fall over. Thinking harmonically, for oscillations to be damped (or at least not be amplified) we require 1≤g . Thus, the only possible value of g that can balance the pendulum is precisely 1. Clearly, this is impossible to attain in practice, and the slightest deviation will, as we will see, lead to instability. The dynamics of the inverted pendulum are thus fundamentally unstable.

Analogue and digital modelling As a control system, the pendulum may be represented by the closed-loop diagram:

Where CG is the controller gain (the controller), pG is the plant gain (the pendulum and associated hardware), R is the set-point, YRE −= the error signal, X the output signal and Y the measured value. This is a closed loop control system.

Page 16: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.5

For any block in a closed loop system the signal transformation or transfer function, H, of a gain is defined in terms of the output signal, O, and the input signal, I, by:

IOH = .

Thus:

XYGp = and

EXGc = .

Defining the transfer function of the entire feedback loop as F and using the block diagram relation for a feedback loop we obtain:

pc

pC

GGGG

RYF

+==

1

(for further explanation refer to a textbook on block diagrams). This relation can be rewritten as:

FF

GG

pC −

=1

1.

These relations will be used later. For the inverted pendulum, the signals are as in the previous section: rR = , xX = and yY = . For the crane,

)0,(rR = , ),( θxX = (output to pendulum) and ),( θxY = (input from pendulum). In particular, θ is under control because its value will tend to zero (damped by friction; to fixed point defined by gravity). The fundamental teaching point of the Pendulum Control System is the relation between the linear and oscillatory modes of behaviour and the consequences of this for control. The Labworks discuss the relation between the linear and oscillatory modes through various possible control strategies, and two techniques are used to tackle the relation between the linear and oscillatory modes. These are Laplace transforms and Z transforms. Laplace transforms are a method of analysing continuous systems and as such are particularly useful for discussion of analogue control. Z transforms analyse discrete systems and as such are particularly useful for developing Direct Digital Control. The Laplace and Z transforms are related and reference is made to this in the Labworks. Only outline discussion of the role and properties of block diagrams, Laplace transforms and Z transforms will be given here. For further details, a reference such as those given in the Appendix 6 will be required.

Page 17: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.6

Each technique is generally associated with a distinguishing variable. A lower case s is generally used as the distinguishing variable of Laplace transforms, and Z transforms are generally associated with a lower case z . In each case, when we associate the variable with the control system we write the system in terms of that variable:

or

. Analysis of the system can then take place in terms of the block diagram relations and the properties of the transformation. If

sssGc 01.01

1.01)(++=

then (block diagram relation)

sss

EX

01.011.01)(

++=

so (properties of the Laplace transformation; s represents differentiation with respect to time)

dtdEE

dtdXX 1.001.0 +=+ .

Page 18: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.7

This controller function is used in Labwork 2. Similarly for Z transforms, if

)215.0)(1()981.0)(713.0(7.3)(

−−−−−=

zzzzzGc

then (block diagram relation)

215.0215.1)699.0694.1(7.3)( 2

2

+−+−−=

zzzzz

EX

so (properties of Z transformation; 1−z represents unit drop of difference equation index)

)699.0694.1(7.3215.0215.1 1212 +−−=+− ++++ iiiii eexxx .

Shifting indices, we can then derive the output from previous output and error values. This controller function is used in Labwork 5. In each case, we have taken a system and created a representation of that system. Derivations of CG and pG in terms of s and z are included in the Labworks for both the crane and the inverted pendulum modes. Dynamics analysed in the particular representation will generate valid solutions for the original system so long as we stay within the parameters of that representation. The Laplace transform requires, for example, zero initial conditions. The Laplace condition means in practice that we have to hold the pendulum at the start of analogue control to ensure balance. If the pendulum is not upright the controller can sometimes achieve balance; but this is not guaranteed. The Z transform requires description of the complete system, in particular this means that the zero order hold must be included in the description of the system. The consequences of the need to include the zero order hold are discussed below. In terms of the mathematics, the Laplace and Z transforms are closely related, and the Z transform is usually calculated from the Laplace transform. Direct methods for doing this are given in the Labworks. Conceptually, nonetheless, the process is rather more complicated. In moving from an s to a z transform we are moving from one representation, and associated condition, to another representation, and associated condition. In other words, we are losing one constraint (the requirement for zero initial conditions, that the pendulum be held upright), and imposing another. The new constraint is that we must model a complete description of the system.

Page 19: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.8

For most systems, we approach discrete ( z ) control as an approximation to continuous ( s ) control: we ramp the sample time up as high as possible and assume everything is smooth, and continuous. We are implicitly making a move into the Z representation, finding a controller, and moving back into the Laplace representation. This movement is valid so long as there are no properties of the system which preclude returning from the discrete model to the continuous. For stable, linear systems, there are no such properties, and this approach is valid and is often done without any regard to the underlying process. For harmonic systems, that is systems with oscillatory dynamics, this is not the case. To understand why, we must consider the ADC (Analogue-to-Digital Converter). The ADC is the electronic unit which converts analogue electrical signals to digital numbers for use by the computer. The ADC necessarily has a sample time. Between these sample instants the signal is assumed to be static. The true signal, of course, could move significantly within that sample interval, and the computer would never know. The ADC thus introduces a zero order hold into the system:

.

For a system with oscillatory dynamics, even a stable one, the zero order hold cannot be neglected, because the errors introduced within a single sample interval may be enough for the system to become unstable. Indeed, any sample interval of any size, any delay at all, may be enough for the system to become unstable. This is because any oscillatory system will amplify some signals and damp others. In terms of the Z transform, the zero order hold affects the radius of convergence of the transform.

Page 20: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Overview: The Pendulum Control Problem

© Bytronic International Ltd Pendulum Control System 2.9

Within the radius of convergence the transform is stable; outside it is unstable; and the zero order hold affects this. A practical example of the mathematics may help. In Labwork 2 we derive a Laplace controller for the inverted pendulum of

ss

01.011.01

++

.

This can be implemented in hardware, and works. Transforming this controller into a differential equation and solving, as would be required in software, we obtain a controller of the form:

∫ + dteEdtdE t100)10010( + lower order terms.

It is immediately apparent that the ∫ dte t100 term will explode for any

discrete time period (any range of t to be integrated over where the interval is non zero). Thus the zero order hold cannot be ignored when defining the Z transform.

Page 21: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.1

LABWORKS

The following labworks begin with familiarisation of the Pendulum Control Unit and its dynamic characteristics. As the labworks progress, they cover control of the pendulum control unit by both analogue and direct digital control methods. In the labworks, various connections need to be made on the control console. To ease understanding, we have referred to the 4mm terminals and the control knobs as shown in Figure 4.

Page 22: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.2

Figure 4: The Pendulum Control Module

Page 23: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.3

Labwork 1: Static and Dynamic Characteristics of the Pendulum Control System Apparatus

PCS1, two voltmeters, signal generator, oscilloscope or PCS software and Analogue I/O card (MPIBM3).

Introduction

In this experiment you will:-

1. Familiarise yourself with the PCS1 rig. 2. Examine the characteristics of the carriage servo. Tune its gain and the

degree of velocity feedback to optimise its performance. Obtain a dynamic model of the servo.

3. Examine the dynamic characteristics of the pendulum and hence model it dynamically.

Carriage Servo

Place the rig in the inverted pendulum position and unscrew the pendulum rod. Disconnect all the links on the Control Module. Connect the output of the set-point potentiometer (socket A) to the input of the carriage servo (socket H). Position the set-point potentiometer (P1) so that it is at its mid-range. Adjust the servo gain potentiometer (P3) and the velocity feedback potentiometer (P4) so that they are about mid-range. Switch on the power to the apparatus.

Page 24: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.4

Move the set-point potentiometer to and fro and observe the carriage change position. Using the two voltmeters, measure the set-point voltage and the carriage position voltage, xV (socket J1 or J2). Increase the set-point uniformly from 0 to +10V and then back down to –10V and finally back to 0V in steps of 2V. Plot a graph of the servo position against set-point voltage. Make sure you always move the pot in the required sense. If you move it too far one way, move the set-point potentiometer back and then approach the required value slowly.

a) What is the useful linear range of the carriage servo? b) What is the hysteresis of the carriage servo expressed in volts? c) What is the sensitivity of the carriage servo expressed in volts/volt?

The non-linear behaviour (clipping characteristic) has been introduced deliberately to prevent the carriage hitting the end stops too hard and damaging the rig.

Effect of Servo Gain on Hysteresis

Disconnect the servo input (socket H) from the set-point potentiometer and connect the servo input to ground. Push the carriage to the right with your hand and gently release it. Make a note of the carriage position voltage. Repeat, pushing the carriage in the opposite direction and letting go again. Hence calculate the hysteresis of the carriage servo in volts. Compare this figure with that obtained in b above. Reduce the servo gain pot to about 25% of its range and repeat the test. Finally put the servo gain to maximum and measure the carriage hysteresis once more. What conclusion do you draw about the effect of servo gain on the amount of hysteresis present in the carriage servo? Can you explain the reason for your observation?

Transient response of the Servo Subsystem

Reduce the velocity feedback to zero. Use a signal generator to apply a +1V square wave of frequency 1Hz to the input of the carriage servo. Observe the carriage position on an oscilloscope (socket J1). Adjust the servo gain until the response shows a small overshoot of about 15% (damping ratio of about 0.7). Now increase the servo gain to a maximum and adjust the velocity feedback pot (P4) so that the response is similar to the one observed previously.

Page 25: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.5

Which of these modes of operation is preferable? Explain your reasons. From now on leave the gain of the carriage servo at a maximum and the amount of velocity feedback at the value that produced a step response with a slight overshoot.

Dynamic Model of the Pendulum In this part of the experiment we will model the dynamic behaviour of the pendulum. We shall do this by observing the transient response of the system from an initial value. Before fitting the pendulum rod into the carriage, position the mass at the end of the rod. Estimate the position of the centre of mass of the rod/mass assembly by trying to balance it on your finger. (The centre of mass is located just below the bottom of the mass). We shall call this length the effective pendulum length L. Screw the pendulum rod firmly into the carriage. Tip the rig upside down into the “crane” position. Connect the pendulum angle signal, θV , to the oscilloscope. Alternatively the PCS software can be used to log θV . Connect the Control Module to the computer as described in Getting Started. In the PCS software select Derive Characteristics from the Controller menu. Position the Carriage Module as for crane mode. Press Start and the input values will be plotted on a graph for you. You can select θV alone by un-ticking the other tick boxes on the right hand side of the graph, leaving just the TH (θ ) box ticked. Also the box on the left hand side of the screen in the controller area will log the time and extent of points of maximum displacement. Displace the pendulum by about 30°, release it and record the transient response. Record the magnitude of the points of maximum displacement on either side. After about 20 cycles stop the logging. Estimate the period of oscillation, T. From these values we can calculate the logarithmic decrement. This is calculated according to the following formula:

)/ln( 2+= kk mmα

where km is the magnitude of the kth overshoot. If θV is not equal to zero when the rod is hanging motionless, then you will need to recalibrate the theta potentiometer as described in Appendix 1.

Page 26: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.6

The value of the period can be calculated theoretically from the basic dynamics of a simple pendulum. The well-known formula for the period

is gLπ2 . Do this calculation using the effective centre of mass obtained

earlier and compare the period obtained with that observed experimentally. From the logarithmic decrement the damping ratio, ζ , may be calculated using the formula:

22 4πααζ+

= .

This system is very lightly damped, so in order to arrive at a figure for the damping ratio, it is best to plot a graph of )ln( km versus k . The logarithmic decrement, α , is twice the slope of the graph. Suppose for example the logarithmic decrement is 0.02, then the damping ratio works out to be 0.0033. You may need to modify the damping ratio figure slightly to obtain a better overall fit to the observed response. Assuming that the damping ratio is very small, the natural frequency, nω ,

can be deduced from the period, T using the approximation Tnπω 2≈ .

Suppose T is 1.02s then nω is approximately 6.16 rad/s. Thus, with a natural frequency value of 6.16rad/s and a damping ratio figure of 0.0033, the pendulum can be modelled approximately as a second order system:

22

121

1)(ss

sG

nn ωωζ ++

= ,

i.e. 20264.0011.011)(

sssG

++= .

Page 27: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.7

Modelling of the Carriage Servo We will now obtain a transfer function for the carriage servo. This can be used to obtain more accurate models of the pendulum dynamics. To do this properly, you really need a frequency response analyser, but the method described here is a simple method for obtaining an approximate second order model. First we are going to determine the bandwidth of the carriage servo. Apply a 1Hz sinusoidal signal with a peak to peak amplitude of 1 volt to the input of the servo (socket H). Observe the carriage position voltage on an oscilloscope. You may see a slight distortion because of hysteresis that is present, but the amplitude will be nearly the same as the applied signal, ie the servo-subsystem has unity low frequency gain which confirms the result obtained in c above. Increase the frequency of the

applied signal until the observed voltage has reduced to 0.7V, ie 2

1 of

the low frequency value. The frequency at which this occurs is the bandwidth of the system, bω . For a system with a damping ratio of 0.7, the natural frequency, nω , is equal to the bandwidth. Based on this approximation, calculate the natural frequency, nω . (Don’t forget to work in rad/s). Hence deduce the transfer function of the servo-subsystem assuming that the damping ratio is 0.7. As an example, a system whose bandwidth is 9.6Hz and a damping ratio of 0.7 has the approximate transfer function:

200027.0023.011)(

sssG

++= .

Page 28: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.8

Labwork 2: Analogue Control of an Inverted Pendulum Apparatus

PCS1, PCS software, Analogue I/O card (MPIBM3). Introduction

A simple pendulum swings naturally into an equilibrium position with the centre of mass below the pivot. In order to balance the pendulum in an inverted position the pivot must be continuously moved to correct the falling pendulum. This interesting control problem is fundamentally the same as that involved in rocket or missile propulsion. The rocket has to balance on its engine as it is accelerated. As the rocket tends to fall over the engine thrust must be deflected sideways to restore its course.

Measurement of the Mass Position

The controlled variable in this system is the position of the pendulum mass, y . Unfortunately y cannot be measured directly but it can be calculated simply from the measurements θ and x as

θsinLxy += (see Figure 3 on page 2.1).

For small angles the above equation approximates to

θLxy +≈

with θ in radians.

Page 29: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.9

The voltage from the angle potentiometer, θV , is scaled by a factor a (potentiometer P5), and added, by means of an operational amplifier circuit, to the voltage from the carriage potentiometer, xV :

θaVVV xy += .

The factor a can be adjusted to take account of different values of L .

Setting up the Pendulum

Disconnect all the leads from the PCS1 console including the 25 way cable. Make sure that the carriage servo gain is at a maximum and the velocity feedback potentiometer is at the value determined in Labwork 1. Also ensure that the mass on the pendulum rod is in the same position as in Labwork 1. Connect the set-point pot to the carriage servo input and check that the servo is working. Position the carriage near the centre of the track and screw the pendulum rod into its pivot. Support the pendulum in an upright position by using threaded knob and support bracket locating the end of the rod into the clearance hole machined in the pendulum weight. Tighten the wing nut onto the inside face of the support bracket to remove any slackness. With the rod / mass assembly held steady at its centre of gravity gently move the carriage from side to side using the set-point potentiometer. Monitor the voltage yV (socket L). As this voltage represents the position of the mass, it should not vary as the carriage moves. By trial and error find a value for a which minimises the variation in the calculated voltage yV . Do this test with great care, make a note of the setting and lock the potentiometer in this position. Remove the threaded knob and support bracket.

Software Linear Control of the Pendulum

Connect the Control Module to the computer as described in Getting Started. Run the PCS software. Select Linear Control. Linear control operates a simple gain model: the carriage is moved by a multiple of the displacement of the pendulum bob from the centre of the carriage (set-point is not implemented in this control method). Linear control demonstrates the basic linear characteristics of the pendulum. Linear control will be unstable. Why?

Page 30: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.10

Experiment with different values of gain. Comment on the behaviour of the pendulum when the gain is set to one. Switch in the software phase lead controller. Try it. In this Labwork you will implement in hardware the phase lead controller that just failed in software. Why does this controller work in hardware and not software?

Software Harmonic Control of the Pendulum

Switch the PCS software to Harmonic Control. Harmonic Control is based upon the Simple Harmonic Motion equation applied to y :

22

2

nydt

yd ω−= (equation 3).

Harmonic control is defined by substituting x for y in the left hand side of this equation:

22

2

nydt

xd ω−=

and implementing the resulting differential equation. Harmonic control demonstrates the basic harmonic (oscillatory) behaviour of the pendulum. Experiment with different values of 2

nω . Harmonic control will be unstable. Why?

Transfer Function for the Inverted Pendulum

We will now tackle the dynamics of the pendulum in terms of Laplace transforms. No description of the theory of Laplace transforms is given here. For such a description, please refer to a fuller source such as one of the references given in Appendix 6 at the end of this manual. Initially we will neglect the dynamics of the carriage servo, i.e. assume that its response time is very fast in comparison with the pendulum. The inverted pendulum can be linearised and modelled by the transfer function:

2

2

1

1)(

n

ss

XY

ω−

=

Page 31: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.11

where nω is the natural frequency in rad/s determined experimentally in Labwork 1. (This is equation 3 expressed in Laplace transforms). Using the equation for the period of a pendulum this equation can be rewritten as:

2211)(

sds

XY

−= where

gLd = .

Consider the transfer function for your pendulum. For example, if nω is 6.16 rad/s, the transfer function is:

2264.011)(

ssGp −

= .

Consider this transfer function. Examine the s-plane pole/zero pattern and confirm that the open loop transfer function predicts instability. Comment on the possibility of stabilisation using proportional control. Predict the form of closed-loop step response with proportional gains of –0.5, -1.0 and –2.0. We will now try out proportional control on the PCS1 unit with negative gain. Switch off the power and connect the set point potentiometer as a reference voltage to the overall inverted pendulum control system (link sockets A and B). Set up the compensator as a unity gain inverting amplifier. To do this place large resistors of equal value, e.g. 100K, across terminals D and F. Connect the output of the operational amplifier directly to the servo reference input (link sockets G and H). Make sure the gain switch is set to negative. Support the pendulum by hand and with the gain potentiometer P2, set to zero, switch on the power. You may need to adjust the set point pot to bring the carriage to the centre of the rig. Slowly increase the gain and observe the carriage action as you move the pendulum to one side. Do not release the pendulum completely because proportional control cannot stabilise this system. Examine the frequency of oscillatory behaviour at the different gains described above. Note particularly the behaviour with the gain set at unity.

Page 32: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.12

Stabilisation using Phase Lead Compensation

A compensator of the form

sddssGc )10/(1

1)(+

+=

is suggested for the pendulum. For details on the choice and design of this compensator see Ref. 1, pp 198-202 (Appendix 6).

For the Bytronic pendulum 14.081.92.0 ==d

The actual compensator recommended simply uses round numbers. It is not suggested that this compensator is in any way optimum. Better compensators may be designed taking into account the dynamics of the servo carriage (see Ref. 1, pp. 202-204, Appendix 6). The operational amplifier on the console can be used to implement a phase lead compensator.

We will use the compensator:

sssGc 01.01

1.01)(++= .

Figure 2: Inverted Pendulum Compensator

Page 33: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.13

Combine this compensator with the pG transfer function obtained above and plot the new root locus. Can the system now be stabilised? What value of gain will result in a stable closed-loop system? Choose a gain which gives the closed-loop system dominant poles in a reasonable damping ratio. To implement this transfer function as a physical compensator, consider the following: In general for an op amp circuit:

input

f

input

output

ZZ

VV

−=

where fZ is the feedback impedance round the op amp and inputZ is the impedance between the input voltage and the summing junction. For a parallel circuit consisting of a resistance, R, and a capacitance, C

RRCsCs

RZ+=+= 111

Thus for RRR == 21 and FCinput µ0.1= and FC f µ1.0= , we obtain:

ss

sRCsRC

VV

f

input

input

output

01.011.01

11

++=

++

= .

Add the compensator components as shown in the diagram above. Once more support the pendulum by hand and with the gain P2 set to zero switch on the power. Slowly increase the gain until the pendulum balances itself. Make a note of this critical value of gain. Increase the gain to the value calculated earlier and observe the response. Try gently altering the set-point value to make the pendulum move along the track. Try gently tapping the pendulum to knock it over. The inverted pendulum under the control of a phase lead compensator is reasonably robust. If any problems are experienced try setting a to 2.7, gain to 1.5, compensator components as above, servo gain to maximum and velocity feedback to approximately three-quarters.

Page 34: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.14

The Effect of Hysteresis in the Servo Sub-System

The transfer function derived above is predicted to be stable. You will however note the servo hunting continuously from side to side. This behaviour is due to hysteresis in the carriage servo. For more detail refer to Ref. 1 (Appendix 6).

Page 35: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.15

Labwork 3: Fuzzy Control of the Inverted Pendulum Apparatus

PCS1, PCS software, Analogue I/O card (MPIBM3). Introduction

Fuzzy Control is a form of control of variables which exhibit multiple modes of behaviour. Providing the behaviours can be broken down into discrete areas, the input variables are broken down in terms of the different modes of behaviour of the system and the control response adjusted accordingly. The fuzzy controller provided in the PCS software is a fixed controller (though the methods of accumulation and defuzzification can be changed). The controller was developed using the Fuzzy Control Package available from Bytronic International Ltd. This package is designed to teach the basic principles of fuzzy control and although an outline is given here, it may be necessary to refer to the Fuzzy Control Package for better understanding.

Description of the Fuzzy Controller In the case of the Pendulum, the variable to be controlled is the position of the pendulum bob, y . As we know, y exhibits both linear and oscillatory behaviour and these modes are hard to separate. The pendulum fuzzy controller works on both the error and the change in the error. The fuzzy controller attempts to handle both variables by assigning discrete ranges of behaviour to each. According to which variable is more significant, the response of the fuzzy controller is altered.

Page 36: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.16

Thus when the rate of change of y is large – when the pendulum might be in danger of falling over – the controller acts to slow the movement. When the pendulum is a large distance away from the set point, the controller attempts to move toward it. The most important aspect is the separation of these variables: when acting to balance the pendulum, movement to the set point is set aside. Moving to the set point will only be done when the pendulum is balanced. In fact these actions are in opposition and the pendulum will often balance some distance from the set point. The first step, the breaking down of the variables down into discrete areas of behaviour is known as fuzzification. Fuzzification

Thus error is broken down into five discrete regions -ve Big, -ve Small, Zero, +ve Small, +ve Big. Each of these ranges is indicated above either by a single diagonal line (edges, -ve Big and +ve Big) or by a triangle (in the middle, the others). The carriage position signal ranges from -10 to +10 and these five regions cover the range.

Change in error is similarly broken down into five ranges: -ve Far, -ve Near, Zero, +ve Near, +ve Far. The height of the triangle at each point indicates the degree of membership of that range. Thus a pendulum change in error signal of -4 would be said to be 0.6 a member of -ve Far. Ranges overlap so -4 would also be said to be 0.4 a member of -ve Near. A pendulum change in error signal of -0.5 would be said to be 0.9 a member of Zero and 0.2 a member of -ve Near.

Page 37: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.17

The degree of membership indicates the weight that is given from the signal to that range. The pendulum change in error signal actually ranges from -10 to +10 but signals greater than plus or minus 5 indicate that the pendulum is irrevocably in the process of falling over. Rules

The signals from the two variables Error and Change in Error are now allowed to interact according to the fuzzy rule base. The rule base used here is:

Error

-ve Big -ve Small Zero +ve Small +ve Big -ve Far -ve High -ve High -ve Low -ve Low Zero -ve Near -ve High -ve Low -ve Low Zero +ve Low

d/dt (s-y) Zero -ve Low -ve Low Zero +ve Low +ve Low +ve Near -ve Low Zero +ve Low +ve Low +ve High +ve Far Zero +ve Low +ve Low +ve High +ve High

Thus an error range of –ve Big combines with a change of error range of Zero to give and output of -ve Low. +ve Small combines with -ve Near to give an output of Zero. The advantage of the fuzzy controller is that different requirements of the pendulum and carriage in different circumstances can be accommodated. Thus in the rule base above, when the change in error is -ve Far or +ve Far, the response is always -ve or +ve, regardless of the value of Error. This corresponds to the situation that the pendulum is in danger of toppling over and needs to be stabilised: the positional behaviour can be discarded. For smaller values of change in error, the ‘change in error behaviour’ is less significant and the error value can be given more emphasis. This allows the fuzzy controller to control the two different input variables. Fuzzy controllers are relevant when there are two or more input variables which interact, or a single input variable which demonstrates different modes of behaviour. When a single, stable, variable is to be controlled, PID control is better. The control action is calculated from the overall table (see below). When considering each individual output action, we need to calculate the weight given to each of these output ranges. Thus a signal of 0.2 –ve Big and 0.8 –ve Far gives an output signal of +ve High which needs a weight. There are two ways of calculating this weight: multiplication of the two values, or taking the minimum of the two values. Multiplication gives a weight to +ve High of 0.16. Minimum gives a weight of 0.2. These two

Page 38: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.18

methods are known as Product and Minimum. You can choose between these in the fuzzy controller. Defuzzification

The output signals now need to be transformed back into a physical signal. The physical output range is –15 to +15 in order to allow some signals to be given extra weight over ±10. Zero, 0, obviously corresponds to not moving the carriage. The physical output corresponding to each range is: -ve High -15 -ve Low -7.5 Zero 0 +ve Low +7.5 +ve High +15. At this point we may have, say, an error vector of 0.3 +ve Small, 0.4 Zero, and a change in error vector of 0.7 Zero, 0.3 +ve Near. How do we convert this into a signal? Firstly, we substitute the output strengths for the output ranges in the table above:

Error

-ve Big -ve Small Zero +ve Small +ve Big 0 0 0.4 0.3 0 -ve Far 0 -15 -15 -7.5 -7.5 0

-ve Near 0 -15 -7.5 -7.5 0 7.5d/dt (s-y) Zero 0.7 -7.5 -7.5 0 7.5 7.5

+ve Near 0.3 -7.5 0 7.5 7.5 15 +ve Far 0 0 7.5 7.5 15 15

Then we convert the relative strengths of each signal in the table into an overall signal. There are two methods. The first method weights the signals according to their relative strengths. Using product accumulation: (0.4*0.7*0 + 0.3*0.7*7.5 + 0.4*0.3*7.5 + 0.3*0.3*7.5) / (0.4*0.7 + 0.3*0.7 + 0.4*0.3 + 0.3*0.3) = 4.5. This is known as Centre of Gravity defuzzification. The other takes the largest signal. (Product and minimum accumulation are not relevant here): 0.4>0.3>0,0,0 and 0.7>0.3>0,0,0 so output signal (0.4 column, 0.7 row): 0. This method is known as Middle of Maxima. Selection between those two methods is available in the fuzzy controller.

Page 39: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.19

Use of the Fuzzy Controller

Connect up the PCS1, switch on, run the PCS software, select Fuzzy control and press Start. Fuzzy control is a reasonably good controller for balancing the pendulum. Try using Product and Minimum accumulation, Centre of Gravity and Middle of Maxima defuzzification. Set point positions are amplified: if set point is set to 0.1, the pendulum will move approximately an inch down the track, to roughly the position where 1 or 2 ought to be. This is clearly seen when using a sinusoidal input.

Page 40: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.20

Labwork 4: Direct Digital Controller Design and Implementation: Inverted Pendulum Apparatus

PCS1, PCS software and Analogue I/O card (MPIBM3). Introduction

Balancing the inverted pendulum using a direct digital controller is by no means a trivial exercise, either from the point of view of design or implementation. You can do this labwork simply using the designs given. In order to design controllers you will need access to some Computer Aided Control System Design (CACSD) software. To implement the Z Controller you can use the PCS software. Alternatively a program that implements a control strategy in terms of difference equations at a particular sample rate can be written relatively easily. The procedure for implementing this is given in the PCS software help file. The inverted pendulum controller design is particularly difficult because the model obtained experimentally describes the large signal behaviour of the system. However, near the point of balance it is the small signal behaviour that is significant. In this behaviour factors such as friction and stiction become pronounced. Thus the model used for design is not the one that describes the behaviour well near the normal operating point. This is rather different from process control situations where the small signal behaviour is less affected by the type of non-linearities generally present in such systems.

Page 41: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.21

Thus in designing the controller a very conservative approach must be adopted and the rules derived for well behaved linear systems must be interpreted with a healthy scepticism and invariably some trial and error is necessary to arrive at a workable robust solution.

Design of a DD Controller using a Simplified Model

Design Criteria and Sample Rate Selection

In this exercise we shall design a z-domain compensator using a simplified model of the inverted pendulum in order to show the approach. The servo dynamics and any damping in the pendulum pivot are neglected, ie the plant dynamics can be adequately described as

2

2

1

1)(

n

p ssG

ω−

= .

For the purpose of this exercise a natural frequency of 6.16 rad/s will be assumed, i.e. a period of just over one second. The important decisions are the desired closed-loop behaviour and the sample time. These two factors are linked in the analysis. An exposition follows. As the open loop system is second order, it is not unreasonable to demand that the underlying dynamics of the closed-loop system should also be second order. However, the controller that results produces an inadequate control action. In order to achieve a more robust control system, the target closed-loop dynamics will be specified as third order. For simplicity we will choose a characteristic equation with repeated roots. Now a third order system with three identical lags of 0.25s has a 5% settling time of 1.5s which is a reasonable specification for the system considering the underlying dynamics of the pendulum.

Page 42: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.22

As well as the dynamic design criterion, a target must be set for the steady-state performance of the control system. In the analogue design, a Type 0 phase advance compensator was employed. With this compensator a forward gain of –2 was just achievable. This corresponds to steady-state gain of

5.131

31

=−−=

+ KK

For the DD controller, however, we will specify steady-state set-point following, i.e. unity closed-loop gain. This requires 1)1( =F . The guidelines for sample time selection for DD controllers suggest that the sampling frequency should exceed about 20 times the closed loop bandwidth. (See Ref. 1). Now a system with three repeated lags of time constant 0.25s has a (-3dB) bandwidth of about 0.08/0.25 = 0.32Hz. Hence the sampling frequency should exceed 6.4Hz (150ms sample time). Too high a sampling rate causes real s-plane poles to be bunched very close to z=1 in the z-domain. The same guidelines recommend that the sampling frequency should be less than 0/50 τ where 0τ is the dominant open-loop time constant of the system. Now the system we are dealing with has a pair of real poles at ±6.16. Thus the sampling frequency should be less than 50*6.16 = 310Hz (3.2ms sample time). A certain amount of trial and error is required, but a sampling time of 0.055s (18.2Hz) does produce a working controller and this figure is in agreement with the theoretical limits described above.

In the z-domain a time constant of 0.25s maps to the point 25.0T

ez−

= on the real axis. For T = 0.055s this point on the z-domain is approximately +0.8. Thus the desired closed-loop characteristic equation is:

0)8.0( 3 =−z .

Page 43: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.23

Pole Placement

The assumed transfer function of the inverted pendulum is:

20264.011)(

ssGp −

= .

The z transform of this system including the zero order hold is:

−=−

2

2

1

11)(

n

sT

p sseZzG

ω

.

−−= 22 /)1(

111

nssZ

zz

ω

)7.0)(4.1(

)1(058.0−−+−=

zzz

.

See Appendix 3 for details of how to obtain this result. This open-loop system has an unstable pole at +1.4 and a zero on the unit circle. Since

)(1)(

)(1)(

zFzF

zGzG

pc −

=

the unstable pole can be removed by giving )(1 zF− a zero of the same value, and the zero can be removed by setting )(zF to incorporate the zero of the open-loop system that lies on the unit circle. Thus the form of the closed-loop transfer function will be

310

)8.0())(1()(

−++=

zzbzzbzF

The coefficients 0b and 1b are included to meet all the degrees of freedom required. Their values will be chosen to satisfy the steady-state closed-loop gain criterion 1)1( =F , and the requirement that )(1 zF− has a zero at +1.4.

Page 44: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.24

The numerator, )(zN of )(1 zF− is

))(1(512.092.14.2)( 10

23 bzzbzzzzN ++−−+−=

For a zero at 4.1=z we must have 0)4.1( =N , thus

216.0)4.1(4.2 10 =+ bb

The steady-state requirement 1)1( =F gives the equation

31

0 )8.01()1(21

−+= bb

Solving these two equations simultaneously, we obtain 215.00 =b and

9814.01 −=b . Thus

)301.0916.1615.2()9814.0)(1(215.0

)(1)(

23 −+−−+=

− zzzzz

zFzF

)215.0)(4.1)(1(

)9814.0)(1(215.0−−−

−+=zzz

zz .

So

)(1

)()(

1)(zF

zFzG

zGp

c −=

)215.0)(1(

)981.0)(713.0(7.3−−

−−−=zz

zz .

This controller gives good results, though a slight change in the controller gain may improve matters because of modelling errors.

Implementing the Controller using the PCS software

The above controller is not very robust because it used a simplified model of the pendulum and ignored the servo dynamics, but it should balance it. Connect up and switch on the PCS1. Run the PCS software. Select Direct Digital Control and check that the sample time is set to 0.055 seconds.

Page 45: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.25

The controller comes preset to

)215.0)(1()981.0)(713.0(7.3)(

−−−−−=

zzzzzGc .

Hold the pendulum upright and hit start. The pendulum should balance fairly quickly. Occasionally it can even pick up the pendulum from a standing start. The set-point comes set to a static value, 0. Try changing this value and verify that the pendulum continues to balance. Then switch to the sine wave set point. The pendulum will balance while moving from right to left and back again in a sine wave.

Further work

1. The above compensator did not take into account the slight damping in the pendulum and ignored the dynamics of the servo. Try the following compensator which was designed taking both factors into account:

)97.0)(32.0)(19.0()94.0)(72.0(8.8)(

−++−−−=zzz

zzzzGc

2. Design a compensator neglecting damping and servo dynamics with a

sample time of 0.11s. Try it out.

Page 46: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.26

Labwork 5: Direct Digital Controller Design and Implementation: Swinging Crane Apparatus

PCS1 apparatus, PCS software and Analogue I/O card (MPIBM3). Introduction

When the PCS1 carriage module is inverted, i.e. in the crane position, the apparatus mimics an overhead crane or a grab. In practice the grab is moved out over the material/goods to be raised, the grab is lowered and then raised to lift the material. The problem is that if the top of the grab is moved suddenly, the other end starts to swing violently and it takes a long time before the oscillations have died away and the material can be hoisted safely. The object of this labwork is to devise a control law that will allow the grab to reach a steady-state as fast as possible after a demand change in its horizontal position. The dynamics of the system are essentially those of a pendulum and because of the very low damping, the system shows a pronounced resonance at the natural frequency of the rod/mass combination. Conventional analogue control of such a system using lead or lag compensators is very difficult. The best approach is a ‘notch’ filter, ie a filter that has an anti-resonance. By placing the notch near the natural frequency of the ‘crane’, the overall frequency response characteristic is smoothed out and then a simple compensator can be employed to satisfy the design criteria. However this approach will not be pursued here and it is left for students to explore this method for themselves. Rather than attempt to control the system using analogue methods, discrete controllers will be designed and implemented. The nature of the system

Page 47: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.27

lends itself very well to such methods that result in simple, robust and effective control, for example a dead-beat controller.

Page 48: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.28

Sample Time Selection and Design Objectives

Many of the arguments regarding sample time selection discussed in Labwork 4 for the inverted pendulum are not applicable for the apparatus in this position. Although the system is very oscillatory, it is stable, and even with a sluggish servo the system can be brought to rest. In the inverted pendulum mode, it would not be possible to “catch” the pendulum before it topples over completely if the servo behaviour were too slow or if the sample time were too long. In the case of the crane problem we can design an effective controller with a much slower sampling rate. For this system we can choose a more demanding design objective, ie dead-beat control with steady-state set-point following, ie a compensator with integral action. Dead-beat control brings the system to rest in a finite number of samples. As the system is second order, we can theoretically achieve dead-beat behaviour in two sample intervals. Now, as the system oscillates naturally with a period of 0.94s, it seems natural to try and bring it to rest in a half period. These arguments lead to a sample time of 0.94 / 4 = 0.235s. This value can be selected in the PCS software. In this application we can neglect the dynamics of the servo as it is so much faster and better behaved than the crane. Furthermore as a first approximation we can neglect the damping in the pendulum. The transfer function relating the centre of mass of the rod/mass assembly to the carriage position is assumed to be:

2

2

1

1)(

n

p ssG

ω+

=

with nω = 6.16 rad/s. To transform this into the z-domain we follow the same procedure as before and require partial fractions:

+−=

22

21)(n

nsT

p sseZsG

ωω

+−= 22

211

n

n

ssZ

zz

ωω

Page 49: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.29

+−−= 22

11

nss

sZ

zz

ω

+−−−

−−= 2cos21

)cos(1

1zz

zzz

zz

θ

2

2

cos21)cos)(1(cos21

zzzzzz

+−−−−+−=

θθθ

2cos21coscos1zz

zz+−

−+−=θ

θθ

2cos21)1)(cos1(

zzz+−+−=

θθ .

For the pendulum, 354.122.0*155.6 === Tωθ 215.0cos =⇒ θ . Hence

243.01)1(785.0)(zz

zzGp +−+= .

Plot the root-locus of this transfer function. You will obtain a pair of poles on the unit circle. These poles represent the oscillatory dynamics of the pendulum. A sample time of four times the natural frequency would make these poles on the unit circle pure imaginary.

Dead-Beat Controller Design using Simplified Plant Model

To design this compensator, we allow )(zGc to cancel the two poles on the unit circle. This effectively produces a notch filter that cancels the pendulum resonance. Cancelling the plant zero on the unit circle would result in a marginally stable controller (ref 1, p.311). For steady-state set-point following, the closed-loop transfer function will be:

2)1(5.0)(

zzzF += .

The compensator is given by:

Page 50: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.30

)(1)(1)(zF

zFG

zGp

c −=

Therefore

)5.0)(1()43.01(637.0)(

2

+−+−=

zzzzzGc .

Use of Dead-Beat Controller

Place the PCS1 carriage module into the ‘crane’ position. Connect and switch on the PCS1. In the PCS software, select sample time of 0.235s and enter the compensator transfer function above. Select Reset Pendulum. Press Start, steady the pendulum and hit OK. Is the performance what you would expect? Why does the controller perform like this?

Frequency Response of Plant and Compensator

Plotting the open-loop frequency response of the compensator and plant and the compensator on its own in a suitable package you will observe that the compensator has an anti-resonance that cancels the plant resonance.

Dead-Beat Controller Design using Plant Model with Damping

The modified transfer function including damping is:

20264.0001.011)(

sssGp ++

= .

In the next sections we shall design a controller that takes into account the damping in the actual system.

Page 51: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Labworks

© Bytronic International Ltd Pendulum Control System

3.31

Ringing Pole Problem

When damping is introduced in the plant transfer function, the poles and zeros all move inside the unit circle, ie

91.041.0)97.0(76.0)( 2 +−

+=zz

zsGp .

If a dead-beat controller is designed using the above model where the zero at 9.0−=z is cancelled, the compensator will have a pole at

9.0−=z . The resulting compensator is:

)97.0)(1()91.041.0(32.1)(

2

+−+−=

zzzzzGc .

Run the PCS software and select Direct Digital Control (Crane Mode). The transfer function should be as above and check that the sample time is set to 0.235s. Click Centre Carriage, settle the pendulum and press Start. You will observe an oscillatory mode occurring even in this quiescent state. Switch to the sine wave set-point. Switch back. Clearly, cancelling a zero on the real negative axis is not advisable. In fact there is very little advantage to be gained by cancelling any plant zeroes at all.

Correct Design Approach to Avoid Ringing Pole Problem

This time the compensator is designed without cancelling the zero at

97.0−=z . The resulting compensator is:

)5.0)(1()91.041.0(67.0)(

2

+−+−=

zzzzzGc .

Try the response with this compensator and compare the results with those obtained with the simpler plant model. Switch in the sine wave set-point. The controller will follow the set-point, albeit slowly. Try refining the plant model so the correlation between the actual crane and the simulation is close.

Page 52: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.1

Appendix 1: Recalibrating the Angle θ Servo Potentiometer

Connect a DVM to the angle theta 4mm terminal on the PCS1 control module. Check that when that pendulum is upright, the voltage is 0V. This is most easily done in crane mode. If the voltage is not 0V then the servo potentiometer in the carriage assembly requires adjustment.

Adjusting the Servo Potentiometer

1. Carefully remove the two M3 retaining screws holding the plastic

cover onto the carriage assembly. 2. Gently move the plastic cover off the assembly, exposing the servo

potentiometer. 3. Slacken the three servo potentiometer retaining screws. 4. Adjust the servo potentiometer by rotating it so that when the

pendulum is vertical, the voltage feedback is 0V. 5. Tighten the three retaining screws and re-check angle theta. 6. Reassemble the carriage module and test the operation of the unit.

If the problem recurs check the tightness of the M3 retaining grub screw which clamps the servo potentiometer shaft.

Page 53: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.2

Appendix 2: Resetting the X Position Potentiometer

Connect a DVM to the control panel signal ‘x’. With the system powered up, connect the set point to the servo input. Slide the set point to position the carriage assembly in the middle of the track (the track is 500mm long). If the voltage at ‘x’ is not 0V then the x position potentiometer needs adjustment. The ‘x’ position potentiometer is located at the non-driven end of the carriage module. The detailed assembly is shown in Figure 5.

Figure 5 - Mounting of the X Position Potentiometer

1. Position the carriage assembly accurately in the centre of the track by

sliding the set point potentiometer. 2. Unlock the two retaining grub screws in the flexible coupling Part A,

see Figure 5 above.

Page 54: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.3

3. Rotate the flexible coupling by hand so as to turn the potentiometer shaft but not the timing gear and carriage assembly. Turn the coupling until 0V is achieved on the DVM.

4. Add a little nut lock to the grub screws ‘A’ and lock up tight. 5. Re-check that the voltage at the centre position is 0V. 6. Use the set point potentiometer to move the carriage from one end to

the other. The carriage should be electronically limited to stop approximately 15mm short of the end stops.

If not, recalibrate the limiter as described below:

a) Remove the four retaining screws on the control panel. b) Slide the set point to +10V, the carriage should be at the motor end

of the track. Trim the multiturn potentiometer on the control pendant PCB labelled ‘positive limit’, so that the carriage stops short of the end by approximately 15mm. Now repeat the same adjustment for the set point at –10V and trim the multiturn potentiometer labelled ‘negative limit’.

c) Reassemble the control panel.

7. The carriage should now be correctly calibrated and meet the following criteria:

a) With the carriage assembly at the centre of the track, the ‘x’ voltage

is 0V. b) The carriage assembly should stop short of the end stops by

approximately 15mm. c) The x voltage to your right should be positive and the voltage to

your left should be negative, and both end limits should be approximately equal.

Page 55: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.4

Appendix 3: Derivation of Plant Controller

Consider

2222

2

221

)()/1(11

ass

ssasa

ass −−=

−=

−.

Check

)/1(1

)()( 2222

2

22

222

assassa

asssas

−=

−−=

−−− .

Now

−+

+=

−+

asasass 11

21

22.

Check

22))(()()(

21

ass

asasasas

−=

−+++− .

Consider

21212

12

21 )()(11ββββ

ββββ ++−

−+−=−

+−

=

−+

+ zzzzz

zz

zz

asasZ ,

where aTe−=1β , aTe+=2β .

Page 56: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.5

Thus

1)2/(

222 +−−=

− zzzz

assZ

λλ

where 21 ββλ += . So

)1(

)2/(1/1

11222 +−

−−−

=

− zzzz

zz

assZ

λλ .

1

)2/)(1(1/1

111222 +−

−−−=

−−

⇒zz

zzass

Zz

λ

1

)2/)1/1((12

22

+−++−−+−=

zzzzzzλ

λλ

1

2/1)2/1(2 +−

−+++−=zzzz

λλλ

1

)1)(2/1(2 +−

+−=zz

λ

))(()2/1)(1(

21 ββλ−−

−+=zz

z .

Now for inverted pendulum, a = 6.1546, T = 0.055 second, 1β = 0.712,

2β = 1.403 λ⇒ = 2.115. So:

)403.1)(712.0()1(0574.0)(

−−+−=

zzzzGp .

Page 57: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.6

Appendix 4: Technical Specification

Mains Supply 110V ac or 220-240V ac, switch selectable. Fuses Mains fuses 2 off 5Amp Control unit 2 off 250mA

Internal PSU ±20V dc unregulated ±15V dc Regulated ±4% ±10V dc Regulated

Servo Motor with Integral Tachometer Nominal Supply Voltage 24V dc Maximum Continuous Torque 14Ncm Maximum Peak Torque 36Ncm Motor Voltage Constant 10.3V/1000rpm Motor Torque Constant 9Ncm/A Mechanical Time Constant 20ms Rotor Inertia 214gcm² Motor Inductance 5mH Tachometer Assembly Inertia 10.5gcm²

Servo Power Amplifier

Burr Brown OPA541AP with internal current limit set to 2.0 Amps

Belt 10mm wide 5 mm pitch – 1300mm long Kevlar braided timing

belt

Belt Tension Adjusted by moving motor unit

Angle theta measured using 5K Servo Potentiometer Position X measured using 5K Multiturn Potentiometer

Page 58: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.7

Appendix 5: Header Pin-out Details Connector 1: 26 Way IDC Microcomputer Header

Function Pin No Function GND 1 2 Position X

3 4 Position Y 5 6 Set Point 7 8 Angle θ 9 10 Tacho Feedback 11 12 13 14 15 16 17 18 19 20 21 22 DAC o/p to Limiter 23 24 as pin 22 25 26

Page 59: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.8

Appendix 6: Recommended Texts for Block Diagrams, Laplace and Z Transforms

Reference 1: “Control System Design and Simulation”, Golten, J. and Verwer, A., McGraw-Hill, 1991. Reference 2: “Modern Control Engineering”, Ogata, K., Prentice-Hall, 1990. Reference 3: “Laplace and Z Transforms”, Boulton, W., Longman, 1997.

Page 60: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.9

Appendix 7: MATLAB Solutions for DDC Controllers

Inverted Pendulum

%********************************************************************************%% MATLAB m-file. %% Description: Compensated controller for the Bytronic PCS1 (Pendulum Control %% System), configured for inverted operation. %% %% Series compensator control of pendulum position, x axis. Feedback is position %% Denoted by X on the hardware version of the controller, here it is denoted %% 'y'. %%********************************************************************************%

% initialise

clear;

a=0; ,b=0; ,c=0;d=0; ,e=0; ,f=0;y=0;u=0;

% centre the pendulum cart

dacout(640,0,2047);

echo onmore off

% Press any key to get started

echo offpause;

% user options

userinput=input('\n\nPress 1, for Step Input, Press 2, for Sinusoidal Input \n\n');

setpoint=input('\nEnter a setpoint value between -10 and +10\n\n');

if userinput==1

amplitude=input(\nEnter an amplitude value between -10 and +10\n\n');

end

Page 61: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.10

% control law:% difference equation method

% time stamp

timeref=cputime;

for i=1:1000

% literal value of input

uin=adcinp(640,0,1,1);

% prescalar

u=(uin/204.8)-10;

% error signal

if userinput==1error=setpoint-u;

elseerror=setpoint+amplitude*sin(i*pi/180)-u;

end

% values for u(t), u(t-1), y(t-1) ... etc

a=b;b=c;c=error;d=e;e=y;

% difference equation

y = -(3.7*c) + (6.2678*b) - (2.5882*a) + (1.215*e) - (0.215*d);

% NOTE should be a time delay (to make up net delay of 0.055 secs) but everything isslow anyway% Delay loop may need adjusting% Note delay is crucial to definition of difference equation

dacout(640,0,(y+10)*204.8);

% timer

while cputime<(timeref+(i*.05))end

end

Page 62: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.11

Crane

%********************************************************************************%% MATLAB m-file. %% Description: Compensated controller for the Bytronic PCS1 (Pendulum Control %% System), configured for crane mode. %% %% Series compensator control of pendulum position, x axis. Feedback is position %% Denoted by X on the hardware version of the controller, here it is denoted %% 'y'. %%********************************************************************************%

% initialise

clear;

a=0; ,b=0; ,c=0;d=0; ,e=0; ,f=0;y=0;u=0;

% centre the pendulum cart

dacout(640,0,2047);

echo onmore off

% Press any key to get started

echo offpause;

% user options

userinput=input('\n\nPress 1, for Step Input, Press 2, for Sinusoidal Input \n\n');

setpoint=input('\nEnter a setpoint value between -10 and +10\n\n');

if userinput==2

amplitude=input('\nEnter an amplitude value between - 10 and +10\n\n');

end

% control law:% difference equation method

% time stamp

timeref=cputime;

for i=1:1000

% literal value of input

uin=adcinp(640,0,1,1);

% prescalar

u=(uin/204.8)-10;

Page 63: Documentation for the Bytronic Pendulum Control Systeminconsy/lab/frames/experiments/... · 2007. 4. 4. · linear positioning control system and then an inverted pendulum balancing

Appendices

© Bytronic International Ltd Pendulum Control System

4.12

% error signal

if userinput==1error=setpoint-u;

elseerror=setpoint+amplitude*sin(i*pi/180)-u;

end

% values for u(t), u(t-1), y(t-1) ... etc

a=b;b=c;c=error;e=f;f=y;

% difference equation

y = (0.637*c) - (0.27*b) + (0.637*a) + (0.5*e) + (0.5*f);

% NOTE should be a time delay (to make up net delay of 0.235 secs) but everything isslow anyway% Delay loop may need adjusting% Note delay is crucial to definition of difference equation

dacout(640,0,(y+10)*204.8);

% timer

while cputime < (timeref + (i*0.23) )end

end