Questions about V5 (Arcade control and autonomous )

My team and I are using arcade control and I want the motors to hold when they are not being moved, I have something in the code right now that I think would do that but it doesn’t work. Am I using “else” incorrectly?

Also where in my code should I put my autonomous, outside my “while(1)” or outside my “int main()”, and how do I identify this as a autonomous instead of part of my main code?

    //Drive Control
    LFDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value())/2, vex::velocityUnits::pct);
    RFDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() - Controller1.Axis3.value())/2, vex::velocityUnits::pct);
    LBDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value())/2, vex::velocityUnits::pct);
    RBDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() - Controller1.Axis3.value())/2, vex::velocityUnits::pct);
   
    else {  
        LFDrive.stop(brakeType::hold);
        RFDrive.stop(brakeType::hold);
        LBDrive.stop(brakeType::hold);    
        RBDrive.stop(brakeType::hold);   
    }

You need an if statement before your else for it to work properly

And you would use


vex::competition

to identify and have the auton and driver control work properly

You put the auton code in the autonomous function and the driver control code in the driverControl function

This should work


#include "robot-config.h"

vex::motor LFDrive(1);
vex::motor RFDrive(2);
vex::motor LBDrive(3);
vex::motor RBDrive(4);

vex::competition comp;
vex::controller Controller1;

void preAuton(){
    
}

void autonomous(){
   //Auton code
}

void driverControl(){
    while(true){
        if(Controller1.Axis4.value() == 0 && Controller1.Axis3.value() == 0){
            LFDrive.stop(vex::brakeType::hold);
            LBDrive.stop(vex::brakeType::hold);
            RFDrive.stop(vex::brakeType::hold);
            RBDrive.stop(vex::brakeType::hold);
        }
        else{
            LFDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value())/2, vex::velocityUnits::pct);
            RFDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() - Controller1.Axis3.value())/2, vex::velocityUnits::pct);
            LBDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() + Controller1.Axis3.value())/2, vex::velocityUnits::pct);
            RBDrive.spin(vex::directionType::fwd, (Controller1.Axis4.value() - Controller1.Axis3.value())/2, vex::velocityUnits::pct);
        }
    }
}

int main(){
    preAuton();
    comp.autonomous(autonomous);
    comp.drivercontrol(driverControl);
    while(true){ vex::task::sleep(100); }
    return 0;
}

Thanks for all the help, it works great!