V5 text competition template

Drivetrain does not appear to work in driver control mode. Is this intentional or am I missing something.

Attach the project to this topic and we can have a look.

5 Likes

I’m not sure how to send you the code. Everything that I try to attach give me a message that the file extension is not allowed, i.e. it allows V5 blocks but not .cpp - suggestions?

copy and paste the code

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       Competition drive                                         */
/*    Author:       Joseph                                                    */
/*    Created:      10/23/2019                                                */
/*    Description:  Drive for competition                                     */
/*                                                                            */
/*----------------------------------------------------------------------------*/
// Robot Configuration: 
// [Smart Port]    [Name]        [Type]           [Description]       [Reversed]
// Motor Port 3    ldrive       V5 Smart Motor    Left side motor     false
// Motor Port 4    Rrdrive      V5 Smart Motor    Right side motor    true
// Motor Port 8    trayMotor    V5 Smart Motor    tray motor          false
// Motor Port 1    larm1        V5 Smart Motor    Arm motor           false
// Motor Port 2    larm2        V5 Smart Motor    Arm motor           true
// Motor Port 9    rarm1        V5 Smart Motor    Arm motor           true
// Motor Port 10   rarm2        V5 Smart Motor    Arm motor           false
// Motor Port 12   strafe       V5 Smart Motor    strafe motor        false
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Drivetrain           drivetrain    1, 11           
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// define your global instances of motors and other devices here
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;
vex::controller  Controller1;
// A global instance of vex::competition
vex::competition Competition;
// define your global instances of motors and other devices here
vex::motor ldrive           = vex::motor( vex::PORT3 );
vex::motor rdrive           = vex::motor( vex::PORT13, true);
vex::motor tray             = vex::motor( vex::PORT9 );
vex::motor rntk             = vex::motor( vex::PORT14, true);
vex::motor rarm             = vex::motor( vex::PORT17 );
vex::motor lntk             = vex::motor( vex::PORT1);
vex::motor larm             = vex::motor( vex::PORT10, true );
vex::motor strafe           = vex::motor( vex::PORT2 );

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the cortex has been powered on and    */ 
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton( void ) {
  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
  
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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 ) {
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
   while(1){
   // Wait 2 seconds or 2000 milliseconds before starting the program.
    vex::task::sleep( 2000 );
    // Print to the screen that the program has started.
    Brain.Screen.print("User Program has Started.");
    // while was here, i changed it 
    // Set the velocity of the left and right motors to 50% power. 
    // This command will not make the motor spin. 
    Brain.Screen.newLine();//Move the cursor to a new line on the screen.
    Brain.Screen.print( "Drive activated" );
    ldrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
    rdrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
   // forevery 28.64789115671122 degrees 1 inch
    
    // Spin the right and left motor in the forward direction.
    // The motors will spin at 50% power because you said to.
     vex::task::sleep( 2000 );
    
    // Wait 3 second or 3000 milliseconds.
    vex::task::sleep( 2000 );
    
    // Stop both motors.
    ldrive.stop();
    rdrive.stop();
    
    // Print to the brain's screen that the program has ended.
    Brain.Screen.newLine();//Move the cursor to a new line on the screen.
    Brain.Screen.print( "User Program has Ended. Did it work?" );

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

void usercontrol( void ) {
  // User control code here, inside the loop
  while (1) {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo 
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to 
    // update your motors, etc.
    // ........................................................................
 
    vex::task::sleep(20); //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 );
    ldrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
    rdrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
    Competition.drivercontrol( usercontrol );
    
    //Run the pre-autonomous function. 
    pre_auton();
       
    //Prevent main from exiting with an infinite loop.                        
   
       while(1) {
      //Drive Control
      //Set the left and right motor to spin forward using the controller's Axis positions as the velocity value.
      ldrive.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
      rdrive.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
      // Arm Control
      // If button up is pressed...
      if(Controller1.ButtonDown.pressing()) { 
        //...Spin the arm motor forward.
        larm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
        rarm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
      }
      // else If the down button is pressed...
      else 
      if(Controller1.ButtonUp.pressing()) { 
        //...Spin the arm motor backward.
        rarm.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
        larm.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
      }
      // else If neither up or down button is pressed...
      else { 
        //...Stop the arm motor.  
        rarm.stop(vex::brakeType::hold);
        larm.stop(vex::brakeType::hold);
      }
    
     if(Controller1.ButtonX.pressing()) { 
        //...Spin the arm motor forward.
        lntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
        rntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
      }
      // else If the down button is pressed...
      else 
      if(Controller1.ButtonB.pressing()) { 
        //...Spin the arm motor backward.
        lntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
        rntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
      }
      // else If neither up or down button is pressed...
      else { 
        //...Stop the arm motor.  
        rntk.stop(vex::brakeType::hold);
        lntk.stop(vex::brakeType::hold);
      }
      // tray Control
      // If the A button is pressed...
      if(Controller1.ButtonA.pressing()) { 
        //...Close tray.
        tray.spin(vex::directionType::fwd, 30, vex::velocityUnits::pct);
      }
      // else If the Y button is pressed...
      else 
      if(Controller1.ButtonY.pressing()) { 
        //...Open tray.
        tray.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
      }
      // else If neither the A or Y button is pressed...
      else {
        //...Stop the tray motor.
        tray.stop(vex::brakeType::brake);        
      }
    if(Controller1.ButtonR2.pressing()) { 
        //...Spin the strafe motor left.
        strafe.spin(vex::directionType::fwd,100, vex::velocityUnits::pct);
      }
      // else If the Y button is pressed...
      else 
      if(Controller1.ButtonL2.pressing()) { 
        //...Spin the strafe motor right.
        strafe.spin(vex::directionType::rev,100, vex::velocityUnits::pct);
      }
      // else If neither button is pressed...
      else {
        //...Stop the strafe motor.
        strafe.stop(vex::brakeType::brake);        
      }

    // Sleep the task for a short amount of time to prevent wasted resources.
    vex::task::sleep(20);
   
    }
    
    }

It looks like your code to drive the robot with controller inputs is inside the main function.

Your usercontrol function is where the controller inputs should be, but currently it is in a recurring loop of sleeping for 20ms.

Hope this helps.

2 Likes

Total frustration. At the last competition we were the only team using VEXcode V5 text. Everyone else was using VEX Coding Studio. Our robot did not move in autonomous, but everyone else did. Have we made a mistake by going to VEXcode V5 text?

We can find no code that is known to actually work in autonomous mode while using the competition template. All of the examples show using drivetrain for autonomous movement, but drivetrain and the competition template appear to be mutually exclusive. We must be missing something basic.

The following code compiles without errors but when executed the messages to the brain’s display are correct, but the robot never moves. The driver control section works fine. We are at a loss as to
what to try. Our next competition is Jan 18th and at this point we have zip! Code to follow.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       Competition drive                                         */
/*    Author:       Joseph                                                    */
/*    Created:      10/23/2019                                                */
/*    Description:  Drive for competition                                     */
/*                                                                            */
/*----------------------------------------------------------------------------*/
// Robot Configuration: 
// [Smart Port]    [Name]        [Type]           [Description]       [Reversed]
// Motor Port 3    ldrive       V5 Smart Motor    Left side motor     false
// Motor Port 4    Rrdrive      V5 Smart Motor    Right side motor    true
// Motor Port 8    trayMotor    V5 Smart Motor    tray motor          false
// Motor Port 1    larm1        V5 Smart Motor    Arm motor           false
// Motor Port 2    larm2        V5 Smart Motor    Arm motor           true
// Motor Port 9    rarm1        V5 Smart Motor    Arm motor           true
// Motor Port 10   rarm2        V5 Smart Motor    Arm motor           false
// Motor Port 12   strafe       V5 Smart Motor    strafe motor        false
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Drivetrain           drivetrain    1, 11           
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// define your global instances of motors and other devices here
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;
vex::controller  Controller1;
// A global instance of vex::competition
vex::competition Competition;
// define your global instances of motors and other devices here
vex::motor ldrive           = vex::motor( vex::PORT3 );
vex::motor rdrive           = vex::motor( vex::PORT13, true);
vex::motor tray             = vex::motor( vex::PORT9 );
vex::motor rntk             = vex::motor( vex::PORT14, true);
vex::motor rarm             = vex::motor( vex::PORT17 );
vex::motor lntk             = vex::motor( vex::PORT1);
vex::motor larm             = vex::motor( vex::PORT10, true );
vex::motor strafe           = vex::motor( vex::PORT2 );

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the cortex has been powered on and    */ 
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton( void ) 
{
  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
  Brain.Screen.print("Pre-Autonomous has started");
  Brain.Screen.newLine(); 
  Brain.Screen.print("Position robot for Blue Left");
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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 ) 
{
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................

  // Wait a half second or 500 milliseconds before starting the program
  vex::task::sleep( 500 );

  // Print to the screen that the program has started
  Brain.Screen.newLine();  
  Brain.Screen.print("Autonomous mode has started");
  
  // Set the velocity of the left and right motors to 50% power 
  // This command will not make the motor spin
  ldrive.setVelocity(50, ::percent);
  rdrive.setVelocity(50, ::percent);

  //Move the cursor to a new line on the screen
  Brain.Screen.newLine();    
  Brain.Screen.print("Drive activated");
    
  // Move 1 inch for every 28.6478 degrees
  float distance = 12; 
  float rotationDegrees = 28.6478*distance;

  // Spin the right and left motor in the forward direction
  // The motors will spin at 50% power because you said to
  ldrive.startRotateFor(directionType ::fwd, rotationDegrees, rotationUnits::deg);
  rdrive.startRotateFor(directionType ::fwd, rotationDegrees, rotationUnits::deg);
     
  // Wait 2 seconds or 2000 milliseconds
  vex::task::sleep( 2000 );
    
  // Stop both motors.
  ldrive.stop();
  rdrive.stop();
    
  //Move the cursor to a new line on the screen.
  Brain.Screen.newLine();
  // Print to the brain's screen that the program has ended.
  Brain.Screen.print( "Autonomous has ended. Did it work?" );
  
}

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

void usercontrol( void ) {
  // User control code here, inside the loop
  while (1) {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo 
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to 
    // update your motors, etc.
    // ........................................................................
 
    vex::task::sleep(20); //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 );
    //ldrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
    //rdrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
    Competition.drivercontrol( usercontrol );
    
    //Run the pre-autonomous function. 
    pre_auton();
       
    //Prevent main from exiting with an infinite loop.                        
   
    while(1) 
    {
      //Drive Control
      //Set the left and right motor to spin forward using the controller's Axis positions as the velocity value.
      ldrive.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
      rdrive.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
      // Arm Control
      // If button up is pressed...
      if(Controller1.ButtonDown.pressing()) 
      { 
        //...Spin the arm motor forward.
        larm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
        rarm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
      }
      // else If the down button is pressed...
      else 
      if(Controller1.ButtonUp.pressing()) 
      { 
        //...Spin the arm motor backward.
        rarm.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
        larm.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
      }
      // else If neither up or down button is pressed...
      else 
      { 
        //...Stop the arm motor.  
        rarm.stop(vex::brakeType::hold);
        larm.stop(vex::brakeType::hold);
      }
      if(Controller1.ButtonX.pressing()) 
      { 
        //...Spin the arm motor forward.
        lntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
        rntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
      }
      // else If the down button is pressed...
      else 
      if(Controller1.ButtonB.pressing()) 
      { 
        //...Spin the arm motor backward.
        lntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
        rntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
      }
      // else If neither up or down button is pressed...
      else 
      { 
        //...Stop the arm motor.  
        rntk.stop(vex::brakeType::hold);
        lntk.stop(vex::brakeType::hold);
      }
      // tray Control
      // If the A button is pressed...
      if(Controller1.ButtonA.pressing()) 
      { 
        //...Close tray.
        tray.spin(vex::directionType::fwd, 30, vex::velocityUnits::pct);
      }
      // else If the Y button is pressed...
      else 
      if(Controller1.ButtonY.pressing()) 
      { 
        //...Open tray.
        tray.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
      }
      // else If neither the A or Y button is pressed...
      else 
      {
        //...Stop the tray motor.
        tray.stop(vex::brakeType::brake);        
      }
      if(Controller1.ButtonR2.pressing()) 
      { 
        //...Spin the strafe motor left.
        strafe.spin(vex::directionType::fwd,100, vex::velocityUnits::pct);
      }
      // else If the Y button is pressed...
      else 
      if(Controller1.ButtonL2.pressing()) 
      { 
        //...Spin the strafe motor right.
        strafe.spin(vex::directionType::rev,100, vex::velocityUnits::pct);
      }
      // else If neither button is pressed...
      else 
      {
        //...Stop the strafe motor.
        strafe.stop(vex::brakeType::brake);        
      }

    // Sleep the task for a short amount of time to prevent wasted resources.
    vex::task::sleep(20);
   
  }
    
}

No, VEXcode has a far more evolved SDK than VCS (which means, it’s the same underlying functionality that has had another 15 months of development.

The issue with your code is structure, most (but not all) of the code in the main function should be in usercontrol as main will continue to run, and therefore interfere with any code in autonomous, during all phases of the match.

6 Likes

Have I interpreted what you said correctly? (see code below) Can’t test until I get back to the lab.

Also, we are having a lot of failures with V5 batteries, motors and ports on the brain. One new battery is completely dead, i.e. no lights under any condition. We are not overcharging the batteries because we made a timer that shuts off the charger after 90 minutes. The user forums indicate that these are fairly common problems. Any suggestions?

/----------------------------------------------------------------------------/
/* /
/
Module: Competition drive /
/
Author: Joseph /
/
Created: 10/23/2019 /
/
Description: Drive for competition /
/
/
/
----------------------------------------------------------------------------*/
// Robot Configuration:
// [Smart Port] [Name] [Type] [Description] [Reversed]
// Motor Port 3 ldrive V5 Smart Motor Left side motor false
// Motor Port 4 Rrdrive V5 Smart Motor Right side motor true
// Motor Port 8 trayMotor V5 Smart Motor tray motor false
// Motor Port 1 larm1 V5 Smart Motor Arm motor false
// Motor Port 2 larm2 V5 Smart Motor Arm motor true
// Motor Port 9 rarm1 V5 Smart Motor Arm motor true
// Motor Port 10 rarm2 V5 Smart Motor Arm motor false
// Motor Port 12 strafe V5 Smart Motor strafe motor false
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Drivetrain drivetrain 1, 11
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”

using namespace vex;

// define your global instances of motors and other devices here
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
vex::controller Controller1;
// A global instance of vex::competition
vex::competition Competition;
// define your global instances of motors and other devices here
vex::motor ldrive = vex::motor( vex::PORT3 );
vex::motor rdrive = vex::motor( vex::PORT13, true);
vex::motor tray = vex::motor( vex::PORT9 );
vex::motor rntk = vex::motor( vex::PORT14, true);
vex::motor rarm = vex::motor( vex::PORT17 );
vex::motor lntk = vex::motor( vex::PORT1);
vex::motor larm = vex::motor( vex::PORT10, true );
vex::motor strafe = vex::motor( vex::PORT2 );

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the cortex has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton( void )
{
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
Brain.Screen.print(“Pre-Autonomous has started”);
Brain.Screen.newLine();
Brain.Screen.print(“Position robot for Blue Left”);
}

/---------------------------------------------------------------------------/
/* /
/
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 )
{
// …
// Insert autonomous user code here.
// …

// Wait a half second or 500 milliseconds before starting the program
vex::task::sleep( 500 );

// Print to the screen that the program has started
Brain.Screen.newLine();
Brain.Screen.print(“Autonomous mode has started”);

// Set the velocity of the left and right motors to 50% power
// This command will not make the motor spin
ldrive.setVelocity(50, ::percent);
rdrive.setVelocity(50, ::percent);

//Move the cursor to a new line on the screen
Brain.Screen.newLine();
Brain.Screen.print(“Drive activated”);

// Move 1 inch for every 28.6478 degrees
float distance = 12;
float rotationDegrees = 28.6478*distance;

// Spin the right and left motor in the forward direction
// The motors will spin at 50% power because you said to
ldrive.startRotateFor(directionType ::fwd, rotationDegrees, rotationUnits::deg);
rdrive.startRotateFor(directionType ::fwd, rotationDegrees, rotationUnits::deg);

// Wait 2 seconds or 2000 milliseconds
vex::task::sleep( 2000 );

// Stop both motors.
ldrive.stop();
rdrive.stop();

//Move the cursor to a new line on the screen.
Brain.Screen.newLine();
// Print to the brain’s screen that the program has ended.
Brain.Screen.print( “Autonomous has ended. Did it work?” );

}

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

void usercontrol( void ) {
// User control code here, inside the loop
while (1)
{
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.

// ........................................................................
// Insert user code here. This is where you use the joystick values to 
// update your motors, etc.
// ........................................................................
 
  //Drive Control
  //Set the left and right motor to spin forward using the controller's Axis positions as the velocity value.
  ldrive.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
  rdrive.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
 
  // Arm Control
  // If button up is pressed...
  if(Controller1.ButtonDown.pressing()) 
  { 
    //...Spin the arm motor forward.
    larm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
    rarm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
  }
  // else If the down button is pressed...
  else 
  if(Controller1.ButtonUp.pressing()) 
  { 
    //...Spin the arm motor backward.
    rarm.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
    larm.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
  }
  // else If neither up or down button is pressed...
  else 
  { 
    //...Stop the arm motor.  
    rarm.stop(vex::brakeType::hold);
    larm.stop(vex::brakeType::hold);
  }
  if(Controller1.ButtonX.pressing()) 
  { 
    //...Spin the arm motor forward.
    lntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
    rntk.spin(vex::directionType::fwd, 10000, vex::velocityUnits::pct);
  }
  // else If the down button is pressed...
  else 
  if(Controller1.ButtonB.pressing()) 
  { 
    //...Spin the arm motor backward.
    lntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
    rntk.spin(vex::directionType::rev, 50, vex::velocityUnits::pct);
  }
  // else If neither up or down button is pressed...
  else 
  { 
    //...Stop the arm motor.  
    rntk.stop(vex::brakeType::hold);
    lntk.stop(vex::brakeType::hold);
  }

  // tray Control
  // If the A button is pressed...
  if(Controller1.ButtonA.pressing()) 
  { 
    //...Close tray.
    tray.spin(vex::directionType::fwd, 30, vex::velocityUnits::pct);
  }
  // else If the Y button is pressed...
  else 
  if(Controller1.ButtonY.pressing()) 
  { 
    //...Open tray.
    tray.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
  }
  // else If neither the A or Y button is pressed...
  else 
  {
    //...Stop the tray motor.
    tray.stop(vex::brakeType::brake);        
  }

  if(Controller1.ButtonR2.pressing()) 
  { 
    //...Spin the strafe motor left.
    strafe.spin(vex::directionType::fwd,100, vex::velocityUnits::pct);
  }
  // else If the Y button is pressed...
  else 
  if(Controller1.ButtonL2.pressing()) 
  { 
    //...Spin the strafe motor right.
    strafe.spin(vex::directionType::rev,100, vex::velocityUnits::pct);
  }
  // else If neither button is pressed...
  else 
  {
    //...Stop the strafe motor.
    strafe.stop(vex::brakeType::brake);        
  }

   vex::task::sleep(20); //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 );
//ldrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
//rdrive.startRotateFor(vex::directionType ::fwd, 343.7746938853464, vex::rotationUnits::deg);
Competition.drivercontrol( usercontrol );

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

autonomous();

usercontrol();

//Prevent main from exiting with an infinite loop.

while(1)
{
// Sleep the task for a short amount of time to prevent wasted resources.
vex::task::sleep(20);

}

}

Looks like you made the correct revision.

The rotateFor type commands are affected by the gear cartridge installed (for reasons I hope are obvious.) They probably default to counting rotations for the green / 200 rpm / ratio18_1 cartridges, which you are likely using… but it is worth defining:

motor driveLeft  (PORT1, ratio18_1, false);

red are ratio6_1, blue ratio 36_1

Might also revisit that 10000% intake velocity.

3 Likes

There really should be no need to do that. The original firmware release in Aug 2018 had some issues, but after the Oct 2018 update these problems were solved. I often leave batteries on charge for many days.

5 Likes