SNL and Sequencer 1 Controls EPICS Training Class EPICS Collaboration Meeting SLAC State Notation Language (SNL) and Sequencer April 23, 2012 Kukhee.

Slides:



Advertisements
Similar presentations
January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro KEK January 2009.
Advertisements

1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Bob Dalesio, Deb Kerstiens, Rozelle Wright.
Programming Languages and Paradigms
Names and Bindings.
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
Introduction to C Programming
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
COSC 120 Computer Programming
VBA Modules, Functions, Variables, and Constants
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Run time vs. Compile time
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Guide To UNIX Using Linux Third Edition
Basic Elements of C++ Chapter 2.
Fundamentals of Python: From First Programs Through Data Structures
ORNL is managed by UT-Battelle for the US Department of Energy EPICS State Notation Language (SNL), “Sequencer” Kay Kasemir, SNS/ORNL Many slides from.
Timed UML State Machines Ognyana Hristova Tutor: Priv.-Doz. Dr. Thomas Noll June, 2007.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
1 1999/Ph 514: State Notation Language EPICS State Notation Language (SNL) Ned D. Arnold APS.
1 2001: Beijing State Notation Language EPICS State Notation Language (SNL) Ned D. Arnold APS (Ron Chestnut SLAC)
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
LCLS Timing Software and Plan 1 Controls Timing Workshop EPICS Collaboration Meeting SLAC LCLS Timing Software and Plan April Kukhee Kim.
1 SNL Current State (in transition state) By Matthias Clausen Ron Chestnut.
Hans-Peter Plag November 6, 2014 Session 4 (Programming Languages) (Data Types and Variables) Expressions and Operators Flow Control.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
CPS120: Introduction to Computer Science Decision Making in Programs.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
User Defined Functions Chapter 7 2 Chapter Topics Void Functions Without Parameters Void Functions With Parameters Reference Parameters Value and Reference.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Managed by UT-Battelle for the Department of Energy EPICS Sequencer Kay Kasemir, SNS/ORNL Many slides from Andrew Johnson, APS/ANL Feb
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
EPICS sequencer update Greg White / William Lupton / EPICS ‘99 SLAC, May 27, 1999.
Stanford Linear Accelerator Center New SNL Ideas Possible Next Steps Ron Chestnut – PSI, May, 2001 With ideas from B. Dalesio and M. Clausen.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
1 1999/Ph 514: Lab #3A : SNL Lab#3B : Development Environment EPICS Lab #3a State Notation Language.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
55:032 - Intro. to Digital DesignPage 1 VHDL and Processes Defining Sequential Circuit Behavior.
Chapter – 8 Software Tools.
EPICS and LabVIEW Tony Vento, National Instruments
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Chapter 7 Continued Arrays & Strings. Arrays of Structures Arrays can contain structures as well as simple data types. Let’s look at an example of this,
Chapter 1: Introduction to Computers and Programming.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
State Notation Language and the Sequencer Andrew Johnson APS Engineering Support Division October 2008 INFN EPICS Training.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Monitoring Dynamic IOC Installations Using the alive Record Dohn Arms Beamline Controls & Data Acquisition Group Advanced Photon Source.
Process concept.
Objectives Identify the built-in data types in C++
State Notation Language (SNL) and Sequencer
Channel Access Concepts
Chapter 1 c++ structure C++ Input / Output
Channel Access Concepts
Presentation transcript:

SNL and Sequencer 1 Controls EPICS Training Class EPICS Collaboration Meeting SLAC State Notation Language (SNL) and Sequencer April 23, 2012 Kukhee Kim ICD Software SLAC National Accelerator Laboratory

SNL and Sequencer 2 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Contents State Notation Language / Sequencer Definition of Terms State Transition Diagram Example 1: Simple Switch ON/OFF SNL General Syntax & Structures Declaration for Variable, Assigment, and Event Flags Event Action Example 2: Life Game SNL Variables and its Lifetime and Scopes Dynamic PV assignment Building SNL code Runtime Sequencer Executing SNL Program Debugging Additional Features Advantage of SNL Program

SNL and Sequencer 3 Controls EPICS Training Class EPICS Collaboration Meeting SLAC SNL and Sequencer SNL is “C” like language for programming sequential operations The sequencer runs program which written in the SNL Fast execution using compiled code Common uses automated start-up and sequencing fault recovery or transition to safe state automatic calibration

SNL and Sequencer 4 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Sequencer in an IOC Channel Access LAN Device Support I/O Hardware IOC Database Sequencer

