Okay, so I am having issues when transferring my code to vexcode from VCS. Every “vex” is highlighted, as well as the tilde at the top. Also, is there a template for where to put driver control and autonomous code? Thanks!
Summary
// VEX V5 C++ Project
#include
#include
using namespace vex;
//#region config_globals
vex::brain Brain;
vex::motor back_right_motor(vex::PORT1, vex::gearSetting::ratio18_1, true);
vex::motor back_left_motor(vex::PORT10, vex::gearSetting::ratio18_1, false);
vex::motor front_right_motor(vex::PORT11, vex::gearSetting::ratio18_1, true);
vex::motor front_left_motor(vex::PORT20, vex::gearSetting::ratio18_1, false);
vex::motor intake_arm_mover(vex::PORT5, vex::gearSetting::ratio36_1, false);
vex::motor intake_left(vex::PORT12, vex::gearSetting::ratio18_1, false);
vex::motor intake_right(vex::PORT9, vex::gearSetting::ratio18_1, false);
vex::motor tray_mover(vex::PORT16, vex::gearSetting::ratio36_1, false);
vex::controller con(vex::controllerType::primary);
//#endregion config_globals
int main(void) {
//Setting the speed of the intake rollers and the arms holding the intake rollers
int intakeleftSpeedPCT = 100;
int intakerightSpeedPCT = 100;
int intakearmSpeedPCT = 50;
int traymoverSpeedPCT = 25;
while(true) {
if(con.ButtonL1.pressing()) {
intake_left.spin(directionType::fwd, intakeleftSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonL2.pressing()) {
intake_left.spin(directionType::rev,intakeleftSpeedPCT, velocityUnits::pct);
}
else {
intake_left.stop(brakeType::brake);
}
if(con.ButtonL1.pressing()) {
intake_right.spin(directionType::rev, intakerightSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonL2.pressing()) {
intake_right.spin(directionType::fwd,intakerightSpeedPCT, velocityUnits::pct);
}
else {
intake_right.stop(brakeType::brake);
}
if(con.ButtonUp.pressing()) {
intake_arm_mover.spin(directionType::fwd, intakearmSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonDown.pressing()) {
intake_arm_mover.spin(directionType::rev,intakearmSpeedPCT, velocityUnits::pct);
}
else {
intake_arm_mover.stop(brakeType::brake);
}
if(con.ButtonLeft.pressing()) {
tray_mover.spin(directionType::fwd, traymoverSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonRight.pressing()) {
tray_mover.spin(directionType::rev,traymoverSpeedPCT, velocityUnits::pct);
}
else {
tray_mover.stop(brakeType::brake);
}
//Get the raw sums of the X and Y joystick axes
double front_left = (double)(con.Axis3.position(pct) + con.Axis4.position(pct));
double back_left = (double)(con.Axis3.position(pct) - con.Axis4.position(pct));
double front_right = (double)(con.Axis3.position(pct) - con.Axis4.position(pct));
double back_right = (double)(con.Axis3.position(pct) + con.Axis4.position(pct));
//Find the largest possible sum of X and Y
double max_raw_sum = (double)(abs(con.Axis3.position(pct)) + abs(con.Axis4.position(pct)));
//Find the largest joystick value
double max_XYstick_value = (double)(std::max(abs(con.Axis3.position(pct)),abs(con.Axis4.position(pct))));
//The largest sum will be scaled down to the largest joystick value, and the others will be
//scaled by the same amount to preserve directionality
if (max_raw_sum != 0) {
front_left = front_left / max_raw_sum * max_XYstick_value;
back_left = back_left / max_raw_sum * max_XYstick_value;
front_right = front_right / max_raw_sum * max_XYstick_value;
back_right = back_right / max_raw_sum * max_XYstick_value;
}
//Now to consider rotation
//Naively add the rotational axis
front_left = front_left + con.Axis1.position(pct);
back_left = back_left + con.Axis1.position(pct);
front_right = front_right - con.Axis1.position(pct);
back_right = back_right - con.Axis1.position(pct);
//What is the largest sum, or is 100 larger?
max_raw_sum = std::max(std::abs(front_left),std::max(std::abs(back_left),std::max(std::abs(front_right),std::max(std::abs(back_right),100.0))));
//Scale everything down by the factor that makes the largest only 100, if it was over
front_left = front_left / max_raw_sum * 100.0;
back_left = back_left / max_raw_sum * 100.0;
front_right = front_right / max_raw_sum * 100.0;
back_right = back_right / max_raw_sum * 100.0;
//Write the manipulated values out to the motors
front_left_motor.spin(fwd,front_left, velocityUnits::pct);
back_left_motor.spin(fwd,back_left, velocityUnits::pct);
front_right_motor.spin(fwd,front_right,velocityUnits::pct);
back_right_motor.spin(fwd,back_right, velocityUnits::pct);
}
}