Autonomous Code not working, it doesn't stop

We’ve got a major issue. For some reason, our autonomous command is never cancelled or stopped once teleopinit is run?

Here’s a link to our code:

You have a while loop in your DriveTrain’s driveToDistance function, that shouldn’t be necessary. Just an if statement should work, and remove the tankDrive(0,0).

You are calling execute() instead of schedule() in autonomousInit() in Robot. Likely this, combined with the while loop is causing your code to never leave the init function?

Just some things that immediately jumped out at me. Good luck!

Your autodrivecommand doesn’t actually end.

Your teleopInit() function is a bit odd as well.

If you have an autocommand, you should be scheduling it with .schedule(). Then, in teleopinit if the commands are not null, just end them with .cancel().

I think you want to use .schedule() method instead of .execute(). Every 20ms loop iteration is running your autonomousCommand for 2 seconds. --> every 20 ms your telling the robot to run for 2 seconds.

autonomousCommand.withTimeout(2).execute();

change to:

autonomousCommand.withTimeout(2).schedule();

Tells the robot to run for 2 seconds once.

So using a withTimeout(2).schedule() is actually what we’ve had before, with a .cancel() for the command in the teleopInit().

We’ve tried all of the suggestions listed so far, and none of them have worked - either the robot does not move, or does not stop once teleop begins.

In fact, we just changed the code to use .schedule() (with a timeout) and .cancel() for the teleopInit, and there has been no change in robot behavior.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.