SNL and Sequencer 5 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Sequencer at CA Client side MEDMClient MEDM Server IOC MeterPower SupplyCamera IOC Tools Sequencer LAN

SNL and Sequencer 6 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Definitions SNL: State Notation Language SNC: State Notation Compiler Sequencer: The tool that executes the compiled SNL code Program: A complete SNL application, consisting declarations and one or more state sets State Set: A set of states that make a complete finite state machine State: A particular mode of the state set in which it remains until one of its transition conditions evaluates to TRUE

SNL and Sequencer 7 Controls EPICS Training Class EPICS Collaboration Meeting SLAC State Transition Diagram SNL- A tool to implement State Transition Diagram State A State B Event Action Transition A to B

SNL and Sequencer 8 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 1 – On/Off switch time signal off on Threshold to OFF Threshold to ON State transition to ON State transition to OFF No transition State ON Initialize State OFF Event: Action: turn off the light Event: Action: turn on the light

SNL and Sequencer 9 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 1 – Sneak Look State ON Initialize State OFF Event: Action: turn off the light Event: Action: turn on the light

SNL and Sequencer 10 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 1 – Sneak Look

SNL and Sequencer 11 Controls EPICS Training Class EPICS Collaboration Meeting SLAC SNL: General Structure & Syntax program program_name declarations ss state_set_name { state state_name { entry { entry action statements } when (event) { action statements } state next_state_name when (event) {... } state next_state_name exit{ exit action statements } state state_name {... }

SNL and Sequencer 12 Controls EPICS Training Class EPICS Collaboration Meeting SLAC SNL: General Structure & Syntax program nameA program may contain multiple state sets. The program name is used as a handle to the sequencer manager for state programs. ss name {Each state set becomes a separate task or thread. state name {A state is somewhere the task waits for events. When an event occurs it checks to see which action it should execute. The first state defined in a state set is the initial state. option flag;A state-specific option. when (event) {Define events for which this state waits. } state next Specifies the state to go to when these actions are complete. entry {actions}Actions to do on entering this state. With option -e; it will do these actions even if it enters from the same state. exit {actions}Actions to do on exiting this state. With option -x; it will do these actions even if it exits to the same state.

SNL and Sequencer 13 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Declaration: Variables Appear before a state set and have a scope of the entire program. Scalar variables intvar_name; shortvar_name; longvar_name; charvar_name; floatvar_name; doublevar_name; stringvar_name; /* 40 characters */ Array variables: 1 or 2 dimensions, no strings intvar_name[num_elements]; shortvar_name[num_elements]; long var_name[num_elements]; charvar_name[num_elements]; floatvar_name[num_elements]; doublevar_name[num_elements];

SNL and Sequencer 14 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Declaration: Assignments Assignment connects a variable to a channel access PV name float pressure; assign pressure to "CouplerPressureRB1"; double pressures[3]; assign pressures to {"CouplerPressureRB1", "CouplerPressureRB2", " CouplerPressureRB3"}; To use these channels in when clauses, they must be monitored monitor pressure; monitor pressures; Use preprocessor macros to aid readability: #define varMon(t,n,c) t n; assign n to c; monitor n; varMon(float, pressure, "PressureRB1")

SNL and Sequencer 15 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Declaration: Event Flags Event flags are used to communicate events between state sets, or to receive explicit event notifications from Channel Access Declare them like this: evflagevent_flag_name; An event flag can be synchronized with a monitored variable syncvar_name event_flag_name; The flag will then be set when a monitor notification arrives, e.g. evflagpressure_event; Sync pressure pressure_event;

SNL and Sequencer 16 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Event Event: A specific condition on which associated actions are run and a state transition is made. Possible events: Change in value of a variable that is being monitored: when (achan < 10.0) A timer event (this is not a task delay!): when (delay(1.5)) The delay time is in seconds and is a double; literal constant arguments to the delay function must contain a decimal point. The timer starts when the state containing it was entered. Use the state specific option -t; to stop it from being reset when transitioning to the same state.

SNL and Sequencer 17 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Event (continued) The state of an event flag: when (efTestAndClear(myflag)) when (efTest(myflag)) efTest() does not clear the flag. efClear() must be called sometime later to avoid an infinite loop. If the flag is synced to a monitored variable, it will be set when the channel sends a value update The event flag can also be set by any state set in the program using efSet(event_flag_name) Any change in the channel access connection status: when (pvConnectCount() < pvChannelCount()) when (pvConnected(mychan)) Any combination of the above event types

SNL and Sequencer 18 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Action Built-in action function, e.g. : pvPut(var_name); pvGet(var_name); efSet(event_flag_name); efClear(event_flag_name); Almost any valid C statement switch() is not implemented and code using it must be escaped. % escapes one line of C code %{ escape any number of lines of C code }%

SNL and Sequencer 19 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Life Game

SNL and Sequencer 20 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Life Game Basic Rule of Life Game Rule 1: Any live cell with fewer than two live neighbors died, as caused by under population. Rule 2: Any live cell with two or three live neighbors lives on to the next generation. Rule 3: Any live cell with more than three live neighbors died, as if the overcrowding. Rule 4: Any dead cell with exactly three live neighbors become a live cell, as if production

SNL and Sequencer 21 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2 - Continued Requirements 20x20 Bo records to represents cells Adjustable Initial population density (Ao record, operation range [0. to 1.] If the initial population density is changed, then starts new game Initialize cells with random number generator + constraint for the initial population density Evolution to next generation few times in a second Provides basic statistics: number of live cells and number of dead cells Additional Requirement Monitor the live cell counter in the statistics If the system reaches to thermal equilibrium (the counter values is not changed during 5 seconds) then, start new game. To start new game, apply a slight change on the initial population density (use, random walk, init_pop += small random number();)

SNL and Sequencer 22 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2 – State Diagram Init InitArray Run Event: if the initial population has been changed Entry: 1)Initialize work space with random + initial population density Exit: 1)Copy work space to the PV assigned variables 2)Make statistics for the current generation 3)Update PVs for display Event: always Event: if timer has been expired Event: if the initial population has been changed Entry: evolutes cells for next generation Exit: 1)Copy work space to the PV assigned variables 2)Update PV for display Entry: dynamic assignment for 20x20 PVs

