Back Midas Rome Roody Rootana
  Midas DAQ System, Page 9 of 145  Not logged in ELOG logo
New entries since:Wed Dec 31 16:00:00 1969
IDdown Date Author Topic Subject
  2762   07 May 2024 Musaab Al-BakryForumMidas Sequencer with less than 1 second wait
> Actually I realized that a 1ms wait still works, so I reduced it to that.
> 
> Stefan

Thank you so much, Stefan. I have tested your changes, and it seems like this does 
the job for our purposes. Very appreciated!

Best regards,
Musaab Faozi
  2761   06 May 2024 Stefan RittForumMidas Sequencer with less than 1 second wait
Actually I realized that a 1ms wait still works, so I reduced it to that.

Stefan
  2760   06 May 2024 Stefan RittForumMidas Sequencer with less than 1 second wait
Indeed there was a sleep(100ms) in the sequencer in each loop. I reduced it now to 10ms. I need at least 10ms since otherwise 
the sequencer would run in an infinite loop during the wait and burn 100% CPU. The smallest time slice on Linux to sleep is 
10ms, so that's why I set it to that. Give it a try.

Stefan
  2759   05 May 2024 Musaab Al-BakryForumMidas Sequencer with less than 1 second wait
> > Ok, I implemented the float second wait function. Internally it works in ms, so the maximum resolution is 0.001 s.
> > 
> > Best,
> > Stefan
> 
> Thank you, we will test this soon and let you know if we see any issues (but we're not expecting any).

Hello Stefan,

Thank you for the help you provided for us so far. I tried your code changes on our midas fork. Now, I notice that any 
wait command takes at least 0.2 seconds to run. 

For example, when I use the following script:
SCRIPT source scripts/time_print.sh
WAIT Seconds, 0.1
SCRIPT source scripts/time_print.sh
WAIT Seconds, 0.1
SCRIPT source scripts/time_print.sh

The time_print.sh script prints time segments separated by almost exactly 0.2 seconds. Same goes for when I use 0.01 
second waits.

However, when I use 0.2 seconds wait, then I get time segments separated by 0.3 seconds. I also tried something like 
this:
SCRIPT source scripts/time_print.sh
WAIT Seconds, 0.2
WAIT Seconds, 0.2
SCRIPT source scripts/time_print.sh
WAIT Seconds, 0.2
WAIT Seconds, 0.2
SCRIPT source scripts/time_print.sh

This script results in time segements of 0.6 seconds difference. It is not immidiately clear to me from the sequencer 
code what causes this effect. The code as it stands is a lot better than what we had before the changes, but I am 
wondering if this can be reduced to the order of 1ms or 10ms.

Best regards,
Musaab Faozi
  2758   03 May 2024 Stefan RittBug ReportParams not initialized when starting sequencer
Seems to me like the problem happens less frequently, but I still see it (1 out of 5 or so). The fact that /Sequencer/Params/Value is empty tells me that the GUI 
has the problem and not the sequencer side.

Stefan
Attachment 1: Screenshot_2024-05-03_at_18.19.52.png
Screenshot_2024-05-03_at_18.19.52.png
  2757   03 May 2024 Zaher SalmanBug ReportParams not initialized when starting sequencer
Thanks for the hint Stefan. I pushed a possible fix but I cannot test it since I cannot reproduce the issue.

> Ahh, that rings a bell:
> 
> 1) JS opens start dialog box
> 2) User enters parameters and presses start
> 3) JS writes parameters
> 4) JS starts sequencer
> 5) Sequencer copies parameters to variables
> 
> Now how do you handle 3) and 4). Just issue two mjsonrpc commands together? What then could happen is that 4) is executed before 3) and we get the garbage.
> You have to do 3) and WAIT for the return ("then" in the JS promise), and only then issue 4) from there.
> 
> Stefan
  2756   03 May 2024 Stefan RittBug ReportParams not initialized when starting sequencer
Ahh, that rings a bell:

1) JS opens start dialog box
2) User enters parameters and presses start
3) JS writes parameters
4) JS starts sequencer
5) Sequencer copies parameters to variables

