Design & Implementation of Mechanical System Control Software ...

laboredbumbaileySoftware and s/w Development

Jun 7, 2012 (5 years and 1 month ago)

626 views

Updated: January, 2004

Copyright © 2001
-
04 D. M.
Auslander

1

Design & Implementation of
Mechanical System Control Software

-
Java Edition
-

David M. Auslander

Mechanical Engineering

University of California

Berkeley

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

2

Control Software: Managing
Complexity


Software:


Implementation medium


Base language of discourse


Computers (hardware)


Implementation mechanism


Design


Complexity
-
> Software


High level language of discourse

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

3

Computing Language History


Assembly


Hardware specific


C


Mid
-
level, targeted for Unix, adapted for control


C++


C plus “object
-
oriented”


Java


C++ civilized

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

4

Computers for Mechanical
Systems


Very wide range (unlike the desktop)


$1
-
> $100,000 for control computers


All language levels still in use


Embedded computing


Real Time computing


We use PCs as prototypes for embedded
computers

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

5

Why Java?


Portability


Roots in embedded world


Current interest very high


Good structure


Consistent syntax


Protection from many hard
-
to
-
find errors


Native interface for hardware specific functions


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

6

Portability


Ability to run software across platforms


Source portability


Binary portability


Stages of development cycle


Concept, feasibility, prototype, production


Product upgrades, new models, etc.


Economics: software maintenance top cost

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

7

Java and Portability


Compiles to universal binary code


Java Virtual Machine (JVM) interprets this code


Portability requires only a JVM for target


Java syntax includes more of modern computing


Network (TCP/IP)


Graphic user interface (GUI)


Archive format, packages


Documentation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

8

Applications, Applets


Applications are “normal” programs. They are
invoked and executed on a local computer (our
environment)


Applets are internet (web) programs


Early web (http) was passive


local computer just
displayed


To take advantage of local computing power, various
methods were invented to download a program via
the browser

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

9

Applets


Applets are such programs


Downloaded from server (remote) to client (local)


Executed by software in browser


Total portability required (browser can be on any
kind of computer)


Java was invented for applets (after false start
on embedded use)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

10

Tools


Operating systems


Windows 2000


development, GUI, debug


QNX


real time


Compilers


NetBeans (a Sun
-
sponsored, open
-
source project)


IBM J9 (Visual Age Micro Edition)


for QNX


All (except win2000) available for free download

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

11

Programming Model: Scripts +
Objects


Objects are software modules that are
abstractions (representations) of “things”


Documents (word processors)


Beams (finite
-
element program)


Bank accounts


Student records


Air hockey pucks


Etc.

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

12

“Objects”


The quotes are because they aren’t objects!
They’re just abstractions


A software object is based on a model with


Data, and


Methods that can manipulate the data


Keeping the data and methods together is a
major contribution of object
-
oriented
programming

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

13

Object
-
Oriented Programming


Classes, the models (or templates) for objects


Collect variables (member variables)


Define methods (functions) that can operate on
those variables


A class defines a model


As many copies as needed can be created
(instances, instantiations)


Each one gets a private set of the variables

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

14

Inheritance


There is often a need to create an object
-
model
(class) that is very much like an existing one


Inheritance provides for defining new classes on
the basis of additions to existing classes


Avoids (text) copying and difficulties with
maintenance

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

15

Scripting


Scripting governs what is done with objects


The script can be explicit or implicit, in the same
or another language


Implicit



Typical Windows programs


“Script” is provided by the user taking actions


Many programs provide “macros” to capture those
actions as scripts

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

16

Explicit Scripting


Algorithmic code


In the beginning … that’s all there was


Script can be in Java or another language


Examples


Java can be scripted in Matlab or
Javascript


We will script Java in Java


Control system


script controls order of events

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

17

Scripting Java in Java


Initially uses
main()

for the script


Many scripts are complete in
main()


For script
-
only program,
main()

is all that is
needed


Script language very similar to C or Matlab


Unformatted data output very easy …

System.out.println(“text “ + variable + “ other text “+ etc. …);

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

18

Java Language Details


All variables typed


usual types, int, long, float,
double, …; all are signed (no unsigned types)


Array declaration, usage mostly like C++


double x[] = new double[10];


// or /* */ pairs for comments (like C++)


‘static’ methods are like ‘ordinary’ C or Matlab
functions


Precede with class name if needed, Math.sin()

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

19

Some Personal Views on
Software Development


These come from my experience


Others may have different opinions


