|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Setting PID constants in code for TalonSRX Velocity Control
I'm working with the CTRE Demo code for tuning closed-loop velocity control on the TalonSRX. When I set the PIDF constants in code (using _talon.setP, _talon.setI, etc), the values seem to not get set on the talon itself.
Here's what I'm seeing: When I run the code with any PID constants set, the system doesn't move whatsoever. No matter if I set any combination of P, I, D, or F, there is no response. If I go onto the roborio's web viewer (on http://roborio-<team>-frc.local) I can see the PID constants I set. If I manually re-enter and save the PID constants on the roborio web viewer, the system responds exactly as I would expect. This only seems to be a problem when I set the control mode to TalonControlMode.Speed. I don't see the problem if I'm using TalonControlMode.Position. I've made sure all the firmware on the TalonSRXs, RoboRIO, and PDP are all up to date, as well as my wpilib and ctre lib installs. Last edited by thejerishbrown : 02-02-2017 at 13:35. |
|
#2
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
I just noticed...
Code:
_talon.configPeakOutputVoltage(+12.0f, 0.0f); Code:
_talon.configPeakOutputVoltage(+12.0f, -12.0f); I think the peak outputs get reset to the defaults when you save in web-config. |
|
#3
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Is this for a flywheel (shooter)? |
|
#4
|
|||||
|
|||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
This is a pretty fly wheel...
![]() #bringingdiscoback |
|
#5
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Quote:
|
|
#6
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Depending on your application, you may actually want:
_talon.configPeakOutputVoltage(0.0f, -12.0f); in the case that you only want it to spin in the 'reverse direction' and never apply 'forward' voltage. If you realize you're driving your car faster than you want on the highway usually you just let off the gas, not throw the engine into reverse. |
|
#7
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Quote:
This is ideal for applications where you want both directions, such as drive wheels. Here's an example of a team using speed servo all the time on four mecanum wheels... https://www.chiefdelphi.com/forums/s...+talon+sp eed Notice our velocity walkthrough in the Talon SRX Software Reference Manual does not require you to enforce only driving in one direction. |
|
#8
|
|||
|
|||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
This is our first time use of the SRX. We are programming in LabView and using the velocity example program..
We have followed the example for Java velocity closed-loop with interpretations for what LV wants. I am confused about F-gain. We go through the process. Our motor is running at about 6000 RPM maximum. We get a velocity of 39136 from self-test. Using the formulas we compute F-gain as .026139. If we put that value in the F-gain field in the example, the motor runs to full speed when we set the requested output to -25600 (-3750RPM). Both SRXs are showing Green LEDs. We have tried bringing down F-gain then setting PID values that get us close to what we want. But with our tuning, the SRX doesn't really regulate. When we start other motors, the speed drops 250 RPM, when we put in a fresh battery, the speed goes up 400 RPM. I think that we are doing something fundamental wrong. Does F-gain need to change based on the speed we are running. We are using two motors with one in slave mode. Occasionally the SRXs get out of sync after we download and will buck (one showing RED the other showing GREEN) each other. |
|
#9
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Quote:
We solved this by deleting the 6.8 multiplier and trying a raw rpm value. Once we did that, the F-gain started to make sense and we were able to tune sensible PID numbers. See if this helps: http://imgur.com/a/Ljv4H Edit: I forgot to add, have you checked to make sure your encoder and your motor controllers have the same polarity? Last edited by AustinH : 06-02-2017 at 23:05. Reason: Forgot about encoder polarity |
|
#10
|
|||
|
|||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Quote:
Doh, we were showing Green with the encoder counting positive so I thought it was OK. At sometime, the reverse-control-output got set. I don't understand how it did anything but go to full speed in the wrong direction rather than somewhat working. Thanks again, Hope we see you at World, Randy |
|
#11
|
||||
|
||||
|
Re: Setting PID constants in code for TalonSRX Velocity Control
Glad to hear it. I would be interested to hear if it took anything else to mod the example code to get your desired function or if I just went a bit crazy with the delete key...
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|