Now how do you handle 3) and 4). Just issue two mjsonrpc commands together? What then could happen is that 4) is executed before 3) and we get the garbage.
You have to do 3) and WAIT for the return ("then" in the JS promise), and only then issue 4) from there.

Stefan
  2755   03 May 2024 Zaher SalmanBug ReportParams not initialized when starting sequencer
I have been able to reproduce the problem only once. From what I see, it seems that the Variables ODB tree is not initialized properly from the Param tree. Below are the messages from the failed run compared to a successful one. As far as I could see, the javascript code does not change anything in the Variables ODB tree (only monitors it). The actual changes are done by the sequencer program, or am I wrong?

Failed run:
16:14:25.849 2024/05/03 [Sequencer,INFO]  + 3 * 
16:14:24.722 2024/05/03 [Sequencer,INFO]  + 2 * 
16:14:23.594 2024/05/03 [Sequencer,INFO]  + 1 * 
16:14:23.592 2024/05/03 [Sequencer,INFO] Start of looping
16:14:23.591 2024/05/03 [Sequencer,INFO] (( - )/)
16:14:23.591 2024/05/03 [Sequencer,INFO] 
16:14:23.590 2024/05/03 [Sequencer,INFO] 
16:14:23.590 2024/05/03 [Sequencer,INFO] 
16:14:23.589 2024/05/03 [Sequencer,INFO] Parameters:
16:14:23.562 2024/05/03 [Sequencer,TALK] Sequencer started with script "testpars.msl".


Successful run:
16:15:37.472 2024/05/03 [Sequencer,INFO] 1.820000
16:15:37.471 2024/05/03 [Sequencer,INFO] Start of looping
16:15:37.471 2024/05/03 [Sequencer,INFO] 15
16:15:37.470 2024/05/03 [Sequencer,INFO] 0.020000
16:15:37.470 2024/05/03 [Sequencer,INFO] 2.100000
16:15:37.469 2024/05/03 [Sequencer,INFO] 1.800000
16:15:37.469 2024/05/03 [Sequencer,INFO] Parameters:
16:15:37.450 2024/05/03 [Sequencer,TALK] Sequencer started with script "testpars.msl".
  2754   03 May 2024 Stefan RittSuggestionPossible addition to IF Statements
The tinyexpr library I use to evaluate expressions does not support boolean operations. I would have to switch to the newer 
tineyexpr-plusplus version, which also has much richer functionality:

https://github.com/Blake-Madden/tinyexpr-plusplus/blob/tinyexpr%2B%2B/TinyExprChanges.md

Unfortunately it requires C++17, and at the moment we limit MIDAS to C++11, meaning we would break this requirement. I 
believe at the moment there are still some experiments (mainly at TRIUMF) which are stuck to older OS and therefore cannot 
switch to C++17, but hopefully this will change over time.

Stefan
  2753   03 May 2024 Thomas SengerSuggestionPossible addition to IF Statements
Hello there, 
in our setup we use many variables with many different exceptions. Would it be possible to implement something like an 
IF or/and IF statement? I believe that this is currently not possible.
Best regards, 
Thomas Senger
  2752   03 May 2024 Luigi ViganiBug ReportParams not initialized when starting sequencer
It is pretty much the same as Stefan, I attach here the screenshots. Also in my case it works sometimes, and sometimes partially (one or 2 params, like in 
attachment 3).

