Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanErn committed Dec 22, 2024
1 parent fdfffcf commit 325d47e
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 111 deletions.
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU Lesser General Public License
=================================

_Version 3, 29 June 2007_
_Version 3, 29 June 2007_
_Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_

Everyone is permitted to copy and distribute verbatim copies
Expand Down Expand Up @@ -160,4 +160,4 @@ If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Library.
6 changes: 5 additions & 1 deletion docs/mkdocs/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Team 5152 Robot Code Documentation

Welcome to the comprehensive documentation for Team 5152's robot code. This documentation provides an in-depth look at our robot's sophisticated control and automation systems.
Welcome to the comprehensive documentation for Team 5152's robot code.

If you are starting the new season from scratch, checkout the [quickstart guide](/5152_Template/quickstart)

Javadocs can be found [here](/5152_Template/javadoc)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Parameters:
- Includes brief manual rotation override capability with 0.1s timeout
- Integrates with both [DriveFacingPose](/5152_Template/library/commands/swerve/drivefacingpose) and [DefaultDrive](/5152_Template/library/commands/swerve/defaultdrive) commands

For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/commands/package-summary.html).
For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/commands/package-summary.html).
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ The command requires proper configuration of:
- Generates and executes path to approach position
- Command times out after 0.1 seconds but generated path continues executing

For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/commands/package-summary.html).
For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/commands/package-summary.html).
2 changes: 1 addition & 1 deletion docs/mkdocs/docs/library/subsystems/vision/apriltag.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ The subsystem includes several safeguards for reliable operation:

