This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
5c246e0
commit d6124f3
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/main/java/frc/lib/controller/PositionControllerIO.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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package frc.lib.controller; | ||
|
||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; | ||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; | ||
import frc.lib.Telemetry; | ||
|
||
/** Position controller interface. */ | ||
public interface PositionControllerIO { | ||
|
||
/** Position controller constants. */ | ||
public static class PositionControllerIOConstants { | ||
/** Interpret counterclockwise rotation on the motor face as having positive velocity, if set to true. */ | ||
public boolean ccwPositive = true; | ||
|
||
/** Use the motor to brake the controlled mechanism on neutral output, if set to true. */ | ||
public boolean neutralBrake = false; | ||
|
||
/** Maximum amount of current, in amps, to provide to the motor. */ | ||
public double currentLimitAmps = 40.0; | ||
|
||
/** Ratio between the velocity sensor and the controlled mechanism. */ | ||
public double sensorToMechanismRatio = 1.0; | ||
} | ||
|
||
/** Position controller values. */ | ||
public static class PositionControllerIOValues { | ||
/** Position in rotations. */ | ||
public double positionRotations = 0.0; | ||
|
||
/** Velocity in rotations per second. */ | ||
public double velocityRotationsPerSecond = 0.0; | ||
|
||
/** Acceleration in rotations per second per second. */ | ||
public double accelerationRotationsPerSecondPerSecond = 0.0; | ||
|
||
/** Motor voltage in volts. */ | ||
public double motorVolts = 0.0; | ||
|
||
/** Motor current in amps. */ | ||
public double motorAmps = 0.0; | ||
} | ||
|
||
/** | ||
* Adds position controller values to Shuffleboard. | ||
* | ||
* @param tab | ||
* @param name | ||
* @param values | ||
*/ | ||
public static void addToShuffleboard(ShuffleboardTab tab, String name, PositionControllerIOValues values) { | ||
ShuffleboardLayout positionController = Telemetry.addColumn(tab, name); | ||
|
||
positionController.addDouble("Position (rot)", () -> values.positionRotations); | ||
positionController.addDouble("Velocity (rps)", () -> values.velocityRotationsPerSecond); | ||
positionController.addDouble("Acceleration (rpsps)", () -> values.accelerationRotationsPerSecondPerSecond); | ||
positionController.addDouble("Voltage (V)", () -> values.motorVolts); | ||
positionController.addDouble("Current (A)", () -> values.motorAmps); | ||
} | ||
|
||
/** | ||
* Configures the position controller. | ||
* | ||
* @param constants | ||
*/ | ||
public void configure(PositionControllerIOConstants constants); | ||
|
||
/** | ||
* Updates the position controller's values. | ||
* | ||
* @param values | ||
*/ | ||
public void update(PositionControllerIOValues values); | ||
|
||
/** | ||
* Sets the position setpoint. | ||
* | ||
* @param positionRotations | ||
* @param velocityRotationsPerSecond | ||
*/ | ||
public void setSetpoint(double positionRotations, double velocityRotationsPerSecond); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/frc/lib/controller/PositionControllerIOSim.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package frc.lib.controller; | ||
|
||
/** Simulated position controller. */ | ||
public class PositionControllerIOSim implements PositionControllerIO { | ||
|
||
private double positionRotations = 0.0; | ||
|
||
private double velocityRotationsPerSecond = 0.0; | ||
|
||
@Override | ||
public void configure(PositionControllerIOConstants constants) {} | ||
|
||
@Override | ||
public void update(PositionControllerIOValues values) { | ||
values.positionRotations = positionRotations; | ||
values.velocityRotationsPerSecond = velocityRotationsPerSecond; | ||
} | ||
|
||
@Override | ||
public void setSetpoint(double positionRotations, double velocityRotationsPerSecond) { | ||
this.positionRotations = positionRotations; | ||
this.velocityRotationsPerSecond = velocityRotationsPerSecond; | ||
} | ||
|
||
} |
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