Talon SRX Velocity Control

Could someone please provide some example code for controlling a flywheel with an SRX to run at a certain velocity? We have an encoder hooked up to the wheel, but we’re currently waiting for a breakout board to come in for soldering, so if it’s possible, I’d appreciate the code being without an encoder for now.

Hi Abelbae, Welcome to CD. Can you try going to the product’s website?

Start with the provided reference material at http://www.ctr-electronics.com/talon-srx.html#product_tabs_technical_resources

When you tune it, start with the F parameter then P. If you really need the last 0.1% you could add a small I term.

The new SRX code has a parameters for “peak/nominal closed-loop output”. I have not used this before, but it would have solved an issue I had years ago with the older Jaguars. When driving a flywheel, there is significant inertia and if the loop overshoots, the control loop will try to slow the wheel down, potentially by trying to turn it backwards. Reversing the motor while the flywheel blew half the H-bridge driver inside the speed controller.

So, I will amend my recommendation. The F term is the Forward (open-loop) parameter.

  1. set P,I,D,F to zero
  2. command 800 speed (assuming full range +/- 1023)
  3. find a value for F which gets you to the target RPM
  4. query what the voltage for that RPM is (Vnom)
  5. ConfigPeakOutputVoltage(+12, +Vnom/2)
  6. find a value for P that maintains the RPM over changes in load
  7. if required, tune I for more accurate nominal values

Especially if you use the I term, you may also want to play with the new ConfNominalOutputVoltage command to create a “good enough” voltage band around your desired RPM. This could help if you have minor oscillations near your target RPM.

Thank you for the information. I’m figuring it out right now, but sadly I won’t be able to test it for a few days, as the team is currently getting the electrical on the robot. I’ll post more if I have any questions.

gpetilli,

Thank you for posting your tuning steps. I’ve tried to use them and I am getting unusual results and hoping you might be able to provide some guidance.
We are using velocity closed loop mode, CTRE Mag encoder in Relative.

I’ve set PIDF all to zero, set a RPM speed of 1000 RPM and increased F to 0.84 to obtain ~1006 RPM. Once I start to increase P - in this case 0-> 0.1 the speed slows down to to 600 RPM. If I add some I, the motor goes to max reverse speed (~1200).

Any help would be appreciated.

Thanks,

bohdand

Grab a screenshot of the roboRIO-web-based config Self Test when the closed-loop is misbehaving and post it here.

Sounds your motor and sensor are not in-phase.

gpetilli’s procedure is helpful, but not quite complete. Take a look at section 12.4 for a complete walk through of velocity close-loop (Talon SRX Software reference manual).

Also section 16.31 “My Closed-Loop is not working? Now what?”

it almost sounds like your motor and encoder disagree on which direction is positive. If that is the case, you may be able to use a -0.1 for P. Do post your screen shots as requested by Ether.

The steps I gave are fairly generic and intended to help you through the basic thought process, you should use the more detailed debugging instructions in the CTRE documentation.