My team and I have been banging our heads against the wall for weeks now trying to set a motor to a specific position using the onboard encoders. This is one of many iterations over the last few weeks:
#!/usr/bin/env python3 import wpilib import ctre class MyRobot(wpilib.TimedRobot): def testInit(self): """Robot initialization function""" self.motor_control_mode = ctre.TalonFXControlMode.Position self.feedback_device = ctre.TalonFXFeedbackDevice.IntegratedSensor self.motor0 = ctre.TalonFX(0) self.motor0.configSelectedFeedbackSensor(self.feedback_device) self.joyStick = wpilib.XboxController(3) # initialize the joystick on port 0 print("#"*50) self.motor0.setSelectedSensorPosition(100) print(self.motor0.getSelectedSensorPosition()) print("#"*50) self.sensor_count = 0 def testPeriodic(self): #"""Runs the motor from a joystick.""" #self.sensor_count += 1 #self.motor0.set(self.motor_control_mode, self.sensor_count) pass if __name__ == "__main__": wpilib.run(MyRobot)
The goal of this code is to get a motor, set its integrated sensor to a position, then print that new position out. The code I have never sets the sensor position and always prints out
0.0 in the simulation. There’s a ton of documentation for Robotpy, but there doesn’t seem to be any one page that says “THIS IS HOW TO GET AN ENCODER WORKING”. Any help would be appreciated.