Skip to content

Commit

Permalink
Have TriggerButton take a throttle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gleason committed Jun 28, 2017
1 parent e8e2f03 commit 17f4018
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.usfirst.frc.team449.robot.components.MappedJoystick;
import org.usfirst.frc.team449.robot.components.MappedSmoothedThrottle;
import org.usfirst.frc.team449.robot.components.MappedThrottle;

/**
* A factory for constructing a button..
Expand Down Expand Up @@ -42,7 +44,7 @@ public static FactoryButton constructButton(@NotNull @JsonProperty(required = tr
@Nullable Double triggerAt,
@Nullable Integer angle) {
if (triggerAxis != null) {
return new TriggerButton(joystick, triggerAxis, triggerAt);
return new TriggerButton(new MappedThrottle(joystick, triggerAxis, false), triggerAt);
} else if (angle != null) {
return new dPadButton(joystick, angle);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public class FactoryJoystickButton extends FactoryButton {
/**
* The port of the button on the joystick.
*/
private final int buttonNum;
private final int buttonNumber;

/**
* Default constructor.
*
* @param joystick The joystick the button is on.
* @param buttonNum The port of the button. Note that button numbers begin at 1, not 0.
* @param buttonNumber The port of the button. Note that button numbers begin at 1, not 0.
*/
@JsonCreator
public FactoryJoystickButton(@NotNull @JsonProperty(required = true) MappedJoystick joystick,
@JsonProperty(required = true) int buttonNum) {
@JsonProperty(required = true) int buttonNumber) {
this.joystick = joystick;
this.buttonNum = buttonNum;
this.buttonNumber = buttonNumber;
}

/**
Expand All @@ -45,6 +45,6 @@ public FactoryJoystickButton(@NotNull @JsonProperty(required = true) MappedJoyst
*/
@Override
public boolean get() {
return joystick.getRawButton(buttonNum);
return joystick.getRawButton(buttonNumber);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.usfirst.frc.team449.robot.oi.buttons;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.jetbrains.annotations.NotNull;
import org.usfirst.frc.team449.robot.components.MappedJoystick;
import org.usfirst.frc.team449.robot.components.MappedSmoothedThrottle;
import org.usfirst.frc.team449.robot.components.MappedThrottle;

/**
Expand All @@ -28,14 +27,13 @@ public class TriggerButton extends FactoryButton {
/**
* Argument-based constructor.
*
* @param joystick The the joystick containing the throttle.
* @param axis The axis of the throttle.
* @param throttle The relevant throttle.
* @param triggerAt The percentage pressed to trigger at, from (0, 1]
*/
public TriggerButton(@NotNull @JsonProperty(required = true) MappedJoystick joystick,
@JsonProperty(required = true) int axis,
@JsonCreator
public TriggerButton(@NotNull @JsonProperty(required = true) MappedThrottle throttle,
@JsonProperty(required = true) double triggerAt) {
throttle = new MappedSmoothedThrottle(joystick, axis, 0, 0, false);
this.throttle = throttle;
this.triggerAt = triggerAt;
}

Expand Down
57 changes: 33 additions & 24 deletions RoboRIO/src/main/resources/calcifer_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ nonMPAutoCommand:
drive
buttons:
- button:
org.usfirst.frc.team449.robot.oi.buttons.dPadButton:
org.usfirst.frc.team449.robot.oi.buttons.dPadButton:
'@id': switchToLowButton
joystick:
'@id': gunnerGamepad
Expand All @@ -433,7 +433,7 @@ buttons:
drive
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.dPadButton:
org.usfirst.frc.team449.robot.oi.buttons.dPadButton:
'@id': switchToHighButton
joystick:
gunnerGamepad
Expand All @@ -446,7 +446,7 @@ buttons:
drive
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
'@id': overrideNavXButton
joystick:
gunnerGamepad
Expand All @@ -460,7 +460,7 @@ buttons:
drive
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
overrideNavXButton
command:
org.usfirst.frc.team449.robot.interfaces.subsystem.NavX.commands.OverrideNavX:
Expand All @@ -471,7 +471,7 @@ buttons:
drive
action: WHEN_RELEASED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
'@id': jiggleRobotButton
joystick:
gunnerGamepad
Expand All @@ -491,11 +491,14 @@ buttons:
drive
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
'@id': climbButton
joystick:
driverGamepad
triggerAxis: 2
throttle:
org.usfirst.frc.team449.robot.components.MappedThrottle:
'@id': climbButtonThrottle
stick:
driverGamepad
axis: 2
triggerAt: 0.9
command:
org.usfirst.frc.team449.robot.mechanism.climber.commands.RunMotorWhileConditonMet:
Expand All @@ -505,7 +508,7 @@ buttons:
climber
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
climbButton
command:
org.usfirst.frc.team449.robot.interfaces.subsystem.binaryMotor.commands.TurnMotorOffWithRequires:
Expand All @@ -515,7 +518,7 @@ buttons:
climber
action: WHEN_RELEASED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
'@id': manualClimbButton
joystick:
gunnerGamepad
Expand All @@ -528,14 +531,14 @@ buttons:
climber
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
manualClimbButton
command:
org.usfirst.frc.team449.robot.interfaces.subsystem.binaryMotor.commands.TurnMotorOffWithRequires:
stopClimbCommand
action: WHEN_RELEASED
- button:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
'@id': switchCameraButton
joystick:
gunnerGamepad
Expand All @@ -548,19 +551,22 @@ buttons:
cameras
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
'@id': pushGearButton
joystick:
driverGamepad
triggerAxis: 3
throttle:
org.usfirst.frc.team449.robot.components.MappedThrottle:
'@id': pushGearThrottle
stick:
driverGamepad
axis: 3
triggerAt: 0.9
command:
org.usfirst.frc.team449.robot.interfaces.subsystem.solenoid.commands.SolenoidReverse:
<<: *openGearHandler
'@id': openGearHandlerCommand
action: WHEN_PRESSED
- button:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
pushGearButton
command:
org.usfirst.frc.team449.robot.interfaces.subsystem.solenoid.commands.SolenoidForward:
Expand All @@ -570,7 +576,7 @@ buttons:
gearHandler
action: WHEN_RELEASED
# - button:
# org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
# org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
# '@id': fireShooterButton
# joystick:
# gunnerGamepad
Expand All @@ -583,11 +589,14 @@ buttons:
# shooter
# action: WHEN_PRESSED
# - button:
# org.usfirstfirst.frc.team449.robot.oi.buttons.TriggerButton:
# org.usfirstfirst.frc.team449.robot.oi.buttons.TriggerButton:
# '@id': rackShooterButton
# joystick:
# gunnerGamepad
# triggerAxis: 3
# throttle:
# '@id': rackShooterThrottle
# org.usfirst.frc.team449.robot.components.MappedThrottle:
# stick:
# gunnerGamepad
# axis: 3
# triggerAt: 0.9
# command:
# org.usfirst.frc.team449.robot.mechanism.topcommands.shooter.RackShooter:
Expand All @@ -597,7 +606,7 @@ buttons:
# shooter
# action: WHEN_PRESSED
# - button:
# org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
# org.usfirst.frc.team449.robot.oi.buttons.FactoryJoystickButton:
# '@id': resetShooterButton
# joystick:
# gunnerGamepad
Expand Down

0 comments on commit 17f4018

Please sign in to comment.