Skip to content

Commit

Permalink
Correct suggestions from #12
Browse files Browse the repository at this point in the history
- Fixed elevator code based on comments from #12
- Implemented limit switches as emergency stops
- Mapped commands to Joystick buttons
  • Loading branch information
samuelpiltch committed Feb 15, 2018
1 parent bed8733 commit 3bfa84e
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ hs_err_pid*

.idea/*

bin/
wpilib/
1 change: 0 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


# Samuel Piltch - Elevator
/src/org/usfirst/frc/team334/robot/subsystems/Drive.java @samuelpiltch
/src/org/usfirst/frc/team334/robot/subsystems/Elevator.java @samuelpiltch

/src/org/usfirst/frc/team334/robot/commands/Elevator @samuelpiltch
Expand Down
Binary file modified bin/org/usfirst/frc/team334/robot/OI.class
Binary file not shown.
Binary file modified bin/org/usfirst/frc/team334/robot/subsystems/elevator.class
Binary file not shown.
21 changes: 14 additions & 7 deletions src/org/usfirst/frc/team334/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ public class Constants {
*/

public static final int SWITCH_GEAR_CONTROL = 0;
public static final int ELEVATOR_CONTROL = 1;

// Button mappings. The controller device for each button is set above.
public static final int SWITCH_GEAR_BUTTON = 1;


public static final int ELEVATOR_TO_SWITCH_BUTTON = 2;
public static final int ELEVATOR_TO_SCALE_BUTTON = 3;
public static final int ELEVATOR_TO_EXCHANGE_BUTTON = 4;
public static final int COLLAPSE_ELEVATOR_BUTTON = 5;

