Skip to content

Commit

Permalink
Merge pull request #19 from Merridew1/Odometry
Browse files Browse the repository at this point in the history
Odometry
  • Loading branch information
Merridew1 authored Dec 10, 2024
2 parents 27ec070 + 886863a commit 7bb5aa6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion 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 All @@ -42,7 +46,7 @@ public void drive(Double lPower, double rPower) {
Logger.recordOutput("Drivetrain/leftPower", lPower);
Logger.recordOutput("Drivetrain/rightPower", rPower);
}

public Command driveCommand(CommandXboxController controller) {
return run(() -> drive(controller.getLeftY(), controller.getRightY()));
}
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 7bb5aa6

Please sign in to comment.