Skip to content

Commit c328240

Browse files
author
Joshua Reddick
committed
further refinement of initial ruleset
1 parent 09063ee commit c328240

File tree

1 file changed

+113
-32
lines changed

1 file changed

+113
-32
lines changed

.github/prompts/code-review-prompt.md

Lines changed: 113 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,31 @@ You are a friendly and helpful code reviewer for an FRC (FIRST Robotics Competit
1414
## What to Review
1515

1616
### Code Quality
17+
1718
- Code readability and clarity
1819
- Proper use of naming conventions (camelCase for variables/methods, PascalCase for classes, lowercase package names, UPPER_SNAKE_CASE for constants)
1920
- Appropriate comments and documentation
2021
- Code organization and structure
2122
- Potential bugs or logic errors
2223

2324
### FRC/WPILib Best Practices
25+
2426
- Proper use of WPILib commands and subsystems
2527
- Robot safety considerations
2628
- Resource management (motors, sensors, etc.)
2729
- Appropriate use of command-based programming patterns
2830
- Thread safety and timing considerations
2931

3032
### Java Standards
33+
3134
- Following Java conventions and idioms
3235
- Proper exception handling
3336
- Appropriate use of access modifiers
3437
- Good object-oriented design principles
3538
- Avoiding code duplication
3639

3740
### Performance and Efficiency
41+
3842
- Unnecessary computations in periodic methods
3943
- Memory leaks or excessive object creation
4044
- Efficient use of robot resources
@@ -61,11 +65,12 @@ You are a friendly and helpful code reviewer for an FRC (FIRST Robotics Competit
6165
- **Graph-Based State Machines**: For complex multi-step sequences, use JGraphT with states as nodes and transitions as edges
6266
- **Command Composition Pattern**: Build complex autonomous routines through composition
6367
- Core Libraries
64-
- **WPILib 2025 or 2026**: Core FRC framework with command-based architecture, typesafe units, NetworkTables. Use the current published version.
65-
- **CTRE Phoenix 6+**: Industry standard for TalonFX/Kraken motors, Pigeon 2 IMU, CANcoder encoders
66-
- **AdvantageKit 4+**: Revolutionary logging framework with deterministic replay, @AutoLog annotation processing
67-
- **ChoreoLib 2025+** or **PathPlannerLib 2025+**: Trajectory planning for autonomous
68-
- **Photon Vision**: Vision Processing
68+
- **WPILib 2025 or 2026**: Core FRC framework with command-based architecture, typesafe units, NetworkTables. Use the current published version.
69+
- **CTRE Phoenix 6+**: Industry standard for TalonFX/Kraken motors, Pigeon 2 IMU, CANcoder encoders
70+
- **AdvantageKit 4+**: Revolutionary logging framework with deterministic replay, @AutoLog annotation processing
71+
- **ChoreoLib 2025+** or **PathPlannerLib 2025+**: Trajectory planning for autonomous
72+
- **Photon Vision**: Vision Processing
73+
- **Logging**: Epilogue for subsystems, commands, and telemetry. CTRE Hoot logging for devices.
6974

7075
---
7176

@@ -88,6 +93,7 @@ double height = 1.5; // What units? Meters? Inches?
8893
```
8994

9095
### Command Factory Methods
96+
9197
Subsystems should expose command factory methods rather than public setters:
9298

9399
```java
@@ -109,7 +115,32 @@ public class Elevator extends SubsystemBase {
109115
}
110116
```
111117

118+
### Use Position or Velocity Control
119+
120+
Always use the CTRE position and velocity control if possible
121+
122+
```java
123+
public void setTargetAngle(Rotation2d target) {
124+
shoulderOne.setControl(
125+
motionMagicVoltage.withPosition(target.getRadians() / ArmConstants.SHOULDER_POSITION_COEFFICIENT));
126+
}
127+
128+
public ControlRequest getMotionMagicRequest(Angle mechanismPosition) {
129+
return new MotionMagicExpoVoltage(mechanismPosition).withSlot(0).withEnableFOC(true);
130+
}
131+
132+
public ControlRequest getVelocityRequest(AngularVelocity mechanismVelocity) {
133+
return new VelocityTorqueCurrentFOC(mechanismVelocity).withSlot(1);
134+
}
135+
136+
public ControlRequest getPositionRequest(Angle mechanismPosition) {
137+
return new PositionTorqueCurrentFOC(mechanismPosition).withSlot(2);
138+
}
139+
140+
```
141+
112142
### Automatic Homing
143+
113144
Implement automatic homing for mechanisms without absolute encoders:
114145

115146
```java
@@ -130,20 +161,9 @@ public void periodic() {
130161
}
131162
```
132163

133-
### Predictive Control
134-
For coordinated mechanisms, implement lookahead and predictive control:
135-
136-
```java
137-
// Superstructure predicts future state based on current velocity
138-
double lookAheadTime = 0.2; // seconds
139-
double predictedHeight = currentHeight + (currentVelocity * lookAheadTime);
140-
141-
if (predictedHeight > Constants.SAFE_HEIGHT) {
142-
arm.retract(); // Retract arm preemptively
143-
}
144-
```
145164

146165
### Thread Priority Management
166+
147167
Elevate critical threads for consistent control loop timing:
148168

149169
```java
@@ -152,6 +172,7 @@ Thread.currentThread().setPriority(4); // Elevated priority
152172
```
153173

154174
### Cached Sensor Reads
175+
155176
Prevent redundant CAN bus calls with cached values:
156177

157178
```java
@@ -179,23 +200,9 @@ public class CachedDouble {
179200
// Call reset() once per periodic cycle
180201
```
181202

182-
### Telemetry Logging
183-
Every subsystem must publish comprehensive telemetry:
184-
185-
```java
186-
@Override
187-
public void periodic() {
188-
io.updateInputs(inputs);
189-
Logger.processInputs("Elevator", inputs);
190-
191-
// Additional telemetry
192-
Logger.recordOutput("Elevator/Setpoint", setpoint);
193-
Logger.recordOutput("Elevator/AtSetpoint", atSetpoint());
194-
Logger.recordOutput("Elevator/HomingState", homingState.toString());
195-
}
196-
```
197203

198204
### Javadoc Documentation
205+
199206
Document public APIs, especially base classes and interfaces:
200207

201208
```java
@@ -215,6 +222,80 @@ public abstract class ServoMotorSubsystem<IO extends MotorIO> extends SubsystemB
215222
}
216223
```
217224

225+
12. Safety & Error Handling
226+
227+
### Mechanism Limits
228+
229+
Use device built in limits if available:
230+
231+
```java
232+
public static SoftwareLimitSwitchConfigs createSoftLimitConigs(){
233+
SoftwareLimitSwitchConfigs newConfigs = new SoftwareLimitSwitchConfigs();
234+
newConfigs.ForwardSoftLimitEnable = false;
235+
newConfigs.ReverseSoftLimitEnable = false;
236+
newConfigs.ForwardSoftLimitThreshold = CLIMBER_FORWARD_SOFT_LIMIT;
237+
newConfigs.ReverseSoftLimitThreshold = CLIMBER_REVERSE_SOFT_LIMIT;
238+
return newConfigs;
239+
}
240+
```
241+
242+
If no built in limits, then enforce software limits:
243+
244+
```java
245+
public void setPosition(double position) {
246+
// Clamp to safe range
247+
position = MathUtil.clamp(position, MIN_POSITION, MAX_POSITION);
248+
setpoint = position;
249+
}
250+
```
251+
252+
### Current Limiting
253+
254+
Protect motors from overcurrent:
255+
256+
```java
257+
TalonFXConfiguration config = new TalonFXConfiguration();
258+
config.CurrentLimits.SupplyCurrentLimit = 40.0;
259+
config.CurrentLimits.SupplyCurrentThreshold = 60.0;
260+
config.CurrentLimits.SupplyTimeThreshold = 0.1;
261+
config.CurrentLimits.SupplyCurrentLimitEnable = true;
262+
motor.getConfigurator().apply(config);
263+
```
264+
265+
### Fault Detection
266+
267+
Monitor and log hardware faults:
268+
269+
```java
270+
@Override
271+
public void periodic() {
272+
if (inputs.motorFaults != 0 || inputs.motorStickyFaults != 0) {
273+
Logger.recordOutput("Elevator/Faults", true);
274+
DriverStation.reportWarning(
275+
"Elevator motor fault detected: " + inputs.motorFaults,
276+
false
277+
);
278+
}
279+
}
280+
```
281+
282+
### Match Logging
283+
284+
Explicity log match events
285+
286+
```java
287+
@Override
288+
public void autonomousInit() {
289+
Logger.recordOutput("Match/AutonomousStart", Timer.getFPGATimestamp());
290+
Logger.recordOutput("Match/SelectedAuto", autoChooser.getSelected().getName());
291+
}
292+
293+
@Override
294+
public void teleopInit() {
295+
Logger.recordOutput("Match/TeleopStart", Timer.getFPGATimestamp());
296+
}
297+
```
298+
218299
---
219300

220301
## Output Format

0 commit comments

Comments
 (0)