Spinning motor for certain rotations

Hi everyone,

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!

What mechanism is the motor controlling? I ask because the answer may be different depending on the load on the motors

All it is doing is controlling a motor that spins 180 degrees to move a ball with minor compression.

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.

1 Like

Please don’t bother with integral gains for this mechanism. It’s much more likely to cause headaches than help for a more novice programmer.

1 Like

Thank you for the help! Super informational and I will try this later tonight when I have access to a robot. Thank you!

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