Go to Post Imagine a time before alliances. A time when secrecy was rampid and the Delphi Forum was just in it's baby stage. - Andy Grady [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2017, 13:26
thejerishbrown's Avatar
thejerishbrown thejerishbrown is offline
Registered User
FRC #0190 (Gompei and the Herd)
Team Role: Mentor
 
Join Date: Apr 2015
Rookie Year: 2013
Location: United States
Posts: 5
thejerishbrown is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2017, 13:42
ozrien's Avatar
ozrien ozrien is online now
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 559
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: Setting PID constants in code for TalonSRX Velocity Control

I just noticed...
Code:
 _talon.configPeakOutputVoltage(+12.0f, 0.0f);
... which caps the output to forward only. If you want to spin reverse you should do...
Code:
_talon.configPeakOutputVoltage(+12.0f, -12.0f);
... which allows full motor output in both directions.

I think the peak outputs get reset to the defaults when you save in web-config.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2017, 13:51
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,136
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Setting PID constants in code for TalonSRX Velocity Control


Is this for a flywheel (shooter)?


Reply With Quote
  #4   Spotlight this post!  
Unread 02-02-2017, 13:52
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,729
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Setting PID constants in code for TalonSRX Velocity Control

Quote:
Originally Posted by Ether View Post

Is this for a flywheel (shooter)?


This is a pretty fly wheel...

#bringingdiscoback
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2017, 14:01
thejerishbrown's Avatar
thejerishbrown thejerishbrown is offline
Registered User
FRC #0190 (Gompei and the Herd)
Team Role: Mentor
 
Join Date: Apr 2015
Rookie Year: 2013
Location: United States
Posts: 5
thejerishbrown is an unknown quantity at this point
Re: Setting PID constants in code for TalonSRX Velocity Control

Quote:
Originally Posted by ozrien View Post
I just noticed...
Code:
 _talon.configPeakOutputVoltage(+12.0f, 0.0f);
... which caps the output to forward only. If you want to spin reverse you should do...
Code:
_talon.configPeakOutputVoltage(+12.0f, -12.0f);
... which allows full motor output in both directions.

I think the peak outputs get reset to the defaults when you save in web-config.
This was the problem. Thanks!
Reply With Quote
  #6   Spotlight this post!  
Unread 02-02-2017, 16:42
KrazyCarl92's Avatar
KrazyCarl92 KrazyCarl92 is offline
Registered User
AKA: Carl Springli
FRC #0020 (The Rocketeers)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Clifton Park, NY
Posts: 523
KrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond reputeKrazyCarl92 has a reputation beyond repute
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.
__________________
[2017-present] FRC 0020 - The Rocketeers
[2016] FRC 5811 - BONDS Robotics
[2010-2015] FRC 0020 - The Rocketeers
Reply With Quote
  #7   Spotlight this post!  
Unread 02-02-2017, 17:54
ozrien's Avatar
ozrien ozrien is online now
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 559
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: Setting PID constants in code for TalonSRX Velocity Control

Quote:
Originally Posted by KrazyCarl92 View Post
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.
Capping the output to one direction is perfectly legitimate. However depending on the Fgain, you may not get a direction change caused by being under the target velocity. This happens when the F term provides most of the motor output, and the PID simply tweaks the output to approach the target speed.

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.
Reply With Quote
  #8   Spotlight this post!  
Unread 06-02-2017, 21:00
rwood359 rwood359 is offline
Registered User
AKA: Randy
FRC #0359 (Hawaiian Kids)
Team Role: Mentor
 
Join Date: Aug 2008
Rookie Year: 2008
Location: Waialua, HI
Posts: 216
rwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to all
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.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 06-02-2017, 23:03
AustinH's Avatar
AustinH AustinH is offline
Registered User
FRC #4918 (The Roboctopi)
Team Role: Coach
 
Join Date: Apr 2013
Rookie Year: 2013
Location: Port Townsend
Posts: 91
AustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to behold
Re: Setting PID constants in code for TalonSRX Velocity Control

Quote:
Originally Posted by rwood359 View Post
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.
I'm assuming you're using a CTRE Magnetic Encoder?
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?
__________________
3826: 2013 Seattle Regional Industrial Design Award & Semi-Finalists
4918: 2014 PNW Glacier Peak District Event Rookie Inspiration Award & Quarter-Finalists, 2014 PNW Mount Vernon District Event Highest Rookie Seed Award, Rookie All Star & Semi-Finalists, 2015 PNW West Valley District Event Engineering Excellence Award & Semi-Finalists, 2015 PNW Mount Vernon District Event Semi-Finalists





Visit us on the web at www.team4918.org

Last edited by AustinH : 06-02-2017 at 23:05. Reason: Forgot about encoder polarity
Reply With Quote
  #10   Spotlight this post!  
Unread 07-02-2017, 03:55
rwood359 rwood359 is offline
Registered User
AKA: Randy
FRC #0359 (Hawaiian Kids)
Team Role: Mentor
 
Join Date: Aug 2008
Rookie Year: 2008
Location: Waialua, HI
Posts: 216
rwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to allrwood359 is a name known to all
Re: Setting PID constants in code for TalonSRX Velocity Control

Quote:
Originally Posted by AustinH View Post
Edit: I forgot to add, have you checked to make sure your encoder and your motor controllers have the same polarity?
Austin, you are a life saver.
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
__________________
Reply With Quote
  #11   Spotlight this post!  
Unread 07-02-2017, 09:24
AustinH's Avatar
AustinH AustinH is offline
Registered User
FRC #4918 (The Roboctopi)
Team Role: Coach
 
Join Date: Apr 2013
Rookie Year: 2013
Location: Port Townsend
Posts: 91
AustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to beholdAustinH is a splendid one to behold
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...
__________________
3826: 2013 Seattle Regional Industrial Design Award & Semi-Finalists
4918: 2014 PNW Glacier Peak District Event Rookie Inspiration Award & Quarter-Finalists, 2014 PNW Mount Vernon District Event Highest Rookie Seed Award, Rookie All Star & Semi-Finalists, 2015 PNW West Valley District Event Engineering Excellence Award & Semi-Finalists, 2015 PNW Mount Vernon District Event Semi-Finalists





Visit us on the web at www.team4918.org
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:58.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi