Example V5 Code


#1

So ive recently switched to V5 and have been on the struggle bus. A lot of the times it will run fine, and then run something completely different the next run, Do you have to clear values? Can someone show me the code for that?

I was wondering if someone could provide an example or a sample of their own autonomous code. (Im not a mad man im not asking for the whole thing just a taste.)

       FRDrv.startRotateTo(-3.2,rotationUnits::rev,50,velocityUnits::pct); // Slightly Moves Forward
    BLDrv.startRotateTo(-3.2,rotationUnits::rev,50,velocityUnits::pct);
    FLDrv.startRotateTo(3.2,rotationUnits::rev,50,velocityUnits::pct);
    BRDrv.rotateTo(3.2,rotationUnits::rev,50,velocityUnits::pct);
         task::sleep(50);

    FLDrv.stop(brakeType::coast); 
    BLDrv.stop(brakeType::coast); 
      FRDrv.stop(brakeType::coast); 
    BRDrv.stop(brakeType::coast); 
 

This is an example of the drive code im using. Is there a better way to do this?


#2

this is without sensors but it is what we currently use

void autonomous( void ) {
// …
int AutonBase = 100;
int AutonLift = 50;
int AutonFly = 90;
LeftMotorF.spin (directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
vex::task::sleep(1); /////////////////////////////////////////////////how far forward
LeftMotorF.stop(brakeType::brake);
RightMotorF.stop(brakeType::brake);
LeftMotorB.stop(brakeType::brake);
RightMotorB.stop(brakeType::brake);
Flywheel.spin(directionType::fwd, AutonFly, velocityUnits::pct);
vex::task::sleep(1); /////////////////////////////////////////////////how long to spin up plus shoot
LeftMotorF.spin (directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
Flywheel.stop(brakeType::coast);
vex::task::sleep(1);/////////////////////////////////////////////////////// hit flag
LeftMotorF.spin (directionType::rev, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::rev, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::rev, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::rev, AutonBase, velocityUnits::rpm);
vex::task::sleep(1);//////////////////////////////////////////////////////// turn 90d
LeftMotorF.spin (directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::rev, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::rev, AutonBase, velocityUnits::rpm);
vex::task::sleep(1);/////////////////////////////////////////////////////////
LeftMotorF.spin (directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
vex::task::sleep(1);
LeftMotorF.spin (directionType::rev, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::rev, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
vex::task::sleep(1);
LeftMotorF.spin (directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorF.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
LeftMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
RightMotorB.spin(directionType::fwd, AutonBase, velocityUnits::rpm);
vex::task::sleep(100000);

// …

}


#3

rotateTo rotates to an absolute position no matter how far, with zero being the position that the motor initialized at (or was last zeroed at). rotateFor rotates for the specified amount from the current position.

You probably want rotateFor in that snippet for a small forward move.