From 6a4c6476085e4be10d0766a9591aa6104e36c195 Mon Sep 17 00:00:00 2001 From: Sachet Korada Date: Fri, 13 Dec 2024 10:54:51 -0500 Subject: [PATCH] Use Drive Subsystem object over Mecanum Drive --- .../ftc/teamcode/MecanumDrive.kt | 515 ----------------- .../firstinspires/ftc/teamcode/TankDrive.kt | 509 ----------------- .../ftc/teamcode/TwoDeadWheelLocalizer.kt | 138 ----- .../ftc/teamcode/tuning/LocalizationTest.kt | 79 --- .../teamcode/tuning/ManualFeedbackTuner.kt | 66 --- .../auto/blue/basket/left/Blue1Plus1.kt | 125 +++++ .../auto/blue/basket/left/Blue1Plus2.kt | 197 +++++++ .../auto/blue/basket/left/Blue1Plus2V2.kt | 185 +++++++ .../auto/blue/basket/left/Blue1Plus1.kt | 140 ----- .../auto/blue/basket/left/Blue1Plus2.kt | 212 ------- .../auto/blue/basket/left/Blue1Plus2V2.kt | 201 ------- .../ftc/teamcode/opModes/teleOp/MainTeleOp.kt | 8 +- .../teamcode/opModes/tuning/IntakeTuner.kt | 2 +- .../opModes/tuning/slides/SlidesPIDTuner.kt | 6 +- .../ftc/teamcode/roadrunner}/Drawing.kt | 2 +- .../ftc/teamcode/roadrunner}/Localizer.kt | 2 +- .../roadrunner}/ThreeDeadWheelLocalizer.kt | 22 +- .../messages/DriveCommandMessage.kt | 2 +- .../messages/MecanumCommandMessage.kt | 2 +- .../messages/MecanumLocalizerInputsMessage.kt | 2 +- .../roadrunner}/messages/PoseMessage.kt | 2 +- .../messages/TankCommandMessage.kt | 2 +- .../messages/TankLocalizerInputsMessage.kt | 2 +- .../messages/ThreeDeadWheelInputsMessage.kt | 2 +- .../messages/TwoDeadWheelInputsMessage.kt | 2 +- .../roadrunner/tuning/LocalizationTest.kt | 55 ++ .../roadrunner/tuning/ManualFeedbackTuner.kt | 44 ++ .../teamcode/roadrunner}/tuning/SplineTest.kt | 22 +- .../roadrunner}/tuning/TuningOpModes.kt | 128 ++--- .../subsystems/arm/OpenArmSubsystem.kt | 3 +- .../subsystems/drive/DriveSubsystem.kt | 524 +++++++++++++++++- .../slides/OpenElevatorSubsystem.kt | 31 +- .../subsystems/slides/OpenSlidesSubsystem.kt | 42 -- 33 files changed, 1218 insertions(+), 2056 deletions(-) delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MecanumDrive.kt delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TankDrive.kt delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TwoDeadWheelLocalizer.kt delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/tuning/LocalizationTest.kt delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/tuning/ManualFeedbackTuner.kt create mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/legacy/auto/blue/basket/left/Blue1Plus1.kt create mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/legacy/auto/blue/basket/left/Blue1Plus2.kt create mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/legacy/auto/blue/basket/left/Blue1Plus2V2.kt delete mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/opModes/auto/blue/basket/left/Blue1Plus1.kt delete mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/opModes/auto/blue/basket/left/Blue1Plus2.kt delete mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/opModes/auto/blue/basket/left/Blue1Plus2V2.kt rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/Drawing.kt (90%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/Localizer.kt (74%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/ThreeDeadWheelLocalizer.kt (89%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/DriveCommandMessage.kt (90%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/MecanumCommandMessage.kt (79%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/MecanumLocalizerInputsMessage.kt (93%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/PoseMessage.kt (80%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/TankCommandMessage.kt (70%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/TankLocalizerInputsMessage.kt (87%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/ThreeDeadWheelInputsMessage.kt (81%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/messages/TwoDeadWheelInputsMessage.kt (95%) create mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/roadrunner/tuning/LocalizationTest.kt create mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/roadrunner/tuning/ManualFeedbackTuner.kt rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/tuning/SplineTest.kt (54%) rename TeamCode/src/main/{java/org/firstinspires/ftc/teamcode => kotlin/org/firstinspires/ftc/teamcode/roadrunner}/tuning/TuningOpModes.kt (56%) delete mode 100644 TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/subsystems/slides/OpenSlidesSubsystem.kt diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MecanumDrive.kt b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MecanumDrive.kt deleted file mode 100644 index 0f3263e..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MecanumDrive.kt +++ /dev/null @@ -1,515 +0,0 @@ -package org.firstinspires.ftc.teamcode - -import com.acmerobotics.dashboard.canvas.Canvas -import com.acmerobotics.dashboard.config.Config -import com.acmerobotics.dashboard.telemetry.TelemetryPacket -import com.acmerobotics.roadrunner.AccelConstraint -import com.acmerobotics.roadrunner.Action -import com.acmerobotics.roadrunner.AngularVelConstraint -import com.acmerobotics.roadrunner.DualNum -import com.acmerobotics.roadrunner.HolonomicController -import com.acmerobotics.roadrunner.MecanumKinematics -import com.acmerobotics.roadrunner.MecanumKinematics.WheelIncrements -import com.acmerobotics.roadrunner.MinVelConstraint -import com.acmerobotics.roadrunner.MotorFeedforward -import com.acmerobotics.roadrunner.Pose2d -import com.acmerobotics.roadrunner.PoseVelocity2d -import com.acmerobotics.roadrunner.PoseVelocity2dDual -import com.acmerobotics.roadrunner.ProfileAccelConstraint -import com.acmerobotics.roadrunner.ProfileParams -import com.acmerobotics.roadrunner.Rotation2d -import com.acmerobotics.roadrunner.Time -import com.acmerobotics.roadrunner.TimeTrajectory -import com.acmerobotics.roadrunner.TimeTurn -import com.acmerobotics.roadrunner.TrajectoryActionBuilder -import com.acmerobotics.roadrunner.TrajectoryBuilderParams -import com.acmerobotics.roadrunner.TurnConstraints -import com.acmerobotics.roadrunner.Twist2dDual -import com.acmerobotics.roadrunner.Vector2d -import com.acmerobotics.roadrunner.Vector2dDual -import com.acmerobotics.roadrunner.VelConstraint -import com.acmerobotics.roadrunner.ftc.DownsampledWriter -import com.acmerobotics.roadrunner.ftc.Encoder -import com.acmerobotics.roadrunner.ftc.FlightRecorder.write -import com.acmerobotics.roadrunner.ftc.LazyImu -import com.acmerobotics.roadrunner.ftc.OverflowEncoder -import com.acmerobotics.roadrunner.ftc.RawEncoder -import com.acmerobotics.roadrunner.ftc.throwIfModulesAreOutdated -import com.acmerobotics.roadrunner.now -import com.acmerobotics.roadrunner.range -import com.qualcomm.hardware.lynx.LynxModule -import com.qualcomm.hardware.rev.RevHubOrientationOnRobot -import com.qualcomm.hardware.rev.RevHubOrientationOnRobot.UsbFacingDirection -import com.qualcomm.robotcore.hardware.DcMotor -import com.qualcomm.robotcore.hardware.DcMotorEx -import com.qualcomm.robotcore.hardware.HardwareMap -import com.qualcomm.robotcore.hardware.IMU -import com.qualcomm.robotcore.hardware.VoltageSensor -import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit -import org.firstinspires.ftc.teamcode.messages.DriveCommandMessage -import org.firstinspires.ftc.teamcode.messages.MecanumCommandMessage -import org.firstinspires.ftc.teamcode.messages.MecanumLocalizerInputsMessage -import org.firstinspires.ftc.teamcode.messages.PoseMessage -import java.util.LinkedList -import kotlin.math.ceil -import kotlin.math.max - -@Config -class MecanumDrive(hardwareMap: HardwareMap, var pose: Pose2d) { - class Params { - // IMU orientation - // TODO: fill in these values based on - // see https://ftc-docs.firstinspires.org/en/latest/programming_resources/imu/imu.html?highlight=imu#physical-hub-mounting - var logoFacingDirection: RevHubOrientationOnRobot.LogoFacingDirection = - RevHubOrientationOnRobot.LogoFacingDirection.UP - var usbFacingDirection: UsbFacingDirection = UsbFacingDirection.FORWARD - - // drive model parameters - var inPerTick: Double = 1.0 - var lateralInPerTick: Double = inPerTick - var trackWidthTicks: Double = 0.0 - - // feedforward parameters (in tick units) - var kS: Double = 0.0 - var kV: Double = 0.0 - var kA: Double = 0.0 - - // path profile parameters (in inches) - var maxWheelVel: Double = 50.0 - var minProfileAccel: Double = -30.0 - var maxProfileAccel: Double = 50.0 - - // turn profile parameters (in radians) - var maxAngVel: Double = Math.PI // shared with path - var maxAngAccel: Double = Math.PI - - // path controller gains - var axialGain: Double = 0.0 - var lateralGain: Double = 0.0 - var headingGain: Double = 0.0 // shared with turn - - var axialVelGain: Double = 0.0 - var lateralVelGain: Double = 0.0 - var headingVelGain: Double = 0.0 // shared with turn - } - - val kinematics: MecanumKinematics = MecanumKinematics( - PARAMS.inPerTick * PARAMS.trackWidthTicks, PARAMS.inPerTick / PARAMS.lateralInPerTick - ) - - val defaultTurnConstraints: TurnConstraints = TurnConstraints( - PARAMS.maxAngVel, -PARAMS.maxAngAccel, PARAMS.maxAngAccel - ) - val defaultVelConstraint: VelConstraint = MinVelConstraint( - listOf( - kinematics.WheelVelConstraint(PARAMS.maxWheelVel), - AngularVelConstraint(PARAMS.maxAngVel) - ) - ) - val defaultAccelConstraint: AccelConstraint = - ProfileAccelConstraint(PARAMS.minProfileAccel, PARAMS.maxProfileAccel) - - val leftFront: DcMotorEx - val leftBack: DcMotorEx - val rightBack: DcMotorEx - val rightFront: DcMotorEx - - val voltageSensor: VoltageSensor - - val lazyImu: LazyImu - - val localizer: Localizer - - private val poseHistory = LinkedList() - - private val estimatedPoseWriter = DownsampledWriter("ESTIMATED_POSE", 50000000) - private val targetPoseWriter = DownsampledWriter("TARGET_POSE", 50000000) - private val driveCommandWriter = DownsampledWriter("DRIVE_COMMAND", 50000000) - private val mecanumCommandWriter = DownsampledWriter("MECANUM_COMMAND", 50000000) - - inner class DriveLocalizer : Localizer { - val leftFront: Encoder = - OverflowEncoder(RawEncoder(this@MecanumDrive.leftFront)) - val leftBack: Encoder = - OverflowEncoder(RawEncoder(this@MecanumDrive.leftBack)) - val rightBack: Encoder = - OverflowEncoder(RawEncoder(this@MecanumDrive.rightBack)) - val rightFront: Encoder = - OverflowEncoder(RawEncoder(this@MecanumDrive.rightFront)) - val imu: IMU = lazyImu.get() - - private var lastLeftFrontPos = 0 - private var lastLeftBackPos = 0 - private var lastRightBackPos = 0 - private var lastRightFrontPos = 0 - private var lastHeading: Rotation2d? = null - private var initialized = false - - init { - // TODO: reverse encoders if needed - // leftFront.setDirection(DcMotorSimple.Direction.REVERSE); - } - - override fun update(): Twist2dDual