1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 <2025> | Index | 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 <2025> |
<== Date ==> | <== Thread ==> |
---|
Subject: | Re: Generation of state diagram documentation from SNL |
From: | "Hao, Hao via Tech-talk" <tech-talk at aps.anl.gov> |
To: | "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov> |
Date: | Tue, 29 Jul 2025 21:43:52 +0000 |
Hi, Ed,
TDM (https://github.com/diverhao/tdm/releases/tag/v2507)
has a “Seq Graph” tool to visualize and run a state machine in the frontend. This tool roughly follows the snl grammar to define the state machine, such as ss/state/when(). The logic must be written in _javascript_. It provides several functions to read/write
PVs. For example, await delay(2) to delay 2 seconds, value_of(“pv_name”) to obtain the value, caput(“pv_name”, 33) to PUT a value, connect(“pv_name1”, “pv_name2”) to connect and monitor the PVs.
You can also visualize an existing C-like snl code using the “Emulation mode”, but you cannot run the code.
How to run a _javascript_ state machine code: https://github.com/diverhao/misc/blob/main/tdm/run-state-machine.gif How to visualize a SNL code: https://github.com/diverhao/misc/blob/main/tdm/visualize-snl-state-machine.gif
The following code is a simple _javascript_ traffic light state machine:
// --------------------------------------------
// global variables must be written in global.xxx
global.R = 0;
global.Y = 1;
global.G = 2;
global.lights = [
"traffic:red_light",
"traffic:yellow_light",
"traffic:green_light"
];
connect(...global.lights);
global.red_time = 3.0;
global.red_yellow_time = 1.0;
global.green_time = 4.0;
global.yellow_time = 1.0;
ss light {
// no code allowed here
state red {
// no code allowed here
entry {
caput(global.lights[global.R], 1);
caput(global.lights[global.Y], 0);
caput(global.lights[global.G], 0);
}
when (await delay(global.red_time)) {
print("switch to red-yellow light");
} state red_yellow
}
state red_yellow {
entry {
caput(global.lights[global.R], 1);
caput(global.lights[global.Y], 1);
caput(global.lights[global.G], 0);
}
when (await delay(global.red_yellow_time)) {
print("switch to green light");
} state green
}
state green {
entry {
caput(global.lights[global.R],0);
caput(global.lights[global.Y],0);
caput(global.lights[global.G],1);
}
when (await delay(global.green_time)) {
print("switch to yellow light");
} state yellow
}
state yellow {
entry {
caput(global.lights[global.R],0);
caput(global.lights[global.Y],1);
caput(global.lights[global.G],0);
}
when (await delay(global.yellow_time)) {
print("switch to red light");
} state red
}
}
// --------------------------------------------
Best,
Hao |