Скачать презентацию Experimental Physics and Industrial Control System EPICS Sequencer Скачать презентацию Experimental Physics and Industrial Control System EPICS Sequencer

ad4ca89fd8ea2048d73c5b50602d0837.ppt

  • Количество слайдов: 27

Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Bob Dalesio, Deb Kerstiens, Rozelle Wright Oct 1, 2001

Sequencer Version • These slides describe SNL/SEQ version 1. 9. 5 • This version Sequencer Version • These slides describe SNL/SEQ version 1. 9. 5 • This version is available for downloading at http: //pipeline. keck. hawaii. edu: 3636/realpublic/epics/seq/ • Documentation for Version 2. 0. 0 which is being distributed with EPICS 3. 14 is available at this same site. • Version 1. 9. 5 has all the functionality of Version 2. 0. 0 except that SEQ does not run on UNIX.

Outline • What is state notation and what function does it serve • Components Outline • What is state notation and what function does it serve • Components of a state notation program • Building, running and debugging a state notation program • Additional Features • Some Notes on the Runtime Sequencer

Purpose • A language to facilitate sequential programming in the EPICS realtime environment • Purpose • A language to facilitate sequential programming in the EPICS realtime environment • Fast execution - compiled code • Programming interface to extend EPICS in the real-time environment • Easy for first-time user to learn and apply

Common Uses of the State Notation Language • Provide automated start-up sequences like vacuum Common Uses of the State Notation Language • Provide automated start-up sequences like vacuum or RF where subsystems need coordination • Provide fault recovery or transition to a safe state • Provide access to the Unix file system for save/restore or restoration of parameters on reboot • Provide automatic calibration of equipment

State Transition Diagram Start Low vacuum State A Transition A to B State B State Transition Diagram Start Low vacuum State A Transition A to B State B Event pressure <. 0000049 Torr Open the valve Action High vacuum pressure >. 0000051 Torr Close the valve