> Could you please export and send me the /Sequencer ODB tree (or just /Sequencer/Param and /Sequencer/Variables) in both cases while the sequence is running. 
> 
> thanks,
> Zaher
> 
> 
> > Good afternoon,
> > 
> > After updating Midas to the latest develop commit 
> > (0f5436d901a1dfaf6da2b94e2d87f870e3611cf1) we found out a bug when starting 
> > sequencer. If we have a simple loop from start value to stop value and step 
> > size, just printing the value at each iteration, we see everything good (see 
> > first attachment). Then we included another script though, which contains 
> > several subroutines we defined for our detector, and we try to run the same 
> > script. Unfortunately after this the parameters seem uninitialized, and the 
> > value at each loop does not make sense (see second attachment). Also, sometimes 
> > when pressing run the set parameter window would pop-up, but sometimes not.
> > 
> > The script is this one:
> > 
> > >>>
> > COMMENT Test script to check for a specific bug
> > 
> > INCLUDE global_basic_functions
> > 
> > #CALL setup_paths
> > #CALL generate_DUT_params
> > 
> > PARAM lv_start, "Start of LV", 1.8
> > PARAM lv_stop, "Stop of LV", 2.1
> > PARAM lv_step, "Step of LV", 0.02
> > 
> > n_iterations = (($lv_stop - $lv_start)/$lv_step)
> > 
> > MSG "Parameters:"
> > MSG $lv_start
> > MSG $lv_stop
> > MSG $lv_step
> > MSG $n_iterations
> > 
> > MSG "Start of looping"
> > 
> > LOOP n, $n_iterations
> >    lv_now = $lv_start + $n * $lv_step
> >    MSG $lv_now
> >    WAIT SECONDS, 1
> > ENDLOOP
> > <<<
> > 
> > and the only difference comes from commenting the line:
> > 
> > >>>
> > INCLUDE global_basic_functions
> > <<<
> > 
> > as global_basic_functions is defined as a LIBRARY and it includes 75 (!) 
> > subroutines...
> > 
> > Is it possible that when loading a large script it messes up the loading of 
> > parameters?
> > 
> > Thank you very much,
> > Regards,
> > Luigi.
Attachment 1: seq1.PNG
seq1.PNG
Attachment 2: seq2.PNG
seq2.PNG
Attachment 3: seq3.PNG
seq3.PNG
  2751   03 May 2024 Stefan RittBug ReportParams not initialized when starting sequencer
Ok, here is the complete code to reproduce the problem. Load parameter_test.msl which includes functions.msl. From the screenshot you see the variables containing 
garbage, and you also see that from the ODB screenshot. For completeness, I added Sequencer.json which contains the whole sequencer tree.

The interesting thing is that this works sometimes, and sometimes not. I'm not sure if this in the GUI or in the sequencer program, so we have to sort out who can 
fix it ;-)

Best,
Stefan
Attachment 1: param_test.msl
INCLUDE functions

PARAM lv_start, "Start of LV", 1.8
PARAM lv_stop, "Stop of LV", 2.1
PARAM lv_step, "Step of LV", 0.02

n_iterations = (($lv_stop - $lv_start)/$lv_step)

MSG "Parameters:"
MSG $lv_start
MSG $lv_stop
MSG $lv_step
MSG $n_iterations

MSG "Start of looping"

LOOP n, $n_iterations
   lv_now = $lv_start + $n * $lv_step
   MSG $lv_now
   WAIT SECONDS, 1
ENDLOOP
Attachment 2: functions.msl
SUBROUTINE sub1
   WAIT seconds, 1
ENDSUBROUTINE

SUBROUTINE sub2
   WAIT seconds, 1
ENDSUBROUTINE

SUBROUTINE sub3
   WAIT seconds, 1
ENDSUBROUTINE

SUBROUTINE sub4
   WAIT seconds, 1
ENDSUBROUTINE

SUBROUTINE sub5
   WAIT seconds, 1
ENDSUBROUTINE

SUBROUTINE sub6
   WAIT seconds, 1
ENDSUBROUTINE

