When I run a timed run or autonomous skills challenge, about 75% of the time the program skips to the last couple lines of code that drop the cubes. The other 25% of the time, the program works perfectly. Does anyone have any ideas why this is happening? We have a competition on Saturday, February 1st and this is pretty urgent.
Here’s the program:
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: C:\Users\th12093 */
/* Created: Thu Jan 09 2020 */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// LeftMotor motor 1
// RightMotor motor 2
// RampMotor motor 3
// LeftCube motor 4
// RightCube motor 5
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
//Global instance of competition
competition Competition;
//Define other global instances of motors and other devices below
//Start of Pre-Autonomous
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
}
//End of Pre-Autonomous
//Start of Autonomous
void autonomous(void) {
//Moving forward to pick up cubes
LeftCube.spinFor(10, turns, false);
RightCube.spinFor(10, turns, false);
LeftMotor.spinFor(540, degrees, false);
RightMotor.spinFor(540, degrees);
//Turning left to go to the alliance scoring zone
RightMotor.spinFor(610, degrees);
//Moving to the scoring zone
LeftMotor.spinFor(520, degrees, false);
RightMotor.spinFor(520, degrees);
//Dropping cubes in the scoring zone
RampMotor.spinFor(270, degrees);
LeftCube.spin(reverse);
RightCube.spin(reverse);
}
//End of Autonomous
//Start of User Control
void usercontrol(void) {
int deadband = 1;
while (1) {
//START OF JOYSTICK CONTROL ______________________________________________________________________________________________
//Setting the velocity of the cube motors
LeftCube.setVelocity(100, percent);
RightCube.setVelocity(100, percent);
RampMotor.setMaxTorque(100, percent);
//Get the percentage of the left motor and right motor
int leftMotorSpeed = Controller1.Axis3.position();
int rightMotorSpeed = Controller1.Axis2.position();
//Set the speed of the left motor. If the value is less than the deadband, set to zero. Else, set speed to leftMotorSpeed
if (abs(leftMotorSpeed) < deadband) {
LeftMotor.setVelocity(0, percent);}
else {
LeftMotor.setVelocity(leftMotorSpeed, percent);
}
//Set the speed of the right motor. If value is less than the deadband, set to zero. Else, set speed to rightMotorSpeed
if (abs(rightMotorSpeed) < deadband) {
RightMotor.setVelocity(0, percent);}
else {
RightMotor.setVelocity(rightMotorSpeed, percent);
}
//Spinning all motors
LeftMotor.spin(forward);
RightMotor.spin(forward);
//END OF JOYSTICK CONTROL _________________________________________________________________________________________________
//START OF BUTTON CONTROL _________________________________________________________________________________________________
//R1 spins the motors to pick up the cubes
if (Controller1.ButtonR1.pressing()) {
RightCube.spin(forward);
LeftCube.spin(forward);}
//R2 Spins the motors to drop up the cubes
else if (Controller1.ButtonR2.pressing()) {
RightCube.spin(reverse);
LeftCube.spin(reverse);
}
else {
RightCube.stop();
LeftCube.stop();
}
//END OF BUTTON CONTROL __________________________________________________________________________________________________
wait(1, msec);
}
}
//End of User Control
// 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);
// Runining pre-auton
pre_auton();
// Prevents main from exiting with an infinite loop
while (true) {
wait(100, msec);
}
}