-
Notifications
You must be signed in to change notification settings - Fork 0
Created odometry for Drivetrain.java #33
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,11 +1,31 @@ | ||
| package org.firstinspires.ftc.teamcode; | ||
|
|
||
| import com.arcrobotics.ftclib.geometry.Translation2d; | ||
| import com.arcrobotics.ftclib.kinematics.wpilibkinematics.MecanumDriveKinematics; | ||
|
|
||
| public final class Constants { | ||
| public static class Drivetrain { | ||
| public static final String flMotorName = "frontLeftDrive"; | ||
| public static final String frMotorName = "frontRightDrive"; | ||
| public static final String blMotorName = "backLeftDrive"; | ||
| public static final String brMotorName = "backRightDrive"; | ||
|
|
||
| private static final double length = 0.2873375; | ||
| private static final double width = 0.3444875; | ||
|
||
| public static final Translation2d frontLeftLocation = | ||
| 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); | ||
|
|
||
| public static final MecanumDriveKinematics kinematics = new MecanumDriveKinematics | ||
| ( | ||
| frontLeftLocation, frontRightLocation, | ||
| backLeftLocation, backRightLocation | ||
| ); | ||
| } | ||
|
|
||
| public static class Shooter { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,10 @@ | |||||
| import com.arcrobotics.ftclib.command.CommandOpMode; | ||||||
| import com.arcrobotics.ftclib.gamepad.GamepadEx; | ||||||
| import com.arcrobotics.ftclib.gamepad.GamepadKeys; | ||||||
| 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; | ||||||
|
||||||
| import com.qualcomm.robotcore.hardware.IntegratingGyroscope; |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
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.
| import com.qualcomm.robotcore.hardware.IntegratingGyroscope; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,26 +2,60 @@ | |||||
|
|
||||||
| import com.arcrobotics.ftclib.command.SubsystemBase; | ||||||
| import com.arcrobotics.ftclib.drivebase.MecanumDrive; | ||||||
| import com.arcrobotics.ftclib.geometry.Pose2d; | ||||||
| import com.arcrobotics.ftclib.geometry.Rotation2d; | ||||||
| import com.arcrobotics.ftclib.hardware.GyroEx; | ||||||
| import com.arcrobotics.ftclib.hardware.motors.Motor; | ||||||
| import com.arcrobotics.ftclib.kinematics.wpilibkinematics.MecanumDriveOdometry; | ||||||
| import com.arcrobotics.ftclib.kinematics.wpilibkinematics.MecanumDriveWheelSpeeds; | ||||||
| import com.qualcomm.robotcore.hardware.HardwareMap; | ||||||
|
|
||||||
| import org.firstinspires.ftc.teamcode.Constants; | ||||||
|
|
||||||
| public class Drivetrain extends SubsystemBase { | ||||||
| private final Motor fL, fR, bL, bR; | ||||||
| private final Motor.Encoder fLE, fRE, bLE, bRE; | ||||||
|
|
||||||
| private final MecanumDrive drive; | ||||||
| private final MecanumDriveOdometry odometry; | ||||||
| private final GyroEx gyroscope; | ||||||
| private Pose2d pose; | ||||||
|
||||||
|
|
||||||
| public Drivetrain(HardwareMap hardwareMap, String flName, String frName, String blName, String brName) { | ||||||
| public Drivetrain(HardwareMap hardwareMap, String flName, String frName, String blName, String brName, GyroEx gyroscope) { | ||||||
| fL = new Motor(hardwareMap, flName); | ||||||
| fLE = fL.encoder; | ||||||
| fR = new Motor(hardwareMap, frName); | ||||||
| fRE = fR.encoder; | ||||||
| bL = new Motor(hardwareMap, blName); | ||||||
| bLE = bL.encoder; | ||||||
| bR = new Motor(hardwareMap, brName); | ||||||
| bRE = bR.encoder; | ||||||
| this.gyroscope = gyroscope; | ||||||
|
|
||||||
| drive = new MecanumDrive(fL, fR, bL, bR); | ||||||
|
|
||||||
| odometry = new MecanumDriveOdometry( | ||||||
| Constants.Drivetrain.kinematics, gyroscope.getRotation2d(), | ||||||
| new Pose2d(0.0, 0.0, new Rotation2d() | ||||||
| )); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void periodic(){ | ||||||
|
||||||
| public void periodic(){ | |
| public void periodic() { |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
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
AI
Nov 19, 2025
There was a problem hiding this comment.
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.
| public Pose2d getPose() {return pose;} | |
| public Pose2d getPose() { return pose; } |
There was a problem hiding this comment.
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.