// Motors
public static final int DRIVETRAIN_LEFT = 0;
public static final int DRIVETRAIN_RIGHT = 1;
Expand All @@ -35,14 +41,14 @@ public class Constants {
public static final int FORCE_COMPRESSOR_BUTTON = 2;

// Elevator
public static final int ELEVATOR_MOTOR_LEFT = 6;
public static final int ELEVATOR_MOTOR_RIGHT = 7;
public static final int ELEVATOR_MOTOR_LEFT = -1;
public static final int ELEVATOR_MOTOR_RIGHT = -1;

// Elevator Sensors (Limit Switches + Encoder)
public static final int ELEVATOR_LIMIT_TOP = 0;
public static final int ELEVATOR_LIMIT_BOTTOM = 2;
public static final int ELEVATOR_ENCODER_A = 4;
public static final int ELEVATOR_ENCODER_B = 5;
public static final int ELEVATOR_LIMIT_TOP = -1;
public static final int ELEVATOR_LIMIT_BOTTOM = -1;
public static final int ELEVATOR_ENCODER_A = -1;
public static final int ELEVATOR_ENCODER_B = -1;
// Elevator PID
public static final double ELEVATOR_P = 0;
public static final double ELEVATOR_I = 0;
Expand All @@ -51,6 +57,7 @@ public class Constants {
public static final int ELEVATOR_SWITCH = 5;
public static final int ELEVATOR_SCALE = 5;
public static final int ELEVATOR_EXCHANGE = 5;
public static final int ELEVATOR_BOTTOM = 5;

// Ultrasonics
public static final int ULTRASONIC_L_DRIVETRAIN_PING = 0;
Expand Down
17 changes: 15 additions & 2 deletions src/org/usfirst/frc/team334/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.util.Arrays;

import org.usfirst.frc.team334.robot.commands.Drivetrain.ToggleTransmissionCommand;
import org.usfirst.frc.team334.robot.commands.Elevator.CollapseElevatorCommand;
import org.usfirst.frc.team334.robot.commands.Elevator.SetElevatorToExchangeCommand;
import org.usfirst.frc.team334.robot.commands.Elevator.SetElevatorToScaleCommand;
import org.usfirst.frc.team334.robot.commands.Elevator.SetElevatorToSwitchCommand;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
Expand All @@ -24,14 +28,23 @@ public OI() {
leftJoystick = new Joystick(Constants.JOYSTICK_LEFT);
rightJoystick = new Joystick(Constants.JOYSTICK_RIGHT);
xbox = new XboxController(Constants.XBOX);
controls = new ArrayList<>(
Arrays.asList(leftJoystick, rightJoystick, xbox));
controls = new ArrayList<>(Arrays.asList(leftJoystick, rightJoystick, xbox));

// Init Buttons
Button shiftGears = new JoystickButton(controls.get(Constants.SWITCH_GEAR_CONTROL), Constants.SWITCH_GEAR_BUTTON);

Button raiseElevatorToSwitch = new JoystickButton(controls.get(Constants.ELEVATOR_CONTROL), Constants.ELEVATOR_TO_SWITCH_BUTTON);
Button raiseElevatorToScale = new JoystickButton(controls.get(Constants.ELEVATOR_CONTROL), Constants.ELEVATOR_TO_SCALE_BUTTON);
Button raiseElevatorToExchange = new JoystickButton(controls.get(Constants.ELEVATOR_CONTROL), Constants.ELEVATOR_TO_EXCHANGE_BUTTON);
Button collapseElevator = new JoystickButton(controls.get(Constants.ELEVATOR_CONTROL), Constants.COLLAPSE_ELEVATOR_BUTTON);

// Button Actions
shiftGears.whenPressed(new ToggleTransmissionCommand());

raiseElevatorToSwitch.whenPressed(new SetElevatorToSwitchCommand());
raiseElevatorToScale.whenPressed(new SetElevatorToScaleCommand());
raiseElevatorToExchange.whenPressed(new SetElevatorToExchangeCommand());
collapseElevator.whenPressed(new CollapseElevatorCommand());
}

public Joystick getLeftJoystick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.usfirst.frc.team334.robot.commands.Elevator;

import org.usfirst.frc.team334.robot.Constants;
import org.usfirst.frc.team334.robot.Robot;

import edu.wpi.first.wpilibj.command.Command;
Expand All @@ -15,13 +16,18 @@ public CollapseElevatorCommand() {
@Override
protected void initialize() {
System.out.println("COLLAPSING ELEVATOR");

Robot.sElevator.setSetpoint(Constants.ELEVATOR_BOTTOM);
Robot.sElevator.enable();
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.sElevator.setSetpoint(0);
Robot.sElevator.enable();
// End command if either limit switches are triggered.
if (Robot.sElevator.getTopLimitSwitch() || Robot.sElevator.getBottomLimitSwitch()) {
end();
}
}

// Make this return true when this Command no longer needs to run execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public SetElevatorToExchangeCommand() {
@Override
protected void initialize() {
System.out.println("MOVING ELEVATOR TO EXCHANGE POSITION");

Robot.sElevator.setSetpoint(Constants.ELEVATOR_EXCHANGE);
Robot.sElevator.enable();
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.sElevator.setSetpoint(Constants.ELEVATOR_EXCHANGE);
Robot.sElevator.enable();
// End command if either limit switches are triggered.
if (Robot.sElevator.getTopLimitSwitch() || Robot.sElevator.getBottomLimitSwitch()) {
end();
}
}

// Make this return true when this Command no longer needs to run execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public SetElevatorToScaleCommand() {
@Override
protected void initialize() {
System.out.println("MOVING ELEVATOR TO SCALE POSITION");

Robot.sElevator.setSetpoint(Constants.ELEVATOR_SCALE);
Robot.sElevator.enable();
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.sElevator.setSetpoint(Constants.ELEVATOR_SCALE);
Robot.sElevator.enable();
// End command if either limit switches are triggered.
if (Robot.sElevator.getTopLimitSwitch() || Robot.sElevator.getBottomLimitSwitch()) {
end();
}
}

// Make this return true when this Command no longer needs to run execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ public SetElevatorToSwitchCommand() {
@Override
protected void initialize() {
System.out.println("MOVING ELEVATOR TO SWITCH POSITION");

Robot.sElevator.setSetpoint(Constants.ELEVATOR_SWITCH);
Robot.sElevator.enable();
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.sElevator.setSetpoint(Constants.ELEVATOR_SWITCH);
Robot.sElevator.enable();
// End command if either limit switches are triggered.
if (Robot.sElevator.getTopLimitSwitch() || Robot.sElevator.getBottomLimitSwitch()) {
end();
}
}

// Make this return true when this Command no longer needs to run execute()
Expand Down
8 changes: 4 additions & 4 deletions src/org/usfirst/frc/team334/robot/subsystems/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public Elevator() {
rElevatorEncoder = new Encoder(Constants.ELEVATOR_ENCODER_A, Constants.ELEVATOR_ENCODER_B);

this.disable();
this.setAbsoluteTolerance(0);
this.setOutputRange(-1, 0);
this.setAbsoluteTolerance(5);
this.setOutputRange(-1, 1);
}

public void setMotors(double speed) {
Expand All @@ -50,8 +50,8 @@ protected double returnPIDInput() {

@Override
protected void usePIDOutput(double output) {
// System.out.println("Error: " + output + "Encoder Value: " + rElevatorEncoder.get());
setMotors(output);
// System.out.println("Error: " + output + "Encoder Value: " + rElevatorEncoder.get());
setMotors(output * .1);
}

public boolean getTopLimitSwitch() {
Expand Down

0 comments on commit 3bfa84e

Please sign in to comment.