I have been trying to create some competition code using the template, but it will not function consistently. Basically, the code will run correctly about a quarter of the time. The code is below.
Thanks for any help.
#include "robot-config.h"
/*---------------------------------------------------------------------------*/
/* */
/* Description: Competition template for VCS VEX V5 */
/* */
/*---------------------------------------------------------------------------*/
//Creates a competition object that allows access to Competition methods.
vex::competition Competition;
/*---------------------------------------------------------------------------*/
/* 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 cortex has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void pre_auton( void ) {
// 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. */
/*---------------------------------------------------------------------------*/
void autonomous( void ) {
// ..........................................................................
// Insert autonomous user code here.
// ..........................................................................
LeftDriveFront.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
LeftDriveMiddle.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
LeftDriveBack.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveFront.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveMiddle.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveBack.rotateFor(3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
while (LeftDriveFront.isSpinning() || LeftDriveMiddle.isSpinning() || LeftDriveBack.isSpinning())
{
}
LeftDriveFront.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
LeftDriveMiddle.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
LeftDriveBack.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveFront.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveMiddle.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
RightDriveBack.rotateFor(-3.82, rotationUnits::rev, 200,velocityUnits::rpm, false);
Flywheel.spin(directionType::fwd,200,velocityUnits::rpm);
while (LeftDriveFront.isSpinning() || LeftDriveMiddle.isSpinning() || LeftDriveBack.isSpinning())
{
}
Ball.spin(directionType::fwd,200,velocityUnits::rpm);
vex::task::sleep(2000);
}
/*----------------------------------------------------------------------------*/
/* */
/* 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 ) {
#include "robot-config.h"
while (1==1)
{
LeftDriveFront.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
LeftDriveMiddle.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
LeftDriveBack.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
RightDriveFront.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
RightDriveFront.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
RightDriveBack.spin(directionType::fwd, Controller1.Axis2.value(),velocityUnits::pct);
if (Controller1.ButtonL1.pressing()==1){
Flywheel.spin(directionType::rev,200,velocityUnits::rpm);
}
else{
Flywheel.stop(brakeType::coast);
}
if (Controller1.ButtonR1.pressing()==1) {
Ball.spin(directionType::fwd,200,velocityUnits::rpm);
}
else{
if (Controller1.ButtonR2.pressing()==1){
Ball.spin(directionType::rev,200,velocityUnits::rpm);
}
else{
Ball.stop(brakeType::brake);
}
}
vex::task::sleep(20);
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
//Run the pre-autonomous function.
pre_auton();
//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}