Development cycle


Debugging


The Demo demon

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

20

Development Rule


Test execution as often as possible


Test compilation even more often


If doing cross
-
platform work, run on all platforms
as often as possible


If something strange happens, the source of the
problem is easily identified


Violate this rule at your peril!

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

21

Debugging


Where
not

what


Debugging is an exercise in instrumenting


Look for anomalous intermediate results


If you don’t know what’s right you can’t tell
what’s wrong


Learn how to use the debugger


it can save
huge amounts of time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

22

The Demo Demon


Ever noticed that things tend to fail when most needed
(as in a critical demo)?


Working rule: archive and freeze working versions of
software.


Demo failures of software that “worked yesterday” are
usually the result of changes that were considered
“inconsequential”


Zip files make good informal archives


Many formal version control methods available

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

23

Classes and Objects


Define a class

public class NameOfClass

{


public int anInt;


private double v1; // variables …


public NameOfClass(int x, …) // Constructor


{






}


public int firstMethod(int a,double b) // Methods …


{



double q = 2.0 * b; // Body of method



return (int)q;


}

}


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

24

Creating and Using an Object


Creating (instantiating) an object means creating
a space in memory for it

NameOfClass anObject = new NameOfClass(
-
arguments of constructor
-
);


Use it by invoking its (public) methods or
accessing its public variables




anObject.firstMethod(I,z);



anObject.anInt +



It is not necessary to erase an object; Java
does that automatically


garbage collection

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

25

Typographic Conventions


Class names begin with capital letters


Method, variable names begin with lower case


Braces
--

standard convention seems ridiculous
to me!


that is, start brace on same line


I put matching braces at the same indent level

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

26

Graphical User Interfaces
(GUIs)


The screen consists of objects


windows,
pictures, text, numbers, controls, …


The operating system maintains them on the
screen


Programs populate them through a very complex
set of function calls


IDEs often provide graphical means to do this

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

27

Events


The user interacts with the GUI via keyboard and
mouse events


Programs respond to these events via “callback”
methods


Methods that are set up in advance to respond to specific
events


In a nutshell, GUI programming involves designing the
screen elements (objects) and writing code to respond
to events involving those objects

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

28

Layout Managers


Java is portable so programs can execute in
many environments


Layout managers try to maintain portability in
graphic elements


Aspect ratio, color maps, screen size and resolution..


Read help section on different layouts


‘Absolute’ layout manager is simple, but least
portable, border layout is also popular

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

29

Graphics


Plotting Data


No Java native functions for plotting


A variety of commercial and public domain
packages are available


A list of some is found at:

http://dmoz.org/Computers/Programming/Languages/Java/Class_Li
braries/Graphics/Charts/


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

30

PtPlot, JMathPlot


PtPlot is part of the Ptolemy project, Berkeley,
EECS

http://ptolemy.eecs.berkeley.edu/java/ptplot/


A very rich package


we just scratch the surface
here


JMathPlot is another package for graphics; it
seems simpler to use,

http://jmathplot.sourceforge.net/

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

31

Using PtPlot


Example shows two plots in a single window


Uses the constructor to draw the graph


PtPlot has an elaborate thread structure


Lots of experimentation required to find out other modes of
operation


One plot constructs ranges, ticks, manually


The other allows automatic internal construction

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

32

PtPlot Sample Result

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

33

Printing, Copying Plots


Print is built
-
in (to any installed printers)


Copy to clipboard is only via screen capture


Gives bitmaps rather than object versions


Don’t look nearly as good in documents

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

34

The Glue Machine


An imagined manufacturing assembly system


Use as the basis for a set of simulations that
explore much of the design and implementation
process


Start very simple; each exercise adds in more of
the system

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

35

The Object to be Assembled


Start with cylinders, bases


Glue them together


Glue is thermosetting


Automate this


Use robots for placement
and removal

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

36

Two Variants of Assembly
Configuration: #1

Conveyors
Glue
Applicator
Oven
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

37

Two Variants of Assembly
Configuration: #2

A
s
s
e
m
b
l
y
a
r
e
a
O
v
e
n
1
U
n
l
o
a
d
a
r
e
a
C
o
n
v
e
y
o
r
O
v
e
n
2
U
n
l
o
a
d
a
r
e
a
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

38

Glue00: Conveyor Motion


For simulation, approximate as a motor that supplies
torque, and a purely inertial load


Purpose of
this

simulation


Provide a model that captures just enough of the dynamic
behavior so that control software can be designed and tested


