Skip to content

Commit

Permalink
Merge pull request #134 from guineawheek/canandcoder-tweaks-v2024
Browse files Browse the repository at this point in the history
Canandcoder tweaks
  • Loading branch information
thenetworkgrinch authored Jan 16, 2024
2 parents 25ae048 + 24aada6 commit a93f433
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/main/java/swervelib/encoders/CanAndCoderSwerve.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package swervelib.encoders;

import com.reduxrobotics.sensors.canandcoder.Canandcoder;
import edu.wpi.first.wpilibj.DriverStation;

/**
* HELIUM {@link Canandcoder} from ReduxRobotics absolute encoder, attached through the CAN bus.
Expand All @@ -12,11 +11,7 @@ public class CanAndCoderSwerve extends SwerveAbsoluteEncoder
/**
* The {@link Canandcoder} representing the CANandCoder on the CAN bus.
*/
public Canandcoder encoder;
/**
* Inversion state of the encoder.
*/
private boolean inverted = false;
public Canandcoder encoder;

/**
* Create the {@link Canandcoder}
Expand All @@ -30,6 +25,8 @@ public CanAndCoderSwerve(int canid)

/**
* Reset the encoder to factory defaults.
*
* This will not clear the stored zero offset.
*/
@Override
public void factoryDefault()
Expand All @@ -47,14 +44,14 @@ public void clearStickyFaults()
}

/**
* Configure the CANandCoder to read from [0, 360) per second.
* Configure the Canandcoder to read from [0, 360) per second.
*
* @param inverted Whether the encoder is inverted.
*/
@Override
public void configure(boolean inverted)
{
this.inverted = inverted;
encoder.setSettings(new Canandcoder.Settings().setInvertDirection(inverted));
}

/**
Expand All @@ -65,7 +62,7 @@ public void configure(boolean inverted)
@Override
public double getAbsolutePosition()
{
return (inverted ? -1.0 : 1.0) * encoder.getPosition() * 360;
return encoder.getAbsPosition() * 360;
}

/**
Expand All @@ -80,18 +77,15 @@ public Object getAbsoluteEncoder()
}

/**
* Cannot set the offset of the CanAndCoder.
* Cannot set the offset of the Canandcoder.
*
* @param offset the offset the Absolute Encoder uses as the zero point.
* @return always false due to CanAndCoder not supporting offset changing.
* @return true if setting the zero point succeeded, false otherwise
*/
@Override
public boolean setAbsoluteEncoderOffset(double offset)
{
//CanAndCoder does not support Absolute Offset Changing
DriverStation.reportWarning("Cannot Set Absolute Encoder Offset of CanAndCoders ID: " + encoder.getAddress(),
false);
return false;
return encoder.setSettings(new Canandcoder.Settings().setZeroOffset(offset));
}

/**
Expand All @@ -102,6 +96,6 @@ public boolean setAbsoluteEncoderOffset(double offset)
@Override
public double getVelocity()
{
return encoder.getVelocity();
return encoder.getVelocity() * 360;
}
}

0 comments on commit a93f433

Please sign in to comment.