mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-06-19 06:21:40 +00:00
Upgrading to 2025.7.0
This commit is contained in:
@@ -3,6 +3,7 @@ package swervelib.encoders;
|
||||
import com.revrobotics.REVLibError;
|
||||
import com.revrobotics.spark.SparkAnalogSensor;
|
||||
import com.revrobotics.spark.SparkMax;
|
||||
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor;
|
||||
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||
import edu.wpi.first.wpilibj.Alert;
|
||||
import edu.wpi.first.wpilibj.Alert.AlertType;
|
||||
@@ -47,8 +48,7 @@ public class SparkMaxAnalogEncoderSwerve extends SwerveAbsoluteEncoder
|
||||
{
|
||||
sparkMax = motor;
|
||||
encoder = ((SparkMax) motor.getMotor()).getAnalog();
|
||||
motor.setAbsoluteEncoder(this);
|
||||
sparkMax.configureIntegratedEncoder(360 / maxVoltage);
|
||||
setConversionFactor(360.0 / maxVoltage);
|
||||
} else
|
||||
{
|
||||
throw new RuntimeException("Motor given to instantiate SparkMaxEncoder is not a CANSparkMax");
|
||||
@@ -64,6 +64,15 @@ public class SparkMaxAnalogEncoderSwerve extends SwerveAbsoluteEncoder
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
// SPARK MAX Analog encoder gets closed with the motor
|
||||
// I don't think an encoder getting closed should
|
||||
// close the entire motor so i will keep this empty
|
||||
// sparkMax.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the configuration until it succeeds or times out.
|
||||
*
|
||||
@@ -81,6 +90,49 @@ public class SparkMaxAnalogEncoderSwerve extends SwerveAbsoluteEncoder
|
||||
failureConfiguring.set(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the conversion factor of the {@link SparkMaxAnalogEncoderSwerve}.
|
||||
*
|
||||
* @param conversionFactor Position conversion factor from ticks to unit.
|
||||
*/
|
||||
public void setConversionFactor(double conversionFactor)
|
||||
{
|
||||
SparkMaxConfig cfg = null;
|
||||
if (sparkMax instanceof SparkMaxSwerve)
|
||||
{
|
||||
cfg = ((SparkMaxSwerve) sparkMax).getConfig();
|
||||
|
||||
} else if (sparkMax instanceof SparkMaxBrushedMotorSwerve)
|
||||
{
|
||||
cfg = ((SparkMaxBrushedMotorSwerve) sparkMax).getConfig();
|
||||
}
|
||||
if (cfg != null)
|
||||
{
|
||||
cfg.closedLoop.feedbackSensor(FeedbackSensor.kAnalogSensor);
|
||||
|
||||
cfg.signals
|
||||
.analogVelocityAlwaysOn(true)
|
||||
.analogVoltageAlwaysOn(true)
|
||||
.analogPositionAlwaysOn(true)
|
||||
.analogVoltagePeriodMs(20)
|
||||
.analogPositionPeriodMs(20)
|
||||
.analogVelocityPeriodMs(20);
|
||||
|
||||
cfg.analogSensor
|
||||
.positionConversionFactor(conversionFactor)
|
||||
.velocityConversionFactor(conversionFactor / 60);
|
||||
}
|
||||
if (sparkMax instanceof SparkMaxSwerve)
|
||||
{
|
||||
((SparkMaxSwerve) sparkMax).updateConfig(cfg);
|
||||
} else if (sparkMax instanceof SparkMaxBrushedMotorSwerve)
|
||||
{
|
||||
((SparkMaxBrushedMotorSwerve) sparkMax).updateConfig(cfg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset the encoder to factory defaults.
|
||||
*/
|
||||
@@ -110,12 +162,12 @@ public class SparkMaxAnalogEncoderSwerve extends SwerveAbsoluteEncoder
|
||||
if (sparkMax instanceof SparkMaxSwerve)
|
||||
{
|
||||
SparkMaxConfig cfg = ((SparkMaxSwerve) sparkMax).getConfig();
|
||||
cfg.analogSensor.inverted(true);
|
||||
cfg.analogSensor.inverted(inverted);
|
||||
((SparkMaxSwerve) sparkMax).updateConfig(cfg);
|
||||
} else if (sparkMax instanceof SparkMaxBrushedMotorSwerve)
|
||||
{
|
||||
SparkMaxConfig cfg = ((SparkMaxBrushedMotorSwerve) sparkMax).getConfig();
|
||||
cfg.analogSensor.inverted(true);
|
||||
cfg.analogSensor.inverted(inverted);
|
||||
((SparkMaxBrushedMotorSwerve) sparkMax).updateConfig(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user