|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Switching between Kinect drive / Joystick drive / Autonomous drive
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? Last edited by F22Rapture : 17-08-2012 at 21:32. |
|
#2
|
||||
|
||||
|
Re: Switching between Kinect drive / Joystick drive / Autonomous drive
Code:
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();
}
}
|
|
#3
|
||||
|
||||
|
Re: Switching between Kinect drive / Joystick drive / Autonomous drive
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. Code:
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: Code:
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. Code:
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();
Last edited by F22Rapture : 19-08-2012 at 12:52. |
|
#4
|
||||
|
||||
|
Re: Switching between Kinect drive / Joystick drive / Autonomous drive
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|