I asked this question on Teks forum, but I didn't get a response after my the replay. So I'll ask here in case anybody knows (maybe E-Design?)
I'm having trouble with "trigger.BLOCK_WAIT", it doesn't behave as I would expect, unless I'm missing something. Here is a piece of code that produces the unexpected behavior:
local function timerSetup()
trigger.timer[1].reset()
trigger.timer[1].delay = 1.
trigger.timer[1].start.stimulus = trigger.EVENT_NOTIFY1
trigger.timer[1].start.generate = trigger.OFF
trigger.timer[1].count = 0
trigger.timer[1].enable = trigger.ON
end
local function modelTiming()
timer.cleartime()
trigger.model.initiate()
waitcomplete()
print(timer.gettime())
end
reset()
timerSetup()
trigger.model.load("Empty")
trigger.model.setblock(1, trigger.BLOCK_NOTIFY, trigger.EVENT_NOTIFY1)
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
modelTiming()
timerSetup()
trigger.model.load("Empty")
trigger.model.setblock(1, trigger.BLOCK_NOTIFY, trigger.EVENT_NOTIFY1)
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
trigger.model.setblock(3, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
modelTiming()
timerSetup()
trigger.model.load("Empty")
trigger.model.setblock(1, trigger.BLOCK_NOTIFY, trigger.EVENT_NOTIFY1)
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
trigger.model.setblock(3, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
trigger.model.setblock(4, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
modelTiming()
timerSetup()
trigger.model.load("Empty")
trigger.model.setblock(1, trigger.BLOCK_NOTIFY, trigger.EVENT_NOTIFY1)
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
trigger.model.setblock(3, trigger.BLOCK_DELAY_CONSTANT, 0.2)
trigger.model.setblock(4, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
modelTiming()
timerSetup()
trigger.model.load("Empty")
trigger.model.setblock(1, trigger.BLOCK_NOTIFY, trigger.EVENT_NOTIFY1)
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
trigger.model.setblock(3, trigger.BLOCK_DELAY_CONSTANT, 0.3)
trigger.model.setblock(4, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1)
modelTiming()
That piece of code outputs:
1.000224076
1.000238197
2.00022641
1.200241196
2.000275546
while I was expecting instead to get:
1
2
3
2
2
Any ideas why this occurs?
Also, is there any way to restart the timer without having to "reset()" it (since reset() also clears all the timer parameters)?
Thanks
"Andreas C" from the tek forum replied to me:
Event detectors can latch events.
Since your event timer is essentially free running (count = 0), your BLOCK_WAIT is proceeding (too soon) due to a latched timer event from an "old" EVENT_TIMER1.
You can optionally clear as you enter wait blocks:
trigger.model.setblock(2, trigger.BLOCK_WAIT, trigger.EVENT_TIMER1, trigger.CLEAR_ENTER)
With that, you'll get your expected 1, 2, 3, 2, 2 reported duration.
To which I replied:
Thanks for the response!
Manual says "Set the count to zero (0) to cause the timer to generate trigger events indefinitely.", so the timer still needs a trigger.EVENT_NOTIFY1, to start. If I set "trigger.timer[1].count = 3" I get the exact same results. If an event detector had a latched event I would expect the first model not to ever wait, but instead it waits 1s, just like the second model (with 2 waits).
Yes, the "trigger.CLEAR_ENTER", fixes it, but I want to be able to check for events occurring before entering the wait block (not in this particular example model but in a real model). Now oddly enough a "trigger.CLEAR_ENTER" on the first wait block doesn't fix anything, but one on the second, it does.
It appears to me that the first wait delays the clearance of the event ~0.25 s after it detects it. So unless I add a 0.3 s delay after the first wait, the second wait will be bypassed as it detects the exact same event detected by the first wait.
And I didn't receive any further response (since 2 weeks)...