Hello everyone, my team is in need of help as we’ve hit a roadblock. In our code we have run into two problems. Firstly, whenever our robot executes a certain piece of code in our autonomous, the robot doesn’t finish any of its other commands during autonomous and just lies on the field without making any moves. In our code linked down below, the command is, “FrontClampForward(100,500);”. Additionally, at the beginning of our code for each Auton, its seems that if our robot is drifting toward the left side. Does anyone know why this happens? Lastly, if you have any suggestions or tips for our code, please let us know, this is our first year in participating in vexV5 competitions!
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: {} */
/* Created: {1/14/21} */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
// Include the V5 Library
#include "vex.h"
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// BumperA bumper A
// ---- END VEXCODE CONFIGURED DEVICES ----
// Allows for easier use of the VEX Library
using namespace vex;
//Main Competition
vex::competition Competition;
//Robot Controller
vex::controller Controller1 = vex::controller();
//vex::gearSetting::ratio18_1
//The Wheels
vex::motor BackLeftMotor (vex::PORT2, false);
vex::motor BackRightMotor (vex::PORT14, false);
vex::motor FrontLeftMotor (vex::PORT10, false);
vex::motor FrontRightMotor (vex::PORT18, true);
//Forklift
vex::motor ForkLiftLeftMotor (vex::PORT12, vex::gearSetting::ratio18_1, false);
vex::motor ForkLiftRightMotor (vex::PORT13, vex::gearSetting::ratio18_1, true);
//Forklift Clamp
vex::motor ForkLiftClampMotor (vex::PORT9, vex::gearSetting::ratio18_1, true);
//Backside Claw
vex::motor BackClawMotor (vex::PORT4, vex::gearSetting::ratio18_1, true);
////////////////////////////////////////////////
////////////////////////////////////////////////
//Degrees to Inches
float inch = 28.6487346;
//Arm Speed In UserControl
int ArmSpeed = 300;
//Auton Select Variaables
int HS = 1;
int AutonLeft1 = 0;
int AutonLeft2 = 0;
int AutonLeft3 = 0;
int TrialandError = 0;
int AutonRight1 = 0;
int AutonRight2 = 0;
int AutonRight3 = 0;
int Skills = 0;
//Function For Moving Forward
void TurnLeft(int speed, int TurnValue){
FrontRightMotor.spinFor(-TurnValue, rotationUnits::deg, speed, velocityUnits::pct, false );
FrontLeftMotor.spinFor(TurnValue , rotationUnits::deg, -speed, velocityUnits::pct, false);
BackRightMotor.spinFor(TurnValue, rotationUnits::deg, -speed, velocityUnits::pct, false);
BackLeftMotor.spinFor(TurnValue , rotationUnits::deg, -speed, velocityUnits::pct, true);
}
//Function For Turning Right
void TurnRight(int speed, int TurnValue){
FrontRightMotor.spinFor(TurnValue, rotationUnits::deg, -speed, velocityUnits::pct, false );
FrontLeftMotor.spinFor(-TurnValue, rotationUnits::deg, speed, velocityUnits::pct, false);
BackRightMotor.spinFor(-TurnValue, rotationUnits::deg, speed, velocityUnits::pct, false);
BackLeftMotor.spinFor(-TurnValue, rotationUnits::deg, speed, velocityUnits::pct, true);
}
//Function For Moving Forward
void MoveForward(int speed, int NumberOfInches){
FrontRightMotor.spinFor(-NumberOfInches * inch, rotationUnits::deg, speed, velocityUnits::pct, false );
FrontLeftMotor.spinFor(-NumberOfInches * inch, rotationUnits::deg, speed, velocityUnits::pct, false);
BackRightMotor.spinFor(NumberOfInches * inch, rotationUnits::deg, -speed, velocityUnits::pct, false);
BackLeftMotor.spinFor(-NumberOfInches * inch, rotationUnits::deg, speed, velocityUnits::pct, true);
}
//Function For Moving Backward
void MoveBackward(int speed, int NumberOfInches){
FrontRightMotor.spinFor(NumberOfInches * inch, rotationUnits::deg, -speed, velocityUnits::pct, false);
FrontLeftMotor.spinFor(NumberOfInches * inch, rotationUnits::deg, -speed, velocityUnits::pct, false);
BackRightMotor.spinFor(-NumberOfInches * inch, rotationUnits::deg, speed, velocityUnits::pct, false);
BackLeftMotor.spinFor(NumberOfInches * inch, rotationUnits::deg, -speed, velocityUnits::pct, true);
}
//Function For Moving Arms Down
void MoveArmDown(int speed, int ArmMillimeters){
ForkLiftRightMotor.spinFor(ArmMillimeters, rotationUnits::deg, speed, velocityUnits::pct, true );
ForkLiftLeftMotor.spinFor(ArmMillimeters, rotationUnits::deg, speed, velocityUnits::pct, true );
}
//Function For Moving Arms Up
void MoveArmUp(int speed, int ArmMillimeters){
ForkLiftRightMotor.spinFor(-ArmMillimeters, rotationUnits::deg, -speed, velocityUnits::pct, true );
ForkLiftLeftMotor.spinFor(-ArmMillimeters, rotationUnits::deg, -speed, velocityUnits::pct, true );
}
//Function For Grabbing Neutral Mobile Goals
void FrontClampForward(int speed, int ClampMillimeters){
ForkLiftClampMotor.spinFor(-ClampMillimeters, rotationUnits::deg, -speed, velocityUnits::pct, true );
}
//Function For Dropping Neutral Mobile Goals
void FrontClampBackward(int speed, int ClampMillimeters){
ForkLiftClampMotor.spinFor(ClampMillimeters, rotationUnits::deg, speed, velocityUnits::pct, true );
}
//Function For Grabbing Alliance Mobile Goals
void BackClawFoward(int speed, int ClawMillimeters){
BackClawMotor.spinFor(-ClawMillimeters, rotationUnits::deg, -speed, velocityUnits::pct, true );
}
//Function For Dropping Alliance Mobile Goals
void BackClawBackward(int speed, int ClawMillimeters){
BackClawMotor.spinFor(ClawMillimeters, rotationUnits::deg, speed, velocityUnits::pct, true );
}
//HomeScreen Of Brain On AutonSelect
void HomeScreen(){
Brain.Screen.clearScreen();
Brain.Screen.drawRectangle(0,0,120,120, black);
Brain.Screen.printAt(45,60, false, "L#1");
Brain.Screen.drawRectangle(120,0,120,120, black);
Brain.Screen.printAt(165,60, false, "L#2");
Brain.Screen.drawRectangle(240,0,120,120, black);
Brain.Screen.printAt(285,60, false, "L#3");
Brain.Screen.drawRectangle(360,0,120,120, red);
Brain.Screen.printAt(405,60, false, "T&E");
Brain.Screen.drawRectangle(0,120,120,120, blue);
Brain.Screen.printAt(45,180, false, "R#1");
Brain.Screen.drawRectangle(120,120,120,120, blue);
Brain.Screen.printAt(165,180, false, "R#2");
Brain.Screen.drawRectangle(240,120,120,120, blue);
Brain.Screen.printAt(285,180, false, "R#3");
Brain.Screen.drawRectangle(360,120,120,120, green);
Brain.Screen.printAt(405,180, false, "SK");
Brain.Screen.drawLine(240,0,240,240);
Brain.Screen.drawLine(0,120,480,120);
Brain.Screen.drawLine(120,0,120,240);
Brain.Screen.drawLine(360,0,360,240);
//While Loop Used To Determine Which Side Of Autonomous Will Be Used
while(HS == 1){
if(Brain.Screen.pressing()){
//Set Up Auton Left #1
if(Brain.Screen.xPosition() >= 0 && Brain.Screen.xPosition() <= 120 && Brain.Screen.yPosition() >= 0 && Brain.Screen.yPosition() <= 120){
AutonLeft1 = 1;
HS = 0;
Brain.Screen.print("Autonomous Left Side #1");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Left #2
if(Brain.Screen.xPosition() >= 120 && Brain.Screen.xPosition() <= 240 && Brain.Screen.yPosition() >= 0 && Brain.Screen.yPosition() <= 120){
AutonLeft2 = 1;
HS = 0;
Brain.Screen.print("Autonomous Left Side #2");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Left #3
if(Brain.Screen.xPosition() >= 240 && Brain.Screen.xPosition() <= 360 && Brain.Screen.yPosition() >= 0 && Brain.Screen.yPosition() <= 120){
AutonLeft3 = 1;
HS = 0;
Brain.Screen.print("Autonomous Left Side #3");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Trial and Error
else if(Brain.Screen.xPosition() >= 360 && Brain.Screen.xPosition() <= 480 && Brain.Screen.yPosition() >= 0 && Brain.Screen.yPosition() <= 120){
TrialandError = 1;
HS = 0;
Brain.Screen.print("Autonomous Trial & Error");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Right #1
else if(Brain.Screen.xPosition() >= 0 && Brain.Screen.xPosition() <= 120 && Brain.Screen.yPosition() >= 120 && Brain.Screen.yPosition() <= 240){
AutonRight1 = 1;
HS = 0;
Brain.Screen.print("Autonomous Right Side #1");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Right #2
else if(Brain.Screen.xPosition() >= 120 && Brain.Screen.xPosition() <= 240 && Brain.Screen.yPosition() >= 120 && Brain.Screen.yPosition() <= 240){
AutonRight2 = 1;
HS = 0;
Brain.Screen.print("Autonomous Right Side #2");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Right #3
else if(Brain.Screen.xPosition() >= 240 && Brain.Screen.xPosition() <= 360 && Brain.Screen.yPosition() >= 120 && Brain.Screen.yPosition() <= 240){
AutonRight3 = 1;
HS = 0;
Brain.Screen.print("Autonomous Right Side #3");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
//Set Up Auton Skills
else if(Brain.Screen.xPosition() >= 360 && Brain.Screen.xPosition() <= 480 && Brain.Screen.yPosition() >= 120 && Brain.Screen.yPosition() <= 240){
Skills = 1;
HS = 0;
Brain.Screen.print("Skills Auton");
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
}
else{}
}
}
}
//AutonSelect Will Be Played During Pre Auton
void pre_auton( void ){
HomeScreen();
ForkLiftClampMotor.setStopping(hold);
BackClawMotor.setStopping(hold);
}
void auton_left1(){
//Robot Moves Forward
MoveForward(100,48);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Moves Backward
MoveBackward(100,46);
//Robot Turns Left
TurnLeft(70,325);
//Robot Moves Backward
MoveBackward(100,3);
wait(1000, msec);
//Robot Moves Backward
MoveBackward(80,1);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
}
void auton_left2(){
//Robot Moves Forward
MoveForward(100,78);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Moves Backward
MoveBackward(100,68);
//Robot Turns Left
TurnLeft(70,325);
//Robot Moves Backward
MoveBackward(100,8);
wait(1000, msec);
//Robot Moves Backward
MoveBackward(80,1);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
}
void auton_left3(){
//Robot Moves Forward
MoveForward(100,48);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Turns Left
TurnLeft(70,355);
//Robot Moves Backward
MoveBackward(100, 33);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
//Robot Turns Left
TurnLeft(70,163);
//Robot Moves Forward
MoveForward(100,48);
}
void TandE(){
//Robot Claw Moves Forward
BackClawFoward(100, 500);
}
void auton_right1(){
//Robot Moves Forward
MoveForward(80,44);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Moves Backward
MoveBackward(100,35);
//Robot Turns Left
TurnLeft(70,325);
//Robot Moves Backward
MoveBackward(100,12);
wait(1000, msec);
//Robot Moves Backward
MoveBackward(80,1);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
//Robot Moves Forward
MoveForward(100,8);
}
void auton_right2(){
//Robot Moves Forward
MoveForward(80,78);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Moves Backward
MoveBackward(100, 51);
//Robot Turns Left
TurnLeft(70,163);
//Robot Moves Backward
MoveBackward(80,12);
wait(1000, msec);
//Robot Moves Backward
MoveBackward(80,1);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
//Robot Moves Forward
MoveForward(100,8);
}
void auton_right3(){
//Robot Moves Forward
MoveForward(80,56);
wait(1000, msec);
//Robot Moves Forward
MoveForward(80,1);
//Robot Clamp Moves Forward
FrontClampForward(100,500);
//Robot Turns Right
TurnRight(70,325);
//Robot Moves Backward
MoveBackward(100, 33);
wait(1000, msec);
//Robot Moves Backward
MoveBackward(80,1);
//Robot Claw Moves Forward
BackClawFoward(100, 500);
//Robot Turns Right
TurnRight(70,163);
//Robot Moves Forward
MoveForward(100,48);
}
void auton_skills(){
//Robot Moves Forward
MoveForward(50,100);
//Robot Turns Left
TurnLeft(50,30);
//Robot Moves Backward
MoveBackward(50,70);
//Robot Turns Right
TurnRight(50,60);
//Robot Moves Forward
MoveForward(50,70);
//Robot Turns Left
TurnLeft(50,60);
//Robot Moves Backward
MoveBackward(50,70);
}
//Void Function For Autonomous
void autonomous( void ){
//Code for left side of field will be displayed for autonomous
if (AutonLeft1 == 1){
auton_left1();
}
//Code for left side of field will be displayed for autonomous
else if (AutonLeft2 == 1){
auton_left2();
}
//Code for left side of field will be displayed for autonomous
else if (AutonLeft3 == 1){
auton_left3();
}
//Code for trial and error will be displayed for autonomous
else if (TrialandError == 1){
TandE();
}
//Code for right side of field will be displayed for autonomous
else if (AutonRight1 == 1){
auton_right1();
}
//Code for right side of field will be displayed for autonomous
else if (AutonRight2 == 1){
auton_right2();
}
//Code for right side of field will be displayed for autonomous
else if (AutonRight3 == 1){
auton_right3();
}
//Code for skills will be displayed
else if (Skills == 1){
auton_skills();
}
else{}
}
//Void Function For Driver Control
void usercontrol( void ) {
while(1) {
//Using Arcade Control
//////////////////////
//Motors Allow Robot To Move Forward, Backward, Right, and Left
BackLeftMotor.spin(vex::directionType::rev, Controller1.Axis3.value()+Controller1.Axis1.value(), vex::velocityUnits::pct);
BackRightMotor.spin(vex::directionType::fwd, Controller1.Axis3.value()-Controller1.Axis1.value(), vex::velocityUnits::pct);
FrontLeftMotor.spin(vex::directionType::rev, Controller1.Axis3.value()+Controller1.Axis1.value(), vex::velocityUnits::pct);
FrontRightMotor.spin(vex::directionType::rev, Controller1.Axis3.value()-Controller1.Axis1.value(), vex::velocityUnits::pct);
//Arms Can Move Down
if (Controller1.ButtonR1.pressing()) {
ForkLiftLeftMotor.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);
ForkLiftRightMotor.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);
}
//Clamp Can Move Down
else if (Controller1.ButtonX.pressing()) {
ForkLiftClampMotor.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);
}
//Claw Can Move Down
else if (Controller1.ButtonUp.pressing()) {
BackClawMotor.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);
}
//Arms Can Move Up
else if (Controller1.ButtonR2.pressing()) {
ForkLiftLeftMotor.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);
ForkLiftRightMotor.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);
//Bumper Used To Stop Arms From Moving Too Far Back
if (BumperA.pressing()){
ForkLiftLeftMotor.stop(brakeType::hold);
ForkLiftRightMotor.stop(brakeType::hold);
}
}
//Clamp Can Move Up
else if (Controller1.ButtonB.pressing()) {
ForkLiftClampMotor.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);
}
//Claw Can Move Up
else if (Controller1.ButtonDown.pressing()) {
BackClawMotor.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);
}
//Motors Will Not Move
else {
ForkLiftLeftMotor.stop(vex::brakeType::brake);
ForkLiftRightMotor.stop(vex::brakeType::brake);
ForkLiftClampMotor.stop(vex::brakeType::brake);
BackClawMotor.stop(vex::brakeType::brake);
}
vex::task::sleep(20);
}
}
int main(){
//Tells Competition To Run 'Usercontrol' During Drivercontrol
Competition.drivercontrol(usercontrol);
//Tells Competition To Run 'Autonomous' During Autonomous
Competition.autonomous(autonomous);
pre_auton();
while(1){
//Conserves Energy During Competition
vex::task::sleep(100);
}
}
edit: code tags added by mods, please remember to use them,