mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[examples] Update Romi template and example (#2996)
Updated the RomiReference example to have autonomous example. Updated RomiReference and both Romi templates to use Encoder.getDistance(). Removed motor inversion.
This commit is contained in:
@@ -11,7 +11,7 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
public class RomiDrivetrain extends SubsystemBase {
|
||||
private static final double kCountsPerRevolution = 1440.0;
|
||||
private static final double kWheelDiameterInch = 2.75;
|
||||
private static final double kWheelDiameterInch = 2.75591; // 70 mm
|
||||
|
||||
// The Romi has the left and right motors set to
|
||||
// PWM channels 0 and 1 respectively
|
||||
@@ -28,10 +28,9 @@ public class RomiDrivetrain extends SubsystemBase {
|
||||
|
||||
/** Creates a new RomiDrivetrain. */
|
||||
public RomiDrivetrain() {
|
||||
// DifferentialDrive defaults to having the right side flipped
|
||||
// We don't need to do this because the Romi has accounted for this
|
||||
// in firmware/hardware
|
||||
m_diffDrive.setRightSideInverted(false);
|
||||
// Use inches as unit for encoder distances
|
||||
m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
|
||||
m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
|
||||
resetEncoders();
|
||||
}
|
||||
|
||||
@@ -44,20 +43,12 @@ public class RomiDrivetrain extends SubsystemBase {
|
||||
m_rightEncoder.reset();
|
||||
}
|
||||
|
||||
public int getLeftEncoderCount() {
|
||||
return m_leftEncoder.get();
|
||||
}
|
||||
|
||||
public int getRightEncoderCount() {
|
||||
return m_rightEncoder.get();
|
||||
}
|
||||
|
||||
public double getLeftDistanceInch() {
|
||||
return Math.PI * kWheelDiameterInch * (getLeftEncoderCount() / kCountsPerRevolution);
|
||||
return m_leftEncoder.getDistance();
|
||||
}
|
||||
|
||||
public double getRightDistanceInch() {
|
||||
return Math.PI * kWheelDiameterInch * (getRightEncoderCount() / kCountsPerRevolution);
|
||||
return m_rightEncoder.getDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
|
||||
|
||||
public class RomiDrivetrain {
|
||||
private static final double kCountsPerRevolution = 1440.0;
|
||||
private static final double kWheelDiameterInch = 2.75;
|
||||
private static final double kWheelDiameterInch = 2.75591; // 70 mm
|
||||
|
||||
// The Romi has the left and right motors set to
|
||||
// PWM channels 0 and 1 respectively
|
||||
@@ -27,10 +27,9 @@ public class RomiDrivetrain {
|
||||
|
||||
/** Creates a new RomiDrivetrain. */
|
||||
public RomiDrivetrain() {
|
||||
// DifferentialDrive defaults to having the right side flipped
|
||||
// We don't need to do this because the Romi has accounted for this
|
||||
// in firmware/hardware
|
||||
m_diffDrive.setRightSideInverted(false);
|
||||
// Use inches as unit for encoder distances
|
||||
m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
|
||||
m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
|
||||
resetEncoders();
|
||||
}
|
||||
|
||||
@@ -43,19 +42,11 @@ public class RomiDrivetrain {
|
||||
m_rightEncoder.reset();
|
||||
}
|
||||
|
||||
public int getLeftEncoderCount() {
|
||||
return m_leftEncoder.get();
|
||||
}
|
||||
|
||||
public int getRightEncoderCount() {
|
||||
return m_rightEncoder.get();
|
||||
}
|
||||
|
||||
public double getLeftDistanceInch() {
|
||||
return Math.PI * kWheelDiameterInch * (getLeftEncoderCount() / kCountsPerRevolution);
|
||||
return m_leftEncoder.getDistance();
|
||||
}
|
||||
|
||||
public double getRightDistanceInch() {
|
||||
return Math.PI * kWheelDiameterInch * (getRightEncoderCount() / kCountsPerRevolution);
|
||||
return m_rightEncoder.getDistance();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user