## Related Links
- [JavaDoc Reference](/5152_Template/javadoc/frc/alotobots/library/subsystems/vision/photonvision/apriltag/package-summary.html)
- [PhotonVision Documentation](https://docs.photonvision.org/en/latest/)
- [PhotonVision Documentation](https://docs.photonvision.org/en/latest/)
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ The subsystem requires several constants to be configured in the ObjectDetection
- At least one compatible camera connected and configured
- WPILib 2024 or newer

For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/package-summary.html).
For detailed method documentation, refer to the [JavaDoc reference](PROJECT_ROOT/javadoc/frc/alotobots/library/subsystems/vision/photonvision/objectdetection/package-summary.html).
14 changes: 6 additions & 8 deletions docs/mkdocs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ When starting a new season:
// In Constants.java
public static final TunerConstants tunerConstants = new TunerConstants2024();
// or if using different configurations for simulation:
public static final TunerConstants tunerConstants =
Constants.currentMode == Mode.SIM ?
new TunerConstantsSim() :
public static final TunerConstants tunerConstants =
Constants.currentMode == Mode.SIM ?
new TunerConstantsSim() :
new TunerConstants2024();
```
This static field is used throughout the codebase to access swerve configurations.
Expand Down Expand Up @@ -104,7 +104,7 @@ The swerve drive configuration is generated using Phoenix Tuner X's Swerve Gener
```java
// Replace generated values like:
public static final int kFrontLeftDriveMotorId = 1;

// With references to Constants:
public static final int kFrontLeftDriveMotorId = Constants.CanId.FRONT_LEFT_DRIVE_MTR_CAN_ID;
```
Expand All @@ -129,7 +129,7 @@ After configuring modules and before PID tuning, verify basic functionality:
.withKV(1.59)
.withKA(0)
.withStaticFeedforwardSign(StaticFeedforwardSignValue.UseClosedLoopSign);

// Default drive gains
private static final Slot0Configs driveGains = new Slot0Configs()
.withKP(0.1)
Expand Down Expand Up @@ -672,7 +672,7 @@ Accurate camera position measurements are critical for AprilTag vision:
new Transform3d(
new Translation3d(0.245, 0.21, 0.17), // X, Y, Z in meters
new Rotation3d(0, Math.toRadians(-35), Math.toRadians(45))), // Roll, Pitch, Yaw

// Front Middle Camera
new Transform3d(
new Translation3d(0.275, 0.0, 0.189),
Expand Down Expand Up @@ -948,5 +948,3 @@ After configuring cameras and game elements:
- Position jumps: Try decreasing POSITION_MATCH_TOLERANCE

Congratulations! Your project should now be fully configured and tuned for optimal performance.


Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ public void runCharacterization(double output) {
io.setDriveOpenLoop(output);
io.setTurnPosition(new Rotation2d());
}
// Replace this to estimate MOI via SysID
// public void runCharacterization(double output) {
// io.setDriveOpenLoop(output);
// io.setTurnPosition(new Rotation2d(constants.LocationX, constants.LocationY).plus(Rotation2d.kCCW_Pi_2));
//}

// Replace this to estimate MOI via SysID
// public void runCharacterization(double output) {
// io.setDriveOpenLoop(output);
// io.setTurnPosition(new Rotation2d(constants.LocationX,
// constants.LocationY).plus(Rotation2d.kCCW_Pi_2));
// }

/** Disables all outputs to motors. */
public void stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.littletonrobotics.junction.Logger;

/**
* A subsystem that handles AprilTag detection and processing using PhotonVision.
* This subsystem processes AprilTag data from multiple cameras and provides pose estimation
* with statistical confidence measures.
* A subsystem that handles AprilTag detection and processing using PhotonVision. This subsystem
* processes AprilTag data from multiple cameras and provides pose estimation with statistical
* confidence measures.
*/
public class AprilTagSubsystem extends SubsystemBase {
/** Consumer interface for receiving AprilTag pose data with statistical confidence */
Expand Down Expand Up @@ -69,16 +69,16 @@ public AprilTagSubsystem(AprilTagConsumer consumer, AprilTagIO... io) {
this.disconnectedAlerts = new Alert[io.length];
for (int i = 0; i < inputs.length; i++) {
disconnectedAlerts[i] =
new Alert(
"Vision camera " + CAMERA_CONFIGS[i].name() + " is disconnected.",
AlertType.kWarning);
new Alert(
"Vision camera " + CAMERA_CONFIGS[i].name() + " is disconnected.",
AlertType.kWarning);
}

// Ensure no illegal values for STD factors
for (double factor : CAMERA_STD_DEV_FACTORS) {
if (factor < 1.0)
throw new IllegalArgumentException(
"[AprilTagSubsystem] Value must be greater than or equal to 1, but was: " + factor);
"[AprilTagSubsystem] Value must be greater than or equal to 1, but was: " + factor);
}
}

Expand All @@ -93,13 +93,9 @@ public Rotation2d getTargetX(int cameraIndex) {
}

/**
* Periodic function that processes AprilTag data from all cameras.
* This method:
* - Updates camera inputs
* - Processes pose observations
* - Applies statistical confidence calculations
* - Logs vision data
* - Sends accepted pose estimates to the consumer
* Periodic function that processes AprilTag data from all cameras. This method: - Updates camera
* inputs - Processes pose observations - Applies statistical confidence calculations - Logs
* vision data - Sends accepted pose estimates to the consumer
*/
@Override
public void periodic() {
Expand Down Expand Up @@ -137,17 +133,17 @@ public void periodic() {
for (var observation : inputs[cameraIndex].poseObservations) {
// Check whether to reject pose
boolean rejectPose =
observation.tagCount() == 0 // Must have at least one tag
|| (observation.tagCount() == 1
&& observation.ambiguity() > MAX_AMBIGUITY) // Cannot be high ambiguity
|| Math.abs(observation.pose().getZ())
> MAX_Z_ERROR // Must have realistic Z coordinate

// Must be within the field boundaries
|| observation.pose().getX() < 0.0
|| observation.pose().getX() > APRIL_TAG_LAYOUT.getFieldLength()
|| observation.pose().getY() < 0.0
|| observation.pose().getY() > APRIL_TAG_LAYOUT.getFieldWidth();
observation.tagCount() == 0 // Must have at least one tag
|| (observation.tagCount() == 1
&& observation.ambiguity() > MAX_AMBIGUITY) // Cannot be high ambiguity
|| Math.abs(observation.pose().getZ())
> MAX_Z_ERROR // Must have realistic Z coordinate

// Must be within the field boundaries
|| observation.pose().getX() < 0.0
|| observation.pose().getX() > APRIL_TAG_LAYOUT.getFieldLength()
|| observation.pose().getY() < 0.0
|| observation.pose().getY() > APRIL_TAG_LAYOUT.getFieldWidth();

// Add pose to log
robotPoses.add(observation.pose());
Expand All @@ -164,7 +160,7 @@ public void periodic() {

// Calculate standard deviations
double stdDevFactor =
Math.pow(observation.averageTagDistance(), 2.0) / observation.tagCount();
Math.pow(observation.averageTagDistance(), 2.0) / observation.tagCount();
double linearStdDev = LINEAR_STD_DEV_BASE * stdDevFactor;
double angularStdDev = ANGULAR_STD_DEV_BASE * stdDevFactor;

Expand All @@ -175,24 +171,24 @@ public void periodic() {

// Send vision observation
consumer.accept(
observation.pose().toPose2d(),
observation.timestamp(),
VecBuilder.fill(linearStdDev, linearStdDev, angularStdDev));
observation.pose().toPose2d(),
observation.timestamp(),
VecBuilder.fill(linearStdDev, linearStdDev, angularStdDev));
}

// Log camera data
Logger.recordOutput(
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/TagPoses",
tagPoses.toArray(new Pose3d[tagPoses.size()]));
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/TagPoses",
tagPoses.toArray(new Pose3d[tagPoses.size()]));
Logger.recordOutput(
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPoses",
robotPoses.toArray(new Pose3d[robotPoses.size()]));
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPoses",
robotPoses.toArray(new Pose3d[robotPoses.size()]));
Logger.recordOutput(
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPosesAccepted",
robotPosesAccepted.toArray(new Pose3d[robotPosesAccepted.size()]));
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPosesAccepted",
robotPosesAccepted.toArray(new Pose3d[robotPosesAccepted.size()]));
Logger.recordOutput(
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPosesRejected",
robotPosesRejected.toArray(new Pose3d[robotPosesRejected.size()]));
"Vision/Camera" + CAMERA_CONFIGS[cameraIndex].name() + "/RobotPosesRejected",
robotPosesRejected.toArray(new Pose3d[robotPosesRejected.size()]));
allTagPoses.addAll(tagPoses);
allRobotPoses.addAll(robotPoses);
allRobotPosesAccepted.addAll(robotPosesAccepted);
Expand All @@ -201,20 +197,18 @@ public void periodic() {

// Log summary data
Logger.recordOutput(
"Vision/Summary/TagPoses", allTagPoses.toArray(new Pose3d[allTagPoses.size()]));
"Vision/Summary/TagPoses", allTagPoses.toArray(new Pose3d[allTagPoses.size()]));
Logger.recordOutput(
"Vision/Summary/RobotPoses", allRobotPoses.toArray(new Pose3d[allRobotPoses.size()]));
"Vision/Summary/RobotPoses", allRobotPoses.toArray(new Pose3d[allRobotPoses.size()]));
Logger.recordOutput(
"Vision/Summary/RobotPosesAccepted",
allRobotPosesAccepted.toArray(new Pose3d[allRobotPosesAccepted.size()]));
"Vision/Summary/RobotPosesAccepted",
allRobotPosesAccepted.toArray(new Pose3d[allRobotPosesAccepted.size()]));
Logger.recordOutput(
"Vision/Summary/RobotPosesRejected",
allRobotPosesRejected.toArray(new Pose3d[allRobotPosesRejected.size()]));
"Vision/Summary/RobotPosesRejected",
allRobotPosesRejected.toArray(new Pose3d[allRobotPosesRejected.size()]));
}

/**
* Functional interface for consuming AprilTag pose data with statistical confidence measures.
*/
/** Functional interface for consuming AprilTag pose data with statistical confidence measures. */
@FunctionalInterface
public static interface AprilTagConsumer {
/**
Expand All @@ -225,8 +219,8 @@ public static interface AprilTagConsumer {
* @param visionMeasurementStdDevs Standard deviations for the measurement [x, y, theta]
*/
public void accept(
Pose2d visionRobotPoseMeters,
double timestampSeconds,
Matrix<N3, N1> visionMeasurementStdDevs);
Pose2d visionRobotPoseMeters,
double timestampSeconds,
Matrix<N3, N1> visionMeasurementStdDevs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import frc.alotobots.library.subsystems.vision.photonvision.objectdetection.util.GameElement;

/**
* A command that automatically rotates the robot to face detected game objects while allowing manual translation control.
* The robot will face the highest priority detected game element while driving. If no objects are detected,
* or if manual rotation override is active, falls back to standard manual control.
* A command that automatically rotates the robot to face detected game objects while allowing
* manual translation control. The robot will face the highest priority detected game element while
* driving. If no objects are detected, or if manual rotation override is active, falls back to
* standard manual control.
*/
public class DriveFacingBestObject extends Command {

Expand Down Expand Up @@ -58,9 +59,9 @@ public class DriveFacingBestObject extends Command {
* @param targetGameElementNames Array of game elements to target, in priority order
*/
public DriveFacingBestObject(
ObjectDetectionSubsystem objectDetectionSubsystem,
SwerveDriveSubsystem swerveDriveSubsystem,
GameElement... targetGameElementNames) {
ObjectDetectionSubsystem objectDetectionSubsystem,
SwerveDriveSubsystem swerveDriveSubsystem,
GameElement... targetGameElementNames) {
this.objectDetectionSubsystem = objectDetectionSubsystem;
this.swerveDriveSubsystem = swerveDriveSubsystem;
this.targetGameElementNames = targetGameElementNames;
Expand All @@ -71,10 +72,10 @@ public DriveFacingBestObject(
}

/**
* Executes the command logic. Gets the latest object detections and controls robot movement:
* - If objects are detected, rotates to face highest priority object while allowing manual translation
* - If no objects detected, allows full manual control
* - If manual rotation override active, starts timeout timer
* Executes the command logic. Gets the latest object detections and controls robot movement: - If
* objects are detected, rotates to face highest priority object while allowing manual translation
* - If no objects detected, allows full manual control - If manual rotation override active,
* starts timeout timer
*/
@Override
public void execute() {
Expand All @@ -84,9 +85,9 @@ public void execute() {
var matchingObject = java.util.Optional.<ObjectDetectionIO.DetectedObjectFieldRelative>empty();
for (GameElement element : targetGameElementNames) {
matchingObject =
detectedObjects.stream()
.filter(obj -> GAME_ELEMENTS[obj.classId()].equals(element))
.findFirst();
detectedObjects.stream()
.filter(obj -> GAME_ELEMENTS[obj.classId()].equals(element))
.findFirst();
if (matchingObject.isPresent()) {
break;
}
Expand Down Expand Up @@ -119,4 +120,4 @@ public void execute() {
public boolean isFinished() {
return overrideTimer.hasElapsed(OVERRIDE_TIMEOUT_SECONDS);
}
}
}
Loading

0 comments on commit 325d47e

Please sign in to comment.