Go to Post Before anyone accuses FIRST of being in the pocket of the sponsoring corporations, they might spend a minute and a half to actually apply some of that critical analytical ability that we are supposed to be demonstrating as educated engineers. - dlavery [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2016, 22:23
E Dawg E Dawg is offline
... is not done with FRC yet.
AKA: Ethan
FRC #0159 (Alpine Robotics)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Fort Collins, CO
Posts: 267
E Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud of
Using functions in PIDController

We are trying to use the PIDController class. However, it seems that most of the functions are virtual and therefore unusable. Although we can still use the PIDController, it would be nice if we could do things like get the current error without writing our own functions. Does anybody know if there is a way to use these virtual functions, like through a possible derived class somewhere?
  #2   Spotlight this post!  
Unread 11-02-2016, 22:47
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,685
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Using functions in PIDController

The functions are virtual so they are overridable in derived classes. In case you want to make a PID controller with gravity compensation or static friction feedforward or something. They're all implemented in the base PIDController class, so you should be able to call them without exceptions.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #3   Spotlight this post!  
Unread 11-02-2016, 22:59
Justin Buist Justin Buist is offline
Registered User
FRC #4003 (TriSonics)
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Allendale, MI
Posts: 22
Justin Buist is an unknown quantity at this point
Re: Using functions in PIDController

Just because a method is virtual doesn't mean there's no implementation behind it. The PIDController::GetError() method has a definition behind it.
Code:
/**
 * Returns the current difference of the input from the setpoint
 * @return the current error
 */
float PIDController::GetError() const {
  double pidInput;
  {
    std::lock_guard<priority_recursive_mutex> sync(m_mutex);
    pidInput = m_pidInput->PIDGet();
  }
  return GetSetpoint() - pidInput;
}
The virtual keyword just ensures you get the "right" method call if you extend PIDController and want your own implementation of GetError to run. So, if you extend PIDController and make a new ShooterPIDController and you implement your own implementation of GetError() and your instance of ShooterPIDController is cast into PIDController and you call ->GetError() on that pointer you will get the ShooterPIDController::GetError implementation. If it wasn't virtual you'd get PIDController::GetError() because then the decision would be made at compile time and not runtime.

You're only forced to implement a virtual method when the base class makes it null. So something declared: virtual float GetError() = 0; would force you to actually implement it if you wanted to use it, and that would have to be in a derived class.

I do not miss C++ at all.
  #4   Spotlight this post!  
Unread 12-02-2016, 09:50
E Dawg E Dawg is offline
... is not done with FRC yet.
AKA: Ethan
FRC #0159 (Alpine Robotics)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Fort Collins, CO
Posts: 267
E Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud of
Re: Using functions in PIDController

Quote:
Originally Posted by Kevin Sevcik View Post
The functions are virtual so they are overridable in derived classes. In case you want to make a PID controller with gravity compensation or static friction feedforward or something. They're all implemented in the base PIDController class, so you should be able to call them without exceptions.
I did some hunting in the class hierarchy and there are no derived classes. That's why we're confused. Maybe it is a good idea to create our own derived classes instead of using PIDController directly?

Last edited by E Dawg : 12-02-2016 at 09:53.
  #5   Spotlight this post!  
Unread 12-02-2016, 10:05
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,685
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Using functions in PIDController

Quote:
Originally Posted by E Dawg View Post
I did some hunting in the class hierarchy and there are no derived classes. That's why we're confused. Maybe it is a good idea to create our own derived classes instead of using PIDController directly?
You CAN use PIDController directly, because it has all those functions implemented. Why don't you try it first, then tell us if you have any problems with how it's working.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #6   Spotlight this post!  
Unread 12-02-2016, 10:24
fsilberberg fsilberberg is offline
WPILib Developer
AKA: Fred Silberberg
FRC #0190
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Redmond
Posts: 147
fsilberberg has a spectacular aura aboutfsilberberg has a spectacular aura aboutfsilberberg has a spectacular aura about
Quote:
Originally Posted by E Dawg View Post
I did some hunting in the class hierarchy and there are no derived classes. That's why we're confused. Maybe it is a good idea to create our own derived classes instead of using PIDController directly?
Unless you have specific reasons to do so, such as a custom error calculation or other changes from the default PID calculations done by WPILib, it's easier to just use the built in implementation. As everyone else has said, the functions are virtual so that IF you decide to create a custom controller, you can override the default implementation.
  #7   Spotlight this post!  
Unread 12-02-2016, 15:26
E Dawg E Dawg is offline
... is not done with FRC yet.
AKA: Ethan
FRC #0159 (Alpine Robotics)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Fort Collins, CO
Posts: 267
E Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud ofE Dawg has much to be proud of
Re: Using functions in PIDController

Quote:
Originally Posted by Kevin Sevcik View Post
You CAN use PIDController directly, because it has all those functions implemented. Why don't you try it first, then tell us if you have any problems with how it's working.
I have tried it, that's why I'm asking for help. I'm able to instantiate the PIDController class just fine. The problem is that when I try to use the virtual functions it causes problems, and eclipse says it has something to do with those functions being virtual.
  #8   Spotlight this post!  
Unread 15-02-2016, 10:37
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,113
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: Using functions in PIDController

Quote:
Originally Posted by E Dawg View Post
...when I try to use the virtual functions it causes problems...eclipse says it has something to do with...
If you want helpful advice, you need to be more specific about what exactly you're having trouble with. What do you expect to happen when you call the functions, and what happens instead? What is the actual error message from Eclipse?
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 10:40.

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