Vision Sensor Snapshot Errors

consider this senario:

int visionDetect () {

  while (1) {

    Vision1.takeSnapshot(2);
    Vision1.takeSnapshot(3);

    Controller1.Screen.ClearLine();
    Controller1.Screen.Print(Vision1.largestObject.exists);

    task::sleep(10);

  }

return 1;

}

The program can detect signature 3, but it does not detect signature 2. I have tried going onto the brain and testing whether it sees that signature at all and it does, it just does not see it when the program is running. I have also tried going into the vision configuration window and playing with the signature values but it likewise did not solve my problem. The only thing I can think of is that it is not taking a data sample as it should be. Has anyone else had this problem and why is this happening?

you never use any of the results from the first call to takeSnapshot. Think of takeSnapshot as a filter, after calling it largestObject etc. are set to the result of the takeSnapshot filter, so in the code above, you are effectively only ever looking for signature 3.

2 Likes

@jpearman
Ok, just for clarification, are you saying that you can’t take two snapshots because the second data sample will overwrite the first?

No. Strictly speaking, you are taking many snapshots, twice each time thru the loop. Your program, as written, simply does nothing with the first snapshot. You could:

If your goal is to find the largestObject of either Snapshot 2 or 3 (but not 1 - and assuming all 3 snapshot types could be detected at the same time), you’ll need to implement that logic yourself.

1 Like

Ok, that makes a lot more sense and yes, I will be able to implement that into my code I just needed to know what was going on. Thank you!

One technique when dealing with loops is to do “loop unrolling”. So where one might have a loop:

  int i = 0;
  while (i < 2) {
    doSomething();
    doSomethingElse();
    i = i + 1;
    task::sleep(10);
  }

You could think about it as though it really were:

  doSomething();
  doSomethingElse();
  task::sleep(10);
  doSomething();
  doSomethingElse();
  task::sleep(10);
1 Like