CTRE SRX Mag Absolute Encoder Using Spark Max Data Port

My team is trying to use SRX Mag Encoders as absolute encoders. Preferably I would like to use the data port on the Spark Max, here team 4739 show how to wire the SRX Mag Encoder for absolute position but I am still very confused if this will work if the Spark Max is in brushless mode.

You can take a look at the Alternate Encoder Mode Page on the Rev docs. It should work after some config.

Despite the naming, alternate encoder mode is only used for using quadrature signals with brushless motors. For absolute position you want to use the SparkAbsoluteEncoder class and getAbsoluteEncoder function, as the SRX Mag outputs a PWM “duty cycle” signal to measure absolute position.

// (adapted from https://docs.reduxrobotics.com/canandcoder/spark-max#code-example-java)
//
// Instantiate a Spark MAX and get a handle to a PWM absolute encoder
CANSparkMax sparkmax = new CANSparkMax(0, MotorType.kBrushed);
var sparkencoder = sparkmax.getAbsoluteEncoder(SparkMaxAbsoluteEncoder.Type.kDutyCycle);

// Change this as needed, 8 points to average for velocity measurement is a
// decent starting point
sparkencoder.setAverageDepth(8);

// Reads the absolute position in rotations
sparkencoder.getPosition();

// configure the Spark Max to use the PWM-connected encoder for
// closed-loop control
sparkmax.getPIDController().setFeedbackDevice(sparkencoder);

// Additionally, SparkMaxPIDController.setPositionPIDWrappingEnabled() and
// similar functions may be useful for swerve pivot applications.

See also: SparkAbsoluteEncoder (FRC-REVLib API)

I tried this today with the standard ribbon cable and I couldn’t get it to work, is there any rewiring I need to do? Thanks!

You need to adapt pin 9 on the SRX mag side to pin 6 on the Spark Max side.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.