Team 5684 here. It is our third year in FRC, my first. We have made the switch to a command based build in java. However we are having some trouble with the autonomous mode. The chooser seems to be getting the command and identifying it however when we switch to autonomous mode in the driver dashboard the command does not run. I know these commands work because i can use them during tel-op when assigned to buttons. (also as a side note i seem to have no drop down menu on the dashboard to select which autonomous mode i want. Below is some of my code and a sample of the output i see in the command prompt. Thank sall for your help
Command autonomousCommand;
SendableChooser<Command> chooser = new SendableChooser<>();
chooser.addDefault("Test Shooter",new StartShoot());
chooser.addObject("Drive Forward", new Collect(Collect.FORWARD));
chooser.addObject("Climb", new Climb(.25));
SmartDashboard.putData("Auto mode", chooser);
public void autonomousInit() {
System.out.println("chooser: "+ chooser);
System.out.println("command: " + chooser.getSelected());
autonomousCommand = chooser.getSelected();
System.out.println("command: " + autonomousCommand);
// schedule the autonomous command (example)
if (autonomousCommand != null)
{
System.out.println(" We got inside");
}
}
/**
* This function is called periodically during autonomous
*/
@Override
public void autonomousPeriodic() {
//if(s.isFinished())
//{
//s.end();
//}
if (autonomousCommand != null) {
autonomousCommand.cancel();
}
}
Output:
chooser: edu.wpi.first.wpilibj.smartdashboard.SendableChooser@1327b79
command: StartShoot
command: StartShoot
We got inside
Try this instead (taken from the Command Based template):
@Override
public void autonomousInit() {
autonomousCommand = chooser.getSelected();
// schedule the autonomous command (example)
if (autonomousCommand != null)
autonomousCommand.start();
}
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (autonomousCommand != null)
autonomousCommand.cancel();
}
Thank you so very much that seems to have done. However I still have the problem where it just automatically does the default the Driver station does not seem to display all the options. Any idea?
We were able to successfully downloaded the update however now when we try to start Java driver station the window opens a quickly closes before the driver station window is able to be used
Last year was our first year with command based and aut-choosers. We to had lots of trouble with the selected command not running. At our off season events we started to close the smartdashboard and we had a short cut to reopen on the desk the top after robot coms reestablished on the field. It seemed to fix it. We will likely continue with this as it also fixed the videostream from GRIP on the Kangaroo.