Autonomous Programming Help

Me and my team have been working on our autonomous programming, and although our code looks okay, we can’t figure out why it seems to be messing up. I have attached it, and any help is appreciated since we do have a sompetition tomorrow morning. (For more context, our auton consists of our bot starting on the roller, spinning the roller, driving uo the center line, turning, and shooting into the high goal.)

/----------------------------------------------------------------------------/
/* /
/
Module: main.cpp /
/
Author: VEX /
/
Created: Thu Sep 26 2019 /
/
Description: Competition Template /
/
/
/
----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// RightFront motor 1
// RightBack motor 4
// LeftFront motor 10
// LeftBack motor 6
// FlyWheelRight motor 11
// FlyWheelLeft motor 18
// Indexer motor 20
// Intake motor 5
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the V5 has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

///Autonomous Codes///

void autonomous(void) {

///Intake Codes///
Indexer.setVelocity(100, percent);
RightFront.setVelocity(100, percent);
RightBack.setVelocity(100, percent);
LeftFront.setVelocity(100, percent);
LeftBack.setVelocity(100, percent);
FlyWheelLeft.setVelocity(100, percent);
FlyWheelRight.setVelocity(100, percent);
Intake.setVelocity(100, percent);

//Intake Code//

Intake.startRotateFor(vex::directionType::rev, 300, vex::rotationUnits::deg);

wait(0.3, sec);

///Reverse Codes///

LeftFront.startRotateFor(vex::directionType::rev, 125, vex::rotationUnits::deg);
LeftBack.startRotateFor(vex::directionType::rev, 125, vex::rotationUnits::deg);
RightFront.startRotateFor(vex::directionType::rev, 125, vex::rotationUnits::deg);
RightBack.startRotateFor(vex::directionType::rev, 125, vex::rotationUnits::deg);

wait(0.5, sec);

///180 Turn///

LeftFront.startRotateFor(vex::directionType::fwd, 150, vex::rotationUnits::deg);
LeftBack.startRotateFor(vex::directionType::fwd, 150, vex::rotationUnits::deg);
RightFront.startRotateFor(vex::directionType::rev, 150, vex::rotationUnits::deg);
RightBack.startRotateFor(vex::directionType::rev, 150, vex::rotationUnits::deg);

wait(0.5, sec);

LeftFront.startRotateFor(vex::directionType::fwd, 455, vex::rotationUnits::deg);
LeftBack.startRotateFor(vex::directionType::fwd, 455, vex::rotationUnits::deg);
RightFront.startRotateFor(vex::directionType::fwd, 455, vex::rotationUnits::deg);
RightBack.startRotateFor(vex::directionType::fwd, 455, vex::rotationUnits::deg);

wait(0.5, sec);

LeftFront.startRotateFor(vex::directionType::rev, 1300, vex::rotationUnits::deg);
LeftBack.startRotateFor(vex::directionType::rev, 1300, vex::rotationUnits::deg);
RightFront.startRotateFor(vex::directionType::fwd, 1300, vex::rotationUnits::deg);
RightBack.startRotateFor(vex::directionType::fwd, 1300, vex::rotationUnits::deg);

wait(0.5, sec);

LeftFront.startRotateFor(vex::directionType::rev, 1300, vex::rotationUnits::deg);
LeftBack.startRotateFor(vex::directionType::rev, 1300, vex::rotationUnits::deg);
RightFront.startRotateFor(vex::directionType::fwd, 1300, vex::rotationUnits::deg);
RightBack.startRotateFor(vex::directionType::fwd, 1300, vex::rotationUnits::deg);

wait(0.5, sec);

FlyWheelLeft.startRotateFor(vex::directionType::fwd, 5000, vex::rotationUnits::deg), FlyWheelRight.startRotateFor(vex::directionType::fwd, 5000, vex::rotationUnits::deg), Indexer.startRotateFor(vex::directionType::fwd, 1300, vex::rotationUnits::deg);

}

/---------------------------------------------------------------------------/
/* /
/
User Control Task /
/
/
/
This task is used to control your robot during the user control phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void usercontrol(void) {
// User control code here, inside the loop
while (1) {

///Motor Velocity codes///

///Motor/Drive Codes///

LeftFront.spin(vex::directionType::rev, Controller1.Axis3.position() + Controller1.Axis1.position(), vex::velocityUnits::pct);
LeftBack.spin(vex::directionType::rev, Controller1.Axis3.position() + Controller1.Axis1.position(), vex::velocityUnits::pct);
RightFront.spin(vex::directionType::fwd, Controller1.Axis3.position() - Controller1.Axis1.position(), vex::velocityUnits::pct);
RightBack.spin(vex::directionType::fwd, Controller1.Axis3.position() - Controller1.Axis1.position(), vex::velocityUnits::pct);

///Velocity Shift Codes///

///FlyWheel Codes///

if(Controller1.ButtonL1.pressing()) FlyWheelLeft.setVelocity(100,percent) , FlyWheelRight.setVelocity(100,percent) , FlyWheelRight.spin(vex::directionType::fwd) , FlyWheelLeft.spin(vex::directionType::rev);

else if(Controller1.ButtonL2.pressing()) FlyWheelLeft.setVelocity(65,percent) , FlyWheelRight.setVelocity(65,percent) , FlyWheelRight.spin(vex::directionType::fwd) , FlyWheelLeft.spin(vex::directionType::rev);

else FlyWheelRight.stop(vex::brakeType::brake),FlyWheelLeft.stop(vex::brakeType::brake);

///Indexer Code///

Indexer.setVelocity(100, percent);

if(Controller1.ButtonR1.pressing()) Indexer.spin(vex::directionType::fwd);

else Indexer.stop(vex::brakeType::brake);

///Intake Codes///

if(Controller1.ButtonR2.pressing()) Intake.spin(vex::directionType::fwd);

else Intake.stop(vex::brakeType::brake);

Intake.setVelocity(100,percent);

///

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);
}}

Can you please add code tags ("`" before and after your code). Can you please describe how exactly it is messing up during your auton? A potential issue could be you are telling your motor to start to rotate but never telling them to stop

How is it messing up? Does it fail to build and throws out errors or does it just not do what you want it to?

1 Like