Skip to content

Commit

Permalink
Differential odometry completed*
Browse files Browse the repository at this point in the history
  • Loading branch information
Merridew1 committed Dec 10, 2024
1 parent 27ec070 commit 3476f89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.littletonrobotics.junction.Logger;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.kinematics.DifferentialDriveOdometry;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
Expand All @@ -19,6 +20,8 @@ public class Drivetrain extends SubsystemBase {
Constants.PID.DriveTrain.I, Constants.PID.DriveTrain.D);
PIDController driveTrainLeftPIDController = new PIDController(0, 0, 0);
SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(0, 0);
private DifferentialDriveOdometry odometry =
new DifferentialDriveOdometry(inputs.gyroYaw, inputs.leftDistance, inputs.rightDistance);

/**
* Create Wrist Intake Subsystem
Expand All @@ -31,6 +34,7 @@ public Drivetrain(DrivetrainIO io) {
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Drivetrain", inputs);
odometry.update(inputs.gyroYaw, inputs.leftDistance, inputs.rightDistance);
}

public void drive(Double lPower, double rPower) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DrivetrainIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static class DrivetrainIOInputs {
public Rotation2d gyroYaw = new Rotation2d();
public double rightVelocity;
public double leftVelocity;
public double rightDistance;
public double leftDistance;
}

/** Updates the set of loggable inputs. */
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DrivetrainReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DrivetrainReal implements DrivetrainIO {
TalonFX right2 = new TalonFX(Constants.Motors.DriveTrain.BACK_RIGHT_MOTOR_ID, "CANivore");
StatusSignal<Double> rightVelocity = right1.getVelocity();
StatusSignal<Double> leftVelocity = left1.getVelocity();
StatusSignal<Double> leftDistance = left1.getPosition();
StatusSignal<Double> rightDistance = right1.getPosition();

/**
* Drivetrain Real
Expand All @@ -31,6 +33,8 @@ public void updateInputs(DrivetrainIOInputs inputs) {
inputs.gyroYaw = Rotation2d.fromDegrees(0);
inputs.leftVelocity = leftVelocity.getValueAsDouble();
inputs.rightVelocity = rightVelocity.getValueAsDouble();
inputs.leftDistance = leftDistance.getValueAsDouble();
inputs.rightDistance = rightDistance.getValueAsDouble();

}

Expand Down

0 comments on commit 3476f89

Please sign in to comment.