Testing is primarily for logic; the simulation is not complex
enough to predict performance

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

39

What is a (Digital) Simulation?


Software that can predict on a moment
-
by
-
moment
basis the behavior of a system in response to external
inputs and disturbances


The prediction cannot be done analytically (typically)


Simulation is often based on a numerical model


In many cases, the numerical model is based on a
differential equation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

40

Basic Motor Model




is angular velocity


t is time


i is applied current


J is rotary inertia


k


is torque constant




is angular position

J
i
k
dt
d





dt
d

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

41

Getting the Differential
Equation Model


Engineering ingenuity and creativity!


Decide on study goals


Key step


everything follows from this


What parts of real system need be considered?


Color of motor?


Mathematical representation


real world is
messy!

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

42

Numerical Model


For ODEs, many methods are available to solve


Dependent variables appear on both sides


All involve changing dx
n

to delta
-
x
n

and dt to
delta
-
t, stepping delta
-
t by some “small” amount,
and multiplying equations by delta
-
t


This process begins from some known initial
conditions (state variables are known at some
time).

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

43

Euler’s Method Applied to
Motor


Assume dependent variables do not change over step


Integrand becomes constant


Easy to implement, not very accurate or stable


Requires small step size

t
t
t
t





)
(
)
(


t
J
i
k
t
t
t








)
(
)
(
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

44

Validation


Two steps


Does the numerical solution correspond to the ODE
it comes from?


Is it an accurate prediction of the physical system’s
behavior?


Important process, difficult and expensive


Often shortchanged!

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

45

Are the Numerics Right?


Step size sensitivity


If solution is sensitive to step size, step size is too
big


Step size must be small enough for fastest mode


Test cases


Simplifications for which analytic solutions are
available


Order
-
of
-
magnitude analysis

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

46

Is the Prediction Right?


Much harder to answer


Does the system exist? Is it testable?


If yes, experiments will help validation


Experiments are expensive


If no, ???


Experience, common sense, luck

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

47

The Motor Simulation


Stand
-
alone program


Java sample
-
>
ODE1

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

48

Motor Simulation Results

0
0.5
1
1.5
2
2.5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time
Position
Position of Load
0
0.5
1
1.5
2
2.5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time
Velocity
Velocity of Load
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

49

What it comes down to...


Write the ODEs that represent the system


Chose a suitable ODE solving algorithm


Provide initial conditions, step sizes, and error
tolerances


Solver steps time, computes state variables


Given the state variables, your code computes
the derivatives of the state variables

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

50

Example ODE
-

Predator/prey


x[0] = prey population


x[1] = predator population


x’[0] = d/dt (prey population)


x’[1] = d/dt (predator population)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

51

Predator/prey ODE


Simple form of a predator/prey model is:



x’[0] = alpha
-

beta * x[1]



x’[1] =
-
gamma + delta * x[0]


alpha = natural growth rate of prey


gamma = natural death rate of predator


beta = loss factor of prey (fn of predators)


delta = growth factor of predator (fn of prey)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

52

Predator/prey code

// This code goes in the constructor...

state[0] = 5.0; // Initial number of prey.

state[1] = 1.0; // Initial number of predators.


// This code goes in the deriv() function...

dx[0] = alpha
-

beta * x[1];

dx[1] =
-
gamma + delta * x[0];


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

53

Predator/prey results

Predator vs. prey
0.00E+00
1.00E+00
2.00E+00
3.00E+00
4.00E+00
5.00E+00
6.00E+00
0
5
10
15
20
25
30
35
40
45
50
Time
# of predators, prey
Prey
Predators
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

54

Potential problems


# of predators or prey can go below 0, and
recover


Note that stepsize used is significantly smaller
than the time of one cycle of the system

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

55

For more than first order
problems...


Turn the higher order ODE(s) into first order
ODEs


For example, given y” = ay’ + by + c


Substitute for solution and derivative(s):



z
1

= y, z
2

= y’


Then solve the two first order ODEs:



z
2
’ = az
2

+ bz
1

+ c and z
1
’ = z
2





Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

56

Example ODE
-

Exploding
Canonball


Problem wants to shoot an exploding canonball
from ground level, and have it reach a target
within some precision


We define “z” as up and down, “y” in direction of
canonball travel (to avoid confusion with x)


Need a position and a velocity in both y and z

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

57

Exploding Canonball State
Variables


x[0] = position in y


x[1] = velocity in y


x[2] = position in z


x[3] = velocity in z

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

58

Exploding Canonball ODE


Time derivatives are simple physics:


x’[0] = x[1]

// d/dt of position = velocity


x’[1] = 0


// Acceleration in y is 0


x’[2] = x[3]

// d/dt of position = velocity


x’[3] =
-
32


// Acceleration in z is gravity

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

59

Exploding Canonball code

// This code goes in the constructor…


double[] state0 = {0, 100, 0, 1500};


// This code goes in the deriv() function...

dx[0] = x[1];

dx[1] = 0.0;

dx[2] = x[3];

dx[3] =
-
32.0;

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

60

Exploding Canonball results

-1.50E+04
-1.00E+04
-5.00E+03
0.00E+00
5.00E+03
1.00E+04
1.50E+04
2.00E+04
2.50E+04
3.00E+04
3.50E+04
4.00E+04
0
10
20
30
40
50
60
70
80
90
100
Time
Positon (y and z)
-2.00E+03
-1.50E+03
-1.00E+03
-5.00E+02
0.00E+00
5.00E+02
1.00E+03
1.50E+03
2.00E+03
Velocity (y and z)
Y position
Z position
Y velocity
Z velocity
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

61

Improved exploding Canonball
code

// This code goes in the constructor…


double[] state0 = {0, 100, 0, 1500};

// Drag will reduce horizontal velocity

double windResistance =
-
0.0003


// This code goes in the deriv() function...

dx[0] = x[1];

// Drag is proportional to square of velocity

dx[1] = windResistance * x[1] * x[1];

dx[2] = x[3];

dx[3] =
-
32.0;

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

62

Improved exploding Canonball
results

-1.50E+04
-1.00E+04
-5.00E+03
0.00E+00
5.00E+03
1.00E+04
1.50E+04
2.00E+04
2.50E+04
3.00E+04
3.50E+04
4.00E+04
0.00E+00
5.00E+02
1.00E+03
1.50E+03
2.00E+03
2.50E+03
3.00E+03
3.50E+03
4.00E+03
4.50E+03
5.00E+03
Y position
Z position
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

63

Simulation/ODE overview…


Getting a proper system model is perhaps the
largest challenge


There is a large (huge?) body of work on ODE
solvers; you will most likely be a solver user, not
a solver developer


In general, use a faster computer, smaller step
sizes, and smaller error limits

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

64

Java classes and inheritance


Code reuse is the driving force


Code reuse has been around for ages:


Engineering libraries for Fortran


Standard C library


Many, many others


OO techniques meant to facilitate code reuse.

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

65

Composition


Using one class from another


The relationship is:


“Has a...” OR


“Uses a…”


For a “has a…” relationship, used class goes
away when using class goes away


For a “uses a…” relationship, this is not
necessarily true

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

66

Composition (continued)


Consider a “sprinkler system” class


It should have a single “water source” object


It should have an array of “valve” objects


For each “valve”, there should be a data structure
that can encapsulate the pipes, connections, and
outlets that are downstream.


A “sprinkler system” won’t inherit from a “valve”
or a “water source”.

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

67

Composition syntax

public class SprinklerSystem {


private WaterSource water;


private Valve valves[];


private PipingTree pipes;


…..

}

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

68

Composition syntax (cont)

public SprinklerSystem(){


water = new WaterSource();


valves = new Valves[numValves];


for(int i = 0; i < numValves; i++){



valves[i] = new Valve();


}

}

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

69

Inheritance


Use only when necessary


Programmers new to OO tend to overuse


Inheritance creates a more specialized class
from a more general class


Relationship is “is a…”


The specialized class can do everything the
general class can do an more

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

70

Inheritance syntax

class Motor {….}

class MotorBrushed extends Motor

{


// Add behavior specific to Brushed type motors.

}

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

71

Inheritance syntax (cont)

public class Machine {


Motor m[2];


public void main(String[] args) {



Machine mach = new Machine();



mach.m[0] = new Motor();



mach.m[1] = new MotorBrushed();



….

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

72

TranRunJ


TranRunJ is a software base that will be used for
all control work


TranRunJ is one (of many) ways to implement a
control system designed with state transition
logic.

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

73

Tasks and States


TranRunJ is based on
tasks

and
states


This is the design model that will be used for
describing and constructing control software

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

74

Tasks


Functional, cooperating subunits


Operate in parallel (
i.e.
, “simultaneously”)


In quotes because of the basic sequential nature of
computers


Reflect parallelism in the target system


Task definition is independent of computing language or
hardware implementation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

75

Task Hierarchy Diagram


Shows relationships among hardware and
software elements of a system


Separate hierarchical levels


Show communication paths

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

76

Hierarchy for Simple Motor
-
Driven System


Velocity control


No tasks
needed for
sensor or
actuator


Operator
commands
velocity

Motor
Velocity
sensor
Amplifier
Feedback
control
Operator
interface
Data
logging
Software
Hardware
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

77

More Complex Sensor
-
Actuator Systems


Still velocity
control


Example:
Encoder, PWM


Feedback
includes
motion profile

Motor
Velocity
sensor
Amplifier
Feedback
control
Operator
interface
Data
logging
Software
Hardware
Signal
processing
(hardware)
Signal
processing
(hardware)
Signal
processing
(software)
Signal
processing
(software)
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

78

Beginning of Goal
-
Oriented
Control


Supervisor
layer does
not have to
know details
of how
motion is
done

Cell Controller
Mode Control
Plant-wide information
system
Data logging
Supervisory
control
Feedback control
Position signal
processing
Quadrature decoder
PWM generation,
amplifier (drive)
Motor
Command signal
processing
Software
Hardware
External
Internal
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

79

States


States provide structure inside tasks


States are sequential


only one is active at a
time


Contrast to tasks which are parallel


BeltAxis defines only one state, RunState

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

80

State Functions


Entry()


runs once each time state is entered


Action()


runs every time state is invoked


Transition()


checks to see what the next state
should be (not relevant here


only one state!)


More details on state later

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

81

Computer Operating Principles

The Nickel Tour!


Data


collections of binary signals


Data items coded according to a variety of
conventions


Integers (signed or unsigned), floats, characters, etc.


Instructions


tell computer what to do


Central Processing Unit (CPU)


Registers


hold data


Processors


operate on data in registers

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

82

Memory


Technically, a separate memory is not needed


A “register” (see CPU) is memory


Register circuitry, however, is very expensive (and very
fast)


“Memory” is much slower, much bigger, and much
cheaper


Memory contains a mix of instructions and data


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

83

Address Space


The memory uses “addresses” to identify specific data


Addresses used in programs translate into electrical
signals that operate the memory


“Logical” addresses (in programs) can correspond
directly to physical addresses (in memory) or can be
mapped by access circuits

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

84

How It Works


“Instruction”


unit activity


CPU gets instruction from memory (stores it in a
register) and figures out what to do


Gets data from memory if necessary


Operates on data in registers


Returns result(s) to registers


Writes data to memory if necessary


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

85

Sequential Device


Computing is thus entirely sequential


One instruction at a time


Instructions are quite primitive


High level languages retain sequential nature
(Java, etc.)


line
-
at
-
a
-
time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

86

Timing


This activity is synchronized by the system
“clock”


A clock is a circuit that provides a constant
frequency square
-
wave output


Instruction takes one or more ticks (cycles) to
complete


Typical desktop (2001) has ~1 GHz clock, so
instruction completes in a modest number of
nanoseconds

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

87

Speed of Embedded
Processors


Embedded applications have a much wider
range


Economics drives computing power (and how
much can be accomplished)


Speeds can be as much as 1000 Xs slower!

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

88

Connecting the Computer to the
Outside World


Peripheral devices


printers, disk drives, keyboard,
display, control I/O, etc.


These are MUCH slower than the computer


Separate facilities (hardware) are used to connect them


They use an address space


sometimes common with
memory, sometimes separate

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

89

Real Computers


This is a simplified model (corresponds to early
computers)


Computers use many tricks to speed up
operation


Cache, pipelines, multiple data paths, etc.


General principles remain the same (and have
been for half a century!)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

90

What Makes it Work?


Almost error free, regardless of scale!


This is accomplished by


Discrete data representation (bits)


Discrete time (clock synchronized)


Minimize size to reduce power, increase speed


Flexibility: intermix data of various codings and
instructions in memory


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

91

Class BeltAxis


Classes are templates for tasks


Extend an appropriate task type


PeriodicTask in this
case


Any number of actual tasks can be instantiated from this
class


Use data via the constructor to differentiate them


Use virtual functions (and another inheritance layer) if
needed for further differentiation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

92

BeltAxis File


Contains the code specific to belt axes, but
generic so that several belt axes could be
instantiated


Note


in statements such as:

this.inertia = inertia;


The “this” is only needed because the same
name is used for local and class variables


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

93

Simulation


Performed in the action function


Same set of Euler ODE solver equations as we used in
the earlier program


In a real program this task would probably get data from
the physical system


In this case, it creates the data from a simulation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

94

Task Instantiation


Look in GlueMain.java


These statements create two BeltAxis tasks

beltAxis1 = new BeltAxis (process1, "Belt Axis 1", 5, 0.1, 25.0, 4.0,
2.0);

beltAxis2 = new BeltAxis (process1, "Belt Axis 2", 5, 0.1, 25.0, 4.0,
3.0);


They obey the same system equations but have
independent parameters (ie, represent two
pieces of hardware)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

95

Data Logging


BeltLogger is a class that creates data logging
tasks


In this case, one such task is created


It collects data from both belt axis tasks so they
can be written to a file for analysis


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

96

Intertask Communication


In BeltAxis, put data in global data base

copyToGlobalBox("Position", position);

copyToGlobalBox("Velocity", velocity);


In BeltLogger, retrieve that data

float belt1pos = (float)readGlobalDouble(GlueMain.beltAxis1,
"Position");

float belt1vel = (float)readGlobalDouble(GlueMain.beltAxis1,
"Velocity");


Why not just share data in a simpler way?

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

97

Multi
-
Process Computing


For simple data sharing there must be a
common address space


This occurs in single
-
computer, single
-
process
computing


For generality and portability, we write control
programs that can operate in single or multi
process environments

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

98

Global DataBase
--

Messages


TranRunJ implements two mechanisms for data
communication among tasks


Global database as used in Glue00


Messages


will be used later


If used for all intertask communication programs
will be usable in all these environments

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

99

taskMain() in BeltLogger


Note that BeltLogger does not create any state
classes


For tasks that always do the same thing when
they are invoked, taskMain() can be used
instead of state classes


Gives a simpler structure for simple tasks

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

100

Idle()


Note that the task or state code ends with a call
to idle()


Periodic tasks are given CPU access until they
signal to the scheduler that they are done


The call to idle() gives that signal


If not done, task will “hang” the whole program

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

101

“Package” Glue00


Package is part of Java


It establishes grouping of classes


Classes and associated members are visible
across the whole package


Requires a different directory structure for
compiling


Root is one level back from sources

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

102

Running Glue00


Notes


The TranRunJ package must be included in the build


the easiest is TranRunJ.jar via
Filesystems/Mount/Archive


TranRunJ requires command line value for process
to be run


“Process_One”


set via
Build/SetArguments


main file window must be
selected

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

103

Running Glue00 …


More notes …


NetBeans writes data files to the NetBeans directory,
not the local directory


Put the cursor on the file containing main() to build
and run


Program can be run from the command line with

C:
\
AAAA
-
Working
\
JavaProjects
\
ProjGlue00>java
-
cp
../TranRunj.jar; Glue00.GlueMain Process_One

(Directory name must match package name)


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

104

Pulse Width Modulation (PWM)


Simulation (such as Glue) assume a continuous
signal to the motor


Often, this is not practical


Power delivery is an expensive, tricky part of any
system


It is much easier and more efficient to limit power
control to On/Off

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

105

Modulating an On/Off Signal


If the on/off signal is switched frequently enough the
object output (motor velocity, position) will only show a
small part of the variation


Pulse Width Modulation: vary the proportion of time the
signal is “on” within a constant
-
period repeating signal


On
-
Time/Period is called “duty cycle”


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

106

PWM Signal


Repetition period
is constant


Vary on
-
time vs.
off
-
time

50% Duty Cycle
75% Duty Cycle
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

107

PWM in Software


Getting the period short enough is key


Hard to do that with software for fast objects


We will use software PWM to simplify lab
systems


this will provide a real time challenge!


PWM task uses state logic as follows …

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

108

PWM State Diagram

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

109

TranRunJ Implementation


Implement as an Event Task (several versions are
around, some using Periodic Task)


Each state can compute when the next “event” will
occur


This is usually the highest priority task


PWM1 in JavaSamples.zip, includes a motor simulation
(run in simulated time mode below)

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

110

Simulation Results

PWM Period = 10 ms

0
1
2
3
4
0
2
4
6
8
10
12
Time
Velocity
Motor Velocity
0
1
2
3
4
0
5
10
15
20
25
30
35
40
Time
Position
Motor Position
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

111

Small Section of Velocity
Response


“Buzz” is
residual of
PWM signal

2.95
3
3.05
3.1
3.15
3.2
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
Time
Velocity
Motor Velocity
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

112

Longer Period

PWM Period = 50 ms


Longer period
means more
residual of PWM
(buzz) in
response

0
1
2
3
4
0
2
4
6
8
10
12
Time
Velocity
Motor Velocity
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

113

Glue01


Adds ovens to the simulation


Modeled as simple thermal processes


Almost no change in basic structure


No new Java stuff


Note difference in time scales in results


Motor changes much faster than oven

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

114

Glue02


Glue02 adds feedback control for both the
conveyors and the ovens


This provides a way to maintain position (or
temperature) at desired values


Considered a basic utility for many (almost all!)
mechanical system control problems


First some notes on feedback control


Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

115

What is Feedback Control?


Measure desired behavior of target system


Compare measured to desired behavior


Based on comparison, decide on appropriate actuation
so measured will move closer to desired


Note: see the complete FeedbackBasics slide set for
additional information

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

116

Feedback Control System

Target
System
Output from
target system
Measuring
Instrument
Measurement of
target system output
Actuation
command
Computational
element
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

117


Why Use It?


To compensate for lack of knowledge


With “perfect” knowledge the target system can be
made to do anything desired


No need to measure
-

behavior is “known,” i.e.
predictable from our knowledge


The real world is not so nice! Unknown disturbances
and imperfect system models are more the norm

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

118

Demonstrations


Matlab animations
-

tank(s) and mass(es)


Single tank with drain
-



IntroTank1.m and IntroTank2.m


No feedback (open loop) and with feedback


Single mass


IntroMass1.m and IntroMass2.m


No feedback, with feedback

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

119


Example
-

Tank

h
Qin
Qout
Q flowrate, m^3/s
V volume, m^3
A tank area, m^2
h height of liquid, m
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

120

Single Tank, No Feedback


Top line (2.9) is
desired value


System output
(liquid height)
never quite gets
there


Actuation constant
at 5

0

10

20

30

40

50

0

1

2

3

System Output

time

0

10

20

30

40

50

4

5

6

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

121

Single Tanks, With Feedback


Liquid level
reaches desired
value


Gets there faster


Actuation is
adjusted based on
feedback
measurement

0

10

20

30

40

50

0

1

2

3

System Output

time

0

10

20

30

40

50

4

6

8

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

122

Example
-

Mass

m
F
x,v
F force, N
x position, m
v velocity, m/s
m mass, kg
H momentum, kg N
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

123

Position a Mass
-

No Feedback


Turn actuation on
full blast to
accelerate


Turn it full negative
to decelerate


Doesn’t quite reach
desired position

0

1

2

3

4

5

0

5

10

System Output

time

0

1

2

3

4

5

-
10

0

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

124

Position a Mass
-

With
Feedback


Gets to desired
position


Similar actuation
pattern


Final stage is much
more conservative


Overall response is
slower

0

1

2

3

4

5

0

5

10

System Output

time

0

1

2

3

4

5

-
10

0

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

125

Feedback Control Risks


Improper use of feedback can make behavior
worse than non
-
feedback case


In these cases, open
-
loop system is stable


Feedback can make it unstable


IntroMassUnstable.m

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

126

Controller Induced Instability


Motion diverges from
the desired position
(0.05, red)


Oscillation levels off
when actuator
reaches its limit (at
+/
-

10)

0

2

4

6

8

-
4

-
2

0

2

System Output

time

0

2

4

6

8

-
10

0

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

127

Difficulties Making Feedback
Work


Dynamics


Nonlinearity


Noise


Dimensionality

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

128

Dynamics: Definition


History dependence


Output depends on the history of the input


Example, tank


Instantaneous value of level depends on recent inflow history


Knowledge of current inflow does not say anything about
level


Vice
-
versa,

knowledge of the level does not say anything
about current inflow

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

129

Two
-
Tank Demo


Contrast single and double tank systems:


IntroTank1.m (back a couple of slides)


Two tanks connected with a pipe


Inflow to first tank; outflow from second


Dyn2Tank.m

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

130

Two Tanks, Open Loop


Change in first
tank (blue) shows
up right away


Second tank
(green) “hides”
change in inflow
initially

0

50

100

0

1

2

3

System Output

time

0

50

100

1

2

3

4

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

131

Single Mass (repeated)


Velocity slope
changes
immediately


Position (blue)
hides change in
force

0

1

2

3

4

5

0

5

10

System Output

time

0

1

2

3

4

5

-
10

0

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

132

Two Masses, No Feedback


Connected by
spring


Energy stays
internal to
system


Simple open
loop control is
unacceptable

0

2

4

6

8

0

2

4

6

System Output

time

0

2

4

6

8

-
10

0

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

133

Equilibrium, Stability


State space: the Cartesian space with state variables
on each axis


Equilibrium: a point in the state space at which none of
the state variables are changing


Stability: the behavior near an equilibrium point


Stable: stays near the equilibrium point


Asymptotically stable: converges to the equilibrium point


Unstable: does not stay near the equilibrium point

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

134

Control and Stability


Target system can be


Open
-
loop stable


Open
-
loop unstable


First goal of feedback control: assure stability of closed
-
loop system


Danger in applying feedback control: produce unstable
behavior in case when target system is open
-
loop
stable


Feedback can be used to stabilize an open
-
loop
unstable target system

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

135

Feedback Control
Implementation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

136

Single Loop Systems


Single
-
input, single output systems (SISO)


One actuator


One instrument


No limit to internal dynamic complexity


But hard to control if internal dynamics get too
complicated

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

137

Canonical Diagram

Target
system
Instrument
Control
computation
Desired
value
(Setpoint,
reference)
+
-
Error
r
e
m
y
System
output
Measurement
(estimate of system
output)
Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

138

Discrete/Continuous Time


Various devices can be used for the “control
computation”


If computer is used its peculiarities must be
accommodated


Sequential instruction execution


Finite precision


Sequential execution means computers do only one
thing at a time


Result: sampled data; discrete time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

139

Information Loss


Alternative devices, such as op
-
amps, are continuous
time


Discrete time devices ignore information between
samples


Finite precision
-

causes noise injection into the control
loop


Computers make up for these deficiencies by their
ability to implement complex computations economically

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

140

Computer Control


Computers are currently the most common way of
implementing feedback control


Continuous
-
time implementations (usually op
-
amp, but
could be dedicated digital logic) still used where
computers aren’t practical


Formulations here will be presented for digital computer
implementation

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

141

Dynamic Range


The ability to handle a wide range of values


Important in coping with a variety of situations


Example, rapid slewing and slow scanning


Hardest to achieve in actuators, then
instruments, then computers

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

142

Control Algorithm


Computes the manipulated variable (amplifier
command)


Uses error as input,


Must figure out value of “m” that will bring the system
output to its desired (setpoint) value


First problem in designing the control algorithm is the
dynamics of the target system …


The measured value of the output only hints at what the
system is about to do!

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

143

PID


Proportional/integral/derivative


Most popular


Broadly applicable


Not limited to any type or class of system


Limited in its ability to cope with complicated
dynamics


“Knowledge” requirement for any system is
reduced to three parameters

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

144

Proportional


Strength of actuation proportional to error


m = k
p

e


k
p

is known as “gain”


Simplest PID mode to apply


May solve problem by itself

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

145

Simulations of P Control


Single tank, Prop1Tank.m


Higher gain, Prop1TankHiGain.m


Still higher gain, Prop1TankTooHiGain.m


Slower sampling, Prop1TankSloSamp.m

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

146

Tank, Proportional Control

0

5

10

15

0

1

2

3

System Output

time

P Control, Kp=5

0

5

10

15

0

5

10

Actuation Command

time

0

5

10

15

0

1

2

3

System Output

time

P Control, Kp=10

0

5

10

15

0

5

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

147

Tank
-

Very High P Gain


Too much of a
good thing!


Error goes
down


But behavior is
not acceptable

0

5

10

15

0

1

2

3

System Output

time

P Control, Kp=40

0

5

10

15

0

5

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

148

Tank
-

Slow Sampling


Same gain as
2nd case
(kp=10)


Behavior is
much worse


Sampling
interval from 2 to
8

0

10

20

30

0

1

2

3

System Output

time

0

10

20

30

0

5

10

Actuation Command

time

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

149

Integral


Improves long
-
term behavior


Note that desired level was never quite reached
with just P control


Adding I action can fix this


“If the error persists, push harder!”

Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

150

Integral Implementation


Integral term formulation

I
k
e
dt
But
computer
can
only
approximat
e
this
I
k
e
t
or
in
operationa
l
form
I
t
t
I
t
k
e
t
i
i
i







,
:
;
,
:
(
)
(
)



Flyballs
Shaft which
Rotates at
Engine Speed
Sliders
Steam Control
Valve
Linkage
Open
Close
Updated: January, 2004

Copyright © 2001
-
04 D. M. Auslander

151

PI Control