View Single Post
  #6   Spotlight this post!  
Unread 04-07-2016, 19:46
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,041
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: Why won't this PID loop stop?

There are a number of bugs with the current WPILib PIDController implementation. The python implementation follows the java implementation closely, so it shares these issues. Here are bug reports on WPILib's github site:
  • #29: PIDController: setSetpoint causes onTarget to be false
  • #30: PIDController: race condition for enable/disable and PIDWrite
  • #31: PIDController: getError() is incorrect when setContinuous is True

In particular, #29 is probably the one that is biting you (it bit me for a similar reason). If you keep calling setSetpoint (like that example does), each time it is called it will reset things such that onTarget is false, which means the robot will never stop oscillating.

There are a number of ways of dealing with this problem -- the easiest is to not call setSetpoint if the input is close (within 0.001) to the original input. However, this isn't satisfactory either for a number of reasons... so I ended up writing my own magicbot-compatible implementation, it'll be part of magicbot next year.
__________________
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
Reply With Quote