Auto adjusting vision sensor

I am trying to figure out what I need to use to code the vision sensor to auto aline with the high goal. I am using blocks coding. and have already configured both high goals.

The best way to do it is to find the center of the object and then use the difference between that value and the center of the vision sensor (158 iirc) to make an auto aligner.

OK so I am trying to do the same thing as @15352A , and have had a few problems with the code. To explain, I pretty much have a button.pressed command, which goes to a void as follows:

Vision1.takeSnapshot(REDGOAL);

  if(Vision1.largestObject.centerX > 158){

    Drivetrain.turnFor(right,((Vision1.largestObject.centerX-158))/5.26666666666666,degrees);

    }

  if(Vision1.largestObject.centerX < 157){

    Drivetrain.turnFor(left,((157-Vision1.largestObject.centerX))/5.26666666666666,degrees);

    }

else{

the long lines of code convert the vision sensor pixels into degrees, and last year, this code was really effective. This year, however, it just turns too far, or in the wrong direction. I initially thought it was an issue of the vision sensor just “not seeing” , but after checking on the brain, I have proven that it is. Further, it is not an issue with the driver control conflicting with the vision sensor code, because I have a command that disables driver control when the vision code is in operation. I would have a Controller.playRumble() in the else statement, but for simplicity’s sake I have left it out. Any help would be appreciated.

Can anyone help me with this issue? I do not know what to do about it, and it does not appear like anyone has bothered to try to fix it. Maybe @jpearman would know.

Here are some ways to figure out why code is not working

  1. Print the vision sensor values to the screen and check if it is working.
  2. Check if you’re drivebase is turning correctly.
  3. Align the robot to the goal, turn a set amount of degrees then see if the divide by 5.26666666 gives you the right angle.
1 Like