Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 28903f4

Browse files
committed
fixes to make odometry work, now uses through bore encoders
1 parent 0f5da0f commit 28903f4

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/main/java/com/team766/odometry/DifferentialDriveOdometry.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.team766.odometry;
22

3-
import com.team766.hal.MotorController;
3+
import com.team766.hal.wpilib.REVThroughBoreDutyCycleEncoder;
44
import com.team766.library.RateLimiter;
55
import edu.wpi.first.math.geometry.Pose2d;
66
import edu.wpi.first.math.geometry.Rotation2d;
@@ -10,7 +10,7 @@ public class DifferentialDriveOdometry {
1010
private static final double RATE_LIMITER_TIME = 0.05;
1111

1212
private RateLimiter odometryLimiter;
13-
private MotorController leftMotor, rightMotor;
13+
private REVThroughBoreDutyCycleEncoder leftEncoder, rightEncoder;
1414

1515
private Pose2d currentPosition;
1616

@@ -34,15 +34,15 @@ public class DifferentialDriveOdometry {
3434
* @param wheelBaseWidth The distance between the left and right wheels (in meters).
3535
*/
3636
public DifferentialDriveOdometry(
37-
MotorController leftMotor,
38-
MotorController rightMotor,
37+
REVThroughBoreDutyCycleEncoder leftEncoder,
38+
REVThroughBoreDutyCycleEncoder rightEncoder,
3939
double wheelCircumference,
4040
double gearRatio,
4141
double encoderToRevolutionConstant,
4242
double wheelBaseWidth) {
4343

44-
this.leftMotor = leftMotor;
45-
this.rightMotor = rightMotor;
44+
this.leftEncoder = leftEncoder;
45+
this.rightEncoder = rightEncoder;
4646
this.wheelCircumference = wheelCircumference;
4747
this.gearRatio = gearRatio;
4848
this.encoderToRevolutionConstant = encoderToRevolutionConstant;
@@ -70,11 +70,11 @@ public void setCurrentPosition(Pose2d position) {
7070
* Updates the encoder values for both the left and right wheels.
7171
*/
7272
private void setCurrentEncoderValues() {
73-
currLeftEncoderValue = leftMotor.getSensorPosition();
74-
currRightEncoderValue = rightMotor.getSensorPosition();
75-
7673
prevLeftEncoderValue = currLeftEncoderValue;
7774
prevRightEncoderValue = currRightEncoderValue;
75+
76+
currLeftEncoderValue = leftEncoder.getAbsolutePosition();
77+
currRightEncoderValue = rightEncoder.getAbsolutePosition();
7878
}
7979

8080
/**

src/main/java/com/team766/robot/common/mechanisms/BurroDrive.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.team766.hal.MotorController;
66
import com.team766.hal.MotorController.ControlMode;
7+
import com.team766.hal.wpilib.REVThroughBoreDutyCycleEncoder;
78
import com.team766.hal.RobotProvider;
89
import com.team766.logging.Category;
910
import com.team766.odometry.DifferentialDriveOdometry;
@@ -18,37 +19,48 @@ public class BurroDrive extends Drive {
1819

1920
private final MotorController leftMotor;
2021
private final MotorController rightMotor;
22+
private final REVThroughBoreDutyCycleEncoder leftEncoder;
23+
private final REVThroughBoreDutyCycleEncoder rightEncoder;
2124
private DifferentialDriveKinematics differentialDriveKinematics;
2225
private DifferentialDriveOdometry differentialDriveOdometry;
2326

24-
// todo set actual ratio
27+
// TODO set actual ratio
2528
private static final double DRIVE_GEAR_RATIO = 1; // Gear ratio
2629

27-
// todo set actual radius
30+
// TODO set actual radius
2831
private static final double WHEEL_RADIUS = 1; // Radius of the wheels
2932

33+
// TODO
34+
private static final double ENCODER_UNIT_TO_REVOLUTION_CONSTANT = 1.;
35+
3036
private static final double MOTOR_WHEEL_FACTOR_MPS =
3137
1.
3238
/ WHEEL_RADIUS // Wheel radians/sec
3339
* DRIVE_GEAR_RATIO // Motor radians/sec
34-
/ (2 * Math.PI); // Motor rotations/sec (what velocity mode takes));
40+
/ (2 * Math.PI) // Motor rotations/sec (what velocity mode takes))
41+
* ENCODER_UNIT_TO_REVOLUTION_CONSTANT; // Encoder units/sec
42+
43+
// TODO
44+
private static final double TRACK_WIDTH_METERS = 0.4; // Distance between left and right wheel
3545

36-
public BurroDrive(double trackWidthMeters) {
46+
public BurroDrive() {
3747
loggerCategory = Category.DRIVE;
3848

3949
leftMotor = RobotProvider.instance.getMotor(DRIVE_LEFT);
4050
rightMotor = RobotProvider.instance.getMotor(DRIVE_RIGHT);
4151

42-
differentialDriveKinematics = new DifferentialDriveKinematics(trackWidthMeters);
52+
leftEncoder = null; //FIXME
53+
rightEncoder = null; //FIXME
54+
55+
differentialDriveKinematics = new DifferentialDriveKinematics(TRACK_WIDTH_METERS);
4356
differentialDriveOdometry =
4457
new DifferentialDriveOdometry(
45-
leftMotor,
46-
rightMotor,
58+
leftEncoder,
59+
rightEncoder,
4760
WHEEL_RADIUS * 2 * Math.PI,
4861
DRIVE_GEAR_RATIO,
49-
1.,
50-
0 // TODO
51-
);
62+
ENCODER_UNIT_TO_REVOLUTION_CONSTANT,
63+
TRACK_WIDTH_METERS);
5264
}
5365

5466
/**
@@ -109,4 +121,9 @@ public ChassisSpeeds getChassisSpeeds() {
109121
}
110122

111123
public void setCross() {}
124+
125+
@Override
126+
public void run() {
127+
differentialDriveOdometry.run();
128+
}
112129
}

0 commit comments

Comments
 (0)