SNL: General Structure and Syntax program_name declarations ss state_set_name { state_name { enter{ action SNL: General Structure and Syntax program_name declarations ss state_set_name { state_name { enter{ action statements } when (event) { action_statements } state new_state_name when(event) … exit{ action statements } } state_name {. . } }

SNL: General Structure and Syntax program name ss name { environment. state name{ and SNL: General Structure and Syntax program name ss name { environment. state name{ and state option flag; when (event) { waits. A Program contains many state sets. The program is used as the handle to the sequencer manager for state programs. A state set becomes a task in the vx. Works A state is an area where the task waits for events. The related task waits until one of the events occurs then checks to see which it should execute. The first defined in a state set is the initial state. A state specific option Is used to define the events for which this state } statename Is used to define the new state after the actions are taken. entry{ state) } Do these actions on entry to this state from another (using option -e; will do these actions even if it enters from the same

Declarations Occur before a state set and have a scope of the entire program. Declarations Occur before a state set and have a scope of the entire program. Scalar types int short long char float double string variable. Iname; variable. Sname; variable. Lname; variable. Cname; variable. Fname; variable. Dname; variable. Strname; /* currently limited to 40 characters*/ Vector types int short long char float double array. Iname[array_length]; array. Sname[array_length]; array. Lname[array_length]; array. Cname[array_length]; array. Fname[array_length]; array. Dname[array_length];

Declarations - continued Assignment to channel access server channels float assign pressure; pressure to Declarations - continued Assignment to channel access server channels float assign pressure; pressure to “Tank 1 Coupler. Pressure. RB 1”; double assign pressures[2]; pressures to {“Tank 1 Coupler. Pressure. RB 1”, ”Tank 1 Coupler. Pressure. RB 2”, ”Tank 1 Coupler. Pressure. RB 3”}; To use these channel in when clauses they must be monitored monitor pressure; monitor pressures; Declaring Event Flags evflag event_flag_name; sync pressure flag_monitor; /* event for state sets to set, clear, /* and test /* flag monitor is set when pressure /* changes (posts a monitor)

Events An event is the condition on which statements following a when are executed Events An event is the condition on which statements following a when are executed and a state transition is made Possible events: • Change in value of a variable that is being monitored example: when(achan < 10. 0) • A timed event (not a task delay!) example: when(delay(1. 5)) The delay value is in seconds. It is delclared internally as a double and constant arguments to the delay function must contain a decimal point. A delay is normally reset whenever the state containing it is exited. Use the state specific option -t to keep it from being reset when exiting to the same state. .

Events (continued) • An internally generated event (event flag) examples: when(ef. Test. And. Clear(myflag)) Events (continued) • An internally generated event (event flag) examples: when(ef. Test. And. Clear(myflag)) when(ef. Test(myflag)) ef. Test does not clear the flag. ef. Clear must be called sometime later to avoid an infinite loop. The event flag can be set internally by ef. Set(event_flag_name) or if the flag is synced to a monitored channel it will be set when the channel changes. • Change in the channel access connection status. examples: when(pv. Connect. Count() < pv. Channel. Count()) when(pv. Connected(mychan) )

Actions almost any C expression switch is not implemented and code using it must Actions almost any C expression switch is not implemented and code using it must be escaped. %% escape one line of C code %{ escape any number of lines of C code }% Built-in action function: pv. Put (variable_name); pv. Get (variable_name); ef. Set (event_flag_name); ef. Clear (event_flag_name);

State Definitions and State Transitions Inital. State pressure >. 0000051 Rough. Pump on Cryo. State Definitions and State Transitions Inital. State pressure >. 0000051 Rough. Pump on Cryo. Pump off Valve closed pressure <=. 0000049 Rough. Pump off Cryo. Pump on Valve open Low Vacuum 10 minutes Rough. Pump off Cryo. Pump off Valve closed Fault pressure <=. 0000049 Rough. Pump off Cryo. Pump on Valve open High Vacuum pressure >. 0000051 Rough. Pump on Cryo. Pump off Valve closed

Declarations for Example double pressure; assign pressure to “Tank 1 Coupler 1 Pressure. RB”; Declarations for Example double pressure; assign pressure to “Tank 1 Coupler 1 Pressure. RB”; monitor pressure; short assign string assign Rough. Pump; Rough. Pump to “Tank 1 Coupler 1 Rough. Pump”; Cryo. Pump to “Tank 1 Coupler 1 Cryo. Pump”; Valve to “Tank 1 Coupler 1 Isolation. Valve”; Current. State to “Tank 1 Coupler 1 Vacuum. State”;

State Transitions for the Example program vacuum_control ss coupler_control { state init{ } when(pressure State Transitions for the Example program vacuum_control ss coupler_control { state init{ } when(pressure >. 0000051){ } state low_vacuum when(pressure <=. 0000049){ } state high_vacuum{ when(pressure >. 0000051){ } state low_vacuum{ when(pressure <=. 0000049){ }state high_vacuum when(delay(600. 0)){ }state fault } state fault{ }

States for the Example - Init state init{ } entry{ strcpy(Current. State, ”Init”); pv. States for the Example - Init state init{ } entry{ strcpy(Current. State, ”Init”); pv. Put(Current. State); } when(pressure >. 0000051){ Rough. Pump = 1; pv. Put(Rough. Pump); Cryo. Pump = 0; pv. Put(Cryo. Pump); Valve = 0; pv. Put(Valve); } state low_vacuum when(pressure <=. 0000049){ Rough. Pump = 0; pv. Put(Rough. Pump); Cryo. Pump = 1; pv. Put(Cryo. Pump); Valve = 1; pv. Put(Valve); } state high_vacuum

States for the Example state high_vacuum{ entry{ strcpy(Current. State, ”High Vacuum”); pv. Put(Current. State); States for the Example state high_vacuum{ entry{ strcpy(Current. State, ”High Vacuum”); pv. Put(Current. State); } when(pressure >. 0000051){ Rough. Pump = 1; pv. Put(Rough. Pump); Cryo. Pump = 0; pv. Put(Cryo. Pump); Valve = 0; pv. Put(Valve); } state low_vacuum{ entry{ } state fault{ } strcpy(Current. State, ”Low Vacuum”); pv. Put(Current. State); } when(pressure <=. 0000049){ Rough. Pump = 0; pv. Put(Rough. Pump); Cryo. Pump = 1; pv. Put(Cryo. Pump); Valve = 1; pv. Put(Valve); }state high_vacuum when(delay(600. 0)){ }state fault entry{ } strcpy(Current. State, ”Vacuum Fault”); pv. Put(Current. State);

Building a state program 1. Use editor to build the source file: file name Building a state program 1. Use editor to build the source file: file name must end with ". st", e. g. "example. st". 2. “gmake” automates these steps: Runs the C preprocessor Compiles the state program with SNC to produce C code: snc example. st -> example. c Compiles the resultant C code with the C compiler: cc example. c -> example. o The file "example. o” becomes part of the application library, which is ready to be loaded by Vx. Works. 3. Note: For class purposes, we will be reloading the object code as a module instead of rebooting to reload the library.

The Run-Time Sequencer 1. The sequencer executes the state program in the Vx. Works The Run-Time Sequencer 1. The sequencer executes the state program in the Vx. Works environment. 2. The sequencer supports the event-driven execution; no polling needed. 3. Each state set becomes a Vx. Works task. 4. The sequencer manages connections to database channels through "channel access". 5. The sequencer provides support for channel access (put, get, and monitor). 6. The sequencer supports asynchronous execution of delay and event flag functions. 7. Only one copy (object module) of the sequencer is required on each IOC. 8. Query commands display information about executing state programs.

Executing a state program Assume that Vx. Works is running in an IOC and Executing a state program Assume that Vx. Works is running in an IOC and the proper database is loaded. 1. Telnet to the IOC: telnet ts 1 log in ts 1> you should get a prompt 2. Load the object module: ( ts 1> ld < /example. o 3. Execute the state program: ts 1> seq &example this is the program name This will create one task for each state set. 4. Exercise the program. 5. Print a summary of state programs ts 1> seq. Show 6. If it doesn’t work properly: Delete the tasks that were created in step 3. ts 1> td "example” Go back to step 2.

Hints for debugging a state program 1. Use printf statements in program: printf( Hints for debugging a state program 1. Use printf statements in program: printf("entering state: light_on"); 2. Manually enter database values using CAU: cau: put hv 03: temp 1 150 3. Print database values using CAU: cau: get hv 03: temp 1 150. 00 4. Use special state program query commands: seq. Show displays information on all running state programs seq. Show "example" displays detailed information on program seq. Chan. Show "example" /* all channels */ seq. Chan. Show "example”, ”-” /* disconnected */ displays information on all channels 5. Use spy to find a sequence with an infinite loop with no delays

Example of seq. Show output -> seq. Show Program Name lights Task ID Task Example of seq. Show output -> seq. Show Program Name lights Task ID Task Name 28868216 lights 28857812 lights_1 SS Name ss 1 switch_to_auto

Example of seq. Show output(continued) ->seq. Show Example of seq. Show output(continued) ->seq. Show "lights” State Program: "lights” initial task id=28868216=0 x 1 b 87 e 78 task priority=100 number of state sets=2 number of sync. Q queues=0 number of channels=16 number of channels assigned=16 number of channels connected=16 options: async=0, debug=0, newef=1, reent=0, conn=1 log file fd=8 log file name="/pty/telnet. S” State Set: "ss 1” task name=lights; task id=28868216=0 x 1 b 87 e 78 First state = "init” Current state = "auto” Previous state = "auto” Elapsed time since state was entered = 0. 0 seconds)

Example of seq. Show output (continued) State Set: Example of seq. Show output (continued) State Set: "switch_to_auto” task name=lights_1; task id=28857812=0 x 1 b 855 d 4 First state = "man” Current state = "auto” Previous state = "man” Elapsed time since state was entered = 10794. 0 seconds)

Additional Features • Connection management: – when ( pv. Connect. Count() != pv. Channel. Additional Features • Connection management: – when ( pv. Connect. Count() != pv. Channel. Count() ) – when ( pv. Connected(Vin) ) • Macros: – assign Vout to "{unit}: Output. V"; – (must use the +r compiler options for this if more than one copy of the sequence is running on the same ioc) – ts 1> seq &example, "unit=HV 01" • Compiler options: – +r make program reentrant (default is -r) – -c don't wait for all channel connections (default is +c) – +a asynchronous pv. Get() (default is -a) – -w don't print compiler warnings (default is +w) – +e eftest automatically clears flag (default is -e)

Additional Features(continued) • Pass parameters to programs at run time: – #----- this line Additional Features(continued) • Pass parameters to programs at run time: – #----- this line is executed in the st. cmd file – ts 1> seq &example, "bias = 2. 55" – p. Str = mac. Value. Get("bias"); /* this statement in the. st file gets value */ • Access to alarm status and severity: – pv. Status(var_name) – pv. Severity(var_name) • Queueable monitors -- saves monitors in queue in the order they come in -- no missing monitors. – sync. Q variable. Name to event. Flagname [optionally the length of the queue] – pv. Get. Q( variable. Name ) • removes oldest value from variables monitor queue. Remains true until queue is empty. – pv. Free. Q( variable Name)