Go to Post Purpose over pimpness is a policy that we are trying to adhere to. - santosh [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

 
Closed Thread
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 04-01-2016, 22:19
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
PID with encoder

Last spring was my first introduction to FRC and with my 17 years of Automation controls background I help a team figure out how to use some of their feedback devices I.E. pot, Ultrasonic, encoders. They had a lifting arm that fit itself well to a pot and PID subsystem. They where using Iterative type coding and with a little research and video tutorial on Command Base programming I quickly became a fan special with the test mode and how easily it was to test code bits and PID systems. The past few weeks during pre-launch I was teaching a new bunch of programmers the command base system and how the different parts work. We have only a robot drive train sub system currently with four wheels and encoders on each. Diving with joysticks and selecting different modes on the smartdashboard has been successful. Today I thought why don't we try a PID subsystem. We created a new project with only a PID subsystem with a motor and associated encoder. With 360 pulses per one rev of the output wheel verified by manually spinning the motor in test mode. When I enable the PID the motor shacks rapidly. It seems real hot but with turning down the P and leaving the I,D at 0 dose not seem to help.

Is using an encoder not a good idea for PID?
Is there a way to set the max output so if the error is large the motor output can not raise above 50%?
Maybe its because the resolution is to course?
Maybe we should try setting the units per pulse to .1 and set point to 3600?
  #2   Spotlight this post!  
Unread 05-01-2016, 00:16
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: PID with encoder

How much play is there between your motors and your encoder mount?
  #3   Spotlight this post!  
Unread 05-01-2016, 01:10
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,045
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: PID with encoder

I'm not super familiar with PID theory, but I do know that for 2016 they've added a velocity mode that does the PID calculations slightly differently. That might explain why you're having issues.

Here's a link to the new code: https://github.com/robotpy/allwpilib...ller.java#L265
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #4   Spotlight this post!  
Unread 05-01-2016, 01:16
BL0X3R BL0X3R is offline
Registered User
AKA: Nick
FRC #4488 (ShockWave)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2013
Location: Hillsboro
Posts: 43
BL0X3R is on a distinguished road
Re: PID with encoder

I have a few questions about your system so that we might be able to help you better, if you don't mind me asking.

What language are you using?

Are you controlling speed or position with your PID system? Getting the encoder speed has been known to not work entirely properly all the time, having large jumps in value, because of how the roboRIO does timing loops. Taking a manual derivative [(oldSpeed - currentSpeed) / periodicInterval (20 ms, unless you are making your own loops)] works much better and smoother.

Is there any other system controlling the motor? I know that in labVIEW, the same motor set to different values in different places will cause the motor to rapidly twitch between them, due to the parallel nature of the language. Our team hasn't run into this problem in any of the text based options, but we also haven't had as much experience with them, and have very little experience in command-based programming (we've programmed all our new robots iteratively). If you are doing any threading or parallel processes, then definitely search for race conditions.

Now, to answer your questions:

"Is using an encoder not a good idea for PID?"
Encoders work great - they are the best (only?) method of getting the position and velocity of a robot. We've used them ourselves in 2014 on our drive train and had great success with them. If you know what you're doing, you can do some really cool things with them (note: this isn't completely PID, but it is motion profiling with encoders as feedback sensors)

"Is there a way to set the max output for PID?"
the PIDSubsystem and PIDController classes both seem to have "setOutputRange" methods. I haven't used them myself, but the documentation says "Sets the maximum and minimum values to write", so I would start there.

"Maybe its resolution is too coarse?"
Most teams use encoders with resolutions of 360 or 256 and have reasonable success with both, so it's not likely that the resolution is where the problem lies.

"Maybe we should try setting the units per pulse to .1 and set point to 3600?"
If you are controlling the position of the encoders, then that would work well for finding any offending behaviors in the PID controller (obviously it's not a permanent solution).

Best of luck, it's good to see mentors helping students learn and explore more advanced control options in FRC
__________________
Carson Finalists (4488, 67, 225, 5659)
2x District Winner + Gracious Professionalism & Engineering Excellence, DCMP Finalist and Entrepreneurship
Galileo Finalists (1153, 4488, 1318, 1218)
2x District Winner + Chairman's & Industrial Design, DCMP Finalist and Quality Award
http://www.chiefdelphi.com/forums/image.php?type=sigpic&userid=74752&dateline=139804  7731 Oregon Rookie All Star, Curie Rookie All Star
  #5   Spotlight this post!  
Unread 05-01-2016, 06:40
phurley67 phurley67 is offline
Programming Mentor
FRC #0862 (Lightning Robotics)
Team Role: Mentor
 
Join Date: Apr 2014
Rookie Year: 2013
Location: Michigan
Posts: 65
phurley67 is an unknown quantity at this point
Re: PID with encoder

BL0X3R was on the money, but I will add graph it. When I graph our encoder data, depending on a number of factors I have seen very "jittery" velocity data (solutions are as mentioned, calculate yourself, if necessary calculate an average velocity over the last n encoder reads).

If you are using labVIEW visualizing data in real time is trivial. If not, I have taken to writing my logs in JSON and then using javascript and the browser for visualizing (I use http://www.flotcharts.org/), rather than trying to write code in C++ or Java to display graphs.

In many cases seeing is understanding.
  #6   Spotlight this post!  
Unread 05-01-2016, 10:16
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,572
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: PID with encoder

By shakes (shacks?), do you mean that the motor just reciprocates but doesn't make any net revolution, or that it goes in the right direction but have a shake riding on top of that?

If it's the first, you may want to try swapping your encoder channels.

If it's the second, check for loose connections, especially on the encoder but also on the power.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
  #7   Spotlight this post!  
Unread 05-01-2016, 12:55
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: PID with encoder

Quote:
SoftwareBug2.0
Quite Sloppy gear box. Is a likely problem. I did try to place the wheel attach on the ground to try and eliminate the backlash and is why I asked about setting the max speed. (answered possibly by GeeTwo)

Quote:
virtuald
I did just see the Velocity mode in RobotBuilder and was going to play some with changing that. I was not aware this is new for 2016.

Quote:
BL0X3R
We are using Command Based Java

As virtuald stated and I found it was set to velocity.

Is there any other system controlling the motor?
No this is a fresh program with only the few components declared.

Some of my ideas posted where me brain storming for tonight to get the community input. Thanks for the kind words too.

Quote:
phurley67
Graphing is a great idea. I need to show them how to get the data in the smartdashboard displayed this way and see the power of the tool. I remember myself doing this last spring when I was testing the new PDP current draw of each channel. Thanks for reminding me to show this to them.

Quote:
GeeTwo
Shakes yes like over shoot. I could not see if it made a revolution. Graphing and trying to use the "setOutputRange" the others have mentioned should help identify this. We did have the encoder channels swapped and seen the motor run away with the error growing not closing.


Thanks to all lots of great ideas given and confirmed.
  #8   Spotlight this post!  
Unread 05-01-2016, 13:29
feverittm's Avatar
feverittm feverittm is offline
Registered User
FRC #0997 (Spartans)
Team Role: Mentor
 
Join Date: Apr 2010
Rookie Year: 2010
Location: Corvallis, OR
Posts: 120
feverittm will become famous soon enoughfeverittm will become famous soon enough
Re: PID with encoder

Another thing you can do to work on this issue is to leverage the smartdashboard (I know you can't use it very much while in test mode) to display the distance/rate as you run the system manually (outside the PID loop) and see that things are changing as you expect (direction, magnitude, sensitivity).
__________________
Floyd Moore
Mentor Electrical and Pneumatics
Team 997 - Spartan Robotics
Corvallis High School, Corvallis Oregon
  #9   Spotlight this post!  
Unread 05-01-2016, 14:11
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: PID with encoder

SUCCESS!

The setOutputRange worked perfectly to slow things down so not to overshoot so violently. Also with closer examination of Robotbuilder and only after manually entering the code into the PID subsystem there is a check box and min/max value boxes. With kDistance selected as PID source I was able to tune the P factor to .005 and eliminate the overshoot. Tonight will be a successful learning experience thanks to your input.
  #10   Spotlight this post!  
Unread 05-01-2016, 14:29
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: PID with encoder

A very lightly loaded motor is going to be extremely difficult to tune for speed control, unless (as you discovered) you limit the power. What really works best is limiting the acceleration so the system is not as prone to oscillation. You can do that in software by limiting the rate of change of motor power, or you can do it in hardware by adding inertia.
  #11   Spotlight this post!  
Unread 10-03-2016, 00:56
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: PID with encoder

Quote:
Originally Posted by Alan Anderson View Post
A very lightly loaded motor is going to be extremely difficult to tune for speed control, unless (as you discovered) you limit the power. What really works best is limiting the acceleration so the system is not as prone to oscillation. You can do that in software by limiting the rate of change of motor power, or you can do it in hardware by adding inertia.
Do you have any suggestions on how to software limit the acceleration?
  #12   Spotlight this post!  
Unread 10-03-2016, 01:57
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: PID with encoder

Quote:
Originally Posted by cpapplefamily View Post
Do you have any suggestions on how to software limit the acceleration?
You could run a current loop on the talon and limit the current.

My favorite method is to limit the voltage difference from the BEMF voltage. That will limit the current, which will limit the torque. You won't be able to do that with the standard PID controller, but it isn't very hard to write a new one.
  #13   Spotlight this post!  
Unread 10-03-2016, 09:31
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: PID with encoder

Quote:
Originally Posted by cpapplefamily View Post
Do you have any suggestions on how to software limit the acceleration?


CANTalons have a "setVoltageRampRate" function
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Closed Thread


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 22:15.

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