Originally Posted by jwakeman
(Post 1360765)
My intent is to be able to have a different set of controls (xbox controller mapping) for the field and for the pit at the flip of a switch. The code below is not tested yet but the idea is to create new Button objects and set their WhenPressed()/WhileHeld() methods each time I want to switch the interface. I have a command that will check the switch as a DigitalInput and reconfigure the interface when needed.
CheckOIConfig.java
Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates.commands;
/**
*
* @author team63
*/
public class CheckOIConfig extends CommandBase {
public CheckOIConfig() {
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
if(throwSwitch1.get() && oi.current_interface == oi.CONFIG_FIELD_INTERFACE)
{
oi.setPitInterface();
}
if(!throwSwitch1.get() && oi.current_interface == oi.CONFIG_PIT_INTERFACE)
{
oi.setFieldInterface();
}
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return true;
}
// Called once after isFinished returns true
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
OI.java:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.templates.command.CommandGroup.GoToCatchPosition;
import edu.wpi.first.wpilibj.templates.command.CommandGroup.GoToGrabPosition;
import edu.wpi.first.wpilibj.templates.command.CommandGroup.GoToShootPosition;
import edu.wpi.first.wpilibj.templates.command.CommandGroup.ShootBall;
import edu.wpi.first.wpilibj.templates.command.CommandGroup.SpitBall;
import edu.wpi.first.wpilibj.templates.commands.ElbowExtend;
import edu.wpi.first.wpilibj.templates.commands.ElbowRetract;
import edu.wpi.first.wpilibj.templates.commands.FeedMotorManual;
import edu.wpi.first.wpilibj.templates.commands.ForkExtend;
import edu.wpi.first.wpilibj.templates.commands.ForkRetract;
import edu.wpi.first.wpilibj.templates.commands.HighDriveCommand;
import edu.wpi.first.wpilibj.templates.commands.HighGear;
import edu.wpi.first.wpilibj.templates.commands.LowGear;
import edu.wpi.first.wpilibj.templates.commands.ShooterDriveOverride;
import edu.wpi.first.wpilibj.templates.commands.ShooterDriveRelease;
import edu.wpi.first.wpilibj.templates.commands.WinchManual;
import edu.wpi.first.wpilibj.templates.commands.WinchPinExtend;
import edu.wpi.first.wpilibj.templates.commands.WinchPinRetract;
import edu.wpi.first.wpilibj.templates.commands.WristExtend;
import edu.wpi.first.wpilibj.templates.commands.WristRetract;
/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
public final int CONFIG_FIELD_INTERFACE = 1;
public final int CONFIG_PIT_INTERFACE = 2;
public int current_interface = CONFIG_FIELD_INTERFACE;
public Joystick stick1 = new Joystick(1);
public Joystick stick2 = new Joystick(2);
public Button stick1_BACK;
public Button stick1_START;
public Button stick1_LEFT_BUMPER;
public Button stick1_RIGHT_BUMPER;
public Button stick1_Y;
public Button stick1_X;
public Button stick1_B;
public Button stick1_A;
public Button stick2_BACK;
public Button stick2_START;
public Button stick2_LEFT_BUMPER;
public Button stick2_RIGHT_BUMPER;
public Button stick2_Y;
public Button stick2_X;
public Button stick2_B;
public Button stick2_A;
public OI()
{
this.setFieldInterface();
}
public final void setFieldInterface()
{
current_interface = CONFIG_FIELD_INTERFACE;
stick1_BACK = new JoystickButton(stick1, RobotMap.XBOX_BACK);
stick1_START = new JoystickButton(stick1, RobotMap.XBOX_START);
stick1_LEFT_BUMPER = new JoystickButton(stick1, RobotMap.XBOX_LEFT_BUMPER);
stick1_RIGHT_BUMPER = new JoystickButton(stick1, RobotMap.XBOX_RIGHT_BUMPER);
stick1_Y = new JoystickButton(stick1, RobotMap.XBOX_Y);
stick1_X = new JoystickButton(stick1, RobotMap.XBOX_X);
stick1_B = new JoystickButton(stick1, RobotMap.XBOX_B);
stick1_A = new JoystickButton(stick1, RobotMap.XBOX_A);
stick2_BACK = new JoystickButton(stick2, RobotMap.XBOX_BACK);
stick2_START = new JoystickButton(stick2, RobotMap.XBOX_START);
stick2_LEFT_BUMPER = new JoystickButton(stick2, RobotMap.XBOX_LEFT_BUMPER);
stick2_RIGHT_BUMPER = new JoystickButton(stick2, RobotMap.XBOX_RIGHT_BUMPER);
stick2_Y = new JoystickButton(stick2, RobotMap.XBOX_Y);
stick2_X = new JoystickButton(stick2, RobotMap.XBOX_X);
stick2_B = new JoystickButton(stick2, RobotMap.XBOX_B);
stick2_A = new JoystickButton(stick2, RobotMap.XBOX_A);
stick1_Y.whenPressed(new GoToGrabPosition());
stick1_X.whenPressed(new GoToShootPosition());
stick1_LEFT_BUMPER.whenPressed(new GoToCatchPosition());
stick1_RIGHT_BUMPER.whileHeld(new HighDriveCommand());
stick2_RIGHT_BUMPER.whileHeld(new ShooterDriveOverride());
stick2_RIGHT_BUMPER.whenReleased(new ShooterDriveRelease());
stick2_B.whenPressed(new ShootBall());
stick2_A.whenPressed(new SpitBall());
}
public final void setPitInterface()
{
current_interface = CONFIG_PIT_INTERFACE;
stick1_BACK = new JoystickButton(stick1, RobotMap.XBOX_BACK);
stick1_START = new JoystickButton(stick1, RobotMap.XBOX_START);
stick1_LEFT_BUMPER = new JoystickButton(stick1, RobotMap.XBOX_LEFT_BUMPER);
stick1_RIGHT_BUMPER = new JoystickButton(stick1, RobotMap.XBOX_RIGHT_BUMPER);
stick1_Y = new JoystickButton(stick1, RobotMap.XBOX_Y);
stick1_X = new JoystickButton(stick1, RobotMap.XBOX_X);
stick1_B = new JoystickButton(stick1, RobotMap.XBOX_B);
stick1_A = new JoystickButton(stick1, RobotMap.XBOX_A);
stick2_BACK = new JoystickButton(stick2, RobotMap.XBOX_BACK);
stick2_START = new JoystickButton(stick2, RobotMap.XBOX_START);
stick2_LEFT_BUMPER = new JoystickButton(stick2, RobotMap.XBOX_LEFT_BUMPER);
stick2_RIGHT_BUMPER = new JoystickButton(stick2, RobotMap.XBOX_RIGHT_BUMPER);
stick2_Y = new JoystickButton(stick2, RobotMap.XBOX_Y);
stick2_X = new JoystickButton(stick2, RobotMap.XBOX_X);
stick2_B = new JoystickButton(stick2, RobotMap.XBOX_B);
stick2_A = new JoystickButton(stick2, RobotMap.XBOX_A);
stick1_LEFT_BUMPER.whenPressed(new LowGear());
stick1_RIGHT_BUMPER.whenPressed(new HighGear());
stick1_X.whenPressed(new ForkRetract());
stick1_B.whenPressed(new ForkExtend());
stick1_Y.whenPressed(new ElbowExtend());
stick1_A.whenPressed(new ElbowRetract());
stick2_BACK.whenPressed(new WinchPinRetract());
stick2_START.whenPressed(new WinchPinExtend());
stick2_LEFT_BUMPER.whileHeld(new FeedMotorManual());
stick2_RIGHT_BUMPER.whileHeld(new WinchManual());
stick2_Y.whenPressed(new WristExtend());
stick2_A.whenPressed(new WristRetract());
}
}
|