How do you code your robot to pick up something after tracking it with the vision sensor

I can drive forward and then track a mobile goal but i need it to stop tracking after the robot is already centered so i can continue to code my auto. After it starts tracking a mobile goal i can’t do anything else in auto Vexcode pro V5.

1 Like

Can you send your code? Make sure to put it in code tags

[Code]
Put your code here
[/Code]

Make sure the lines with [Code] and /Code are empty.

Without looking at your code, you could alter it so if a value is 0 then to move onto the next step of the ai, and once it’s centered to make the value 0. Sure it’s probably not gonna work, but if it does work shabbily, that’s the true way

How do I write it in code tags

  1. Type [code]
  2. Add a new line
  3. Paste your code
  4. Add a new line
  5. Type [/code]
2 Likes

You have text code, right? If not, just put screenshots of the blocks

Yeah and thanks I’ll post it later I don’t have my laptop rn



int main() {
 int centerFOV = 158;
 int offsetX = 25;


   RightDrive.setVelocity(100,pct);
   rightdrive.setVelocity(100,pct);
   LeftDrive.setVelocity(100,pct);
   leftdrive.setVelocity(100,pct);

    LeftDrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
   leftdrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
   RightDrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
   rightdrive.rotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
   
    
   Brain.Screen.clearLine();
   Vision14.takeSnapshot(Vision14__SIG_1);

   if(Vision14.largestObject.exists)
  {
    if(Vision14.largestObject.centerX > centerFOV + offsetX)
    {
      RightDrive.spin(directionType::rev,20,velocityUnits::pct);
      rightdrive.spin(directionType::rev,20,velocityUnits::pct);
      leftdrive.spin(directionType::fwd,20,velocityUnits::pct);
      LeftDrive.spin(directionType::fwd,20,velocityUnits::pct);
    }

    else if(Vision14.largestObject.centerX < centerFOV - offsetX)
    {
      RightDrive.spin(directionType::fwd,20,velocityUnits::pct);
      rightdrive.spin(directionType::fwd,20,velocityUnits::pct);
      leftdrive.spin(directionType::rev,20,velocityUnits::pct);
      LeftDrive.spin(directionType::rev,20,velocityUnits::pct);
    }

    else
    {
      RightDrive.stop(brakeType::hold);
      rightdrive.stop(brakeType::hold);
      leftdrive.stop(brakeType::hold);
      LeftDrive.stop(brakeType::hold);

    }

  }

  


  RightDrive.setVelocity(100,pct);
   rightdrive.setVelocity(100,pct);
   LeftDrive.setVelocity(100,pct);
   leftdrive.setVelocity(100,pct);

    LeftDrive.startRotateFor(vex::directionType::fwd, 500, vex::rotationUnits::deg);
   leftdrive.startRotateFor(vex::directionType::fwd, 500, vex::rotationUnits::deg);
   RightDrive.startRotateFor(vex::directionType::fwd, 500, vex::rotationUnits::deg);
   rightdrive.rotateFor(vex::directionType::fwd, 500, vex::rotationUnits::deg);
   
 
 
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit(); 
}

void pre_auton(void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
}


bool enabledrivePID = true;


int drivePID()
{
  

  while(enabledrivePID)
  {
      int centerFOV = 158;
 int offsetX = 25;

 while(true)
 {
   Brain.Screen.clearLine();
   Vision14.takeSnapshot(Vision14__SIG_1);

   if(Vision14.largestObject.exists)
  {
    if(Vision14.largestObject.centerX > centerFOV + offsetX)
    {
      RightDrive.spin(directionType::rev,20,velocityUnits::pct);
      rightdrive.spin(directionType::rev,20,velocityUnits::pct);
      leftdrive.spin(directionType::fwd,20,velocityUnits::pct);
      LeftDrive.spin(directionType::fwd,20,velocityUnits::pct);
    }

    else if(Vision14.largestObject.centerX < centerFOV - offsetX)
    {
      RightDrive.spin(directionType::fwd,20,velocityUnits::pct);
      rightdrive.spin(directionType::fwd,20,velocityUnits::pct);
      leftdrive.spin(directionType::rev,20,velocityUnits::pct);
      LeftDrive.spin(directionType::rev,20,velocityUnits::pct);
    }

    else
    {
    
      RightDrive.stop(brakeType::hold);
      rightdrive.stop(brakeType::hold);
      leftdrive.stop(brakeType::hold);
      LeftDrive.stop(brakeType::hold);

    }

  }
 }
   

   vex::task::sleep(20);
  }


  return 1;
}


/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void autonomous(void) {
  // ..........................................................................
   vex::task VisionSensor(drivePID);

  leftdrive.setVelocity(50,pct);
  LeftDrive.setVelocity(50,pct);
  rightdrive.setVelocity(50,pct);
  RightDrive.setVelocity(50,pct);
 
  LeftDrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
  leftdrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
  RightDrive.startRotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);
  rightdrive.rotateFor(vex::directionType::rev, 3000, vex::rotationUnits::deg);

  while(true)
  {

  


 enabledrivePID = true;
 wait(1000,msec);

 enabledrivePID = false;

  }

  leftdrive.setVelocity(50,pct);
  LeftDrive.setVelocity(50,pct);
  rightdrive.setVelocity(50,pct);
  RightDrive.setVelocity(50,pct);
 
  LeftDrive.startRotateFor(vex::directionType::rev, 500, vex::rotationUnits::deg);
  leftdrive.startRotateFor(vex::directionType::rev, 500, vex::rotationUnits::deg);
  RightDrive.startRotateFor(vex::directionType::rev, 500, vex::rotationUnits::deg);
  rightdrive.rotateFor(vex::directionType::rev, 500, vex::rotationUnits::deg);



  





  // ..........................................................................
}

Those are the two codes I have been trying to get to work I am not sure if any of those are correct.

yeah but like what line of code tells it to move on to the next step.