Can it be done? TalonFX & Cancoder & Absolute Encoder

Our team is in the middle of some off-season projects to improve and hone our skills. We’ve got a fun project that I hope the team can showcase to the community if we’re successful, but as is often the case when learning new things - we’re running into some problems.

As part of our larger project we are attempting to feed an absolute position sensor (PWM output) into a canifier, to a position controller running on a Falcon500 motor. We are able to successfully control the rotary position of the mechanism, but the sensor exhibits discontinuities when it transitions through its zero crossing (see image below).

It seems like the feedbackNotContinuous parameter in BaseMotorControllerConfiguration (src) is the parameter which should enable/disable the accumulation of position through absolute position sensor discontinuities. We haven’t changed this parameter in our code, and I’ve verified it’s set to false from within the Phoenix Tuner.

There are many teams and individuals who are more well-versed in the intricacies of the CTRE Phoenix libraries than we are. Show us the error of our ways.

Are we just overlooking the correct method call, in the Phoenix documentation?
Is what we are trying to do not supported in the Phoenix libraries?

Hardware setup

  • Absolute encoder (MA3-P10-250N).
    This encoder outputs a PWM signal, with pulse widths correlating to the rotational position of the sensor. This is the first time we’ve used this model sensor before, and they were selected primarily because the canifier supported 4x PWM inputs.

  • Talon FX (firmware 20.5.6.0)

  • Canifier (firmware 20.0)

All devices above. PDP, and RIO are wired together over CAN bus.

Code excerpt

        private final boolean ENABLE_CURRENT_LIMIT = true;
        private final double CONTINUOUS_CURRENT_LIMIT = 40.0; //amps
        private final double TRIGGER_THRESHOLD_LIMIT = 60.0; //amps
        private final double TRIGGER_THRESHOLD_TIME = 0.2; //s

        SupplyCurrentLimitConfiguration talonCurrentLimit;
        talonCurrentLimit = new SupplyCurrentLimitConfiguration(ENABLE_CURRENT_LIMIT,
        CONTINUOUS_CURRENT_LIMIT, TRIGGER_THRESHOLD_LIMIT, TRIGGER_THRESHOLD_TIME);

        CANifier _canifier = new CANifier(0);
        _canifier.setStatusFramePeriod(CANifierStatusFrame.Status_4_PwmInputs1, 10);
	
        TalonFXConfiguration config = new TalonFXConfiguration();
        config.remoteFilter0.remoteSensorDeviceID = _canifier.getDeviceID();
        config.remoteFilter0.remoteSensorSource = RemoteSensorSource.CANifier_PWMInput1;
        config.primaryPID.selectedFeedbackSensor = FeedbackDevice.RemoteSensor0;
        config.slot0.kP = 1.0;
        config.slot0.kI = 0.0;
        config.slot0.kD = 10.0;
        config.slot0.kF = 0.0;
        config.slot0.integralZone = 0;
        config.slot0.allowableClosedloopError = 0;
        config.motionAcceleration = 1000;
        config.motionCruiseVelocity = 100;
        
        TalonFX talon = new TalonFX(11);
        talon.configFactoryDefault();
        talon.setInverted(true);
        talon.setSensorPhase(true);
        talon.configAllSettings(config);
        talon.configSupplyCurrentLimit(talonCurrentLimit);
3 Likes

@ozrien is the guy to ask if you don’t get a quick answer here.

With a CANifier you’re always going to see discontinuities. The feedbackNotContinuous setting only applies to integrated or native sensors (like an analog/pwm sensor plugged in to an SRX data port).

Solutions

Our recommended solution is to just use the internal sensor on the Talon FX. You can set a config to sync the internal sensor’s position with the internal absolute position measurement on boot, which ensures you’re starting from a known position.

If your gearing is such that you need to get your starting position post-gear-reduction, use a CANcoder (or another sensor, if you don’t have a CANcoder) to get your absolute position and then manually sync that position with the Talon FX. Then you can just use the FX’s position. If for some reason you have excessive backlash and really need to use the post-gear-reduction sensor as your feedback device, use the CANcoder as a remote sensor.

1 Like

We implemented this on our swerve with NEOs and that worked really well. We would continuously check if there were differences between the cancoder and the internal encoder so that if we were to lose position on the motor we could reset its position automatically.

Thanks!
This is a good near term solution. We will likely give this a go.

I guess I’m still wondering why ‘feedbackNotContinuous’ couldn’t/doesn’t work with remote sensors as well. I’m probably oversimplifying things, but seems like the same logic used for the internal sensors could apply to remote sensors. It’s an unfortunate constraint for the F500 line, since there isn’t a way to wire such a sensor into it natively. As you pointed out, in cases where backlash or resolution is a concern, using the internal F500 encoder isn’t always a desirable option.

Could you point to documentation describing this constraint? Not saying you’re incorrect, I just haven’t come across this in the documentation yet, and it’s a parameter of the BaseMotorControllerConfiguration class, implying it’s supported by both the F500 and SRX.

I’ll let @Jacob_C answer authoritatively, but it sounds to me like the decoding logic happens on the CANcoder, and it just broadcasts an absolute position value over some standard CAN frame. That would mean that the “NotContinuous” magic would have to be implemented on the CANcoder itself.

Just to be clear, there are two different devices being talked about here: CANifier and CANcoder. CANifier is the device that lets you wire various i/o to the CAN Bus - it “CAN-ifies” signals. This is what’s being used to decode the PWM sensor.
CANcoder is the CAN-connected magnetic encoder.

Carlos is correct. With remote sensors, all decoding/configuration/data manipulation happens on the device doing the decoding.

This should be in all of the API docs, but I just double checked and it looks like the description isn’t specific enough. That description should match the config description in Tuner, which gives more clear examples of the places the config applies.

The resolution shouldn’t be a concern since the Talon FX has a fairly high resolution internal sensor. You may need to sync your starting position because of gearing, but once you do that the resolution of the FX should be sufficient.
Also, unless your backlash is significant I suspect this won’t be an issue.

1 Like

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