diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/Action.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/Action.java index f24ad2c..bf08634 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/Action.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/Action.java @@ -23,5 +23,10 @@ public interface Action { */ void end(double timestamp); + /** + * Returns whether action should be removed when robot has been disabled. + * + * @return Always returns false + */ default boolean getRemoveOnDisabled() {return false;} } \ No newline at end of file diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/FunctionAction.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/FunctionAction.java index d30c8e0..250ae5e 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/FunctionAction.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/FunctionAction.java @@ -9,6 +9,11 @@ public class FunctionAction implements Action { private final Runnable function; private final boolean removeOnDisabled; + /** + * Creates a new action from a function + * @param function + * @param removeOnDisabled + */ public FunctionAction(Runnable function, boolean removeOnDisabled) { this.function = function; this.removeOnDisabled = removeOnDisabled; diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/ParallelAction.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/ParallelAction.java index 00f1462..20c573b 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/ParallelAction.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/ParallelAction.java @@ -15,10 +15,18 @@ public class ParallelAction implements Action { private List actions; + /** + * Creates a new action that runs a list of actions to be run simultaneously + * @param actions + */ public ParallelAction(List actions) { this.actions = new ArrayList<>(actions); } + /** + * Creates a new action that runs a list of actions to be run simultaneously + * @param actions + */ public ParallelAction(Action...actions) { this(Arrays.asList(actions)); } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/SeriesAction.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/SeriesAction.java index 24cf43f..572a7a2 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/SeriesAction.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/SeriesAction.java @@ -15,10 +15,18 @@ public class SeriesAction implements Action { private Action currentAction; + /** + * Creates a new action from a list of actions to be run sequentially + * @param actions + */ public SeriesAction(List actions) { this.actions = new LinkedList<>(actions); } + /** + * Creates a new action from a list of actions to be run sequentially + * @param actions + */ public SeriesAction(Action... actions) { this(Arrays.asList(actions)); } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/WaitAction.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/WaitAction.java index 3327da5..743e0cd 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/WaitAction.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/actions/WaitAction.java @@ -5,6 +5,10 @@ public class WaitAction implements Action { private double duration; private double startTime; + /** + * Create a new action to wait an amount of time in seconds + * @param durationInSeconds + */ public WaitAction(double durationInSeconds) { this.duration = durationInSeconds; } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Subsystem1d.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Subsystem1d.java index 3aab459..46f061e 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Subsystem1d.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Subsystem1d.java @@ -19,7 +19,7 @@ abstract class Subsystem1d

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) { diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/ArcadeDrive.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/ArcadeDrive.java index 8c0f552..9465f20 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/ArcadeDrive.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/ArcadeDrive.java @@ -1,5 +1,8 @@ package com.team2813.lib.drive; +/** + * Arcade Drive: determine steer using x, y, and a deadzone + */ public class ArcadeDrive { private double deadzone; @@ -23,10 +26,6 @@ public DriveDemand getDemand(double x, double y) { double xMax = 0.4; steer = 1.0 * x; } -// -// System.out.println(throttleLeft + " " + throttleRight); - -// System.out.println((throttleLeft - steer) + " " + (throttleLeft + steer)); return new DriveDemand(throttleLeft + steer, throttleRight - steer); } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/CurvatureDrive.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/CurvatureDrive.java index c1c419a..2e6aadc 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/CurvatureDrive.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/CurvatureDrive.java @@ -1,5 +1,10 @@ package com.team2813.lib.drive; +/** + * Curvature Drive: use one axis for forward, another + * for reverse, and a third for steering, with a pivot + * button + */ public class CurvatureDrive { private ArcadeDrive arcadeDrive; @@ -7,8 +12,8 @@ public CurvatureDrive(double deadzone) { arcadeDrive = new ArcadeDrive(deadzone); } - public DriveDemand getDemand(double throttleForward, double throttleBackward, double steerX, boolean pivot) { - double throttle = 2 * Math.asin(throttleForward - throttleBackward) / Math.PI; + public DriveDemand getDemand(double throttleForward, double throttleReverse, double steerX, boolean pivot) { + double throttle = 2 * Math.asin(throttleForward - throttleReverse) / Math.PI; double steer = 2 * Math.asin(steerX) / Math.PI; steer = -steer; diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/VelocityDrive.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/VelocityDrive.java index a6bbdef..a9000bd 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/VelocityDrive.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/drive/VelocityDrive.java @@ -13,6 +13,12 @@ public VelocityDrive(double maxVelocity) { this.maxVelocity = maxVelocity; } + /** + * Configure a CANSparkMaxWrapper with configuration for velocity drive. + * @param spark + * @param config + * @throws SparkMaxException + */ public void configureMotor(CANSparkMaxWrapper spark, SparkConfig config) throws SparkMaxException { this.spark = spark; PIDControllerConfig pidConfig = config.getPidControllers().get(0); @@ -29,14 +35,6 @@ public void setMaxVelocity(int maxVelocity) { this.maxVelocity = maxVelocity; } -// public void setAccelerating(boolean accelerating) { -// if (accelerating) { -// spark.getPIDController().setSmartMotionMaxAccel(maxAccel, 0); -// } else { -// spark.getPIDController().setSmartMotionMaxAccel(maxAccel * .4, 0); -// } -// } - public double getVelocityFromDemand(double demand) { return maxVelocity * demand; } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/sparkMax/CANSparkMaxWrapper.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/sparkMax/CANSparkMaxWrapper.java index 793c07d..5ad7d85 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/sparkMax/CANSparkMaxWrapper.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/sparkMax/CANSparkMaxWrapper.java @@ -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; @@ -50,37 +51,6 @@ protected void throwIfNotOk(CANError error) throws SparkMaxException { SparkMaxException.throwIfNotOk(subsystemName, error); } - /** - * TODO spark max doesn't have a way to get the last error thrown - * Helper function for handling talon methods that do not return an error code but still need to check for one - * - *

from TalonSRX.getLastError():

- *
- * Gets the last error generated by this object. Not all functions return an - * error code but can potentially report errors. This function can be used - * to retrieve those error codes. - *
- * - * @param value - value to return - * @return value - * @throws SparkMaxException - if talon had error code - */ - //TODO better name for this -// protected T throwIfNotOkElseReturn(T value) throws SparkMaxException { -// throwLastError(); -// return value; -// } - -// public CANError getLastError() { -// return this.getLastError(); -// } - -// FIXME temporary fix -// public void throwLastError() throws SparkMaxException { -// CANError code = getLastError(); -// throwIfNotOk(code); -// } - // #endregion //#region Smart Current Limit @@ -340,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 { @@ -356,10 +330,32 @@ public void setMotorBrushless() throws SparkMaxException { //#endregion + /** + * Set the rate of transmission for periodic frames from the SPARK MAX + * + * Each motor controller sends back three status frames with different data at + * set rates. Use this function to change the default rates. + * + * Defaults: Status0 - 10ms Status1 - 20ms Status2 - 50ms + * + * This value is not stored in the FLASH after calling burnFlash() and is reset + * on powerup. + * + * Refer to the SPARK MAX reference manual on details for how and when to + * configure this parameter. + * + * @param frameID The frame ID can be one of PeriodicFrame type + * @param periodMs The rate the controller sends the frame to the controller. + * + */ public void setPeriodicFrame(PeriodicFrame frameID, int periodMs) throws SparkMaxException { 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)); } @@ -636,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; + } + } + } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/BaseMotorControllerWrapper.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/BaseMotorControllerWrapper.java index dd102ee..e5aed6f 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/BaseMotorControllerWrapper.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/BaseMotorControllerWrapper.java @@ -38,7 +38,6 @@ public abstract class BaseMotorControllerWrapper T throwIfNotOkElseReturn(T value) throws CTREException { throwLastError(); return value; @@ -92,6 +91,11 @@ public void setNeutralMode(NeutralMode mode) throws CTREException { // #region Invert behavior + /** + * Invert the encoder + * @param inverted + * @throws CTREException + */ public void setSensorPhaseInverted(boolean inverted) throws CTREException { motorController.setSensorPhase(inverted); throwLastError(); @@ -121,7 +125,7 @@ public InvertType getInvertType() { // #region Factory Default Configuration public void setFactoryDefaults() throws CTREException { - throwIfNotOk(motorController.configFactoryDefault(timeoutMode.value)); + throwIfNotOk(motorController.configFactoryDefault(timeoutMode.valueMs)); } // #endregion @@ -129,35 +133,35 @@ public void setFactoryDefaults() throws CTREException { // #region general output shaping public void setOpenLoopRamp(double seconds) throws CTREException { - throwIfNotOk(motorController.configOpenloopRamp(seconds, timeoutMode.value)); + throwIfNotOk(motorController.configOpenloopRamp(seconds, timeoutMode.valueMs)); } public void setClosedLoopRamp(double seconds) throws CTREException { - throwIfNotOk(motorController.configClosedloopRamp(seconds, timeoutMode.value)); + throwIfNotOk(motorController.configClosedloopRamp(seconds, timeoutMode.valueMs)); } public void setPeakOutputForward(double percentOut) throws CTREException { - throwIfNotOk(motorController.configPeakOutputForward(percentOut, timeoutMode.value)); + throwIfNotOk(motorController.configPeakOutputForward(percentOut, timeoutMode.valueMs)); } public void setPeakOutputReverse(double percentOut) throws CTREException { - throwIfNotOk(motorController.configPeakOutputReverse(percentOut, timeoutMode.value)); + throwIfNotOk(motorController.configPeakOutputReverse(percentOut, timeoutMode.valueMs)); } public void setNominalOutputForward(double percentOut) throws CTREException { - throwIfNotOk(motorController.configNominalOutputForward(percentOut, timeoutMode.value)); + throwIfNotOk(motorController.configNominalOutputForward(percentOut, timeoutMode.valueMs)); } public void setNominalOutputReverse(double percentOut) throws CTREException { - throwIfNotOk(motorController.configNominalOutputReverse(percentOut, timeoutMode.value)); + throwIfNotOk(motorController.configNominalOutputReverse(percentOut, timeoutMode.valueMs)); } public void setNeutralDeadband(double percentDeadband) throws CTREException { - throwIfNotOk(motorController.configNeutralDeadband(percentDeadband, timeoutMode.value)); + throwIfNotOk(motorController.configNeutralDeadband(percentDeadband, timeoutMode.valueMs)); } // #endregion @@ -166,12 +170,12 @@ public void setNeutralDeadband(double percentDeadband) throws CTREException { public void setVoltageCompensationSaturation(double voltage) throws CTREException { - throwIfNotOk(motorController.configVoltageCompSaturation(voltage, timeoutMode.value)); + throwIfNotOk(motorController.configVoltageCompSaturation(voltage, timeoutMode.valueMs)); } public void setVoltageMeasurementFilter(int filterWindowSamples) throws CTREException { - throwIfNotOk(motorController.configVoltageMeasurementFilter(filterWindowSamples, timeoutMode.value)); + throwIfNotOk(motorController.configVoltageMeasurementFilter(filterWindowSamples, timeoutMode.valueMs)); } @@ -217,31 +221,51 @@ public double getTemperature() throws CTREException { // #region Sensor Selection public void setSelectedFeedbackSensor(RemoteFeedbackDevice feedbackDevice, PidIdx pidIdx) throws CTREException { - throwIfNotOk(motorController.configSelectedFeedbackSensor(feedbackDevice, pidIdx.value, timeoutMode.value)); + throwIfNotOk(motorController.configSelectedFeedbackSensor(feedbackDevice, pidIdx.value, timeoutMode.valueMs)); } public void setSelectedFeedbackSensor(FeedbackDevice feedbackDevice, PidIdx pidIdx) throws CTREException { - throwIfNotOk(motorController.configSelectedFeedbackSensor(feedbackDevice, pidIdx.value, timeoutMode.value)); + throwIfNotOk(motorController.configSelectedFeedbackSensor(feedbackDevice, pidIdx.value, timeoutMode.valueMs)); } public void setSelectedFeedbackCoefficient(double coefficient, PidIdx pidIdx) throws CTREException { - throwIfNotOk(motorController.configSelectedFeedbackCoefficient(coefficient, pidIdx.value, timeoutMode.value)); + throwIfNotOk(motorController.configSelectedFeedbackCoefficient(coefficient, pidIdx.value, timeoutMode.valueMs)); } public void setRemoteFeedbackFilter(int deviceID, RemoteSensorSource remoteSensorSource, int remoteOrdinal) throws CTREException { - throwIfNotOk(motorController.configRemoteFeedbackFilter(deviceID, remoteSensorSource, remoteOrdinal, timeoutMode.value)); + throwIfNotOk(motorController.configRemoteFeedbackFilter(deviceID, remoteSensorSource, remoteOrdinal, timeoutMode.valueMs)); } - + + /** + * Select what sensor term should be bound to switch feedback device. + * Sensor Sum = Sensor Sum Term 0 - Sensor Sum Term 1 + * Sensor Difference = Sensor Diff Term 0 - Sensor Diff Term 1 + * The four terms are specified with this routine. Then Sensor Sum/Difference + * can be selected for closed-looping. + * + * @param sensorTerm Which sensor term to bind to a feedback source. + * @param feedbackDevice The sensor signal to attach to sensorTerm. + */ public void setSensorTerm(SensorTerm sensorTerm, FeedbackDevice feedbackDevice) throws CTREException { - throwIfNotOk(motorController.configSensorTerm(sensorTerm, feedbackDevice, timeoutMode.value)); + throwIfNotOk(motorController.configSensorTerm(sensorTerm, feedbackDevice, timeoutMode.valueMs)); } - + + /** + * Select what sensor term should be bound to switch feedback device. + * Sensor Sum = Sensor Sum Term 0 - Sensor Sum Term 1 + * Sensor Difference = Sensor Diff Term 0 - Sensor Diff Term 1 + * The four terms are specified with this routine. Then Sensor Sum/Difference + * can be selected for closed-looping. + * + * @param sensorTerm Which sensor term to bind to a feedback source. + * @param feedbackDevice The sensor signal to attach to sensorTerm. + */ public void setSensorTerm(SensorTerm sensorTerm, RemoteFeedbackDevice feedbackDevice) throws CTREException { - throwIfNotOk(motorController.configSensorTerm(sensorTerm, feedbackDevice, timeoutMode.value)); + throwIfNotOk(motorController.configSensorTerm(sensorTerm, feedbackDevice, timeoutMode.valueMs)); } // #endregion @@ -265,7 +289,7 @@ public int getSelectedSensorVelocity() throws CTREException { } public void setSelectedSensorPosition(PidIdx pidIdx, int sensorPos) throws CTREException { - throwIfNotOk(motorController.setSelectedSensorPosition(sensorPos, pidIdx.value, timeoutMode.value)); + throwIfNotOk(motorController.setSelectedSensorPosition(sensorPos, pidIdx.value, timeoutMode.valueMs)); } public void setSelectedSensorPosition(int sensorPos) throws CTREException { @@ -287,23 +311,23 @@ public void setControlFramePeriod(int frame, int periodMs) throws CTREException } public void setStatusFramePeriod(int frameValue, int periodMs) throws CTREException { - throwIfNotOk(motorController.setStatusFramePeriod(frameValue, periodMs, timeoutMode.value)); + throwIfNotOk(motorController.setStatusFramePeriod(frameValue, periodMs, timeoutMode.valueMs)); } public void setStatusFramePeriod(StatusFrame frame, int periodMs) throws CTREException { - throwIfNotOk(motorController.setStatusFramePeriod(frame, periodMs, timeoutMode.value)); + throwIfNotOk(motorController.setStatusFramePeriod(frame, periodMs, timeoutMode.valueMs)); } public int getStatusFramePeriod(int frameValue) throws CTREException { - return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frameValue, timeoutMode.value)); + return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frameValue, timeoutMode.valueMs)); } public int getStatusFramePeriod(StatusFrame frame) throws CTREException { - return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frame, timeoutMode.value)); + return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frame, timeoutMode.valueMs)); } public int getStatusFramePeriod(StatusFrameEnhanced frame) throws CTREException { - return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frame, timeoutMode.value)); + return throwIfNotOkElseReturn(motorController.getStatusFramePeriod(frame, timeoutMode.valueMs)); } // #endregion @@ -312,12 +336,12 @@ public int getStatusFramePeriod(StatusFrameEnhanced frame) throws CTREException public void setVelocityMeasurementPeriod(VelocityMeasPeriod period) throws CTREException { - throwIfNotOk(motorController.configVelocityMeasurementPeriod(period, timeoutMode.value)); + throwIfNotOk(motorController.configVelocityMeasurementPeriod(period, timeoutMode.valueMs)); } public void setVelocityMeasurementWindow(VelocityMeasurementWindow windowSize) throws CTREException { - throwIfNotOk(motorController.configVelocityMeasurementWindow(windowSize.value, timeoutMode.value)); + throwIfNotOk(motorController.configVelocityMeasurementWindow(windowSize.value, timeoutMode.valueMs)); } // #endregion @@ -326,19 +350,19 @@ public void setVelocityMeasurementWindow(VelocityMeasurementWindow windowSize) t public void setForwardLimitSwitchSource(RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose, int deviceID) throws CTREException { throwIfNotOk( - motorController.configForwardLimitSwitchSource(type, normalOpenOrClose, deviceID, timeoutMode.value) + motorController.configForwardLimitSwitchSource(type, normalOpenOrClose, deviceID, timeoutMode.valueMs) ); } public void setReverseLimitSwitchSource(RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose, int deviceID) throws CTREException { throwIfNotOk( - motorController.configReverseLimitSwitchSource(type, normalOpenOrClose, deviceID, timeoutMode.value) + motorController.configReverseLimitSwitchSource(type, normalOpenOrClose, deviceID, timeoutMode.valueMs) ); } public void setForwardLimitSwitchSource(LimitSwitchSource type, LimitSwitchNormal normalOpenOrClose) throws CTREException { - throwIfNotOk(motorController.configForwardLimitSwitchSource(type, normalOpenOrClose, timeoutMode.value)); + throwIfNotOk(motorController.configForwardLimitSwitchSource(type, normalOpenOrClose, timeoutMode.valueMs)); } // #endregion @@ -346,11 +370,11 @@ public void setForwardLimitSwitchSource(LimitSwitchSource type, LimitSwitchNorma // #region Forward soft limit public void setForwardSoftLimitThreshold(int threshold) throws CTREException { - throwIfNotOk(motorController.configForwardSoftLimitThreshold(threshold, timeoutMode.value)); + throwIfNotOk(motorController.configForwardSoftLimitThreshold(threshold, timeoutMode.valueMs)); } public void setForwardSoftLimitEnable(boolean enable) throws CTREException { - throwIfNotOk(motorController.configForwardSoftLimitEnable(enable, timeoutMode.value)); + throwIfNotOk(motorController.configForwardSoftLimitEnable(enable, timeoutMode.valueMs)); } public void disableForwardSoftLimit() throws CTREException { @@ -379,12 +403,12 @@ public void setSoftLimit(LimitDirection direction, int threshold, boolean enable * @param threshold Reverse Sensor Position Limit (in raw sensor units). */ public void setReverseSoftLimitThreshold(int threshold) throws CTREException { - throwIfNotOk(motorController.configReverseSoftLimitThreshold(threshold, timeoutMode.value)); + throwIfNotOk(motorController.configReverseSoftLimitThreshold(threshold, timeoutMode.valueMs)); } public void setReverseSoftLimitEnable(boolean enable) throws CTREException { - throwIfNotOk(motorController.configReverseSoftLimitEnable(enable, timeoutMode.value)); + throwIfNotOk(motorController.configReverseSoftLimitEnable(enable, timeoutMode.valueMs)); } public void disableReverseSoftLimit() throws CTREException { @@ -416,19 +440,21 @@ public void setReverseSoftLimit(int threshold, boolean enable) throws CTREExcept // #region Motion Profile Settings used in Motion Magic and Motion Profile /** + * Set the peak velocity in Motion Magic mode * @param velocity - sensor units / 100ms * @throws CTREException */ public void setMotionMagicCruiseVelocity(int velocity) throws CTREException { - throwIfNotOk(motorController.configMotionCruiseVelocity(velocity, timeoutMode.value)); + throwIfNotOk(motorController.configMotionCruiseVelocity(velocity, timeoutMode.valueMs)); } /** + * Set the acceleration of the Motion Magic controller * @param acceleration - raw sensor units per 100 ms per second * @throws CTREException */ public void setMotionMagicAcceleration(int acceleration) throws CTREException { - throwIfNotOk(motorController.configMotionAcceleration(acceleration, timeoutMode.value)); + throwIfNotOk(motorController.configMotionAcceleration(acceleration, timeoutMode.valueMs)); } // #endregion @@ -471,7 +497,7 @@ public MotionProfileStatus getMotionProfileStatus() throws CTREException { } public void clearMotionProfileHasUnderrun() throws CTREException { - throwIfNotOk(motorController.clearMotionProfileHasUnderrun(timeoutMode.value)); + throwIfNotOk(motorController.clearMotionProfileHasUnderrun(timeoutMode.valueMs)); } public void setMotionControlFramePeriod(int periodMs) throws CTREException { @@ -483,11 +509,11 @@ public void setMotionControlFramePeriod(int periodMs) throws CTREException { * @throws CTREException */ public void setMotionProfileTrajectoryPeriod(int baseTrajectoryDuration) throws CTREException { - throwIfNotOk(motorController.configMotionProfileTrajectoryPeriod(baseTrajectoryDuration, timeoutMode.value)); + throwIfNotOk(motorController.configMotionProfileTrajectoryPeriod(baseTrajectoryDuration, timeoutMode.valueMs)); } public void setMotionProfileTrajectoryInterpolation(boolean enable) throws CTREException { - throwIfNotOk(motorController.configMotionProfileTrajectoryInterpolationEnable(enable, timeoutMode.value)); + throwIfNotOk(motorController.configMotionProfileTrajectoryInterpolationEnable(enable, timeoutMode.valueMs)); } public void enableMotionProfileTrajectoryInterpolation() throws CTREException { @@ -503,7 +529,7 @@ public void disableMotionProfileTrajectoryInterpolation() throws CTREException { // #region Feedback Device Integration Settings public void setFeedbackNotContinuous(boolean enable) throws CTREException { - throwIfNotOk(motorController.configFeedbackNotContinuous(enable, timeoutMode.value)); + throwIfNotOk(motorController.configFeedbackNotContinuous(enable, timeoutMode.valueMs)); } public void enableFeedbackNotContinuous() throws CTREException { @@ -516,7 +542,7 @@ public void disableFeedbackNotContinuous() throws CTREException { public void setRemoteSensorClosedLoopDisableNeutralOnLOS(boolean enable) throws CTREException { - throwIfNotOk(motorController.configRemoteSensorClosedLoopDisableNeutralOnLOS(enable, timeoutMode.value)); + throwIfNotOk(motorController.configRemoteSensorClosedLoopDisableNeutralOnLOS(enable, timeoutMode.valueMs)); } public void enableRemoteSensorClosedLoopDisableNeutralOnLOS() throws CTREException { @@ -526,14 +552,20 @@ public void enableRemoteSensorClosedLoopDisableNeutralOnLOS() throws CTREExcepti public void disableRemoteSensorClosedLoopDisableNeutralOnLOS() throws CTREException { setRemoteSensorClosedLoopDisableNeutralOnLOS(false); } - + + /** + * Reset selected feedback sensor (encoder) on a limit + * @param direction + * @param clearOnLimit + * @throws CTREException + */ public void setClearPositionOnLimit(LimitDirection direction, boolean clearOnLimit) throws CTREException { if (direction == LimitDirection.FORWARD) setClearPositionOnLimitF(clearOnLimit); else if (direction == LimitDirection.REVERSE) setClearPositionOnLimitR(clearOnLimit); } public void setClearPositionOnLimitF(boolean enable) throws CTREException { - throwIfNotOk(motorController.configClearPositionOnLimitF(enable, timeoutMode.value)); + throwIfNotOk(motorController.configClearPositionOnLimitF(enable, timeoutMode.valueMs)); } public void enableClearPositionOnLimitF() throws CTREException { @@ -546,7 +578,7 @@ public void disableClearPositionOnLimitF() throws CTREException { public void setClearPositionOnLimitR(boolean enable) throws CTREException { - throwIfNotOk(motorController.configClearPositionOnLimitR(enable, timeoutMode.value)); + throwIfNotOk(motorController.configClearPositionOnLimitR(enable, timeoutMode.valueMs)); } public void enableClearPositionOnLimitR() throws CTREException { @@ -558,7 +590,7 @@ public void disableClearPositionOnLimitR() throws CTREException { } public void setClearPositionOnQuadIdx(boolean enable) throws CTREException { - throwIfNotOk(motorController.configClearPositionOnQuadIdx(enable, timeoutMode.value)); + throwIfNotOk(motorController.configClearPositionOnQuadIdx(enable, timeoutMode.valueMs)); } public void enableClearPositionOnQuadIdx() throws CTREException { @@ -571,7 +603,7 @@ public void disableClearPositionOnQuadIdx() throws CTREException { public void setLimitSwitchDisableNeutralOnLOS(boolean enable) throws CTREException { - throwIfNotOk(motorController.configLimitSwitchDisableNeutralOnLOS(enable, timeoutMode.value)); + throwIfNotOk(motorController.configLimitSwitchDisableNeutralOnLOS(enable, timeoutMode.valueMs)); } public void enableLimitSwitchDisableNeutralOnLOS() throws CTREException { @@ -584,7 +616,7 @@ public void disableLimitSwitchDisableNeutralOnLOS() throws CTREException { public void setSoftLimitDisableNeutralOnLOS(boolean enable) throws CTREException { - throwIfNotOk(motorController.configSoftLimitDisableNeutralOnLOS(enable, timeoutMode.value)); + throwIfNotOk(motorController.configSoftLimitDisableNeutralOnLOS(enable, timeoutMode.valueMs)); } public void enableSoftLimitDisableNeutralOnLOS() throws CTREException { @@ -597,18 +629,22 @@ public void disableSoftLimitDisableNeutralOnLOS() throws CTREException { public void setPulseWidthPeriodEdgesPerRotation(int edgesPerRotation) throws CTREException { - throwIfNotOk(motorController.configPulseWidthPeriod_EdgesPerRot(edgesPerRotation, timeoutMode.value)); + throwIfNotOk(motorController.configPulseWidthPeriod_EdgesPerRot(edgesPerRotation, timeoutMode.valueMs)); } public void setPulseWidthPeriodFilterWindowSamples(int samples) throws CTREException { - throwIfNotOk(motorController.configPulseWidthPeriod_EdgesPerRot(samples, timeoutMode.value)); + throwIfNotOk(motorController.configPulseWidthPeriod_EdgesPerRot(samples, timeoutMode.valueMs)); } // #endregion // #region Error - + + /** + * Get most recent error from motor controller + * @return + */ public ErrorCode getLastError() { return motorController.getLastError(); } @@ -627,22 +663,22 @@ public void throwLastError() throws CTREException { // FIXME: 12/28/2019 Need to rewrite PIDProfile.Profile for Talons public void setP(PIDProfile.Profile slot, double p) throws CTREException { - throwIfNotOk(motorController.config_kP(slot.id, p, timeoutMode.value)); + throwIfNotOk(motorController.config_kP(slot.id, p, timeoutMode.valueMs)); } public void setI(PIDProfile.Profile slot, double i) throws CTREException { - throwIfNotOk(motorController.config_kI(slot.id, i, timeoutMode.value)); + throwIfNotOk(motorController.config_kI(slot.id, i, timeoutMode.valueMs)); } public void setD(PIDProfile.Profile slot, double d) throws CTREException { - throwIfNotOk(motorController.config_kD(slot.id, d, timeoutMode.value)); + throwIfNotOk(motorController.config_kD(slot.id, d, timeoutMode.valueMs)); } public void setF(PIDProfile.Profile slot, double f) throws CTREException { - throwIfNotOk(motorController.config_kF(slot.id, f, timeoutMode.value)); + throwIfNotOk(motorController.config_kF(slot.id, f, timeoutMode.valueMs)); } public void setPIDF(PIDProfile.Profile slot, double p, double i, double d, double f) throws CTREException { @@ -654,16 +690,16 @@ public void setPIDF(PIDProfile.Profile slot, double p, double i, double d, doubl public void setMaxIntegralAccumulator(PIDProfile.Profile profile, double iaccum) throws CTREException { - throwIfNotOk(motorController.configMaxIntegralAccumulator(profile.id, iaccum, timeoutMode.value)); + throwIfNotOk(motorController.configMaxIntegralAccumulator(profile.id, iaccum, timeoutMode.valueMs)); } public void setIntegralZone(PIDProfile.Profile profile, int izone) throws CTREException { - throwIfNotOk(motorController.config_IntegralZone(profile.id, izone, timeoutMode.value)); + throwIfNotOk(motorController.config_IntegralZone(profile.id, izone, timeoutMode.valueMs)); } public void setAllowableClosedLoopError(PIDProfile.Profile profile, int allowableError) throws CTREException { - throwIfNotOk(motorController.configAllowableClosedloopError(profile.id, allowableError, timeoutMode.value)); + throwIfNotOk(motorController.configAllowableClosedloopError(profile.id, allowableError, timeoutMode.valueMs)); } @@ -671,7 +707,7 @@ public void setAllowableClosedLoopError(PIDProfile.Profile profile, int allowabl public void clearStickyFaults() throws CTREException { - throwIfNotOk(motorController.clearStickyFaults(timeoutMode.value)); + throwIfNotOk(motorController.clearStickyFaults(timeoutMode.valueMs)); } @@ -727,10 +763,24 @@ public void enableOverrideSoftLimits() throws CTREException { public void disableOverrideSoftLimits() throws CTREException { setOverrideSoftLimits(false); } - + /** + * Sets a parameter. Generally this is not used. This can be utilized in - + * Using new features without updating API installation. - Errata + * workarounds to circumvent API implementation. - Allows for rapid testing + * / unit testing of firmware. + * + * @param param + * Parameter enumeration. + * @param value + * Value of parameter. + * @param subValue + * Subvalue for parameter. Maximum value of 255. + * @param ordinal + * Ordinal of parameter. + */ public void setParameter(ParamEnum param, double value, int subValue, int ordinal) throws CTREException { - throwIfNotOk(motorController.configSetParameter(param, value, subValue, ordinal, timeoutMode.value)); + throwIfNotOk(motorController.configSetParameter(param, value, subValue, ordinal, timeoutMode.valueMs)); } public void setDirectionParameterForLimit(LimitDirection direction, double value, int subValue, int ordinal, boolean clearOnLimit) throws CTREException { @@ -740,7 +790,10 @@ public void setDirectionParameterForLimit(LimitDirection direction, double value } } - // TODO document + /** + * Enum storing different timeout values in ms for construction time + * or runtime updates. + */ public enum TimeoutMode { /** Longer timeout, used for constructors */ CONSTRUCTING(100), @@ -748,15 +801,17 @@ public enum TimeoutMode { RUNNING(20), NO_TIMEOUT(0); - final int value; + final int valueMs; - private TimeoutMode(int value) { - this.value = value; + private TimeoutMode(int valueMs) { + this.valueMs = valueMs; } } - //TODO document - public enum PidIdx{ //FIXME give this a name that reflects w/e it actually does + /** + * PID ID Slots: Primary 0; Auxiliary 1 + */ + public enum PidIdx { //FIXME give this a name that reflects w/e it actually does PRIMARY_CLOSED_LOOP(0), AUXILIARY_CLOSED_LOOP(1); diff --git a/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/TalonWrapper.java b/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/TalonWrapper.java index a2a2cf7..277269a 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/TalonWrapper.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/lib/talon/TalonWrapper.java @@ -38,28 +38,28 @@ public void disableCurrentLimit() throws CTREException { } public void setStatusFramePeriod(StatusFrameEnhanced frame, int periodMs) throws CTREException { - throwIfNotOk(motorController.setStatusFramePeriod(frame, periodMs, timeoutMode.value)); + throwIfNotOk(motorController.setStatusFramePeriod(frame, periodMs, timeoutMode.valueMs)); } /** * @param limit Amperes to limit */ public void setContinuousCurrentLimit(int limit) throws CTREException { - throwIfNotOk(motorController.configContinuousCurrentLimit(limit, timeoutMode.value)); + throwIfNotOk(motorController.configContinuousCurrentLimit(limit, timeoutMode.valueMs)); } /** * @param limit Amperes to limit */ public void setPeakCurrentLimit(int limit) throws CTREException { - throwIfNotOk(motorController.configPeakCurrentLimit(limit, timeoutMode.value)); + throwIfNotOk(motorController.configPeakCurrentLimit(limit, timeoutMode.valueMs)); } /** * @param duration How long to allow current-draw past peak limit. (in milliseconds) */ public void setPeakCurrentDuration(int duration) throws CTREException { - throwIfNotOk(motorController.configPeakCurrentDuration(duration, timeoutMode.value)); + throwIfNotOk(motorController.configPeakCurrentDuration(duration, timeoutMode.valueMs)); } //#region Sensor collection wrappers @@ -77,7 +77,7 @@ public boolean isReverseLimitSwitchClosed() throws CTREException { //#endregion public void setReverseLimitSwitchSource(LimitSwitchSource type, LimitSwitchNormal normalOpenOrClose) throws CTREException { - throwIfNotOk(motorController.configReverseLimitSwitchSource(type, normalOpenOrClose, timeoutMode.value)); + throwIfNotOk(motorController.configReverseLimitSwitchSource(type, normalOpenOrClose, timeoutMode.valueMs)); } public void setLimitSwitchSource(LimitDirection direction, LimitSwitchSource type, LimitSwitchNormal normalOpenOrClose) throws CTREException {