I’m still fairly new to java programming for FRC and only know how to do mostly basic tasks. One of our goals this season is to spin a motor using a through bore srx mag encoder attached to a talon srx when a limit switch is pressed. I know that is closed-loop position control examples that ctre puts out but I’m not completely sure if that is the right example to follow.
Any examples (simpler) would be appreciated!
You could call talonSrx.set(ControlMode.Position, somePosition) to have the talon go to that position. The mag encoder has a resolution of 4096, so if you want your mechanism to spin 180 degrees (0.5 rotations), you would substitute somePosition with 0.5 * 4096.
In order for the position control to work, you have to configure the PID values. You can configure them by calling config_kP(someKpValue), config_kI(someKiValue), and config_kD(someKdValue). You only have to set these values once.
There are ways to calculate theoretical values for the PID, but in your case it would probably be easier to guess and check. You might only need P (keeping the other values 0) for the mechanism you described. If the balls get stuck due to the compression, you could try adding a very small value of I to help it power through.