State Notation Language and the Sequencer Andrew Johnson APS Engineering Support Division October 2008 INFN EPICS Training.

Slides:



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

CIMCO Integration Software Products
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Bob Dalesio, Deb Kerstiens, Rozelle Wright.
Simulation executable (simv)
EPICS Base R and beyond Andrew Johnson Computer Scientist, AES Controls Group.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
VBA Modules, Functions, Variables, and Constants
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Guide To UNIX Using Linux Third Edition
Microsoft Visual Basic 2012 CHAPTER ONE Introduction to Visual Basic 2012 Programming.
Input/Output Controller (IOC) Overview Andrew Johnson Computer Scientist, AES Controls Group.
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.
SNL and Sequencer 1 Controls EPICS Training Class EPICS Collaboration Meeting SLAC State Notation Language (SNL) and Sequencer April 23, 2012 Kukhee.
EPICS and EDM Overview 03 October 2008 Matt Boyes EPICS and EDM Overview Lecture 1 Matt Boyes.
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)
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Institute of Computer and Communication Network Engineering OFC/NFOEC, 6-10 March 2011, Los Angeles, CA Lessons Learned From Implementing a Path Computation.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 10Slide 1 Architectural Design l Establishing the overall structure of a software system.
1 SNL Current State (in transition state) By Matthias Clausen Ron Chestnut.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Making LabVIEW look like an IOC Kay-Uwe Kasemir, LANL May 2002.
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.
1 Channel Access Concepts – EPICS Training – K.Furukawa – Mar EPICS Channel Access Concepts Kazuro Furukawa, KEK, ( ) (Bob Dalesio, LANL,
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.
Managed by UT-Battelle for the Department of Energy EPICS Sequencer Kay Kasemir, SNS/ORNL Many slides from Andrew Johnson, APS/ANL Feb
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
EPICS sequencer update Greg White / William Lupton / EPICS ‘99 SLAC, May 27, 1999.
Managed by UT-Battelle for the Department of Energy CSS Update Matthias Clausen, Helge Rickens, Jan Hatje and DESY Delphy Armstrong, Xihui Chen,
EPICS EPICS Limitations Bob Dalesio Marty Kraimer.
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays - done for rsrv in 3.14 Channel access priorities - planned to.
Stanford Linear Accelerator Center New SNL Ideas Possible Next Steps Ron Chestnut – PSI, May, 2001 With ideas from B. Dalesio and M. Clausen.
1. LabVIEW and EPICS Workshop EPICS Collaboration Meeting Fall 2011.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
Intermediate 2 Computing Unit 2 - Software Development.
1 1999/Ph 514: Lab #3A : SNL Lab#3B : Development Environment EPICS Lab #3a State Notation Language.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays Channel access priorities Portable server replacement of rsrv.
Jan Hatje, DESY SNL Editor and Debugger EPICS collaboration meeting SNL Editor and Debugger EPICS collaboration meeting 2008 Shanghai Institute.
B. Dalesio, N. Arnold, M. Kraimer, E. Norum, A. Johnson EPICS Collaboration Meeting December 8-10, 2004 Roadmap for IOC.
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
Chapter – 8 Software Tools.
EPICS and LabVIEW Tony Vento, National Instruments
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Monitoring Dynamic IOC Installations Using the alive Record Dohn Arms Beamline Controls & Data Acquisition Group Advanced Photon Source.
Using COTS Hardware with EPICS Through LabVIEW – A Status Report EPICS Collaboration Meeting Fall 2011.
JavaIOC Overview and Update
State Notation Language (SNL) and Sequencer
Digital Chart Recorder Operation
Writing a Channel Access Client in EPICS
Channel Access Concepts
Capitolo 1 – Introduction C++ Programming
Chapter 1 c++ structure C++ Input / Output
Channel Access Concepts
Presentation transcript:

State Notation Language and the Sequencer Andrew Johnson APS Engineering Support Division October 2008 INFN EPICS Training

2 Outline What is State Notation Language (SNL) Where it fits in the EPICS toolkit Components of a state notation program Some notes on the Sequencer runtime Building, running and debugging a state notation program Additional Features When to use it This talk covers Sequencer version This talk does not cover all the features of SNL and the sequencer. Consult the manual for more information:

3 SNL and the Sequencer The sequencer runs programs written in State Notation Language (SNL) SNL is a ‘C’ like language to facilitate programming of sequential operations Fast execution - compiled code Programming interface to extend EPICS in the real-time environment Common uses –Provide automated start-up sequences like vacuum or RF where subsystems need coordination –Provide fault recovery or transition to a safe state –Provide automatic calibration of equipment

4 Where’s the Sequencer? Channel Access LAN Device Support I/O Hardware IOC The major software components of an IOC (IOC Core) Database Sequencer

5 Where’s the Sequencer Now? MEDMClient MEDM Server IOC MeterPower SupplyCamera IOC Tools Sequencer LAN

6 The Best Place for the Sequencer Recent versions of the sequencer can be run either in an IOC or as a standalone program on a workstation Traditionally sequencers run in the IOC Locating them within the IOC they control makes them easier to manage Running them on a workstation can make testing and debugging easier On a workstation, SNL provides an easy way to write simple CA client programs

7 SNL implements State Transition Diagrams State A State B Event Action Transition A to B

8 STD Example Start Low vacuum High vacuum pressure < 5.1 uTorr Open the valve pressure > 4.9 uTorr Close the valve

9 Some Definitions SNL : State Notation Language SNC : State Notation Compiler sequencer : The tool that executes the compiled SNL code Program : A complete SNL application consisting of 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 is evaluated to be TRUE

10 SNL: General Structure and 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 {... }

11 SNL: General Structure and Syntax program name A program may contain multiple state sets. The program name is used as a handle to the sequencer manager for state programs. ss name { A state set becomes a task in the vxWorks environment. state name { A state is an area where the task waits for events. The related task waits until one of the events occurs and then checks to see which it should execute. The first state defined in a state set is the initial state. option flag; A state specific option when (event) { Defines the events for which this state waits. } state next Specifies the following state after the actions complete. entry {actions} Actions to do on entry to this state from another state. With option -e; it will do these actions even if it re- enters from the same state. exit {actions} Actions to do before exiting this state to another state. With option -x; it will do these actions even if it exits to the same state.

12 Declarations – 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];

13 Declarations – 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 channel 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”)

14 Declarations – Event Flags Event flags are used to communicate between state sets, or to receive explicit event notifications from Channel Access Declare 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 evflagflag_monitor; syncpressure flag_monitor;

15 Event:The condition on which actions associated with a when 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 (not a task delay!): when (delay(1.5)) –The delay time is in seconds. It is declared internally as a double; 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 stop it from being reset when transitioning to the same state. Events

16 Possible Events (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))

