Help with the 2 "advance and rewind" functions, how do I make them execute at a certain time in the autonomous period?

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// llantas_derechas     motor_group   15, 16          
// derecha              motor         20              
// llantas_izquierdas   motor_group   12, 13          
// izquierda            motor         11              
// intaker              motor         2               
// elevacion            digital_out   A               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;


// 12.667061 pulgadas de circunferencia o revolucion
//(36/60) = 0.60 por cada revolucion de la llanta
//el avanze del motor por cada revolucion del motor es igual
//al aumento de revoluciones multiplicado por la circunferencia de las ruedas
// "valor aun indefinido" avanze del robot en pulgadas por cada revolucion del motot



//loadbar= 35.6 pulgadas de longitud

float loadbar= 4.684064704;
// la distancia "la mitad de la llanta" de las llantas por π entre 360
// float grado = 0.087266462;

float grado=0.01157/2;
// por cada grado seria un total de 0.005785

float tatami= 3.5525209834;


void avanzar( float loadbar, int speed){

  llantas_derechas.spinFor(loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  derecha.spinFor(loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  llantas_izquierdas.spinFor(loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  izquierda.spinFor(loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
}

void retroceder ( float loadbar, int speed){

  llantas_derechas.spinFor(-loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  derecha.spinFor(-loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  llantas_izquierdas.spinFor(-loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
  izquierda.spinFor(-loadbar,rotationUnits::rev,speed,velocityUnits::pct, false);
}


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, ...
}



void autonomous(void) {
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
}



void usercontrol(void) {
  // User control code here, inside the loop
  while (1) {



    //-------------chasis

    llantas_derechas.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct),velocityUnits::pct);
    llantas_derechas.setStopping(brake);
    derecha.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct),velocityUnits::pct);
    derecha.setStopping(brake);

    
    llantas_izquierdas.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct),velocityUnits::pct);
    llantas_izquierdas.setStopping(brake);
    izquierda.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct),velocityUnits::pct);
    izquierda.setStopping(brake);


    //----------intaker

     if (Controller1.ButtonR2.pressing()==1){

       intaker.spin(fwd,600,rpm);
     }

     else if(Controller1.ButtonR1.pressing()==1){
       intaker.spin(reverse,600,rpm);
     }

     else{
       intaker.stop(hold);
     }
     
     
     //--------piston elevacion

     
     if (Controller1.ButtonL1.pressing()==1){
       elevacion.set(true);
       }

     else if(Controller1.ButtonL2.pressing()==1){
       elevacion.set(false);
       }









    wait(20, msec); // Sleep the task for a short amount of time to
                    // prevent wasted resources.
  }
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

edit : code tags added by mods, please remember to use them.

Please specify. But if I understand fully the “advance and rewind” are movements of the robot. If so you can either implement a system to tell weather or not you have finished driving there, or you can time how long the movements take and then put wait(example time, msec); this would wait until how it should take to finish, and then run the other command.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.