Launcher Wheels

<< Jaguar Coding | FRC | >> To make subtile adjustments, this scheme has one throttle adjust the overall speed, and the other throttle the top spin or back spin

OI

Here we make two public methods to get the current throttle position, along with a upDateStatus to see current values

public class OI 
{
    Joystick stick1 = new Joystick(1);
    Joystick stick2 = new Joystick(2);

    Button trigger = new JoystickButton(stick1, 1);//Trigger is button 1
    Button button3 = new JoystickButton(stick1, 3);
    Button button4 = new JoystickButton(stick1, 4);
    public OI()
    {
    		trigger.whenPressed(new Launch());
    		button3.whenPressed(new LauncherWheelsOn());
    		button4.whenPressed(new LauncherWheelsOff());   		
    }
    public double getThrottle1(){
    		return stick1.getThrottle();
    }
    public double getThrottle2(){
    		return stick2.getThrottle();
    }
    public void updateStatus(){

	    // to see values on the smartDashboard do this:
    	    // and add to the teleopPeriodic() method a call:
    	    //  if (CommandBase.io!=null) io.updateStatus();
		SmartDashboard.putDouble("Throttle 1:", getThrottle1());	
		SmartDashboard.putDouble("Throttle 2:", getThrottle2());	
	}

}

RobotMap

public class RobotMap 
{
	public static final int lancherArmMotor = 7;//Jag 7
	public static final int topLaunchMotor = 3;//Jag
	public static final int bottomLaunchMotor = 4;//Jag
	public static final int leftDriveMotor = 1;//Jag
	public static final int rightDriveMotor = 2;//Jag
	public static final int bridgeArmMotor = 5;//Jag
	public static final int aimingMotor = 6;//Jag
	//Limit Switches
	public static final int LauncherArmSwitchTop = 1;//Digital IO (sig to NO, ground to ground)
	public static final int LauncherArmSwitchBottom = 2;//Digital IO (sig to NO, ground to ground)
	public static final int aimLimitLeft = 3;//Digital IO (sig to NO, ground to ground)
	public static final int aimLimitRight = 4;//Digital IO (sig to NO, ground to ground)
	public static final int bridgeArmTop = 5;//Digital IO (sig to NO, ground to ground)
	public static final int brigeArmBottom = 6;//Digital IO (sig to NO, ground to ground)
}

Subsystem

Before actually trying this, we should read the values of the throttle using the SmartDashboard-- Here I'm presuming that the throttle goes from 0 to 1.

public class Launcher extends Subsystem {
	Jaguar topMotor = new Jaguar(RobotMap.topLaunchMotor);
	Jaguar bottomMotor = new Jaguar(RobotMap.bottomLaunchMotor);

	public void initDefaultCommand() {
		setDefaultCommand(new LauncherWheelsOff());
	}
	public void onEqualSpin(){
		double power= CommandBase.oi.getThrottle1();
		//here I'm assuming 0 is min, and 1.0 is max on the throttle
		topMotor.set(power);
		bottomMotor.set(power);
	}
	public void on(){
		double speed= CommandBase.oi.getThrottle1();
		double spin = CommandBase.oi.getThrottle2();
		//Not sure of the values from the throttle yet,
		//here I'm assuming 0 is min, and 1.0 is max

		// adjust sensitivity with weightingFactor: 
		// less than 1 for more subtle, 
		// greater than 1 for more dramatic, keep under 2, though
		double weightingFactor=1.0;
		double reduction=1.0-weightingFactor*Math.abs(spin-.5)/.5;
		if (reduction<.1)
			reduction=0.1;
		double slowSpeed=speed*reduction;
		if (spin>.5){//top spin
			topMotor.set(speed);
			bottomMotor.set(slowSpeed);
		}else{//back spin
			topMotor.set(slowSpeed);
			bottomMotor.set(speed);
		}
	}
	public void off(){
		topMotor.set(0);
		bottomMotor.set(0);
	}

}

Command: LauncherWheelsOff

public class LauncherWheelsOff extends CommandBase {
	public LauncherWheelsOff(){
		requires(launcher);
	}
	public void initialize() {}

	public void execute() {
		launcher.off();
	}

	public boolean isFinished() {
		return false;
	}

	public void end() {}

	public void interrupted() {}

}

Command: LauncherWheelsOn

public class LauncherWheelsOn extends CommandBase {
	public LauncherWheelsOn(){
		requires(launcher);
	}
	public void initialize() {}

	public void execute() {
		//launcher.on();//for spin
		launcher.onEqualSpin();// for no spin control
	}

	public boolean isFinished() {
		return false;
	}

	public void end() {}

	public void interrupted() {}

}

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 Launcher launcher = new Launcher();

    public static void init() {

        oi = new OI();
       // Show what command your subsystem is running on the SmartDashboard
        SmartDashboard.putData(launcherArm);
        SmartDashboard.putData(launcher);
    }

    public CommandBase(String name) {
        super(name);
    }

    public CommandBase() {
        super();
    }
}