17 Action Statements 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 }%

18 Example – State Definitions and Transitions pressure > RoughPump on CryoPump off Valve closed pressure <= RoughPump off CryoPump on Valve open pressure <= RoughPump off CryoPump on Valve open pressure > RoughPump on CryoPump off Valve closed 10 minutes RoughPump off CryoPump off Valve closed Initial State Fault High Vacuum Low Vacuum

19 Example – Declarations double pressure; assign pressure to “Tank1Coupler1PressureRB”; monitor pressure; short RoughPump; assign RoughPump to “Tank1Coupler1RoughPump”; short CryoPump; assign CryoPump to “Tank1Coupler1CryoPump”; short Valve; assign Valve to “Tank1Coupler1IsolationValve”; string CurrentState; assign CurrentState to “Tank1Coupler1VacuumState”;

20 Example – State Transitions, Actions Omitted program vacuum_control ss coupler_control { state init{ when (pressure > ){ } state low_vacuum when (pressure <= ){ } state high_vacuum } state high_vacuum{ when (pressure > ){ } state low_vacuum } state low_vacuum{ when (pressure <= ){ } state high_vacuum when (delay(600.0)){ } state fault } state fault { }

21 Example – Initial State state init { entry { strcpy(CurrentState,”Init”); pvPut(CurrentState); } when (pressure > ){ RoughPump = 1; pvPut(RoughPump); CryoPump = 0; pvPut(CryoPump); Valve = 0; pvPut(Valve); } state low_vacuum when (pressure <= ){ RoughPump = 0; pvPut(RoughPump); CryoPump = 1; pvPut(CryoPump); Valve = 1; pvPut(Valve); } state high_vacuum }

22 Example – State low_vacuum state low_vacuum{ entry { strcpy(CurrentState,”Low Vacuum”); pvPut(CurrentState); } when (pressure <= ){ RoughPump = 0; pvPut(RoughPump); CryoPump = 1; pvPut(CryoPump); Valve = 1; pvPut(Valve); } state high_vacuum when (delay(600.0)){ } state fault }

23 Example – State high_vacuum state high_vacuum{ entry { strcpy(CurrentState,”High Vacuum”); pvPut(CurrentState); } when (pressure > ){ RoughPump = 1; pvPut(RoughPump); CryoPump = 0; pvPut(CryoPump); Valve = 0; pvPut(Valve); } state low_vacuum }

24 Example – State fault state fault{ entry{ strcpy(CurrentState,”Vacuum Fault”); pvPut(CurrentState); }

25 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.

26 Run Time 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

27 Executing a State Program From an IOC console On vxWorks: seq &vacuum_control On other operating systems: seq vacuum_control To stop the program – seqStop “vacuum_control”

28 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

29 Debugging (continued) Use printf functions to print to the console printf("Here I am in state xyz \n"); Put strings to pvs sprintf(seqMsg1, "Here I am in state xyz"); pvPut(seqMsg1); On vxWorks you can reload and restart seqStop vacuum_control... edit, recompile... ld < example.o seq &vacuum_control

30 Debugging – seqShow epics> seqShow Program Name Thread ID Thread Name SS Name stabilizer ede78 stabilizer stabilizerSS1 beamTrajectory db360 beamTrajectory bpmTrajectorySS autoControl ed620 autoControl autoCtlSS

31 Debugging – seqShow epics> seqShow stabilizer State Program: "stabilizer" initial thread id = ede78 thread priority = 50 number of state sets = 1 number of syncQ queues = 0 number of channels = 3 number of channels assigned = 3 number of channels connected = 3 options: async=0, debug=0, newef=1, reent=0, conn=1, main=0 State Set: "stabilizerSS1" thread name = stabilizer; thread id = = 0xede78 First state = "init" Current state = "waitForEnable" Previous state = "init" Elapsed time since state was entered = 88.8 seconds

32 Debugging – seqChanShow epics> seqChanShow stabilizer State Program: "stabilizer" Number of channels=3 #1 of 3: Channel name: "stabilizerC" Unexpanded (assigned) name: "stabilizerC" Variable name: "enableButton" address = = 0x25a08 type = short count = 1 Value = 0 Monitor flag = 1 Monitored Assigned Connected Get not completed or no get issued Put not completed or no put issued Status = 17 Severity = 3 Message = Time stamp = Next? ( skip count)

33 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 )

34 Additional Features (continued) 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 variables monitor queue. Remains true until queue is empty. pvFreeQ(var_name)

35 Advantages of SNL 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

36 When to use the sequencer For sequencing complex events E.g. parking and unparking a telescope mirror Photograph courtesy of the Gemini Telescopes project

37 Should I Use the Sequencer? START CAN I DO THIS IN A DB? Y N Y N USE THE SEQUENCER USE A DATABASE END

38 Acknowledgments Slides for this presentation have been taken from talks prepared by the following people –Bob Dalesio (LANL/SNS/LCLS) –Deb Kerstiens (LANL) –Rozelle Wright (LANL) –Ned Arnold (Argonne) –John Maclean (Argonne)