Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Switching between Kinect drive / Joystick drive / Autonomous drive (http://www.chiefdelphi.com/forums/showthread.php?t=107859)

F22Rapture 17-08-2012 20:49

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?

Ginto8 19-08-2012 00:07

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();
    }
}

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

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();


Ginto8 19-08-2012 18:06

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.


All times are GMT -5. The time now is 09:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi