Go to Post Finally, they're getting rid of the spotlights. I'm sick of seeing ridiculous inside jokes up there. - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 23-02-2012, 22:38
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by Joe Ross View Post
I've never heard that before. Where did you hear it? I would have thought that Joe Hershberger would have mentioned the MD5 check instead of helping with instructions on how to rebuild the library in the following thread. http://www.chiefdelphi.com/forums/sh...ad.php?t=89131

I do agree it's better to override a method if possible.
My apologies - I could swear I tried this the first year we had the cRIOs and you got a library version error. When I asked about it, the WPI folks said you had to have special permissions (and be on the "build team") to access the svn repository and do a proper build. Obviously that is no longer the case (if it ever was). Sorry to steer anybody wrong!
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #17   Spotlight this post!  
Unread 23-02-2012, 22:41
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by jwakeman View Post
I think you're correct that there is no danger of segmentation faults. However, if access to the variables is not synchronized then the potential for logic errors exist.
... thus the "may not be desirable" caveat ;o)
__________________
Fast, cheap or working - pick any two!

Last edited by wireties : 24-02-2012 at 11:36.
Reply With Quote
  #18   Spotlight this post!  
Unread 23-02-2012, 22:48
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by jwakeman View Post
Can someone explain the difference between these two uses of the semaphore? I see both being used in the PIDController class.

Code:
CRITICAL_REGION(m_semaphore)
{
}
END_REGION;
Code:
{
    Synchronized sync(m_semaphore);
}

the first is a semaphore used for mutual exclusion (to protect the critical region), in this use-case the semaphore is taken before and given after a critical region of code and always in the same context - the semaphore includes the concept of ownership (by the thread/task) and recursion

the second is a semaphore used for synchronization, in this use-case the semaphore is taken in one context/thread/task and given or flushed in another context - for example given/flushed in a periodic timer callback function (or maybe an interrupt service routine) and taken in a task/thread

hth
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #19   Spotlight this post!  
Unread 24-02-2012, 11:05
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by wireties View Post
the first is a semaphore used for mutual exclusion (to protect the critical region), in this use-case the semaphore is taken before and given after a critical region of code and always in the same context - the semaphore includes the concept of ownership (by the thread/task) and recursion

the second is a semaphore used for synchronization, in this use-case the semaphore is taken in one context/thread/task and given or flushed in another context - for example given/flushed in a periodic timer callback function (or maybe an interrupt service routine) and taken in a task/thread
I figured. So in QNX parlance (which I am most familar with) these would be a Mutex and Condition Variable. However, I don't see where the semaphore is being flushed in the PIDController implementation. The periodic loop is accomplished with a Notifier calling the Calculate() method periodically. Is the sync actually being used somehow here?
Reply With Quote
  #20   Spotlight this post!  
Unread 24-02-2012, 11:32
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by vamfun View Post
What is maximumInput and minimumInput?
It is simply the minimum and maximum setpoint that the controller will accept. In the case of my shooter speed controller they are set to 0 and 100 respectively (units are feet per second in this case). For my turret position controller I am using -45 to 45 (degrees) and my turret speed controller accepts -250 to 250 (degrees/sec)...i think you get the idea.

Quote:
Originally Posted by vamfun View Post
Now that you brought this code up, would someone mind explaining why it is there?
The code I posted actually falls within one more if-statement, if(m_continuous). I've also always wondered what this code is meant to represent. What is meant by continuous in this case? Also running some values though the code doesn't help me understand at all.

Using my example of a shooter speed controller with minimum input of 0 and maximum input of 100 fps. Say I step my setpoint from 0 to 100. My error would be equal to 100 on the first iteration. So 100 is greater than (100 - 0) / 2 and 100 is greater than zero so m_error ends up being set equal to 100 - 100 + 0. So if I step my speed controller from zero to maximum the output will be computed as zero?!

Another scenario, I step the setpoint from 0 to 60. The error of 60 is greater than 50 and greater than zero so the m_error becomes 60 - 100 + 0 = -40. Now my positive error became negative error..I'm confused.

Code:
if (m_continuous)
{
    if (fabs(m_error) > (m_maximumInput - m_minimumInput) / 2)
    {
        if (m_error > 0)
        {
            m_error = m_error - m_maximumInput + m_minimumInput;
        }
        else
        {
            m_error = m_error + m_maximumInput - m_minimumInput;
        }
    }
}
Reply With Quote
  #21   Spotlight this post!  
Unread 24-02-2012, 11:39
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by jwakeman View Post
What is meant by continuous in this case?

Using my example of a shooter speed controller with minimum input of 0 and maximum input of 100 fps. Say I step my setpoint from 0 to 100. My error would be equal to 100 on the first iteration. So 100 is greater than (100 - 0) / 2 and 100 is greater than zero so m_error ends up being set equal to 100 - 100 + 0. So if I step my speed controller from zero to maximum the output will be computed as zero?!

Another scenario, I step the setpoint from 0 to 60. The error of 60 is greater than 50 and greater than zero so the m_error becomes 60 - 100 + 0 = -40. Now my positive error became negative error..I'm confused.
I don't know for sure, but I thought it was for rotary position control for continuous-rotation devices. i.e. 360 degrees is the same as 0 degrees.

For example, if your setpoint is 10 degrees and your process variable is 350 degrees, you want to rotate clockwise 20 degrees, not counterclockwise 340 degrees.

Reply With Quote
  #22   Spotlight this post!  
Unread 24-02-2012, 11:40
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Help me understand PIDController::OnTarget()

m_continuous is used to indicate if the range specified should be considered to be continuous (wraps from max to min) or not (the default is false). This is explained some in the documentation for the SetContinuous method.

So for something like a continuous rotation turret or swerve pod, you may set min as zero, max as 360 and continuous to true using SetContinuous(true). In this case the minimum and maximum represent the same value so the error for your hypothetical is indeed 0.
Reply With Quote
  #23   Spotlight this post!  
Unread 24-02-2012, 11:50
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by jwakeman View Post
I figured. So in QNX parlance (which I am most familar with) these would be a Mutex and Condition Variable. However, I don't see where the semaphore is being flushed in the PIDController implementation. The periodic loop is accomplished with a Notifier calling the Calculate() method periodically. Is the sync actually being used somehow here?
Sounds right, in VxWorks the take and give functions are the same (semTake and semGive) but the semaphores are created differently (semBCreate vs semMCreate vs semCCreate).

Jeez - I've got to stop giving advice from memory - sorry again. Despite the name it seems the Synchronized class is also used for mutual exclusion - weird. The destructor gives the semaphore - I missed that. The Notifier class uses a semaphore for synchronization and the DriverStation has a semFlush example.
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #24   Spotlight this post!  
Unread 24-02-2012, 12:01
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by RufflesRidge View Post
m_continuous is used to indicate if the range specified should be considered to be continuous (wraps from max to min) or not (the default is false). This is explained some in the documentation for the SetContinuous method.

So for something like a continuous rotation turret or swerve pod, you may set min as zero, max as 360 and continuous to true using SetContinuous(true). In this case the minimum and maximum represent the same value so the error for your hypothetical is indeed 0.

OK that's pretty neat. I'm learning a lot about the PIDController implementation on this thread.
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 13:38.

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