ObserveScanRate

Asked by Hasham

Need an explanation on how the setting ObserveScanRate works, say if the setting is set to 1 will it be applied when I do a find operation or only region.wait, region.exists etc?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

ObserveScanRate is for observe() only.

for all other explicit (find, wait, exists, ..) and implicit (click, ...) we have the WaitScanRate.

It simply said, how often per second a search is repeated until found or waiting time exceeded.

So specifying 1 means one per second (standard is 3 - means max 3 per second - searching the whole screen means constantly searching, since 0.5 to 1 second per search ;-).
and values like
0.5 means every 2 seconds
0.2 means every 5 seconds

so values 0.3 ands lower leaving the standard waiting time of 3 seconds would mean 1 search only (same as exists(image, 0) )

hope it helps. see docs for more information (doc.sikuli.org).

Revision history for this message
Hasham (shaikhasham) said :
#2

Thanks, is there a way that I can know if it is really scanning for the times that I specify?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

-- no, you just have to believe it ;-)

here is the java code that scans:

    boolean repeat(double timeout) throws Exception {

      int MaxTimePerScan = (int) (1000.0 / Settings.WaitScanRate);
      long begin_t = (new Date()).getTime();
      do {
        long before_find = (new Date()).getTime();
        run(); // the search
        if (ifSuccessful()) {
          return true; // return if found
        } else if (timeout < MaxTimePerScan) {
          return false; // return immediately if not found and short timeout
        }

 long after_find = (new Date()).getTime();
        if (after_find - before_find < MaxTimePerScan) {
          // wait until time give by scan rate is exceeded
          getScreen().getActionRobot().delay((int) (MaxTimePerScan - (after_find - before_find)));
        } else {
          getScreen().getActionRobot().delay(10);
        }
      } while (begin_t + timeout * 1000 > (new Date()).getTime()); // loop until timeout

      return false;
    }

--- But if you want full control:

use exists(image, 0), which searches only once.

def myScanner(img, max, scan):
    maxTime = max # seconds
    scanTime = scan # seconds
    endTime = time.time() + maxTime
    while time.time < maxTime:
        start = time.time()
        if exists(image, 0): return getLastMatch()
        used = time.time - start
        if used < scanTime: wait(scanTime-used)
    return None

usage:
if myScanner("some-image.png", 60, 5): print "found"
else: print "not found"

Can you help with this problem?

Provide an answer of your own, or ask Hasham for more information if necessary.

To post a message you must log in.