SNL and Sequencer 23 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: C escapes

SNL and Sequencer 24 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: C escapes

SNL and Sequencer 25 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Declarations

SNL and Sequencer 26 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Init State

SNL and Sequencer 27 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: initArray State

SNL and Sequencer 28 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: run State

SNL and Sequencer 29 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Additional State Set State Set: main_loop State Set: new_game loop INIT Event: changed live cell counter Action: update previous live cell counter to current Event: expired timer Action: random walk on the initial population Live cell counter PV Initial Population

SNL and Sequencer 30 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Example 2: Additional State Set

SNL and Sequencer 31 Controls EPICS Training Class EPICS Collaboration Meeting SLAC SNL Variable and Scope Global Variables lifetime/scope: entire program Memory allocation by sequencer with option +r; Static variable in C with option –r; Local Variables State Set Memory allocation by Sequencer State Memory allocation by Sequencer Entry/Exit/Action function Stack variable program mySNL option +r; double a; assign a to pvA; monitor a; ss my_state_set { double b; state low { int i=0; when(a>0.5) { int j ; b = a; i++; for(j=-0;j<MAX;j++) {

SNL and Sequencer 32 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Variable TypeLifetimeScopeImplementationAccess in C escapeInitialization GlobalstaticProgram InstancemallocpVar->myVariableYes, G_prog_init Local in a State Set staticState SetmallocpVar->UserVar_myStateSet.myVariableYes, G_prog_init Local in a StatestaticStatemallocpVar- >UserVar_myStateSet.UserVar_myState.myVariable Yes, G_prop_init Local in a When() Function call Inside the when statement (action function) Stack variablemyVariableNO Local in an entry/exit Function call Inside entry/exit (entry function/exit function) Stack variablemyVariableNO SNL Variable’s Scope and Lifetime with Reentrance

SNL and Sequencer 33 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Variable TypeLifetimeScopeImplementationAccess in C escapeInitialization GlobalstaticProgramStatic variablemyVariableYes, Compiletime Local in a State Set staticState SetStatic structureUserVar_myStateSet.myVariableYes, Compiletime Local in a StatestaticStateStatic structureUserVar_myStateSet.UserVar_myState.myVariableYes, Compiletime Local in a When() Function call Inside the when statement (action function) Stack variablemyVariableNO Local in an entry/exit Function call Inside entry/exit (entry function/exit function) Stack variablemyVariableNO SNL Variable’s Scope and Lifetime with Non-Reentrance

SNL and Sequencer 34 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Dynamic PV assignments To allow PV assignment/re-assignment at runtime Requires an initial assigment (or NULL assignment) in the Declaration Section for single variables for array variables double myVar; assign myVar to “”;... pvAssign(myVar, “PV_MYVAR”); double myVar[MAX]; assign myVar to { “” };... for(i=0;i<MAX;i++) pvAssign(myVar[i], str_pvName[i]);

SNL and Sequencer 35 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Building an SNL Program Use editor to build the source file. File name must end with “.st” or “.stt”, e.g. “example.st” “make” automates these steps: Runs the C preprocessor on “.st” files, but not on “.stt” files. Compiles the state program with SNC to produce C code: snc example.st -> example.c Compiles the resulting C code with the C compiler: cc example.c -> example.o The object file example.o becomes part of the application library, ready to be linked into an IOC binary. The executable file “example” can be created instead.

SNL and Sequencer 36 Controls EPICS Training Class EPICS Collaboration Meeting SLAC.st vs..stt program ex1 Option –r; %{ #define MAX nip --- for(i=0;i<MAX;++) { --- }% double myArray[MAX]; ss myStateSet { state myState { when(index>= MAX) { program ex1 option –r; #define MAX 20 double myArray[MAX]; ss myStateSet { state myState { when(index>= MAX) {.stt Syntax error in SNL Define Macro in C escape OK! to use macro in the C escape and the SNL code both Illegal to use the macro in the declaration

SNL and Sequencer 37 Controls EPICS Training Class EPICS Collaboration Meeting SLAC.st vs..stt - continued program ex1 option –r; #define MAX 20 %{ --- nip --- for(i=0;i<MAX;++) { --- }% double myArray[MAX]; double my2DArray[MAX*MAX] ss myStateSet { state myState { when(index>= MAX) { double a[MAX*MAX];.st program ex1 option –r; /* #define MAX 20 */ %{ --- nip --- for(i=0;i<20;++) { --- }% double myArray[20]; double my2DArray[20*20] ss myStateSet { state myState { when(index>= 20) { double a[20*20]; C preprocessing Illegal, because the SNC doesn’t have compile time arithmetic OK to use in the local variable in action/entry/exit function. C compiler does the compile time arithmetic

SNL and Sequencer 38 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Runtime Sequencer The sequencer executes the state program It is implemented as an event-driven application; no polling is needed Each state set becomes an operating system thread The sequencer manages connections to database channels through Channel Access It provides support for channel access get, put, and monitor operations It supports asynchronous execution of delays, event flag, pv put and pv get functions Only one copy of the sequencer code is required to run multiple programs Commands are provided to display information about the state programs currently executing

SNL and Sequencer 39 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Executing SNL Program From an IOC console On vxWorks: seq &vacuum_control On RTEMS seq(&vacuum_control) On other operating systems: seq vacuum_control To stop the program seqStop "vacuum_control"

SNL and Sequencer 40 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Debugging Use the sequencer's query commands: seqShow displays information on all running state programs seqShow vacuum_control displays detailed information on program seqChanShow vacuum_control displays information on all channels seqChanShow vacuum_control,"-" displays information on all disconnected channels seqcar displays information on all channel access channels

SNL and Sequencer 41 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Additional Features Connection management: when (pvConnectCount() != pvChannelCount()) when (pvConnected(Vin)) Macros: assign Vout to "{unit}:OutputV"; must use the +r compiler options for this if more than one copy of the sequence is running on the same ioc seq &example, "unit=HV01" Some common SNC program options: +r make program reentrant (default is -r ) -c don't wait for all channel connections (default is +c ) +a asynchronous pvGet() (default is -a ) -w don't print compiler warnings (default is +w )

SNL and Sequencer 42 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Additional Features – Cont’d Access to channel alarm status and severity: pvStatus(var_name) pvSeverity(var_name) Queued monitors save CA monitor events in a queue in the order they come in, rather than discarding older values when the program is busy syncQ var_name to event_flag_name [queue_length] pvGetQ(var_name) removes oldest value from variable's monitor queue. Remains true until queue is empty. pvFreeQ(var_name)

SNL and Sequencer 43 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Advantage of SNL Program Can implement complicated algorithms Can stop, reload, restart a sequence program without rebooting Interact with the operator through string records and mbbo records C code can be embedded as part of the sequence All Channel Access details are taken care of for you File access can be implemented as part of the sequence

SNL and Sequencer 44 Controls EPICS Training Class EPICS Collaboration Meeting SLAC Acknowledgements Andrew Johnson, AES basic EPICS Training – January 2011 Benjamin Franksen, new Seq modules