What should i do if my vex vision sensor causes my driver input to register late

when my vision sensor sees the blue ball I set up for it to look for when it sees it spits it out of the robot but the problem is that the robot freezes and I cant do anything then a couple of seconds later all the commands that I did in the time it was still it dose them at this time

my code:

Vision5.takeSnapshot(Vision5__B_BALL);
  if ( Vision5.largestObject.exists  ) {
    up.spin(reverse);
    up2.spin(forward);
    wait( .75,seconds);
    Vision5notseeinganydata = false;
  } else if (!Vision5notseeinganydata) {
    up.stop();
    up2.stop();
    Vision5notseeinganydata = true;
  }

I believe this is because you’re waiting 0.75 seconds; doing this pauses the entire driver control function until the code has waited for that duration.

6 Likes

I will check

//20 ah

1 Like

If you dont have any control code inside the loop that runs when the vision sensor is triggered, then you won’t be able to control your robot.

The better solution here is to remove the vision sensor loop from the main driver task. Starting another task to constantly check the vision senor would be the better option. That way you can still have delays in that loop. Putting driver control code inside the loop would not remove the problem of the wait command inside of the loop.

3 Likes

did not work :confused:

Huh? He just told ypu the problem, not a solution. Try what @Cadaver_42 said.

1 Like

You’re right that what I’m doing rn…

For our team, we still use a wait command but ours is only 20 milliseconds and this seems to work well. We also draw a rectangle on the screen of what the sensor sees and this helps give us a visual.

2 Likes

thats a great idea!

//

I use Vex V5 Text, but this code may give you an idea of what we use:
Brain.Screen.clearScreen();
Brain.Screen.setOrigin(1, 1);
Brain.Screen.drawRectangle(0, 0, 316, 212);

Vision1.takeSnapshot(GREN);
if(Vision1.largestObject.exists){
Brain.Screen.drawRectangle(Vision1.largestObject.originX, Vision1.largestObject.originY, Vision1.largestObject.width, Vision1.largestObject.height, color::green);

task::sleep(20);

If the 20 milliseconds is reduced, the refresh rate of the screen can’t keep up and you won’t see the rectangle.

2 Likes