I have sucessful codes with two controllers, however, when I moved it to one controller the VexCodeInit() lines started to cause errors. I have tried to reload the program, but that has not worked. Can anyone potentially tell me what is wrong with the code?
#include "vex.h"
using namespace vex;
competition Competition;
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
}
// START AUTONOMOUS
void autonomous(void) {
// Display on screen
Brain.Screen.print("Autonomous has started");
// Move forward
FrontLeftDriveMotor.rotateFor(0.9, rotationUnits::rev, false);
FrontRightDriveMotor.rotateFor(0.9, rotationUnits::rev, false);
BackLeftDriveMotor.rotateFor(0.9, rotationUnits::rev, false);
BackRightDriveMotor.rotateFor(0.9, rotationUnits::rev);
}
// START DRIVER CONTROL
void usercontrol(void) {
// User control code here, inside the loop
#include "vex.h"
using namespace vex;
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Display that the program has started on the screen
Brain.Screen.print("Driver control started");
// Create and infinite loop so that the program can pull remote control values every iteration
while(1){
// Set motor speeds
int clawSpeedPCT = 40;
int driveSpeedPCT = 75;
int armSpeedPCT = 50;
// DRIVE CONTROL
// If button left is pressed
if(Controller1.ButtonLeft.pressing()) {
// Move robot left
FrontLeftDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
}
// Else if button right is pressed
else if(Controller1.ButtonRight.pressing()) {
// Move robot right
FrontLeftDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
}
// Else if button up is pressed
else if(Controller1.ButtonUp.pressing()) {
// Move robot forward
FrontLeftDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::fwd, driveSpeedPCT, vex::velocityUnits::pct);
}
// Else if button down is pressed
else if(Controller1.ButtonDown.pressing()) {
// Move robot backward
FrontLeftDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::rev, driveSpeedPCT, vex::velocityUnits::pct);
}
// Else if neither button left or button right is pressed
else {
// Set the left and right motor to spin forward using the controller's axis positions as the velocity units
FrontLeftDriveMotor.spin(vex::directionType::fwd, Controller1.Axis3.position()*0.75, vex::velocityUnits::pct);
BackLeftDriveMotor.spin(vex::directionType::fwd, Controller1.Axis3.position()*0.75, vex::velocityUnits::pct);
FrontRightDriveMotor.spin(vex::directionType::fwd, Controller1.Axis2.position()*0.75, vex::velocityUnits::pct);
BackRightDriveMotor.spin(vex::directionType::fwd, Controller1.Axis2.position()*0.75, vex::velocityUnits::pct);
}
// ARM CONTROL
// If button L1 is pressed
if(Controller1.ButtonL1.pressing()) {
// Spin the arm motors forward
ArmMotorLeft.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
ArmMotorRight.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
}
// Else if button L2 is pressed
else if(Controller1.ButtonL2.pressing()) {
// Spin the arm motors backward
ArmMotorLeft.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
ArmMotorRight.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
}
// Else if neither button L1 or button L2 is pressed
else {
// Stop the arm motors
ArmMotorLeft.stop(vex::brakeType::brake);
ArmMotorRight.stop(vex::brakeType::brake);
}
// CLAW CONTROL
// If button R1 is pressed
if(Controller1.ButtonR1.pressing()) {
// Spin the claw motors forward
ClawMotor1.spin(vex::directionType::fwd, clawSpeedPCT, vex::velocityUnits::pct);
ClawMotor2.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
}
// Else if button R2 is pressed
else if(Controller1.ButtonR2.pressing()) {
// Spin the claw motors backward
ClawMotor1.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
ClawMotor2.spin(vex::directionType::fwd, clawSpeedPCT, vex::velocityUnits::pct);
}
// Else if neither button R1 or button R2 is pressed
else {
// Stop the claw motors
ClawMotor1.stop(vex::brakeType::brake);
ClawMotor2.stop(vex::brakeType::brake);
}
}
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}