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
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public class ParallelAction implements Action {

private List<Action> actions;

/**
* Creates a new action that runs a list of actions to be run simultaneously
* @param actions
*/
public ParallelAction(List<? extends Action> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Action> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
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
@@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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;

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
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 @@ -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
*
* <p>from TalonSRX.getLastError():</p>
* <blockquote>
* 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.
* </blockquote>
*
* @param value - value to return
* @return value
* @throws SparkMaxException - if talon had error code
*/
//TODO better name for this
// protected <T> 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
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down Expand Up @@ -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;
}
}

}
Loading