-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
604 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 39 additions & 39 deletions
78
src/main/java/com/robototes/logging/shuffleboard/AbstractValueConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
package com.robototes.logging.shuffleboard; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A template for all value configurables (Double, String, etc.) | ||
* | ||
* @author Eli Orona | ||
* | ||
* @param <T> The type of the data | ||
* @param <S> Self | ||
*/ | ||
public abstract class AbstractValueConfigurable<T, S extends AbstractValueConfigurable<T, S>> | ||
extends AbstractReporter<T, S> implements IConfigurable<T, S> { | ||
|
||
/** | ||
* The setter for the widget | ||
*/ | ||
protected Consumer<T> setter; | ||
|
||
/** | ||
* | ||
* @param getter The supplier of data | ||
* @param setter The user of the data | ||
* @param name The name of the widget | ||
* @param tabName The tab of the widget | ||
*/ | ||
public AbstractValueConfigurable(Supplier<T> getter, Consumer<T> setter, String name, String tabName) { | ||
super(getter, name, tabName); | ||
this.setter = setter; | ||
} | ||
|
||
@Override | ||
public Consumer<T> getSetter() { | ||
return setter; | ||
} | ||
|
||
} | ||
package com.robototes.logging.shuffleboard; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A template for all value configurables (Double, String, etc.) | ||
* | ||
* @author Eli Orona | ||
* | ||
* @param <T> The type of the data | ||
* @param <S> Self | ||
*/ | ||
public abstract class AbstractValueConfigurable<T, S extends AbstractValueConfigurable<T, S>> | ||
extends AbstractReporter<T, S> implements IConfigurable<T, S> { | ||
|
||
/** | ||
* The setter for the widget | ||
*/ | ||
protected Consumer<T> setter; | ||
|
||
/** | ||
* | ||
* @param getter The supplier of data | ||
* @param setter The user of the data | ||
* @param name The name of the widget | ||
* @param tabName The tab of the widget | ||
*/ | ||
public AbstractValueConfigurable(Supplier<T> getter, Consumer<T> setter, String name, String tabName) { | ||
super(getter, name, tabName); | ||
this.setter = setter; | ||
} | ||
|
||
@Override | ||
public Consumer<T> getSetter() { | ||
return setter; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.robototes.motors; | ||
|
||
public interface Motor { | ||
|
||
public void set(double speed); | ||
|
||
public double get(); | ||
|
||
public void setInverted(boolean inverted); | ||
|
||
public boolean getInverted(); | ||
|
||
public void setP(double value); | ||
|
||
public void setI(double value); | ||
|
||
public void setD(double value); | ||
|
||
public void setF(double value); | ||
|
||
} |
238 changes: 31 additions & 207 deletions
238
src/main/java/com/robototes/motors/RobototesCANSparkMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,207 +1,31 @@ | ||
package com.robototes.motors; | ||
|
||
import com.revrobotics.AlternateEncoderType; | ||
import com.revrobotics.CANAnalog; | ||
import com.revrobotics.CANAnalog.AnalogMode; | ||
import com.revrobotics.CANDigitalInput; | ||
import com.revrobotics.CANDigitalInput.LimitSwitchPolarity; | ||
import com.revrobotics.CANEncoder; | ||
import com.revrobotics.CANError; | ||
import com.revrobotics.CANPIDController; | ||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.EncoderType; | ||
|
||
/** | ||
* Note: This is to be used for testing only, and the class cannot be mocked | ||
* | ||
* @author Eli Orona | ||
* | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class RobototesCANSparkMax extends CANSparkMax { | ||
|
||
private boolean isInSim = false; | ||
|
||
private boolean isInverted; | ||
|
||
private IdleMode mode; | ||
|
||
private double speed; | ||
|
||
private double voltage; | ||
|
||
public RobototesCANSparkMax(int deviceID, MotorType type) { | ||
super(deviceID, type); | ||
} | ||
|
||
public RobototesCANSparkMax(int deviceID, MotorType type, boolean isInSim) { | ||
super(deviceID, type); | ||
this.isInSim = isInSim; | ||
} | ||
|
||
@Override | ||
public CANError follow(CANSparkMax leader) { | ||
// TODO Auto-generated method stub | ||
return super.follow(leader); | ||
} | ||
|
||
@Override | ||
public CANError follow(CANSparkMax leader, boolean invert) { | ||
// TODO Auto-generated method stub | ||
return super.follow(leader, invert); | ||
} | ||
|
||
@Override | ||
public CANError follow(ExternalFollower leader, int deviceID) { | ||
// TODO Auto-generated method stub | ||
return super.follow(leader, deviceID); | ||
} | ||
|
||
@Override | ||
public CANError follow(ExternalFollower leader, int deviceID, boolean invert) { | ||
// TODO Auto-generated method stub | ||
return super.follow(leader, deviceID, invert); | ||
} | ||
|
||
@Override | ||
public double get() { | ||
if (isInSim) { | ||
return speed; | ||
} | ||
return super.get(); | ||
} | ||
|
||
@Override | ||
public CANEncoder getAlternateEncoder(AlternateEncoderType sensorType, int counts_per_rev) { | ||
if (isInSim) { | ||
return null; | ||
} | ||
return super.getAlternateEncoder(sensorType, counts_per_rev); | ||
} | ||
|
||
@Override | ||
public CANAnalog getAnalog(AnalogMode mode) { | ||
if (isInSim) { | ||
return null; | ||
} | ||
return super.getAnalog(mode); | ||
} | ||
|
||
@Override | ||
public CANEncoder getEncoder(EncoderType sensorType, int counts_per_rev) { | ||
if (isInSim) { | ||
return null; | ||
} | ||
|
||
return super.getEncoder(sensorType, counts_per_rev); | ||
} | ||
|
||
@Override | ||
public CANDigitalInput getForwardLimitSwitch(LimitSwitchPolarity polarity) { | ||
if (isInSim) { | ||
return null; | ||
} | ||
return super.getForwardLimitSwitch(polarity); | ||
} | ||
|
||
@Override | ||
public IdleMode getIdleMode() { | ||
if (isInSim) { | ||
return mode; | ||
} | ||
return super.getIdleMode(); | ||
} | ||
|
||
// private int stallLimit; | ||
// private int freeLimit; | ||
// private int limitRPM; | ||
|
||
@Override | ||
public boolean getInverted() { | ||
if (isInSim) { | ||
return isInverted; | ||
} | ||
return super.getInverted(); | ||
} | ||
|
||
@Override | ||
public CANPIDController getPIDController() { | ||
if (isInSim) { | ||
return null; | ||
} | ||
return super.getPIDController(); | ||
} | ||
|
||
@Override | ||
public CANDigitalInput getReverseLimitSwitch(LimitSwitchPolarity polarity) { | ||
if (isInSim) { | ||
return null; | ||
} | ||
return super.getReverseLimitSwitch(polarity); | ||
} | ||
|
||
@Override | ||
public boolean isFollower() { | ||
// TODO Auto-generated method stub | ||
return super.isFollower(); | ||
} | ||
|
||
@Override | ||
public void set(double speed) { | ||
if (isInSim) { | ||
this.speed = speed; | ||
return; | ||
} | ||
|
||
super.set(speed); | ||
} | ||
|
||
@Override | ||
public CANError setIdleMode(IdleMode mode) { | ||
if (isInSim) { | ||
this.mode = mode; | ||
return CANError.kOk; | ||
} | ||
|
||
return super.setIdleMode(mode); | ||
} | ||
|
||
@Override | ||
public void setInverted(boolean isInverted) { | ||
if (isInSim) { | ||
this.isInverted = isInverted; | ||
return; | ||
} | ||
super.setInverted(isInverted); | ||
} | ||
|
||
@Override | ||
public CANError setSecondaryCurrentLimit(double limit, int chopCycles) { | ||
if (isInSim) { | ||
return CANError.kOk; | ||
} | ||
return super.setSecondaryCurrentLimit(limit, chopCycles); | ||
} | ||
|
||
@Override | ||
public CANError setSmartCurrentLimit(int stallLimit, int freeLimit, int limitRPM) { | ||
if (isInSim) { | ||
// this.stallLimit = stallLimit; | ||
// this.freeLimit = freeLimit; | ||
// this.limitRPM = limitRPM; | ||
|
||
return CANError.kOk; | ||
} | ||
return super.setSmartCurrentLimit(stallLimit, freeLimit, limitRPM); | ||
} | ||
|
||
@Override | ||
public void setVoltage(double outputVolts) { | ||
if (isInSim) { | ||
voltage = outputVolts; | ||
return; | ||
} | ||
super.setVoltage(outputVolts); | ||
} | ||
|
||
} | ||
package com.robototes.motors; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
|
||
public class RobototesCANSparkMax extends CANSparkMax implements Motor { | ||
|
||
public RobototesCANSparkMax(int deviceID, MotorType type) { | ||
super(deviceID, type); | ||
} | ||
|
||
@Override | ||
public void setP(double value) { | ||
super.getPIDController().setP(value); | ||
} | ||
|
||
@Override | ||
public void setI(double value) { | ||
super.getPIDController().setI(value); | ||
} | ||
|
||
@Override | ||
public void setD(double value) { | ||
super.getPIDController().setD(value); | ||
} | ||
|
||
@Override | ||
public void setF(double value) { | ||
super.getPIDController().setFF(value); | ||
} | ||
|
||
} |
Oops, something went wrong.