2023-08-09 13:15:02 -05:00
|
|
|
package swervelib.encoders;
|
|
|
|
|
|
2024-01-15 14:37:13 -06:00
|
|
|
import com.reduxrobotics.sensors.canandcoder.Canandcoder;
|
2023-08-09 13:15:02 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-01-15 14:37:13 -06:00
|
|
|
* HELIUM {@link Canandcoder} from ReduxRobotics absolute encoder, attached through the CAN bus.
|
2023-08-09 13:15:02 -05:00
|
|
|
*/
|
2023-08-09 15:05:33 -05:00
|
|
|
public class CanAndCoderSwerve extends SwerveAbsoluteEncoder
|
|
|
|
|
{
|
2023-08-09 13:15:02 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-01-15 14:37:13 -06:00
|
|
|
* The {@link Canandcoder} representing the CANandCoder on the CAN bus.
|
2023-08-09 13:15:02 -05:00
|
|
|
*/
|
2024-01-16 16:53:07 -06:00
|
|
|
public Canandcoder encoder;
|
2023-08-09 13:15:02 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-01-15 14:37:13 -06:00
|
|
|
* Create the {@link Canandcoder}
|
2023-08-09 13:15:02 -05:00
|
|
|
*
|
2023-08-09 15:05:33 -05:00
|
|
|
* @param canid The CAN ID whenever the CANandCoder is operating on the CANBus.
|
2023-08-09 13:15:02 -05:00
|
|
|
*/
|
2023-08-09 15:05:33 -05:00
|
|
|
public CanAndCoderSwerve(int canid)
|
|
|
|
|
{
|
2024-01-15 14:37:13 -06:00
|
|
|
encoder = new Canandcoder(canid);
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the encoder to factory defaults.
|
2024-01-16 16:53:07 -06:00
|
|
|
*
|
|
|
|
|
* This will not clear the stored zero offset.
|
2023-08-09 13:15:02 -05:00
|
|
|
*/
|
|
|
|
|
@Override
|
2023-08-09 15:05:33 -05:00
|
|
|
public void factoryDefault()
|
|
|
|
|
{
|
|
|
|
|
encoder.resetFactoryDefaults(false);
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear sticky faults on the encoder.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2023-08-09 15:05:33 -05:00
|
|
|
public void clearStickyFaults()
|
|
|
|
|
{
|
|
|
|
|
encoder.clearStickyFaults();
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-16 16:53:07 -06:00
|
|
|
* Configure the Canandcoder to read from [0, 360) per second.
|
2023-08-09 13:15:02 -05:00
|
|
|
*
|
|
|
|
|
* @param inverted Whether the encoder is inverted.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2023-08-09 15:05:33 -05:00
|
|
|
public void configure(boolean inverted)
|
|
|
|
|
{
|
2024-01-16 16:53:07 -06:00
|
|
|
encoder.setSettings(new Canandcoder.Settings().setInvertDirection(inverted));
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the absolute position of the encoder.
|
|
|
|
|
*
|
|
|
|
|
* @return Absolute position in degrees from [0, 360).
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2023-08-09 15:05:33 -05:00
|
|
|
public double getAbsolutePosition()
|
|
|
|
|
{
|
2024-01-16 16:53:07 -06:00
|
|
|
return encoder.getAbsPosition() * 360;
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the instantiated absolute encoder Object.
|
|
|
|
|
*
|
|
|
|
|
* @return Absolute encoder object.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2023-08-09 15:05:33 -05:00
|
|
|
public Object getAbsoluteEncoder()
|
|
|
|
|
{
|
2023-08-09 13:15:02 -05:00
|
|
|
return encoder;
|
|
|
|
|
}
|
2023-12-05 16:25:42 -06:00
|
|
|
|
2023-12-12 10:48:54 -06:00
|
|
|
/**
|
2024-01-16 16:53:07 -06:00
|
|
|
* Cannot set the offset of the Canandcoder.
|
2023-12-12 10:48:54 -06:00
|
|
|
*
|
|
|
|
|
* @param offset the offset the Absolute Encoder uses as the zero point.
|
2024-01-16 16:53:07 -06:00
|
|
|
* @return true if setting the zero point succeeded, false otherwise
|
2023-12-12 10:48:54 -06:00
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean setAbsoluteEncoderOffset(double offset)
|
|
|
|
|
{
|
2024-01-16 16:53:07 -06:00
|
|
|
return encoder.setSettings(new Canandcoder.Settings().setZeroOffset(offset));
|
2023-12-12 10:48:54 -06:00
|
|
|
}
|
|
|
|
|
|
2023-12-05 16:25:42 -06:00
|
|
|
/**
|
|
|
|
|
* Get the velocity in degrees/sec.
|
|
|
|
|
*
|
|
|
|
|
* @return velocity in degrees/sec.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public double getVelocity()
|
|
|
|
|
{
|
2024-01-16 16:53:07 -06:00
|
|
|
return encoder.getVelocity() * 360;
|
2023-12-05 16:25:42 -06:00
|
|
|
}
|
2023-08-09 13:15:02 -05:00
|
|
|
}
|