SetSelectedSensorPosition (TalonFX) function not working properly

While working on our swerve, we noticed that the setSelectedSensorPosition function for the chassis falcons wasn’t working like it should. The actual value that we got was true, but randomly it was negative/positive.
Can we do something about it?
Our best guess is that the problem stems from the wpilib and we should wait for an update.


I’ve had seemingly the same issue, and solved it by adding a wait for 1 or 2 seconds in my initialize sequence before setting the motor’s sensor position. not sure why this happens. seems like maybe a CTRE issue with initializing “set inverted” properly.

This is CTRE functionality, not WPILib. My understanding is that the setter functions will not be instantly reflected in getters, as there is CAN bus and periodic telemetry latency (eg the getter retrieves the value sent by the device periodic telemetry).

Thanks! I’ll give that a try, I just don’t get where did you put the timer?

Just start it after you instantiate ur motor controller, and then before you set position, do a “while timer<2”

Risk for all resets of encoders. We teach our beginning Java freshmen this. A page from our (Romi) lessons below. Don’t check for exact zero though. The FRC encoders in general are very accurate and don’t settle at zero if there is still the slightest motion.

  • Modify the RomiDrivetrain class:
    • Override the following methods:
      • public synchronized void readPeriodicInputs()
        • Call the getDistance() method to set the leftEncoderDistanceInch (same for right)
        • Call the get() method to set the leftEncoderRaw (same for right)
      • public synchronized void writePeriodicInputs()
        • Write a nested if…else if…else structure
        • if(resetEncoders) - stop the motors, reset the encoders, set resetEncoders to false
        • else if(!isEncoderReset) -
          • if both raw encoder values are 0, then set isEncoderReset to true
          • else if 0.1 seconds has elapsed on the encoderResetTimer
            • Reset both encoders, then reset and start the encoderResetTimer
        • else - use a switch statement with driveState (kARCADE, kTANK, kNONE)
        • Feed the watchdog
1 Like

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