diff --git a/seq_modulator_state.txt b/seq_modulator_state.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb191ca46225f96905b7b310c4cd6f13b7e3b985 --- /dev/null +++ b/seq_modulator_state.txt @@ -0,0 +1,69 @@ +# +# Description: Calculate the macrostate of $mod$ +# Author: Giulio Gaio +# Date: 2021/0/17 +# +# ON=0, OFF=1, CLOSE=2, OPEN=3, INSERT=4, EXTRACT=5, MOVING=6, STANDBY=7, FAULT=8, INIT=9, RUNNING=10, ALARM=11, DISABLE=12, UNKNOWN=13 +# +step1;(write(this/SleepCount) = 0) && (write(this/ErrorCount) = 0) && goto(2);Reset counter;Error resetting counter;-1 +step2;sleep($sleep_monitor) && (write(this/SleepCount) = (read(this/SleepCount) + 1)) && ((read(this/SleepCount) >= read(this/MaxSleepCount))) ? goto(3) : goto(2);Sleep;Error sleeping;-1 +step3;(write(this/IsOn) = read($devrfamp/IsOn)) && (write(this/CondState) = read($devmodcond/State)) && (write(this/TrigShift) = read($devrttrig/EnableStaticTriggerShift)) && (write(this/TimeToGo) = read($devmodcond/TimeToGo)) && (write(this/Diode) = read($devmodcond/DiodeMode)) && goto(4);Get data;Error getting data;-1;tangoerror=goto(15) +# +step4;read(this/IsOn) == 1 ? (write(this/PhaseResRms) = read($devllrf/phase_res_rms)) && goto(5) : (write(this/PhaseResRms) = 0) && goto(5);Reading residual phase error;Error reading residual phase error;-1;tangoerror=goto(15) +# +# Enable Beam condition +step5;( (read(this/Diode) == 1) || (read(this/TrigShift) == 1) || ((read(this/IsOn) == 1) && (read(this/CondState) == ON) && (read(this/TimeToGo) == 0)) ) ? (write(this/EnableBeam) = 1) && goto(6) : goto(6);Check $mod enable beam conditions;Error checking $mod enable beam conditions;-1 +# +# Disable Beam condition +step6;( (read(this/Diode) == 0) && (read(this/TrigShift) == 0) && ( (read(this/IsOn) == 0) || ( (read(this/CondState) == ON) && (read(this/TimeToGo) > 0) ) ) ) ? (write(this/EnableBeam) = 0) && goto(7) : goto(7);Check $mod disable beam conditions;Error checking $mod disable beam conditions;-1 +# +# FAULT // Automatic recovery OFF && RF OFF +step7;((read(this/CondState) != ON) && (read(this/IsOn) == 0)) ? (write(this/ModState) = FAULT) && sleep($sleep_fault) && goto(1) : goto(8);Setting FAULT state;Error setting FAULT state;-1 +# +# DISABLE // Trigger shifted +step8;read(this/TrigShift) == 1 ? (write(this/ModState) = DISABLE) && goto(1) : goto(9);Setting DISABLE state;Error setting DISABLE state;-1 +# +# STANDBY // Diode mode +step9;(read(this/Diode) == 1 && (read(this/TimeToGo) == 0)) ? (write(this/ModState) = STANDBY) && goto(1) : goto(10);Setting STANDBY state;Error setting STANDBY state;-1 +# +# MOVING // Diode mode && recovery in progress +step10;(read(this/Diode) == 1 && (read(this/TimeToGo) > 0)) ? (write(this/ModState) = MOVING) && goto(1) : goto(11);Setting MOVING state;Error setting MOVING state;-1 +# +# OFF // Automatic recovery OFF && RF ON +step11;((read(this/CondState) != ON) && (read(this/IsOn) == 1)) ? (write(this/ModState) = OFF) && goto(1) : goto(12);Setting OFF state;Error setting OFF state;-1 +# +# MOVING // Recovery in progress +step12;((read(this/TimeToGo) > 0) && (read(this/CondState) == ON)) ? (write(this/ModState) = MOVING) && goto(1) : goto(13);Setting MOVING state;Error setting MOVING state;-1 +# +# ON // RF plant online 100% +step13;((read(this/CondState) == ON) && (read(this/IsOn) == 1)) ? (write(this/ModState) = ON) && goto(1) : goto(14);Setting ON state;Error setting ON state;-1 +# +# ALARM // Phase error above threshold +step14;read(this/PhaseResRms) > read(this/PhaseResRmsThres) ? (write(this/ModState) = ALARM) && goto(1) : goto(15);Setting ALARM state;Error setting ALARM state;-1; +# +# UNKNOWN // Reading error; after 10 consecutive do not take into account the this modulator +step15;(write(this/ModState) = UNKNOWN) && sleep($sleep_fault) && (write(this/ErrorCount) = (read(this/ErrorCount) + 1)) && (read(this/ErrorCount) < 10) ? (write(this/SleepCount) = 0) && goto(2) : (write(this/EnableBeam) = 1) && goto(1);Setting UNKNOWN state;Error setting UNKNOWN state;-1 +# +# +# Dynamic R/W attribute +attr;MaxSleepCount;long;2 +attr;PhaseResRmsThres;double;0.3 +attr;SuperState;long;1 +attr;SleepCount;long;0 +attr;ErrorCount;long;0 +attr;ModState;long;1 +attr;PhaseResRms;double;0 +attr;IsOn;bool;0 +attr;CondState;long;1 +attr;TrigShift;bool;0 +attr;TimeToGo;long;0 +attr;Diode;bool;0 +attr;EnableBeam;bool;1 +# +# Wildcards +# $devrfamp=kg06/mod/rfamp +# $devmodcond=kg06/mod/modcond-kg06-01 +# $devrttrig=f/timing/rttrigger_mod_kg06.01 +# $devllrf=kg06/mod/llrg_kg06.01 +# $sleep_monitor=0.25 +# $sleep_fault=3 diff --git a/seq_shutter_interlock.txt b/seq_shutter_interlock.txt new file mode 100644 index 0000000000000000000000000000000000000000..c273d9f1ebd262b714bf4d57a99bf7b75efa81da --- /dev/null +++ b/seq_shutter_interlock.txt @@ -0,0 +1,94 @@ +# +# Description: Check enable beam count and execute sequence +# Author: Giulio Gaio +# Date: 2021/08/17 +# +# ON=0, OFF=1, CLOSE=2, OPEN=3, INSERT=4, EXTRACT=5, MOVING=6, STANDBY=7, FAULT=8, INIT=9, RUNNING=10, ALARM=11, DISABLE=12, UNKNOWN=13 +# +step1;(write(this/EnableBeam) = 1) && (write(this/OldEnableBeam) = 1) && (write($shutterilockmemo/MPSShutterBeforeCloseState) = read($mpsshutter/State)) && ( write($shutterilockmemo/LinacStopperBeforeCloseState) = ( (read($linacstopper/Linac_bst_1[1]) * CLOSE) + (read($linacstopper/Linac_bst_1[0]) * OPEN) ) ) && (write($shutterilockmemo/DisableDate) = read($curtime_attr)) && (write(this/ErrorCounter) = 0) && goto(2);Resetting variables;Error resetting variables;-1;tangoerror=goto(29) +step2;sleep($sleep_monitor) && (write(this/DisableBeamCount) = 0) && goto(3);Waiting step;Error in waiting step;-1 +# +# MOD status check +step3;( (read($seqmod01$/State) == RUNNING) && (read($seqmod01$/ModState) != UNKNOWN) && (read($seqmod01$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(4) : goto(4);Check $seqmod01$ enable beam state;Error checking $seqmod01$ enable beam state;-1;tangoerror=goto(4) +step4;( (read($seqmod02$/State) == RUNNING) && (read($seqmod02$/ModState) != UNKNOWN) && (read($seqmod02$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(5) : goto(5);Check $seqmod02$ enable beam state;Error checking $seqmod02$ enable beam state;-1;tangoerror=goto(5) +step5;( (read($seqmod03$/State) == RUNNING) && (read($seqmod03$/ModState) != UNKNOWN) && (read($seqmod03$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(6) : goto(6);Check $seqmod03$ enable beam state;Error checking $seqmod03$ enable beam state;-1;tangoerror=goto(6) +step6;( (read($seqmod04$/State) == RUNNING) && (read($seqmod04$/ModState) != UNKNOWN) && (read($seqmod04$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(7) : goto(7);Check $seqmod04$ enable beam state;Error checking $seqmod04$ enable beam state;-1;tangoerror=goto(7) +step7;( (read($seqmod05$/State) == RUNNING) && (read($seqmod05$/ModState) != UNKNOWN) && (read($seqmod05$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(8) : goto(8);Check $seqmod05$ enable beam state;Error checking $seqmod05$ enable beam state;-1;tangoerror=goto(8) +step8;( (read($seqmod06$/State) == RUNNING) && (read($seqmod06$/ModState) != UNKNOWN) && (read($seqmod06$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(9) : goto(9);Check $seqmod06$ enable beam state;Error checking $seqmod06$ enable beam state;-1;tangoerror=goto(9) +step9;( (read($seqmod07$/State) == RUNNING) && (read($seqmod07$/ModState) != UNKNOWN) && (read($seqmod07$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(10) : goto(10);Check $seqmod07$ enable beam state;Error checking $seqmod07$ enable beam state;-1;tangoerror=goto(10) +step10;( (read($seqmod08$/State) == RUNNING) && (read($seqmod08$/ModState) != UNKNOWN) && (read($seqmod08$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(11) : goto(11);Check $seqmod08$ enable beam state;Error checking $seqmod08$ enable beam state;-1;tangoerror=goto(11) +step11;( (read($seqmod09$/State) == RUNNING) && (read($seqmod09$/ModState) != UNKNOWN) && (read($seqmod09$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(12) : goto(12);Check $seqmod09$ enable beam state;Error checking $seqmod09$ enable beam state;-1;tangoerror=goto(12) +step12;( (read($seqmod10$/State) == RUNNING) && (read($seqmod10$/ModState) != UNKNOWN) && (read($seqmod10$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(13) : goto(13);Check $seqmod10$ enable beam state;Error checking $seqmod10$ enable beam state;-1;tangoerror=goto(13) +step13;( (read($seqmod11$/State) == RUNNING) && (read($seqmod11$/ModState) != UNKNOWN) && (read($seqmod11$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(14) : goto(14);Check $seqmod11$ enable beam state;Error checking $seqmod11$ enable beam state;-1;tangoerror=goto(14) +step14;( (read($seqmod12$/State) == RUNNING) && (read($seqmod12$/ModState) != UNKNOWN) && (read($seqmod12$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(15) : goto(15);Check $seqmod12$ enable beam state;Error checking $seqmod12$ enable beam state;-1;tangoerror=goto(15) +step15;( (read($seqmod13$/State) == RUNNING) && (read($seqmod13$/ModState) != UNKNOWN) && (read($seqmod13$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(16) : goto(16);Check $seqmod13$ enable beam state;Error checking $seqmod13$ enable beam state;-1;tangoerror=goto(16) +step16;( (read($seqmod14$/State) == RUNNING) && (read($seqmod14$/ModState) != UNKNOWN) && (read($seqmod14$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(17) : goto(17);Check $seqmod14$ enable beam state;Error checking $seqmod14$ enable beam state;-1;tangoerror=goto(17) +step17;( (read($seqmod15$/State) == RUNNING) && (read($seqmod15$/ModState) != UNKNOWN) && (read($seqmod15$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(18) : goto(18);Check $seqmod15$ enable beam state;Error checking $seqmod15$ enable beam state;-1;tangoerror=goto(18) +step18;( (read($seqmod16$/State) == RUNNING) && (read($seqmod16$/ModState) != UNKNOWN) && (read($seqmod16$/EnableBeam) == 0) ) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(19) : goto(19);Check $seqmod16$ enable beam state;Error checking $seqmod16$ enable beam state;-1;tangoerror=goto(19) +# +# PIL TMU status check +step19;($tmu_attr_cond) ? (write(this/DisableBeamCount) = (read(this/DisableBeamCount) + 1)) && goto(20) : goto(20);Check TMU condition;Error checking TMU condition;-1;tangoerror=goto(20) +# +# Updating EnableBeam internal flag +step20;(write(this/OldEnableBeam) = read(this/EnableBeam)) && (read(this/DisableBeamCount) == 0) ? (write(this/EnableBeam) = 1) && goto(21) : (write(this/EnableBeam) = 0) && goto(21);Setting EnableBeam flag;Error setting EnableBeam flag;-1 +# +# +# ENABLE -> DISABLE transition +step21;( (read(this/EnableClose) == 1) && (read(this/OldEnableBeam) == 1) && (read(this/EnableBeam) == 0) ) ? (write($shutterilockmemo/MPSShutterBeforeCloseState) = read($mpsshutter/State)) && ( write($shutterilockmemo/LinacStopperBeforeCloseState) = ( (read($linacstopper/Linac_bst_1[1]) * CLOSE) + (read($linacstopper/Linac_bst_1[0]) * OPEN) ) ) && (write($shutterilockmemo/DisableDate) = read($curtime_attr)) && goto(22) : goto(25);Detected disable beam transition;Error detecting disable beam transition;-1;tangoerror=goto(29) +# +# Launch closing launcher +step22;read($seq_close/State) == RUNNING ? goto(24) : (write(this/MaxSleepCount) = 0) && command($seq_close/Start) && goto(23);Starting close sequence $seq_close;Error starting close sequence $seq_close;-1;tangoerror=goto(29) +step23;sleep(1) && (write(this/MaxSleepCount) = (read(this/MaxSleepCount) + 1)) && ( (read($seq_close/State) == RUNNING) && (read(this/MaxSleepCount) < $seq_timeout) ) ? goto(23) : goto(24);Waiting $seq_close;Error waiting $seq_close;-1;tangoerror=goto(29) +step24;read($seq_close/State) == RUNNING ? command($seq_close/Abort) && goto(25) : goto(25);Aborting $seq_close;Error aborting $seq_close;-1;tangoerror=goto(29) +# +# +# DISABLE -> ENABLE transition +step25;( (read(this/EnableOpen) == 1) && (read(this/OldEnableBeam) == 0) && (read(this/EnableBeam) == 1) ) ? goto(26) : goto(30);Detected enable beam transition;Error detecting enable beam transition;-1 +# +# Launch opening launcher +step26;read($seq_open/State) == RUNNING ? goto(27) : (write(this/MaxSleepCount) = 0) && command($seq_open/Start) && goto(27);Starting open sequence $seq_open;Error starting open sequence $seq_open;-1;tangoerror=goto(29) +step27;sleep(1) && (write(this/MaxSleepCount) = (read(this/MaxSleepCount) + 1)) && ( (read($seq_open/State) == RUNNING) && (read(this/MaxSleepCount) < $seq_timeout) ) ? goto(27) : goto(28);Waiting $seq_open;Error waiting $seq_open;-1;tangoerror=goto(29) +step28;read($seq_open/State) == RUNNING ? command($seq_open/Abort) && goto(30) : goto(30);Aborting $seq_open;Error aborting $seq_open;-1;tangoerror=goto(29) +# +# +step29;(write(this/ErrorCounter) = (read(this/ErrorCounter) + 1)) && (write(this/OldEnableBeam) = 1) && goto(31);Incrementing error counter;Error incrementing error counter;-1 +step30;(write(this/ErrorCounter) = 0) && goto(31);Resetting error counter;Error resetting error counter;-1 +step31;goto(2);End;End;-1 +step32;goto(33);Finish;Finish;-1;exit +# +# +# R/W dynamic attributes +attr;EnableOpen;bool;0 +attr;EnableClose;bool;0 +attr;EnableBeam;bool;1 +attr;OldEnableBeam;bool;1 +attr;DisableBeamCount;long;0 +attr;MaxSleepCount;long;0 +attr;ErrorCounter;long;0 +# +# Wildcards +# $mpsshutter=usa/mps/shutter +# $linacstopper=f/access_control/safety +# $seq_close=seq/close/shutterinterlock +# $seq_open=seq/open/shutterinterlock +# $shutterinterlockmemo=seq/store/shutterinterlock +# $tmu_attr_cond=(abs(read(pil/timing/tmu_pil.01/PllDeltaF)) > 0.001) +# $curtime_attr=sr/utils/time_rand.01/LDate[0] +# $seq_timeout=600 +# $sleep_monitor=0.1 +# $seqmod01$=seq/monitor/state_mod_kg01.01 +# $seqmod02$=seq/monitor/state_mod_kg02.01 +# $seqmod03$=seq/monitor/state_mod_kg03.01 +# $seqmod04$=seq/monitor/state_mod_kg04.01 +# $seqmod05$=seq/monitor/state_mod_kg05.01 +# $seqmod06$=seq/monitor/state_mod_kg06.01 +# $seqmod07$=seq/monitor/state_mod_kg07.01 +# $seqmod08$=seq/monitor/state_mod_kg08.01 +# $seqmod09$=seq/monitor/state_mod_kg09.01 +# $seqmod10$=seq/monitor/state_mod_kg10.01 +# $seqmod11$=seq/monitor/state_mod_kg11.01 +# $seqmod12$=seq/monitor/state_mod_kg12.01 +# $seqmod13$=seq/monitor/state_mod_kg13.01 +# $seqmod14$=seq/monitor/state_mod_kg14.01 +# $seqmod15$=seq/monitor/state_mod_kg15.01 +# $seqmod16$=seq/monitor/state_mod_kg16.01