Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SumedhP authored Aug 8, 2020
2 parents 5468bfe + e75a22b commit c07a553
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 281 deletions.
16 changes: 8 additions & 8 deletions src/main/java/com/robototes/logging/LogType.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public enum LogType {
*/
public static LogType getLogTypeFromNumber(int logLevel) {
switch (logLevel) {
case 4:
return CRITICAL;
case 3:
return WARNING;
case 2:
return UPDATE;
default:
return DEFAULT;
case 4:
return CRITICAL;
case 3:
return WARNING;
case 2:
return UPDATE;
default:
return DEFAULT;
}
}

Expand Down
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;
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/robototes/motors/Motor.java
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 src/main/java/com/robototes/motors/RobototesCANSparkMax.java
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);
}

}
Loading

0 comments on commit c07a553

Please sign in to comment.