Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to set PID tolerance without using maxmotion #16

Open
mathewdunne opened this issue Jan 9, 2025 · 0 comments
Open

No way to set PID tolerance without using maxmotion #16

mathewdunne opened this issue Jan 9, 2025 · 0 comments

Comments

@mathewdunne
Copy link

My team is looking to use the new SparkMaxConfig APIs for setting up PID controllers this year, but there doesn't seem to be a way to set a tolerance on the PID unless you use the maxmotion config. We're having an issue with our swerve modules "clicking" as they oscillate tiny amounts around the setpoint, I think due to backlash in the module gears. Setting a tolerance of 1-2 degrees on the Spark Max's closed loop controller would be an easy fix, but there doesn't seem to be a way to do this.

From what I understand, SparkMaxConfig.closedLoop.maxMotion.allowedClosedLoopError will do what I want, but that requires using maxmotion's trapezoidal PID controller, which we don't want to do.

This is our motor config, which is copied from Advantagekit's spark swerve example:

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);
    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));

Is there a way to set a tolerance on the closedLoop position controller? Or alternatively, is there a way to use maxmotion just as a normal PID without providing velocity and acceleration constraints?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant