Go to Post I think I have a warning label saved somewhere on my computer that says "Warning: All photos taken with this camera may be photoshopped" but I keep forgetting to put it on my camera. - MissInformation [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-08-2012, 20:49
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 19-08-2012, 00:07
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 19-08-2012, 01:12
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 19-08-2012, 18:06
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:49.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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