VEX Example Program with Controller - C++ - Split Arcade Control

Get more with VEXcode
We recommend you transition to our new software. VEXcode has both block-based and text-based options, that work on Chromebooks, iPads, Android tablets, Windows and Macs. Visit code.vex.com for more details on how to download VEXcode.
VEX Coding studio has been discontinued and is no longer available for download. Already downloaded? The program will continue to function but will no longer be supported.
Users who transition to VEXcode can migrate their C++/C++ Pro projects to VEXcode Text by following this article.

This example program shows how to program your robot to use remote control values to steer your robot.

SplitArcadeDrive.vex

robot-config.h

using namespace vex;
vex::brain Brain;
vex::motor LeftMotor(vex::PORT1, vex::gearSetting::ratio18_1, false);
vex::motor RightMotor (vex::PORT10, vex::gearSetting::ratio18_1, true);
vex::controller Controller1 = vex::controller();
main.cpp
#include "robot-config.h"  
int main() {  
            while (true) {
                   LeftMotor.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis1.value())/2, velocityUnits::pct); //(Axis3+Axis4)/2;
	           RightMotor.spin(directionType::fwd, (Controller1.Axis3.value() - Controller1.Axis1.value())/2, velocityUnits::pct);//(Axis3-Axis4)/2;

	           task::sleep(20);
     }  
}
How it works

First,  the  main function is declared and a  repeating  while loop pulls remote control values during every iteration. This loop causes the program to run forever.

Next, the leftMotor and rightMotor are set  to  spin  forward using the data from the  joystick's  Axis values to calculate the velocity.

Then, it is necessary to calculate the final velocity for each motor independently because only one joystick is used to move the robot in Arcade mode.

Axis3 corresponds to the y-coordinate value of the left joystick. So whether you push the left joystick all the way up to +100 or all the way down to -100, it spins both motors the same direction.

Axis1 corresponds to the x-coordinate value of the right joystick and so it works differently. If you push the right joystick all the way to the right to +100, then the left motor should have a positive velocity and the right motor should have a negative velocity so that the robot turns to the right. If you push the right joystick all the way to the left to -100, then the left motor should have a negative velocity and the right motor should have a positive velocity so that the robot turns to the left. 

The  sleep task of 20 milliseconds between each loop or iteration sets a pace for checking the joystick's coordinates.