VCS Example Program with Controller - C++ - Tank Control

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


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);
#include "robot-config.h"

int main() {
    while(true) {
        LeftMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
        RightMotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis3-Axis4)/2

How it works

First, the main function is declared. An infinite while loop is created so that the program can pull remote control values every iteration. The loop causes the program to run forever.

Next, the leftMotor and rightMotor are set to spin forward using the controller Axisvalues as the velocity value.

Then, a sleep task is added for a short amount of time to prevent wasted energy.

Still need help? Contact Us Contact Us