Attachment 3: Sequencer.json
{
   "/MIDAS version": "2.1",
   "/filename": "Sequencer.json",
   "/ODB path": "/Sequencer",
   "State": {
      "New File/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "New File": false,
      "Path/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Path": "",
      "Filename/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Filename": "param_test.msl",
      "SFilename/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "SFilename": "/Users/ritt/online/userfiles/sequencer/param_test.msl",
      "Next Filename/key": {
         "type": 12,
         "num_values": 10,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Next Filename": [
         "",
         "",
         "",
         "",
         "",
         "",
         "",
         "",
         "",
         ""
      ],
      "Error/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Error": "",
      "Error line/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Error line": 0,
      "SError line/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "SError line": 0,
      "Message/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Message": "",
      "Message Wait/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Message Wait": false,
      "Running/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Running": true,
      "Finished/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Finished": false,
      "Paused/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Paused": false,
      "Debug/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Debug": false,
      "Current line number/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Current line number": 46,
      "SCurrent line number/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "SCurrent line number": 20,
      "Follow Libraries/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Follow Libraries": true,
      "Stop after run/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Stop after run": false,
      "Transition request/key": {
         "type": 8,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Transition request": false,
      "Loop start line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Loop start line": [
         43,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "SLoop start line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "SLoop start line": [
         17,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "Loop end line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Loop end line": [
         47,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "SLoop end line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "SLoop end line": [
         21,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "Loop counter/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Loop counter": [
         6,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "Loop n/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Loop n": [
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "Subdir/key": {
         "type": 12,
         "item_size": 256,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Subdir": "",
      "Subdir end line/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Subdir end line": 0,
      "Subdir not notify/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "Subdir not notify": 0,
      "If index/key": {
         "type": 7,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "If index": 0,
      "If line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "If line": [
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0
      ],
      "If else line/key": {
         "type": 7,
         "num_values": 10,
         "access_mode": 7,
         "last_written": 1714720819
      },
      "If else line": [
         0,
         0,
         0,
         0,
         0,
... 379 more lines ...
Attachment 4: Screenshot_2024-05-03_at_09.19.29.png
Screenshot_2024-05-03_at_09.19.29.png
Attachment 5: Screenshot_2024-05-03_at_09.20.47.png
Screenshot_2024-05-03_at_09.20.47.png
  2750   03 May 2024 Zaher SalmanBug ReportParams not initialized when starting sequencer
Could you please export and send me the /Sequencer ODB tree (or just /Sequencer/Param and /Sequencer/Variables) in both cases while the sequence is running. 

thanks,
Zaher


> Good afternoon,
> 
> After updating Midas to the latest develop commit 
> (0f5436d901a1dfaf6da2b94e2d87f870e3611cf1) we found out a bug when starting 
> sequencer. If we have a simple loop from start value to stop value and step 
> size, just printing the value at each iteration, we see everything good (see 
> first attachment). Then we included another script though, which contains 
> several subroutines we defined for our detector, and we try to run the same 
> script. Unfortunately after this the parameters seem uninitialized, and the 
> value at each loop does not make sense (see second attachment). Also, sometimes 
> when pressing run the set parameter window would pop-up, but sometimes not.
> 
> The script is this one:
> 
> >>>
> COMMENT Test script to check for a specific bug
> 
> INCLUDE global_basic_functions
> 
> #CALL setup_paths
> #CALL generate_DUT_params
> 
> PARAM lv_start, "Start of LV", 1.8
> PARAM lv_stop, "Stop of LV", 2.1
> PARAM lv_step, "Step of LV", 0.02
> 
> n_iterations = (($lv_stop - $lv_start)/$lv_step)
> 
> MSG "Parameters:"
> MSG $lv_start
> MSG $lv_stop
> MSG $lv_step
> MSG $n_iterations
> 
> MSG "Start of looping"
> 
> LOOP n, $n_iterations
>    lv_now = $lv_start + $n * $lv_step
>    MSG $lv_now
>    WAIT SECONDS, 1
> ENDLOOP
> <<<
> 
> and the only difference comes from commenting the line:
> 
> >>>
> INCLUDE global_basic_functions
> <<<
> 
> as global_basic_functions is defined as a LIBRARY and it includes 75 (!) 
> subroutines...
> 
> Is it possible that when loading a large script it messes up the loading of 
> parameters?
> 
> Thank you very much,
> Regards,
> Luigi.
  2749   02 May 2024 Scott OserForumMidas Sequencer with less than 1 second wait
> Ok, I implemented the float second wait function. Internally it works in ms, so the maximum resolution is 0.001 s.
> 
> Best,
> Stefan

Thank you, we will test this soon and let you know if we see any issues (but we're not expecting any).
  2748   02 May 2024 Stefan RittForumMidas Sequencer with less than 1 second wait
Ok, I implemented the float second wait function. Internally it works in ms, so the maximum resolution is 0.001 s.

Best,
Stefan
  2747   30 Apr 2024 Scott OserForumMidas Sequencer with less than 1 second wait
> While I will do it, i'm not sure if this is what you want. If I understand correctly, some process gets triggered and then writes some values to the ODB, then the sequencer 
> should continue. Putting a wait there is dangerous. Maybe your process always takes like 10-20 ms, so you put a wait of let's say 100ms, and things are fine with you. Your 
> script runs many days, but then once in a while your machine is on heavy load because someone starts a web browser, and your process takes 110ms, and you script crashes.
> 
> I would rather go following path: put a "done" flag in the ODB, which is the last one which gets set by your process. Then the sequencer does a 
> 
> WAIT ODBvalue, /path/value, =, 1
> 
> which will work always, independend of the delay of your process.
> 
> Stefan

Our use case is pretty simple and I don't think is affected by the scenario you envision.  We want to turn on a setting in our equipment, and turn it off again some 0.2 s later.  We don't need msec timing.  So something like:

ODBSET /somekey 1   # this will cause a front-end to flip a bit in our hardware     
WAIT seconds, 0.2
ODBSET /somekey 0   # this will cause a front-end to reset a bit in our hardware 

It is true that if the load is high there could be a little delay, and the time that the bit is set will not be 0.2 seconds, but on average it should work, 
and it should be good enough we think.

Yes, we could also check an ODB key to see that something is done, but we'd still need the ability to wait for time intervals less than 1 second, which
right now doesn't exist.
  2746   30 Apr 2024 Stefan RittForumMidas Sequencer with less than 1 second wait
While I will do it, i'm not sure if this is what you want. If I understand correctly, some process gets triggered and then writes some values to the ODB, then the sequencer 
should continue. Putting a wait there is dangerous. Maybe your process always takes like 10-20 ms, so you put a wait of let's say 100ms, and things are fine with you. Your 
script runs many days, but then once in a while your machine is on heavy load because someone starts a web browser, and your process takes 110ms, and you script crashes.

I would rather go following path: put a "done" flag in the ODB, which is the last one which gets set by your process. Then the sequencer does a 

WAIT ODBvalue, /path/value, =, 1

which will work always, independend of the delay of your process.

Stefan
  2745   30 Apr 2024 Scott OserForumMidas Sequencer with less than 1 second wait
> > This would work fine in principle, but isn't implemented in the current MIDAS sequencer as we understand it.  (We tried!) Is your proposal to rewrite the sequencer 
> > to allow fractional waits?  Right now the code seems to store the start_time as a DWORD and uses atoi to parse the wait time, and uses ss_time (which seems only get
> > the time to the nearest second) to fetch the time.
> 
> No it's not implemented, was just my idea. If it would work for you, I can implement it in the next couple of days.
> 
> Stefan

Yes, please!  Something like WAIT seconds, 0.01 would be perfect.
  2744   30 Apr 2024 Stefan RittForumMidas Sequencer with less than 1 second wait
> This would work fine in principle, but isn't implemented in the current MIDAS sequencer as we understand it.  (We tried!) Is your proposal to rewrite the sequencer 
> to allow fractional waits?  Right now the code seems to store the start_time as a DWORD and uses atoi to parse the wait time, and uses ss_time (which seems only get
> the time to the nearest second) to fetch the time.

No it's not implemented, was just my idea. If it would work for you, I can implement it in the next couple of days.

Stefan
  2743   30 Apr 2024 Scott OserForumMidas Sequencer with less than 1 second wait
> I guess the simplest way to do that without breaking with existing code is to change the 
> second number to a float. So a
> 
> WAIT SECONDS, 1
> 
> will still work, and you can then write
> 
> WAIT SECONDS, 0.01
> 
> to get a 10 ms wait. Would that work for you?

This would work fine in principle, but isn't implemented in the current MIDAS sequencer as we understand it.  (We tried!) Is your proposal to rewrite the sequencer 
to allow fractional waits?  Right now the code seems to store the start_time as a DWORD and uses atoi to parse the wait time, and uses ss_time (which seems only get
the time to the nearest second) to fetch the time.
ELOG V3.1.4-2e1708b5