I’m using VexCode v5 text C++ and this is the code.
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
using namespace vex;
// Brain should be defined by default
brain Brain;
// START V5 MACROS
#define waitUntil(condition) \
do { \
wait(5, msec); \
} while (!(condition))
#define repeat(iterations) \
for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS
// Robot configuration code.
controller Controller1 = controller(primary);
motor Motor1 = motor(PORT1, ratio18_1, false);
motor Motor2 = motor(PORT2, ratio18_1, false);
motor Motor3 = motor(PORT3, ratio18_1, false);
motor Motor4 = motor(PORT4, ratio18_1, false);
motor scoop = motor(PORT5, ratio18_1, false);
motor Climbing = motor(PORT6, ratio18_1, false);
// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
printf("VEXPlaySound:%s\n", soundName);
wait(5, msec);
}
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
#pragma endregion VEXcode Generated Robot Configuration
float X1, X2, Y1, OVER;
bool controlmode_auto = true;
bool controlmode_driver = true;
int auto_period = 15;
bool scoop_bool = true;//true = open, false=close
//{forward/backward, crab walk, turn}
int instructions[25][3]{
{0, 50, 0},
{0, 50, 0},
{0, 50, 0},
{0, 50, 0},
{0, 50, 0},
{0, 20, 0},
{0, -50, 0},
{0, -50, 0},
{0, -50, 0},
{0, -50, 0},
{0, -50, 0},
{0, -20, 0},
{0, 0, 20},
{50, 0, 0},
{50, 0, 0},
{0, 70, 0},
{50, 0, 0},
{50, 0, 0},
{-50, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{123, 0, 0} //123 in the first spot signifys the end of the instructions.
};
void Mecanum(){
// Break
if (Y1 + X1 + X2 > 100.0) {
OVER = 100.0 / (Y1 + X1 + X2);
} else if (-100.0 > Y1 + X1 + X2) {
OVER = 100.0 / (Y1 + X1 + X2);
} else if (Y1 - X1 - X2 > 100.0) {
OVER = 100.0 / (Y1 - X1 - X2);
} else if (-100.0 > Y1 - X1 - X2) {
OVER = 100.0 / (Y1 - X1 - X2);
} else if (Y1 + X1 - X2 > 100.0) {
// Break
OVER = 100.0 / (Y1 + X1 - X2);
} else if (-100.0 > Y1 + X1 - X2) {
// Break
OVER = 100.0 / (Y1 + X1 - X2);
}
else if (Y1 - X1 + X2 > 100.0) {
OVER = 100.0 / (Y1 - X1 + X2);
} else if (-100.0 > Y1 - X1 + X2) {
OVER = 100.0 / (Y1 - X1 + X2);
} else {
OVER = 1.0; //Won't Affect Wheel Speed At All
}
Motor1.setVelocity((OVER * (Y1 + X1 + X2)), percent);
Motor2.setVelocity((OVER * (0-Y1 + X1 + X2)), percent);
Motor3.setVelocity((OVER * (Y1 - X1 + X2)), percent);
Motor4.setVelocity((OVER * (0- Y1 - X1 + X2)), percent);
}
void L1_pressed(){
if (scoop_bool == true){
scoop_bool = false;
}else{
scoop_bool = true;
}
if (scoop_bool){
scoop.spinToPosition(90,degrees);
}else{
scoop.spinToPosition(0,degrees);
}}
void R1_pressed(){
Climbing.spin(forward);
}
void R2_pressed(){
Climbing.spin(reverse);
}
void R1_released(){
Climbing.stop();
}
void R2_released(){
Climbing.stop();
}
/*
X1 = Controller1.Axis4.position();
Y1 = Controller1.Axis3.position();
X2 = Controller1.Axis1.position();
X2 = X2*0.75; // Allows For Higher Turning Speed
*/
void control_auto(void){
Motor1.spin(forward); //Setting Up Variables and Motors
Motor2.spin(forward);
Motor3.spin(forward);
Motor4.spin(forward);
OVER = 1.0;
int num_time = round(Brain.Timer.time(seconds)); // Converts Seconds Into Steps
if (num_time == auto_period or num_time > auto_period){
controlmode_auto = false;
}
if (instructions[num_time][0] == 123) {
controlmode_auto = false;
Brain.Screen.print("Auto Done");
}
if (controlmode_auto){
num_time = num_time * 2;
Y1 = instructions[num_time][0];
X1 = instructions[num_time][1];
X2 = instructions[num_time][2];
Mecanum();
}
}
void control_human(){
printf("Human");
Motor1.spin(forward); //Setting Up Variables and Motors
Motor2.spin(forward);
Motor3.spin(forward);
Motor4.spin(forward);
OVER = 1.0;
Y1 = Controller1.Axis3.position();
X1 = Controller1.Axis4.position();
X2 = Controller1.Axis1.position();
Mecanum();
}
void scoops(){
if(Controller1.ButtonL1.pressing()){
L1_pressed();
}}
void R1up(){
if(Controller1.ButtonR1.pressing()){
R1_pressed();
}}
void R2down(){
if(Controller1.ButtonL1.pressing()){
R2_pressed();
}}
/* void R1stop(){
if(Controller1.ButtonR1.released()){
R1_released();
}}
void R2stop(){
if(Controller1.ButtonL1.released()){
R2_released();
}}
*/
void R1stop(){
if(Controller1.ButtonR1.pressing()){
R1_released();
}}
void R2stop(){
if(Controller1.ButtonL1.pressing()){
R2_released();
}}
int whenStarted1() {
Motor1.spin(forward); //Setting Up Variables and Motors
Motor2.spin(forward);
Motor3.spin(forward);
Motor4.spin(forward);
OVER = 1.0;
control_auto();
while (true) {
control_human();
scoops();
R1up();
R2down();
R1stop();
R2stop();
wait(5, msec);
}
}
void preAutonomous(void) {
// actions to do when the program starts
Brain.Screen.clearScreen();
Brain.Screen.print("pre auton code");
wait(1, seconds);
}
int main() {
// create competition instance
competition Competition;
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(control_auto);
Competition.drivercontrol(control_human);
// Run the pre-autonomous function.
preAutonomous();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}
edit: code tags added by mods, please remember to use them.