Date post: | 04-Jan-2016 |
Category: |
Documents |
Upload: | myra-golden |
View: | 217 times |
Download: | 0 times |
Software Control Systems
An Introduction
by Dayle Kotturi ([email protected])
Contols Department
SLAC National Accelerator Laboratory
June 25, 2009
Software Control SystemsOur scope today:What are control systems? Control systems you may knowCreating a new control systemHow could it fail?How could it run forever?Making friends with usersWhat else is there?
What are control systems?
A control system manages devices so that they respond to the commands of the operators within the limits of safetyA control system should be able to run foreverA control system should be smart enough to detect problems and to recover from them
Control systems you may know
Very small: pacemaker, hearing aidSmall: coffee maker, microwave oven, vending machine, ATM, carMedium: building’s heating ventilation air conditioning (HVAC) systemLarge: factory assembly line Very large: telescope arrays
Creating a new control system
The situation:It is your first day on the job for LCLS projectYou are excited because the LCLS photon (X-ray) beam is a billion times brighter than any other terrestrial light source and you are now a part of it
Description of the problem
LCLS uses screens:to image, attenuate and measure the energy of the X-Ray beammade of boron carbide and other compounds to handle high peak power levelsthat get damaged by burns from the intense radiation levelsthat contain holes typically the size of a pin hole that need to be moved so the beam interacts with an undamaged portionthat are imaged by cameras to determine the location of the beam and defects For simplicity in this example, the screen translates in one axis only
Your task
Write a driver that accepts screen position requests and moves screen in responseYour driver should run forever. I.e. wait for input, move screen to that position, repeat Use function calls from the application programmer interface (API) that came with the hardwareYou read the manual and found a function called setPosition(x) You see that the units are in microns
Your first control program
Where to start?
Drawing a blank, you decide to
Start with the world’s most common computer program, helloWorld.c. In C programming language, it looks like this:
#include <stdio.h>
int main() {
printf(“hello world\n”);
}
And make it run forever
#include <stdio.h>#define TRUE (1)#define FALSE (0)int main() { while (TRUE) { printf(“hello world\n”); }}
Running it hangs computer
#include <stdio.h>#define TRUE (1)#define FALSE (0)int main() { while (TRUE) { printf(“hello world\n”); }}Why?
100% CPU usage is too much
That tiny snippet will take 100% of the CPU! Fix it this way:#include <stdio.h>#define TRUE (1)#define FALSE (0)int main() { while (TRUE) { printf(“hello world\n”); sleep(1); /* let CPU do other tasks */ }}
Better now
Compile it:gcc –o helloworld helloworld.c Run it:./helloworldOutput is (1 line per second)hello worldhello world …Stop it:Ctrl-C
Ready for something useful
xDrive.c:#include <stdio.h>#include <3rdPartyCommands.h> /* for setPosition() */#define TRUE (1)#define FALSE (0)int main() { float x; while (TRUE) { printf(“Enter desired x position in microns:”); /* read desired position */ scanf(“%f”,&x); printf(“Driving to %f um\n” x); setPosition(x); sleep(1); /* let CPU do other tasks */ }}
Are we there yet?
This interface will work
Assumption:
operators are willing to run the control at a command prompt and type in the desired position when they need to change it (not so user-friendly, but okay for now)
Where could things go wrong?
Readbacks are important
xDrive is open loopIt has no knowledge of the actual position of the screenYou can set the position, but you don’t know if it ever got thereTo add this, you make use of another function in the screen’s API: getPosition()
Readbacks are important#include <stdio.h>#include <math.h> /* for abs() */#include <3rdPartyCommands.h> /* for set,get Position() */#define TRUE (1)#define FALSE (0)#define xTolerance (0.001) /* xActual must be this close to the xDesired */#define xMinimum (0.)#define xMaximum (20000.)int main() { float xDesired; float xActual; while (TRUE) { /* check if correct position */ xActual = getPosition(); if (abs(xActual – xDesired) < xTolerance) { /* motor got where it was asked to go. Ok to get next request */ printf(“Enter desired x position in microns:”); /* read desired position */ scanf(“%f”,&xDesired); printf(“Driving to %f um\n” xDesired); setPosition(xDesired); } else { /* something could be wrong. Investigate further */ if (xActual >= xMaximum) { printf(“upper limit\n”); else { if (xActual <= xMinimum) { printf(“lower limit\n”); } } } sleep(1); /* let CPU do other tasks */ }}
Now could it run forever?
Yes, if you address these issues:1. Interference from other signals in the
area could affect the readbacks to make faulty values
2. Ambient temperatures could increase and overheat the screen’s motor
3. Power could disappear and come back on by itself
4. The motor could get stuck at a limit5. System resources (eg.memory, file
descriptors) could run out over time
Robustness is possible
Solutions to each are: 1. Read back a series of values and take average
them into a single value or throw away outliers, dismissing them as noise
2. Add temperature sensors and chill/warm the equipment to neutralize the effect of diurnal and seasonal variations
3. Save positions on another machine and restore them on start up if power goes away
4. Define an operating range inside the motor’s absolute range of travel so that it can’t get stuck at the limit
5. Allocate resources at start and reuse them as needed. This way, you can’t run out
Adding operator interface
Create a user interface to control the screen
Operator needs to enter the desired position, start/stop/reset and readback the actual position
Example User Interfaces
open loop mover
open loop mover with readback
closed loop mover
closed loop driver
What else is there?
Given this simple example, here are some ways complexity may arise:
1. There is no API of function calls2. The API functions do not work3. The system must be interrupt driven4. The system needs to be multi-threaded to do several tasks
simultaneously5. Semaphores are needed to protect resources shared by
threads6. State machines are needed to take care of doing all the steps
to run in a given mode of operation and the transitions between modes
7. Other machines need to interact with your system8. Other machines may need to control your system some of the
time, but at other times your system must control itself
The take away Software control systems are a large
and diverse field You can work on controls systems all
over the world Even though systems can look
complex, at the lowest level, they are always very simple and either work or don’t work
It is very rewarding to get something to “just work” and to see it run forever.