Vision sensor exists code

hi i need help with the exists function in the vision sensor class.

im talking about this:
image

when i use the function theres an error:
image

im stupid, can you help me?

You need to add an object to the code. If you are looking for the largest object it would be

VS.largestObject.exists()

exists() is for vision objects, not the sensor itself. You probably want to do something like
VS.largestObject.exists()

This isn’t necessarily super important, but you shouldn’t use a comparison to false. Just use something like

if (!VS.largestObject.exists()) {
code
}

yeah i got this to work

but now i have another problem
the vision sensor wont stop when its in front of the object and always turns left no matter where the object is.

here is the code

while(1){
        // VS.takeSnapshot(VS__RED_HG);
        // if (VS.objectCount == 0){
        //   VS.takeSnapshot(VS__BLUE_HG);
        // }
        // //find if hg is red or blue and take a snapshot
        VS.takeSnapshot(VS__RED_HG);

        if (VS.largestObject.centerX > centerFOV + offsetX){ //object is off to the right of the vision sensor
          RDrive.spin(reverse, 20, pct);
          LDrive.spin(forward, 20, pct);
        }
        else if (VS.largestObject.centerX < centerFOV - offsetX){ //object is off to the left of the vision sensor
          RDrive.spin(forward, 20, pct);
          LDrive.spin(reverse, 20, pct);
        }

        else{ //when bot is aligned, rumble and stop
          Chassis.stop();
          Chassis.setStopping(coast);
          Controller1.rumble("-");
        }

        if (autoAim==false){
          break;
        }
      }
1 Like

I recommend looking into using a PID. Here’s a good guide:
introduction_to_pid_controllers_ed2.pdf (400.2 KB)

hi everyone
I got it to work, turns out the vision sensor I was using was bad

thanks for ur help though!