Sparkmax PID Tolerance Issue

My team is working on our swerve code, and we are having issues with the wheels occasionally jittering. We believe that setting a tolerance on the SPARK PID controller would fix this, as we can see in advantagescope that the fluctuations in the encoder value are tiny, like 0.01 radians.

We are trying to use the maxmotion.allowedClosedLoopError from the rev SparkMaxConfig API to do this, but it seems like changing this value does nothing. Has anyone been able to successfully set a tolerance on a spark PID controller using the new 2025 Revlib APIs?

you’ll want to post a link to your github if you want folks to understand what you’re doing.

We are currently running the stock advantagekit sparkswerve template linked here The file where the line would go is linked.

This is the block of code in question that changes nothing, even when we edit it to a ridiculous tolerance.

    // Configure turn motor
    var turnConfig = new SparkMaxConfig();
    turnConfig
        .inverted(turnInverted)
        .idleMode(IdleMode.kBrake)
        .smartCurrentLimit(turnMotorCurrentLimit)
        .voltageCompensation(12.0);
    turnConfig
        .encoder
        .positionConversionFactor(turnEncoderPositionFactor)
        .velocityConversionFactor(turnEncoderVelocityFactor)
        .uvwAverageDepth(2);
    turnConfig
        .closedLoop
        .feedbackSensor(FeedbackSensor.kPrimaryEncoder)
        .positionWrappingEnabled(true)
        .positionWrappingInputRange(turnPIDMinInput, turnPIDMaxInput)
        .pidf(turnKp, 0.0, turnKd, 0.0)
        .maxMotion.allowedClosedLoopError(Units.degreesToRadians(10.0));
    turnConfig
        .signals
        .primaryEncoderPositionAlwaysOn(true)
        .primaryEncoderPositionPeriodMs((int) (1000.0 / odometryFrequency))
        .primaryEncoderVelocityAlwaysOn(true)
        .primaryEncoderVelocityPeriodMs(20)
        .appliedOutputPeriodMs(20)
        .busVoltagePeriodMs(20)
        .outputCurrentPeriodMs(20);
    tryUntilOk(
        turnSpark,
        5,
        () ->
            turnSpark.configure(
                turnConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters));
    // Reset neo relative encoder using absolute encoder position
    tryUntilOk(
        turnSpark,
        5,
        () ->
            turnEncoder.setPosition(
                turnAbsoluteEncoder.getVoltage()
                    / RobotController.getVoltage5V()
                    * turnAbsoluteEncoderPositionFactor));

This line

        .maxMotion.allowedClosedLoopError(Units.degreesToRadians(10.0));

is the only thing we added but setting the value to anything doesn’t do anything. The maxMotion API seems to be new for 2025 and I am wondering if it might just be broken.

After reading some more at home I read deeper into this page and found that maxmotion needs to be set as the controller type using this line of code

m_controller.setReference(setPoint, SparkBase.ControlType.kMAXMotionPositionControl);

I will test tomorrow and update

yeah, that’s right. if you want to use the maxmotion feature, i think you also need to tell it what velocity and acceleration limits you’d like it to use.

We learned that maxmotion requires a max acceleration and velocity. Has anyone found a way to set a PID tolerance using the 2025 rev library without using this?

if you don’t want the profile feature, just set them to really high numbers, and the underlying PID is the same.