I have some code written for autonomous but when I deploy the code nothing happens. Why is this? Can someone please tell me what I need to include or provide an example?

void RobotInit()
SmartDashboard::PutNumber(“auton”, 0);

void Autonomous()
    autonomous = SmartDashboard::GetNumber("auton", 0);

    if(autonomous == 1)
        cout << "ONE!";
    Robot.Drive(0.5, 0);
    Robot.Drive(0, 0);

    else if(autonomous == 2)
        cout << "TWO!";
    else{cout << "NONE!";}

void OperatorControl()

Are you changing the “auton” parameter from SmartDashboard? You need to tab away from the input box after changing its value for the changes to come through. Try putting a SmartDashboard::PutNumber right after the GetNumber in Autonomous() with a different name in order to make sure that you’re reading the number correctly. Also, I’d suggest not using cout since I’m not sure if you can view console output without Riolog. Try using another SmartDashboard variable for that.

On other small flaws I can see, I suggest using a while loop that runs while the robot is autonomous and enabled around drive code instead of blindly waiting. I’m not sure if just waiting would cause any issues with the code you have right now but if your method gets more complex and requires cleanup after it’s complete, you’re probably going to need to switch to IterativeRobot or have a while loop. And I’m also not sure why you added a SetSafetyEnabled(false).

Two possible problems:

  1. Isn’t it “AutonomousPeriodic()” and not “Autonomous()”
  2. “wait (2)” might give you heartbeat problems. If your periodic code hangs for 2 seconds, FMS might think you have crashed and disable your robot. It is better to set a timer and check the timer each time AutonomousPeriodic is called.

I believe that OP is using SampleRobot, hence OperatorControl() and not OperatorPeriodic().

Thanks for the help guys! I never actually saw these until now but I’ve figured everything out with my autonomous. I’m not even sure what the heck I did before but I understand my new code and it works great. Also, I apologize if quoting each of your posts is a nuisance, I’m not yet sure how to technically reply to all of you at once.

Would you mind reposting your code for the benefit of the community?