Skip to content

Instantly share code, notes, and snippets.

@jhh
Last active January 16, 2019 15:40
Show Gist options
  • Save jhh/77c3dcbae1b9f3fdb85369304114d7c4 to your computer and use it in GitHub Desktop.
Save jhh/77c3dcbae1b9f3fdb85369304114d7c4 to your computer and use it in GitHub Desktop.
Third Coast Azimuth TalonSRX Settings
// azimuth talon configuration
// NOTE: do not rely on these PID parameters, you should tune for your physical plant
TalonSRXConfiguration azimuthConfig = new TalonSRXConfiguration();
azimuthConfig.primaryPID.selectedFeedbackSensor = FeedbackDevice.CTRE_MagEncoder_Relative;
azimuthConfig.continuousCurrentLimit = 10;
azimuthConfig.peakCurrentDuration = 0;
azimuthConfig.peakCurrentLimit = 0;
azimuthConfig.slot0.kP = 10.0;
azimuthConfig.slot0.kI = 0.0;
azimuthConfig.slot0.kD = 100.0;
azimuthConfig.slot0.kF = 0.0;
azimuthConfig.slot0.integralZone = 0;
azimuthConfig.slot0.allowableClosedloopError = 0;
azimuthConfig.motionAcceleration = 10_000;
azimuthConfig.motionCruiseVelocity = 800;
TalonSRX azimuthTalon = new TalonSRX(1);
azimuthTalon.configAllSettings(azimuthConfig);
/**
* Set the azimuthTalon encoder relative to wheel zero alignment position. For example, if current
* absolute encoder = 0 and zero setpoint = 2767, then current relative setpoint = -2767.
*
* <pre>
*
* relative: -2767 0
* ---|---------------------------------|-------
* absolute: 0 2767
*
* </pre>
*
* @param zero zero setpoint, absolute encoder position (in ticks) where wheel is zeroed.
*/
public void setAzimuthZero(int zero) {
int azimuthSetpoint = getAzimuthAbsolutePosition() - zero;
azimuthTalon.setSelectedSensorPosition(azimuthSetpoint, 0, 10);
}
/**
* Returns the wheel's azimuth absolute position in encoder ticks.
*
* @return 0 - 4095, corresponding to one full revolution.
*/
public int getAzimuthAbsolutePosition() {
return azimuthTalon.getSensorCollection().getPulseWidthPosition() & 0xFFF;
}
@jhh
Copy link
Author

jhh commented Jan 16, 2019

See a functional 2019 robot example at swerve-example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment