-
Notifications
You must be signed in to change notification settings - Fork 1
REV Motor IO Layer #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
REV Motor IO Layer #190
Changes from 15 commits
4560855
f70cae7
35fc34f
6b067e8
cd9d261
e152663
cbb9d84
631cc53
1e90100
b9de937
6bdb24f
ee5d549
53a3377
cb649e1
ecf6f8f
e285b3e
f29b6e6
b125589
80e922b
c9cc5b5
afd56fd
97d8fc8
21602a8
81f0df1
078adda
2448e41
01e8bb3
2b5bef9
9952272
3e7c325
475d964
66dc14c
5eed051
c0dd131
6743832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # FRC Team W8 Library - AI Assistant Instructions | ||
|
|
||
| You are a sr Java engineer with 10+ years of expereince. You are helping high school students on an FRC (FIRST Robotics Competition) team. Write clear, educational code that students can learn from and maintain. | ||
|
|
||
| ## Technology Stack | ||
|
|
||
| - **Language**: Java | ||
| - **Framework**: WPILib - https://frcdocs.wpi.edu/en/latest/docs/software/what-is-wpilib.html | ||
| - **Vendor Libraries**: | ||
| - CTRE (Phoenix 6) for motors/sensors: https://v6.docs.ctr-electronics.com/en/stable/docs/api-reference/api-usage/api-overview.html | ||
| - REV (REVLib) for motors/sensors: https://docs.revrobotics.com/revlib | ||
| - **Logging**: AdvantageKit - https://docs.advantagekit.org/ | ||
| - Logs are viewed in AdvantageScope | ||
|
|
||
| ## Library Architecture (`lib` folder) | ||
|
|
||
| This codebase uses a **hardware abstraction layer** to make robot code portable and testable: | ||
|
|
||
| ### Key Patterns | ||
|
|
||
| 1. **IO Interfaces**: Define hardware operations (e.g., `ElevatorIO`, `DriveIO`) | ||
| - Methods for reading sensors and controlling actuators | ||
| - Contain nested `Inputs` class for sensor data logged by AdvantageKit | ||
|
|
||
| 2. **IO Implementations**: Hardware-specific code (e.g., `ElevatorIOSparkMax`, `ElevatorIOSim`) | ||
| - Real hardware implementation uses vendor libraries (CTRE, REV) | ||
| - Simulation implementations for testing without hardware | ||
| - Keep vendor-specific code isolated here | ||
|
|
||
| 3. **Subsystems**: High-level robot logic extends WPILib's `SubsystemBase` | ||
| - Accept an `IO` interface in the constructor (dependency injection) | ||
| - Contain robot behavior and state machines | ||
| - Call `Logger.processInputs()` to log sensor data | ||
|
|
||
| ### Best Practices | ||
|
|
||
| - **Keep subsystems hardware-agnostic**: They should only use the IO interface, never vendor classes directly | ||
| - **Log everything**: Use AdvantageKit's `@AutoLog` for all sensor inputs | ||
| - **One IO implementation per hardware type**: Separate real vs. simulation, different motor controllers, etc. | ||
| - **Throw from default interface methods**: Default methods in IO interfaces should throw `NotImplementedException` to ensure they are explicitly implemented where needed. | ||
| - **Commands for actions**: Use WPILib's command-based framework for robot behaviors | ||
| - **Constants in separate classes**: Keep tunable values organized and easy to find | ||
|
|
||
| ### Example Usage | ||
|
|
||
| ```java | ||
| // IO Interface defines contract | ||
| public interface DriveIO { | ||
| @AutoLog | ||
| class DriveInputs { | ||
| double leftVelocityMPS = 0.0; | ||
| double rightVelocityMPS = 0.0; | ||
| } | ||
|
|
||
| void updateInputs(DriveInputs inputs); | ||
| void setVoltage(double left, double right); | ||
| } | ||
|
|
||
| // Subsystem uses IO interface | ||
| public class Drive extends SubsystemBase { | ||
| private final DriveIO io; | ||
| private final DriveInputsAutoLogged inputs = new DriveInputsAutoLogged(); | ||
|
|
||
| public Drive(DriveIO io) { | ||
| this.io = io; | ||
| } | ||
|
|
||
| @Override | ||
| public void periodic() { | ||
| io.updateInputs(inputs); | ||
| Logger.processInputs("Drive", inputs); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Guidance for Students | ||
|
|
||
| - Explain your code with comments when introducing new concepts | ||
| - Prefer readability over cleverness | ||
| - Break complex logic into small, named methods | ||
| - Use descriptive variable names (`leftMotorVolts` not `lmv`) | ||
| - Test code in simulation before deploying to robot hardware | ||
|
garrett928 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import static edu.wpi.first.units.Units.RadiansPerSecond; | ||
| import static edu.wpi.first.units.Units.Volts; | ||
|
|
||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.littletonrobotics.junction.AutoLog; | ||
|
|
||
| import edu.wpi.first.units.AngularAccelerationUnit; | ||
|
|
@@ -97,7 +98,7 @@ abstract class MotorInputs { | |
| */ | ||
| public default String getName() | ||
| { | ||
| return ""; | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
|
Comment on lines
-100
to
+101
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method needs to be removed for replay support |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -107,35 +108,45 @@ public default String getName() | |
| * @param inputs The structure to populate with updated sensor values. | ||
| */ | ||
| public default void updateInputs(MotorInputs inputs) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Sets the motor to coast mode. | ||
| */ | ||
| public default void runCoast() | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-116
to
+121
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Sets the motor to brake mode. | ||
| */ | ||
| public default void runBrake() | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-122
to
+129
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Runs the motor using direct voltage control. | ||
| * | ||
| * @param voltage Desired voltage output. | ||
| */ | ||
| public default void runVoltage(Voltage voltage) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
| /** | ||
| * Runs the motor with a specified current output. | ||
| * | ||
| * @param current Desired torque-producing current. | ||
| */ | ||
| public default void runCurrent(Current current) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-138
to
+149
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Runs the motor with a specified current output and duty cycle. | ||
|
|
@@ -144,15 +155,19 @@ public default void runCurrent(Current current) | |
| * @param dutyCycle Desired dutycycle of current output, limiting top speed | ||
| */ | ||
| public default void runCurrent(Current current, double dutyCycle) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-147
to
+160
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Runs the motor using duty cycle (percentage of available voltage). | ||
| * | ||
| * @param dutyCycle Fractional output between 0 and 1. | ||
| */ | ||
| public default void runDutyCycle(double dutyCycle) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-155
to
+170
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Runs the motor to a specific position. | ||
|
|
@@ -166,7 +181,20 @@ public default void runDutyCycle(double dutyCycle) | |
| public default void runPosition(Angle position, AngularVelocity cruiseVelocity, | ||
| AngularAcceleration acceleration, | ||
| Velocity<AngularAccelerationUnit> maxJerk, PIDSlot slot) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
|
||
| /** | ||
| * Runs the motor to a specific position. | ||
| * | ||
| * @param position Target position. | ||
| * @param slot PID slot index. | ||
| */ | ||
| public default void runPosition(Angle position, PIDSlot slot) | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-169
to
+197
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Runs the motor at a target velocity. | ||
|
|
@@ -177,13 +205,37 @@ public default void runPosition(Angle position, AngularVelocity cruiseVelocity, | |
| */ | ||
| public default void runVelocity(AngularVelocity velocity, AngularAcceleration acceleration, | ||
| PIDSlot slot) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
|
||
| /** | ||
| * Runs the motor at a target velocity. | ||
| * | ||
| * @param velocity Desired velocity. | ||
| * @param slot PID slot index. | ||
| */ | ||
| public default void runVelocity(AngularVelocity velocity, PIDSlot slot) | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-180
to
+221
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Sets the position of the motor's internal encoder | ||
| * | ||
| * @param position Desired position to set encoder to | ||
| */ | ||
| public default void setEncoderPosition(Angle position) | ||
| {} | ||
| { | ||
| throw new NotImplementedException("This method has not been implemented"); | ||
| } | ||
|
Comment on lines
-188
to
+231
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks replay |
||
|
|
||
| /** | ||
| * Closes and cleans up motor controller resources. Called when the motor is no longer needed to | ||
| * properly release hardware. | ||
| */ | ||
| public default void close() | ||
| { | ||
| // Default implementation does nothing for interfaces that don't need cleanup | ||
| } | ||
|
Comment on lines
+237
to
+240
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the interface extend |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.