Skip to main content

VEX V5 - Driver Control

 

This is the robot-config.h file that tells the code that we have a Brain, Controller and 2 motors named RMotor and LMotor attached to Ports 1, and 2. The true and false indicates if the motor direction should be reversed. The first line of our main code is
#include "robot-config.h" 
this includes the robot-config as part of the program.

 

a custom function called Drive is written:

void Drive(int lspeed, int rspeed, int wt) 
{
    LMotor.spin(forward,lspeed,pct);
    RMotor.spin(forward,rspeed,pct);
    wait(wt);
}

We initialize some global variables:

int lspeed=0;
int rspeed=0;

lspeed and rspeed will be the speed of the two drive motors.

    lspeed=Controller.Axis3.position(pct);
    rspeed=Controller.Axis2.position(pct);

lspeed and rspeed are set by sensing the position of the joysticks on the controller. Here we read Axis3 and Axis2 as a percentage (pct). So pushed full forward is 100%, full backward is -100%. Calling the Drive function :

 Drive(lspeed, rspeed, 10);
Runs the motors and slows the process a little by waiting 10msec for the motors to turn.

 

here is the complete main code:

#include "robot-config.h"

void Drive(int lspeed, int rspeed, int wt) 
{
    LMotor.spin(forward,lspeed,pct);
    RMotor.spin(forward,rspeed,pct);
    wait(wt);
}

int main() {
    int lspeed=0; 
    int rspeed=0;
    while(true)
    {  
    lspeed=Controller.Axis3.position(pct);
    rspeed=Controller.Axis2.position(pct);
    Drive(lspeed, rspeed, 10);
        
    }

}