Go to Post Pit Tools Distraction=bad - Lil' Lavery [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
  #16   Spotlight this post!  
Unread 16-04-2016, 11:32
Oblarg Oblarg is online now
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,120
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Problem with NavX to turn around.

Quote:
Originally Posted by rich2202 View Post
In theory, PID is great. In practice, not so much.

In this exercise, you are trying to turn a robot to a set angle. PID will increase the speed until you get there, and then oscillate back and forth trying to hit the mark. The easier way to do it is to turn at a controlled speed until you get there.

In the original code, I'm guessing that the robot is rotating too fast, and overshoots the error range (self.desired to self.desired+10) that one time in 10. The solution is to turn slower, check the angle more frequently, wider error range. Maybe when you get close, you slow down the turn.
This is kind of (erm, very) misleading.

One can easily cap the max speed of a P loop (let's be honest, for turn-to-angle you're probably not going to need any I or D) or tune the P term to avoid overshoot. In fact, one of the appeals of a P loop is precisely that the output ramps down as you approach the setpoint, such that you do not overshoot. In this capacity, it is quite a bit nicer than bang-bang control (which is what you are describing).
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016
Reply With Quote
  #17   Spotlight this post!  
Unread 16-04-2016, 12:43
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,141
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: Problem with NavX to turn around.

Quote:
Originally Posted by DanielHa View Post
at certain absolute angles, if you simply add or subtract 180 (or in your case the slightly altered values), then you might get a value which is outside the range of the navX.
Let S be your sensor angle reading (in degrees, can be any range, even outside the range +/-360)

Let T be your desired angle position (in degrees, can be any range, even outside the range +/-360)

the angle between them (let's call it ERR) is found by the equation:

ERR = (T-S) - 360*floor(0.5+(T-S)/360);

the above returns a value for ERR between -180 and +180 degrees,
the shortest angle path to the target. Don't believe me? Try it.

So it tells you which direction to rotate as well as how much to rotate.

To use this with a PID, use processVariable = setpoint-ERR


Reply With Quote
  #18   Spotlight this post!  
Unread 16-04-2016, 15:02
Oblarg Oblarg is online now
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,120
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Problem with NavX to turn around.

Quote:
Originally Posted by Ether View Post
Let S be your sensor angle reading (in degrees, can be any range, even outside the range +/-360)

Let T be your desired angle position (in degrees, can be any range, even outside the range +/-360)

the angle between them (let's call it ERR) is found by the equation:

ERR = (T-S) - 360*floor(0.5+(T-S)/360);

the above returns a value for ERR between -180 and +180 degrees,
the shortest angle path to the target. Don't believe me? Try it.

So it tells you which direction to rotate as well as how much to rotate.

To use this with a PID, use processVariable = setpoint-ERR


This is unnecessary with the NavX and WPILib, as one can simply call AHRS pidGet() (which always ranges from -180 to 180) and ensure that the PIDController object is set to have a continuous range and not have to ever explicitly do any of the math.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016

Last edited by Oblarg : 16-04-2016 at 15:06.
Reply With Quote
  #19   Spotlight this post!  
Unread 16-04-2016, 15:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,141
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: Problem with NavX to turn around.

Quote:
Originally Posted by Oblarg View Post
This is unnecessary with the NavX and WPILib, as one can simply call AHRS pidGet() (which always ranges from -180 to 180) and ensure that the PIDController object is set to have a continuous range and not have to ever explicitly do any of the math.
Yes.

I was responding to DanielHa's post, to show a simple way to compute shortest angle... which would be useful to know for situations where the library functions or the hardware don't do the math for you.


Reply With Quote
  #20   Spotlight this post!  
Unread 16-04-2016, 18:27
Foster Foster is offline
Engineering Program Management
VRC #8081 (STEMRobotics)
Team Role: Mentor
 
Join Date: Jul 2007
Rookie Year: 2005
Location: Delaware
Posts: 1,394
Foster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond repute
Re: Problem with NavX to turn around.

Quote:
Originally Posted by Ether View Post
Yes.

I was responding to DanielHa's post, to show a simple way to compute shortest angle... which would be useful to know for situations where the library functions or the hardware don't do the math for you.
Exactly! Always good to go "Umm I need to do this, looks like that library does that, oh wait it won't work in all cases".

There are few things that I hate more than debugging code "What does this do?" "Dunno, think it turns the robot". /sigh.

Quote:
Originally Posted by Jared Russell
I would argue that PID is much more elegant in practice than in theory.
A well tuned PID is a thing of beauty. Most people that hate PID have not taken the time to dial them in.
__________________
Foster - VEX Delaware - 17 teams -- Chief Roboteer STEMRobotics.org
2010 - Mentor of the Year - VEX Clean Sweep World Championship
2006-2016, a decade of doing VEX, time really flies while having fun
Downingtown Area Robotics Web site and VEXMen Team Site come see what we can do for you.
Reply With Quote
  #21   Spotlight this post!  
Unread 16-04-2016, 19:32
Oblarg Oblarg is online now
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,120
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Problem with NavX to turn around.

Quote:
Originally Posted by Foster View Post
Exactly! Always good to go "Umm I need to do this, looks like that library does that, oh wait it won't work in all cases".
I will opine that, while it is often a useful pedagogical exercise (and it's often useful to know how what a library is doing under the hood), reinventing the wheel is not generally good coding practice and if you have a library that does what you want (in this case, you do) it is good to use it.

Sometimes, of course, libraries are inadequate and you have to build your code from the ground up. But this is not always the case.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016
Reply With Quote
  #22   Spotlight this post!  
Unread 16-04-2016, 19:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,141
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: Problem with NavX to turn around.

Quote:
Originally Posted by Oblarg View Post
reinventing the wheel is not generally good coding practice and if you have a library that does what you want (in this case, you do) it is good to use it.
In case you have inferred otherwise, nothing I posted in this thread should be construed as antithetical to the above.


Reply With Quote
  #23   Spotlight this post!  
Unread 16-04-2016, 19:51
Oblarg Oblarg is online now
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,120
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Problem with NavX to turn around.

Quote:
Originally Posted by Ether View Post
In case you have inferred otherwise, nothing I posted in this thread should be construed as antithetical to the above.
Nah, that post was purely in response to Foster's, not yours.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016
Reply With Quote
  #24   Spotlight this post!  
Unread 16-04-2016, 19:53
Foster Foster is offline
Engineering Program Management
VRC #8081 (STEMRobotics)
Team Role: Mentor
 
Join Date: Jul 2007
Rookie Year: 2005
Location: Delaware
Posts: 1,394
Foster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond repute
Re: Problem with NavX to turn around.

While not speaking for Ether, I don't think either one of us was recommending that they reinvent the code / wheel. But the OP wanted to know the details and Ether supplied them. From his simple explanation it would be easy to write the code / PID function.

But I think both of us are recommending understanding how things work for the coders.
__________________
Foster - VEX Delaware - 17 teams -- Chief Roboteer STEMRobotics.org
2010 - Mentor of the Year - VEX Clean Sweep World Championship
2006-2016, a decade of doing VEX, time really flies while having fun
Downingtown Area Robotics Web site and VEXMen Team Site come see what we can do for you.
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 00:17.

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