Jaguar Coding
<< Spike Coding | FRC | Launcher Wheels >>
Looks like using the limit switches directly to the Jaguar violates R62 See referece article so the switches need to be on the digital sidecar.
- One wire from the limit switch goes to signal on a Digital Input on the Digital Sidecar.
- One wire from the limit switch goes to ground on a Digital Input on the Digital Sidecar.
These are the outside wires of the 3 pin connector on the sidecar (Choose 1-14). On the switch side, you connect the center (-) and either the NO (Normally Open) or NC Normally Closed. In software, we can get either true or a false, and act accordingly.... For the bridgeArm or the LauncherArm, we can write a command that executes and ends when a switch is activated. For the aimMotor, we can use the switch as a safety , so It won't go if the switch is pressed.
RobotMap
public class RobotMap { public static final int lancherArmMotor = 7;//Jag 7 public static final int LaucherArmSwitchTop = 1;//Digital IO (sig to NO, ground to ground) public static final int LaucherArmSwitchBottom = 2;//Digital IO (sig to NO, ground to ground) }
Subsystem
public class LauncherArm extends Subsystem { Jaguar arm = new Jaguar(RobotMap.lancherArmMotor); DigitalInput upLimit = new DigitalInput(RobotMap.LaucherArmSwitchTop); DigitalInput downLimit = new DigitalInput(RobotMap.LaucherArmSwitchBottom); public static final double speed=0.5; // 1.0=100% of 12 V public void initDefaultCommand() { setDefaultCommand(new LauncherArmDoNothing()); } public void stop(){ arm.set(0); } public void safelyUp(){ if (!upLimit.get()) //if Normally Open arm.set(speed); } public void safelyDown(){ if (!downLimit.get()) //if Normally Open arm.set(-1.0*speed); } public void up(){ arm.set(speed); } public void down(){ arm.set(-1.0*speed); } public boolean isUp(){ return upLimit.get(); } public boolean isDown(){ return downLimit.get(); } }
CommandBase
public abstract class CommandBase extends Command { public static OI oi; // Create a single static instance of all of your subsystems public static LauncherArm launcherArm = new LauncherArm(); public static void init() { oi = new OI(); // Show what command your subsystem is running on the SmartDashboard SmartDashboard.putData(launcherArm); } public CommandBase(String name) { super(name); } public CommandBase() { super(); } }
Command: LauncherArmDoNothing
This is the default Command of the LaucherArm subsystem.
public class LauncherArmDoNothing extends CommandBase { public LauncherArmDoNothing(){ requires(launcherArm); } public void initialize() {} public void execute() { launcherArm.stop(); } public boolean isFinished() { return false; } public void end() {} public void interrupted() {} }
Command: LauncherArmWait
This is a command that will pause the launcherArm for a specified time, to be used by a Command Group, so the arm can remain in the current position long enough for the ball to be grabbed by the launcherLoader belts.
public class LauncherArmWait extends CommandBase { public LauncherArmWait(double time){ requires(launcherArm); this.setTimeout(time); // time in seconds } public void initialize() {} public void execute() { launcherArm.stop(); } public boolean isFinished() { return this.isTimedOut(); } public void end() {} public void interrupted() {} }
Command: LauncherArmUp
public class LauncherArmUp extends CommandBase { public LauncherArmUp(){ requires(launcherArm); } public void initialize() {} public void execute() { // unconditionally go up: launcherArm.up(); // or if the switch is ok: //launcherArm.safelyUp(); } public boolean isFinished() { return launcherArm.isUp(); } public void end() {} public void interrupted() {} }
Command: LauncherArmDown
public class LauncherArmDown extends CommandBase { public LauncherArmDown(){ requires(launcherArm); } public void initialize() {} public void execute() { // unconditionally go down: launcherArm.down(); // or if the switch is ok: //launcherArm.safelyDown(); } public boolean isFinished() { return launcherArm.isDown(); } public void end() {} public void interrupted() {} }
CommandGroup: Launch
public class Launch extends CommandGroup { public Launch() { addSequential(new LauncherArmUp()); addSequential(new LauncherArmWait(.5));//pause at the top addSequential(new LauncherArmDown()); } }
OI
public class OI { Joystick stick1 = new Joystick(1); Button trigger = new JoystickButton(stick1, 1);//Trigger is button 1 public OI() { trigger.whenPressed(new Launch()); } }