Skip to content

Commit

Permalink
Timeout in CANSparkMaxWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
gradyw committed Dec 28, 2019
1 parent 7fe9e71 commit 28ff85a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class Subsystem1d<P extends Subsystem1d.Position> extends Subsystem {
Subsystem1d(CANSparkMaxWrapper motor) {
try {
this.motor = motor;
motor.setPeriodicFrame(CANSparkMaxLowLevel.PeriodicFrame.kStatus2, 10);
motor.setPeriodicFrame(CANSparkMaxLowLevel.PeriodicFrame.kStatus2);
motor.set(0, ControlType.kDutyCycle);
motor.setNeutralMode(CANSparkMax.IdleMode.kBrake);
} catch (SparkMaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.revrobotics.*;
import com.team2813.lib.config.Inverted;
import com.team2813.lib.config.PeriodicFrame;
import com.team2813.lib.config.SparkConfig;
import com.team2813.lib.talon.CTREException;
import com.team2813.lib.talon.TalonWrapper;
Expand Down Expand Up @@ -309,6 +310,10 @@ public void setTimeout(int timeoutMs) throws SparkMaxException {
throwIfNotOk(setCANTimeout(timeoutMs));
}

public void setTimeout() throws SparkMaxException {
setTimeout(TimeoutMode.RUNNING.valueMs);
}

//#region Motor Type

public void setTypeOfMotor(MotorType type) throws SparkMaxException {
Expand Down Expand Up @@ -347,6 +352,10 @@ public void setPeriodicFrame(PeriodicFrame frameID, int periodMs) throws SparkMa
throwIfNotOk(setPeriodicFramePeriod(frameID, periodMs));
}

public void setPeriodicFrame(PeriodicFrame frameID) throws SparkMaxException {
setPeriodicFrame(frameID, TimeoutMode.RUNNING.valueMs);
}

public void setEncoderPosition(double position) throws SparkMaxException {
throwIfNotOk(setEncPosition(position));
}
Expand Down Expand Up @@ -623,4 +632,22 @@ public void setInverted(InvertType invertType) {

//#endregion

/**
* Enum storing different timeout values in ms for construction time
* or runtime updates.
*/
public enum TimeoutMode {
/** Longer timeout, used for constructors */
CONSTRUCTING(100),
/** Shorter timeout, used for on the fly updates */
RUNNING(10),
NO_TIMEOUT(0);

final int valueMs;

private TimeoutMode(int valueMs) {
this.valueMs = valueMs;
}
}

}

0 comments on commit 28ff85a

Please sign in to comment.