Skip to content

Conversation

@ngarnsworthy
Copy link
Collaborator

Before issuing a pull request:

  • Ensure all constants are in the Constants class
  • Update the backup OpMode if needed
  • Update README.md

Copilot AI review requested due to automatic review settings November 19, 2025 00:38
@ngarnsworthy ngarnsworthy linked an issue Nov 19, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds odometry functionality to the Drivetrain subsystem, enabling the robot to track its position on the field using wheel encoders and a gyroscope.

Key Changes:

  • Added MecanumDriveOdometry with gyroscope integration to track robot pose
  • Updated Drivetrain constructor to require a GyroEx parameter
  • Added kinematics constants for mecanum drive wheel positions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/subsystems/Drivetrain.java Integrated odometry tracking with encoder readings, gyroscope input, and periodic pose updates
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OpModes/PrimaryOpMode.java Instantiated RevIMU gyroscope and passed it to the Drivetrain constructor
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Constants.java Added wheel location constants and MecanumDriveKinematics for odometry calculations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

@Override
public void periodic(){
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after method name - should be periodic() { for consistency with Java style conventions.

Suggested change
public void periodic(){
public void periodic() {

Copilot uses AI. Check for mistakes.
drive.driveRobotCentric(strafe, forward, rotate);
}

public Pose2d getPose() {return pose;}
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after getPose() and before {. Should be formatted as public Pose2d getPose() { return pose; } or split across multiple lines for consistency.

Suggested change
public Pose2d getPose() {return pose;}
public Pose2d getPose() { return pose; }

Copilot uses AI. Check for mistakes.
import com.arcrobotics.ftclib.geometry.Rotation2d;
import com.arcrobotics.ftclib.hardware.GyroEx;
import com.arcrobotics.ftclib.hardware.motors.Motor;
import com.arcrobotics.ftclib.kinematics.HolonomicOdometry;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is unused and should be removed.

Suggested change
import com.arcrobotics.ftclib.kinematics.HolonomicOdometry;

Copilot uses AI. Check for mistakes.
Comment on lines 14 to 15
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;

Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports are unused and should be removed.

Suggested change
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;

Copilot uses AI. Check for mistakes.
private final MecanumDrive drive;
private final MecanumDriveOdometry odometry;
private final GyroEx gyroscope;
private Pose2d pose;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pose field is not initialized and will be null until periodic() is called. This will cause a NullPointerException if getPose() is called before the first periodic() execution. Consider initializing it in the constructor: pose = new Pose2d(0.0, 0.0, new Rotation2d());

Copilot uses AI. Check for mistakes.
Comment on lines 16 to 22
new Translation2d(length/2, 0.381);
public static final Translation2d frontRightLocation =
new Translation2d(length/2, -0.381);
public static final Translation2d backLeftLocation =
new Translation2d(-length/2, 0.381);
public static final Translation2d backRightLocation =
new Translation2d(-length/2, -0.381);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The width variable is defined but never used. The wheel locations use hardcoded values (0.381) instead. Consider using width/2 consistently:

new Translation2d(length/2, width/2);   // frontLeft
new Translation2d(length/2, -width/2);  // frontRight
new Translation2d(-length/2, width/2);  // backLeft
new Translation2d(-length/2, -width/2); // backRight

This ensures consistency and makes the code easier to maintain if the robot dimensions change.

Suggested change
new Translation2d(length/2, 0.381);
public static final Translation2d frontRightLocation =
new Translation2d(length/2, -0.381);
public static final Translation2d backLeftLocation =
new Translation2d(-length/2, 0.381);
public static final Translation2d backRightLocation =
new Translation2d(-length/2, -0.381);
new Translation2d(length/2, width/2);
public static final Translation2d frontRightLocation =
new Translation2d(length/2, -width/2);
public static final Translation2d backLeftLocation =
new Translation2d(-length/2, width/2);
public static final Translation2d backRightLocation =
new Translation2d(-length/2, -width/2);

Copilot uses AI. Check for mistakes.
import com.arcrobotics.ftclib.hardware.GyroEx;
import com.arcrobotics.ftclib.hardware.RevIMU;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is unused and should be removed.

Suggested change
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;

Copilot uses AI. Check for mistakes.
public static final String brMotorName = "backRightDrive";

private static final double length = 0.2873375;
private static final double width = 0.3444875;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before double - should be a single space for consistency.

Suggested change
private static final double width = 0.3444875;
private static final double width = 0.3444875;

Copilot uses AI. Check for mistakes.
@ngarnsworthy ngarnsworthy requested a review from Copilot November 19, 2025 00:45
@ngarnsworthy ngarnsworthy merged commit b677234 into master Nov 19, 2025
5 checks passed
@ngarnsworthy ngarnsworthy deleted the 24-add-odometry branch November 19, 2025 00:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private final MecanumDrive drive;
private final MecanumDriveOdometry odometry;
private final GyroEx gyroscope;
private Pose2d pose;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pose field is not initialized in the constructor, which means it will be null until the first periodic() call. This could cause a NullPointerException if getPose() is called before periodic() runs. Initialize pose in the constructor with the initial pose value: this.pose = new Pose2d(0.0, 0.0, new Rotation2d());

Copilot uses AI. Check for mistakes.
bLE.getRate(), bRE.getRate()
);

pose = odometry.updateWithTime(System.currentTimeMillis()/1000.0, gyroscope.getRotation2d(), wheelSpeeds);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time calculation System.currentTimeMillis()/1000.0 performs integer division before converting to double, potentially losing precision. Use System.currentTimeMillis()/1000.0 which should work, but consider using System.nanoTime() for better precision: System.nanoTime() / 1e9 or explicitly cast to double: (double)System.currentTimeMillis() / 1000.0

Copilot uses AI. Check for mistakes.
import com.arcrobotics.ftclib.hardware.GyroEx;
import com.arcrobotics.ftclib.hardware.RevIMU;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import com.qualcomm.robotcore.hardware.IntegratingGyroscope is unused and should be removed.

Suggested change
import com.qualcomm.robotcore.hardware.IntegratingGyroscope;

Copilot uses AI. Check for mistakes.
public static final String brMotorName = "backRightDrive";

private static final double length = 0.2873375;
private static final double width = 0.3444875;
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space between final and double should be removed for consistency with the line above.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add odometry

2 participants