|
repeating Anonymous |
11 year
|
Hi All
Can anyone tell me what is wrong with this simple script? The idea is that 'resetit' will slowly flash, but the events don't sequence.
if GetVariable("repeatK") = 0 then
SetVariable "resetK", 0
SetTimedVariable "resetK", 1, 2000
SetTimedVariable "repeatK", 1, 3000
end if
if GetVariable("repeatK") = 1 then
SetTimedVariable "repeatK", 0, 4000
end if
Alternatively, how can I;
On power up of RR and my modules, I need RR to pulse a "R" about every 5 seconds until a "r" is received back.
Roland
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
Roland,
Whenever a SetTimedVariable function is called it will overwrite the previous timing. So if you call that on repeatK to set 2 seconds later and then in the next second you call the same function it will reset that timer to the next 2 seconds ... so in essence you never let the timer trigger because you keep setting it again and again to 2 seconds in the future.
The way you get around this is to set it to a dummy value. For example
if GetVariable("repeatK") = 0 then
SetTimedVariable "repeatK", 0, 5000
SetVariable "repeatK", 1 '!!! this prevents this if from executing again until 5 seconds have passed!!!
end if
If you need more complicated patterns, use a state variable that indicates what to set next.
If this is too tricky in code, you can also try the State Machine module with its Timed Transition to change variables after X seconds or based on other triggers. Perhaps that layout is easier to understand than in code?
http://www.roborealm.com/help/State_Machine.php
STeven.
|
|
|
Anonymous |
11 year
|
Hi Steve
What I ended up doing was to use a counter, and if x > 50, say, then a variable is set.
A few other questions;
I have a lot of variables to watch, and the 'variable watch' window is very wide. However, if you make it narrow, you lose the vertical scroll. I just checked and notepad, for example, keeps the scroll bars irrespective of size. Is that amendable?
How can I perform a complete reset of RR from within RR? I can always clear all the variables while I'm working, but I want RR to reboot with a serial command in case the hardware goes out of sync with the RR program.
Is there any watchdog ability to reboot RR in case of lockup?
To ease editing, I am using five 'load file' VB scripts. Is there any drawback to this? I sometimes find that a serial write will just not occur, and have to put the condition into a RR 'if- then- set- variable' module.
Roland
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
Roland,
We reduced the size of the watch variables a bit to allow for more dense viewing but we are limited by the row of buttons at the bottom. That defines the minimum width of this window. If you find you are running out of room, perhaps you can use a secondary screen/external monitor?
There is currently no way to restart or reboot RR. Ideally if this happens we need to fix the problem. Most likely you are getting hung up on some communication timeout which is making it appear like the application has hung ... when in fact, its just waiting for some hardware device to respond.
To help reduce this, we've added a timeout parameter to the serial module. Its default is 5 seconds which is what you have been currently using. I suggest trying something below 1 second (perhaps 250 ms) and see if that helps to reduce the apparent 'hang' in the application.
There isn't a watchdog timer that restarts RR. Its not recommended to just restart just because you think something is going wrong. Best to understand and fix the problem otherwise you'll never be done.
There is no drawback on using load file VB scripts. When executed, it looks the same to the module. The load only happens when the file changes too to reduce any disk activity and this also is only checked at most once a second (its unlikely you will be editing things quicker than once a second).
STeven.
|
|