Vision sensor not detecting when close to camera

My team is trying to use vision sensors to detect blue balls for testing. Unfortunately our robot just stops moving when it is close to the robot. Our vision sensor points down and stops driving forward when the ball is in the center of the image. Here is our code. Our vision sensor detects it when we use the in vision sensor configure but it doesn’t in code.

 while(x == 1) {

    LeftIntake.spin(reverse);
    RightIntake.spin(reverse);
    i = 0;
    Controller1.Screen.clearScreen();
    Controller1.Screen.newLine();
    Vision5.takeSnapshot(Vision5__BLUEBOX);
    if(Vision5.objects[0].exists){
      while(i <= Vision5.objectCount && found == false){
        if(Vision5.objects[i].width > 30 || Vision5.objects[i].height > 30){
          found = true;
          Controller1.Screen.print("found");  
          if(Vision5.objects[i].centerX < 140){
            Drivetrain.setDriveVelocity(10, percent);
            Drivetrain.turn(left);
          }
          else if(Vision5.objects[i].centerX > 160){
            Drivetrain.setDriveVelocity(10, percent);
            Drivetrain.turn(right);
          }
          if(Vision5.objects[i].centerX > 100 && Vision5.objects[i].centerX < 200) {
            Drivetrain.setDriveVelocity(20, percent);
            Drivetrain.drive(forward);
          }
        }
        else{
          Drivetrain.stop();
        }
        Controller1.Screen.newLine();
        Controller1.Screen.print(i);
        i += 1;
      }
    }
    else{
      Drivetrain.stop();
    }
    LeftIntake.stop();
    RightIntake.stop();
    if(BumperA.pressing()){
      x = 3;
      Controller1.Screen.clearScreen();
      Controller1.Screen.newLine();
      Controller1.Screen.print("nextThing");
    }
    found = false;
  }

The ball is about 1.5 ft away from the robot with the vision sensor pointing directly at it.

you can check what the vision sensor is detecting using the dashboard while your program is running. Select the relevant signature for your code.
Usually issues with the vision sensor are due to insufficient light on the object.

vision_1

6 Likes

Just figured it out. We had the wrong vision sensor plugged in (the one on top of our robot point slightly upward) so it was only seeing the balls when they were far away because it was outside of the vision.