Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subsystems/SolenoidSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public SolenoidSubsystem(DoubleSolenoid... solenoids) {
}

/**
* DoubleSolenoid.Value simplified to three simple states
* DoubleSolenoid.Value simplified to three simple states. Never use the state
* OFF
*/
public enum SolenoidState {
OFF(DoubleSolenoid.Value.kOff), EXTEND(DoubleSolenoid.Value.kForward), RETRACT(DoubleSolenoid.Value.kReverse);
Expand Down
102 changes: 5 additions & 97 deletions subsystems/chassis/SolenoidShifters.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package org.usfirst.frc4904.standard.subsystems.chassis;

import org.usfirst.frc4904.standard.subsystems.SolenoidSubsystem;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

/**
* A class that wraps multiple DoubleSolenoid objects with subsystem
* functionality. Allows for easy inversion and setting of default state of
* solenoids
*/
public class SolenoidShifters extends SubsystemBase { // TODO: make solenoidshifters extend solenoidsubsystem
protected DoubleSolenoid[] solenoids;
protected SolenoidState state;
protected SolenoidState defaultState;
protected boolean isInverted;
public class SolenoidShifters extends SolenoidSubsystem {

/**
* A class that wraps multiple DoubleSolenoid objects with subsystem
Expand All @@ -24,12 +21,9 @@ public class SolenoidShifters extends SubsystemBase { // TODO: make solenoidshif
* @param defaultState Set the default state of the SolenoidSystem
* @param solenoids Double solenoids of the system
*/

public SolenoidShifters(String name, boolean isInverted, SolenoidState defaultState, DoubleSolenoid... solenoids) {
setName(name);
this.solenoids = solenoids;
this.isInverted = isInverted;
this.defaultState = defaultState;
this.state = defaultState;
super(name, isInverted, defaultState, solenoids);
}

/**
Expand Down Expand Up @@ -105,61 +99,6 @@ public SolenoidShifters(DoubleSolenoid... solenoids) {
this("SolenoidShifters", solenoids);
}

/**
* DoubleSolenoid.Value simplified to three simple states
*/
public enum SolenoidState {
EXTEND(DoubleSolenoid.Value.kForward), RETRACT(DoubleSolenoid.Value.kReverse);

public final DoubleSolenoid.Value value;

private SolenoidState(DoubleSolenoid.Value value) {
this.value = value;
}
}

/**
* @param state Returns the current state of the system
*/
public SolenoidState getState() {
return state;
}

/**
* Inverts the state given
*
* @param state SolenoidState to be inverted
* @return SolenoidState Inverted state
*
*/
public SolenoidState invertState(SolenoidState state) {
switch (state) {
case EXTEND:
return SolenoidState.RETRACT;
case RETRACT:
return SolenoidState.EXTEND;
}
return state;
}

/**
* Sets the state of the system Only sets if current state is not equal to state
* to be set
*
* @param state State to set system
*/
public void set(SolenoidState state) {
if (isInverted) {
state = invertState(state);
}
this.state = state;
if (this.state != state) {
for (DoubleSolenoid solenoid : solenoids) {
solenoid.set(state.value);
}
}
}

/**
* Sets the state of the system Only sets if current state is not equal to state
* to be set
Expand All @@ -176,35 +115,4 @@ public void set() { // TODO: consider OFF case
set(SolenoidState.RETRACT);
}
}

/**
* Sets the state of the system regardless of current state
*
* @param state State to set
*/
public void setOverride(SolenoidState state) {
if (isInverted) {
state = invertState(state);
}
this.state = state;
for (DoubleSolenoid solenoid : solenoids) {
solenoid.set(state.value);
}
}

/**
* @return solenoids DoubleSolenoid objects of the system
*/
public DoubleSolenoid[] getSolenoids() {
return solenoids;
}

/**
* Returns whether the solenoid is extended.
*
* @return extended
*/
public boolean isExtended() {
return solenoids[0].get() == SolenoidState.EXTEND.value;
}
}