Autonomous Troubles

#include “robot-config.h”

int main() {

LeftWheelMotor.spin(directionType ::fwd, 75, velocityUnits ::pct);

RightWheelMotor.spin(directionType ::rev, 75, velocityUnits ::pct);

task ::sleep(800); 

LeftWheelMotor.stop(brakeType ::brake); 

RightWheelMotor.stop(brakeType ::brake); 

task ::sleep(300); 

LeftWheelMotor.spin(directionType ::rev,75, velocityUnits ::pct); 

RightWheelMotor.spin(directionType ::rev,75, velocityUnits ::pct); 

task ::sleep(575); 

LeftWheelMotor.stop(brakeType ::brake); 

RightWheelMotor.stop(brakeType ::brake); 

task ::sleep(300); 

LeftWheelMotor.spin(directionType ::fwd,75, velocityUnits ::pct); 

RightWheelMotor.spin(directionType ::rev,75, velocityUnits ::pct);     

task ::sleep(2900);     

LeftWheelMotor.stop(brakeType ::brake); 

RightWheelMotor.stop(brakeType ::brake); 

}

My autonomous is having trouble working in matches. In practice we can run it without an autonomous switch and it will work. And if we have the autonomous switch plugged in and already running and then we click run on the robot and that works. But if the switch is plugged in and disabled, we click run on the robot, and then we enable autonomous it doesn’t move. This also happens in competition so our autonomous doesn’t work. Can someone please provide guidance.
Thanks.

Why did you post this twice? It is only needed once, in the other place you posted this. If you posted it the second time due to posting in the wrong channel, you can delete this post (FYI).

Sorry Honest Mistake

All cool. Wasn’t trying to reprimand you, just a helpful tip that you can delete a thread.

You should probably put your code in a competition template if it is not already. Then, you can select the desired auton in pre auton and it will run that one in the auton method (so long as the logic is correct).

@Manager2.0 When your program starts, it will immediately begin running your code. The only thing that the competition switch does is affect how certain commands behave: disable will prevent motor commands from doing anything, and input from the handheld controller is only available in driver control mode. It will also affect what the


isAutonomous

,


isEnabled

, and


isDriverControl

methods of a vex::competition object will return. Basically, you want to wait until you see


isAutonomous

is true, then run your autonomous, and if at any point


isDriverControl

becomes true you want to abort your autonomous and start your driver code.

To that end, those of us who write programming software usually provide a template that manages watching the competition state for you, known as the competition template. Use that. It is much easier than having to figure out multi threading logic just to write a competition program that starts when it is supposed to.