Quote:
Originally Posted by RSNovi
Thank you for sharing your code with me. It is pretty similar to what we have, although yours is more elegant and we put all the code in Robot.java. For some reason we are getting sporadic results. I was thinking that we needed to make sure we toggled the buttons after the robot was connected to the competition system. It was working fine during our normal testing, but something is different when we connect to the competition system. We ended just hard coding the auto choice at our last competition which made it always work, but there were times we needed to change it.
If you get a chance please let me know if you see anything
public void robotInit() {
RobotMap.init();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
driveTrain = new DriveTrain();
ballArm = new BallArm();
pneumaticArm = new PneumaticArm();
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
autoChooser = new SendableChooser();
autoChooser.addDefault("Do Nothing 15 sec", new DoNothing(15));
autoChooser.addObject("Front of low bar", new AutoFrontOfLowBarGroup());
autoChooser.addObject("BW Front of low bar", new AutoFrontOfLowBarBackwardGroup());
autoChooser.addObject("Drive straight forward", new AutoDriveStraightForwardGroup());
autoChooser.addObject("Turn right in front of low bar", new AutoTurnRightLowBar());
autoChooser.addObject("Custom mode", new AutoCustomGroup());
SmartDashboard.putData("Autonomous mode chooser", autoChooser);
SmartDashboard.putData(Scheduler.getInstance());
RobotMap.pneumaticArmCompressor.setClosedLoopContr ol(true);
//autonomousCommand = new DoNothing();
// OI must be constructed after subsystems. If the OI creates Commands
//(which it very likely will), subsystems are not guaranteed to be
// constructed yet. Thus, their requires() statements may grab null
// pointers. Bad news. Don't move it.
oi = new OI();
// instantiate the command used for the autonomous period
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
// autonomousCommand = new LookBothWays();
new DisplayDashboard();
}
/**
* This function is called when the disabled button is hit.
* You can use it to reset subsystems before shutting down.
*/
public void disabledInit(){
}
public void disabledPeriodic() {
Scheduler.getInstance().run();
}
public void autonomousInit() {
// schedule the autonomous command (example)
autonomousCommand = (Command) autoChooser.getSelected();
if (autonomousCommand !=null) autonomousCommand.start();
SmartDashboard.putData(Scheduler.getInstance());
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic()
{
SmartDashboard.putData(Scheduler.getInstance());
Scheduler.getInstance().run();
}
|
Nothing jumps out at me but then again I am not familiar with Command based code. When you said it doesn't work very well, what were the issues/symptoms? Did you get a null back when calling getSelected()? Did you get an exception? What is the exact failure? From the SmartDashboard and SendableChooser's point of view, that should work. However, one major difference between your code and ours is that we only "newing" an auto strategy when it is selected whereas you are newing all your strategies (commands) and added them to the chooser. There shouldn't be anything wrong with it but I am just trying to figure out if the problem lies in the command based code. Again, I am not familiar with command-based code, but depends on what failure you were seeing, you may want to look at it from a different angle.