Go to Post Test your code and your assumptions. - ShotgunNinja [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 44 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 25-01-2014, 12:27
Captain Planet Captain Planet is offline
Apprentice Programmer
FRC #2500 (Herobotics)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Minneapolis, MN
Posts: 7
Captain Planet is an unknown quantity at this point
NI Labview PID Encoder Feedback

My team has been trying to create a PID loop with encoder feedback to control our shooting arm this year. However, the motor output has been very erratic, fluctuating wildly. If we set the P, I and D values very low, (ie 0.001) it slows down, however, it is still not very accurate. Below is the VI we have been using for testing. Could someone provide a little guidance?

Reply With Quote
  #2   Spotlight this post!  
Unread 25-01-2014, 16:21
Iaquinto.Joe's Avatar
Iaquinto.Joe Iaquinto.Joe is offline
RPI 2018
AKA: Joe Iaquinto
FRC #0308 (The Monsters)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2011
Location: United States
Posts: 166
Iaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the rough
Re: NI Labview PID Encoder Feedback

You should be using the rate from the encoderget.vi as opposed to the distance. Additionally, the EncoderOpen.vi distance per tick should be calculated based off your encoder ticks/rotation divided by the circumference of your wheel. The NI PID provided does not work with rates, only distances. Because you are measuring a rate, the PID behaves differently. Distance I becomes Rate P; and Distance P becomes Rate D; Distance D becomes Rate D'. I have a custom PID from team 51, Wings of Fire, that allows you to use a rate PID, but I will have to ask them if it's okay to post here or give to you.

Hope I can help!
__________________
4 year 2011 - 2014 FRC team 308 member, Lead Programmer - C++ / LabVIEW

3 year 2011, 2013, 2014 OCCRA member, Co-Captain OCCRA team 308
  • OCCRA Engineering Excellence - Waterford Kettering 2013
  • Innovation in Control - 2011
  • Quality award- Northville 2012
  • Engineering Excellence- Howell 2014
  • Innovation in Controls- Livonia 2014
Reply With Quote
  #3   Spotlight this post!  
Unread 25-01-2014, 17:13
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,114
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: NI Labview PID Encoder Feedback

Quote:
Originally Posted by Iaquinto.Joe View Post
The NI PID provided does not work with rates, only distances. Because you are measuring a rate, the PID behaves differently.
Where did you get this idea? The PID VI is entirely mathematical - it doesn't care what the inputs are, all it does it brings the error of the system (Setpoint - Process Variable) down to zero. It will work exactly the same with encoder rates and distances, provided that the SP and PV are scaled the same way (and the constants are tuned properly). I'd be more than happy to explain how some of the math works, if you'd like.

As for your specific system issues, it just looks like the constants aren't tuned properly. Read a little bit about PID Theory (also: wikipedia) and take a look at some tips on designing a good controller (the rest of that page is helpful too). You may also want to start with the Ziegler-Nichols method for tuning (start with all zero, bring P up until it oscillates, add D to dampen and add I to correct for steady state error.

Just another note - if I remember, the LabVIEW implementation of the algorithm doesn't use Kp, Ki, and Kd as straight constants. It actually uses time constants for I and D (so it has Kp, Ti, and Td). You can see details of the NI implementation here. You can verify this in the help popup (ctrl-H) for the VI. Plan your constants accordingly.

Quote:
Originally Posted by Iaquinto.Joe View Post
Additionally, the EncoderOpen.vi distance per tick should be calculated based off your encoder ticks/rotation divided by the circumference of your wheel.
You do need to do this though - remember what I said above about proper scaling? That will put the output of the Distance from your encoder Get to be in realistic units (depending on how you scale it).

Also, what is that .02 constant doing? Is it wired to dt? You can delete that - the PID VI will calculate it for you if unwired.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android

Last edited by plnyyanks : 25-01-2014 at 17:22.
Reply With Quote
  #4   Spotlight this post!  
Unread 25-01-2014, 20:19
Iaquinto.Joe's Avatar
Iaquinto.Joe Iaquinto.Joe is offline
RPI 2018
AKA: Joe Iaquinto
FRC #0308 (The Monsters)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2011
Location: United States
Posts: 166
Iaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the rough
Re: NI Labview PID Encoder Feedback

We weren't very sure on how the time constants worked, but we all knew how the traditional constants worked. I guess you could use the NI PID, but the traditional kP kI and KD constants were easier for us to work with. I really like the diagrams and explanations though, I think I'll break them out the next time I'm explaining PIDs to the team
__________________
4 year 2011 - 2014 FRC team 308 member, Lead Programmer - C++ / LabVIEW

3 year 2011, 2013, 2014 OCCRA member, Co-Captain OCCRA team 308
  • OCCRA Engineering Excellence - Waterford Kettering 2013
  • Innovation in Control - 2011
  • Quality award- Northville 2012
  • Engineering Excellence- Howell 2014
  • Innovation in Controls- Livonia 2014
Reply With Quote
  #5   Spotlight this post!  
Unread 25-01-2014, 21:07
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,579
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: NI Labview PID Encoder Feedback

Quote:
Originally Posted by plnyyanks View Post
Where did you get this idea? The PID VI is entirely mathematical - it doesn't care what the inputs are, all it does it brings the error of the system (Setpoint - Process Variable) down to zero. It will work exactly the same with encoder rates and distances, provided that the SP and PV are scaled the same way (and the constants are tuned properly). I'd be more than happy to explain how some of the math works, if you'd like.
Here's a thought experiment for you. When you reach a certain distance, you want the output to be 0. When you reach a desired setpoint of 50% speed, what do you want the output to be?
Reply With Quote
  #6   Spotlight this post!  
Unread 25-01-2014, 21:21
Captain Planet Captain Planet is offline
Apprentice Programmer
FRC #2500 (Herobotics)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Minneapolis, MN
Posts: 7
Captain Planet is an unknown quantity at this point
Re: NI Labview PID Encoder Feedback

Thank you to the people who have posted, I will try your suggestions as soon as I can. However, it seems there is some disagreement, so I'll pose a more specific question. If am I to use a PID loop to control the angle of our shooting arm, should I get the rate output or the distance output from the encoder? As I understand it, the rate becomes 0 as soon as the motor stops moving, so I'm uncertain as to how I'd implement moving the arm to a specific angular position with it.
Reply With Quote
  #7   Spotlight this post!  
Unread 25-01-2014, 22:35
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,579
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: NI Labview PID Encoder Feedback

Quote:
Originally Posted by Captain Planet View Post
However, it seems there is some disagreement, so I'll pose a more specific question. If am I to use a PID loop to control the angle of our shooting arm, should I get the rate output or the distance output from the encoder? As I understand it, the rate becomes 0 as soon as the motor stops moving, so I'm uncertain as to how I'd implement moving the arm to a specific angular position with it.
I think the disagreement came because of the ambiguity of shooting arm. Now that you clarified you want angle, you should definitely be using the distance.
Reply With Quote
  #8   Spotlight this post!  
Unread 25-01-2014, 22:48
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,114
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: NI Labview PID Encoder Feedback

Quote:
Originally Posted by Iaquinto.Joe View Post
We weren't very sure on how the time constants worked, but we all knew how the traditional constants worked.
If you take a look at the implementation, it explains how the time constants relate to the traditional ones.

Here's the overall function:


The P component (Kc * error):


I [(Kc / Ti)integral(e)]:


D (Kc * Td * d(error)/dt ):




So, if you take a simple version of the formula like below...

Then:
Kp = Kc
Ki = Kc / Ti
Kd = Kc * Td

Make sense?
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android

Last edited by plnyyanks : 25-01-2014 at 22:51.
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 21:01.

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