Skip to content

Commit

Permalink
Changed position conversion factor, allowing for the device to be set…
Browse files Browse the repository at this point in the history
… as the feedback device with `SwerveDrive.pushOffsetsToEncoders`. Formatted code.

Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Aug 24, 2024
1 parent 3417bc3 commit 839786b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/swervelib/SwerveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SwerveModule
/**
* Module number for kinematics, usually 0 to 3. front left -> front right -> back left -> back right.
*/
public final int moduleNumber;
public final int moduleNumber;
/**
* Swerve Motors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public class SparkMaxAnalogEncoderSwerve extends SwerveAbsoluteEncoder
* Create the {@link SparkMaxAnalogEncoderSwerve} object as a analog sensor from the {@link CANSparkMax} motor data
* port analog pin.
*
* @param motor Motor to create the encoder from.
* @param motor Motor to create the encoder from.
* @param maxVoltage Maximum voltage for analog input reading.
*/
public SparkMaxAnalogEncoderSwerve(SwerveMotor motor)
public SparkMaxAnalogEncoderSwerve(SwerveMotor motor, double maxVoltage)
{
if (motor.getMotor() instanceof CANSparkMax)
{
encoder = ((CANSparkMax) motor.getMotor()).getAnalog(Mode.kAbsolute);
encoder.setPositionConversionFactor(360 / maxVoltage);
} else
{
throw new RuntimeException("Motor given to instantiate SparkMaxEncoder is not a CANSparkMax");
Expand Down Expand Up @@ -108,7 +110,7 @@ public void configure(boolean inverted)
@Override
public double getAbsolutePosition()
{
return encoder.getPosition() * (360 / 3.3);
return encoder.getPosition();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/ADIS16448Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/ADIS16470Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/ADXRS450Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/AnalogGyroSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/NavXSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/swervelib/imu/Pigeon2Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ public Optional<Translation3d> getAccel()

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/swervelib/imu/PigeonSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ public Optional<Translation3d> getAccel()
return Optional.of(new Translation3d(initial[0], initial[1], initial[2]).times(9.81 / 16384.0));
}

/**
/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public double getRate() {
public double getRate()
{
return imu.getRate();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/swervelib/imu/SwerveIMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class SwerveIMU

/**
* Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
*
* @return {@link Double} of the rotation rate as an {@link Optional}.
*/
public abstract double getRate();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/swervelib/parser/json/DeviceJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SwerveAbsoluteEncoder createEncoder(SwerveMotor motor)
case "attached":
return new SparkMaxEncoderSwerve(motor, 1);
case "sparkmax_analog":
return new SparkMaxAnalogEncoderSwerve(motor);
return new SparkMaxAnalogEncoderSwerve(motor, 3.3);
case "canandcoder":
return new SparkMaxEncoderSwerve(motor, 360);
case "canandcoder_can":
Expand Down

0 comments on commit 839786b

Please sign in to comment.