View Full Version : Switching between Kinect drive / Joystick drive / Autonomous drive
F22Rapture
17-08-2012, 20:49
Currently I have a command for each of them (TeleopCommand, KinectCommand, AutonomousCommand) but I'm not sure how to tell it to use Kinect as opposed to Autonomous (ie. switching between the 2), or end either of them when Teleop starts.
What would be the best way to accomplish this? A switch on the SmartDashboard?
public class Robot extends IterativeRobot {
Scheduler scheduler;
Command autonomousCommand,teleopCommand;
public void robotInit() {
scheduler = Scheduler.getInstance();
CommandBase.init();
autonomousCommand = new AutonomousCommand();
teleopCommand = new TeleopCommand();
}
public void autonomousInit() {
teleopCommand.cancel();
autonomousCommand.start();
}
public void autonomousPeriodic() {
scheduler.run();
}
public void teleopInit() {
autonomousCommand.cancel();
teleopCommand.start();
}
public void teleopPeriodic() {
scheduler.run();
}
public void disabledInit() {
teleopCommand.cancel();
autonomousCommand.cancel();
}
}
This will cause teleopCommand to run only during teleop, autonomousCommand in only autonomous, and neither in disabled. AutonomousCommand and TeleopCommand can be defined by you or changed to whatever you want, as long as they inherit Command.
F22Rapture
19-08-2012, 01:12
Thanks, I'll try it out when I get a chance.
Here's my "switch" code, though I'm not sure whether it's going to work.
Command autonomousCommand, teleopCommand;
DriverStation driverstation = DriverStation.getInstance();
Messager msg = new Messager();
OI kinectSwitch = new OI();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
// instantiate the command used for the autonomous period
msg.printLn("Initializing Robot");
if(kinectSwitch.getKinectStatus()) {
autonomousCommand = new KinectCommand();
} else {
autonomousCommand = new AutonomousCommand();
}
teleopCommand = new TeleopCommand();
AxisCamera camera = AxisCamera.getInstance();
camera.writeMaxFPS(18);
SmartDashboard.putData(Scheduler.getInstance());
msg.printLn("Robot Initialized");
// Initialize all subsystems
CommandBase.init();
}
From OI.java:
InternalButton kinectButton = new InternalButton();
.............
public boolean getKinectStatus() {
return kinectButton.get();
}
.............
public OI(){
SmartDashboard.putData("Enable Kinect", kinectButton);
}
(EDIT)
I've been looking at an alternate way of doing it via the "sendableChooser" method of SmartDashboard.
NetworkTable.initialize();
SendableChooser autonomousSwitch = new SendableChooser();
autonomousSwitch.addDefault("Default autonomous", new AutonomousCommand());
autonomousSwitch.addObject("Kinect hybrid", new KinectCommand());
SmartDashboard.putData("Kinect Switch", autonomousSwitch);
autonomousCommand = (Command) autonomousSwitch.getSelected();
The SendableChooser idea is a good one, I think. I'd also recommend moving the selection to autonomousInit(), so that you can choose the autonomous mode before each run. In robotInit(), it gets decided when the robot turns on, and never again.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.