Go to Post The teams who have the best chance at success are the ones who know where they can save time and money on machining by using or using part of some premade equivalent. - Bill Gold [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Spotlight this post!  
Unread 24-01-2011, 09:34
Alexander Meyer Alexander Meyer is offline
Registered User
FRC #2358 (Bearbotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Lake Zurich, Illinois
Posts: 36
Alexander Meyer is on a distinguished road
Re: Encoder as PIDSource

cplusplus.com has a good guide if you want to solidify your knowledge of C++.

To use the class that jwakeman posted, you need to make use of PIDController. Basically, initialize a PIDController with P, I, and D values, a PIDSource, and a PIDOutput in your constructor.

So, say you use a victor to drive your elevator and an encoder to measure distance, you might have something like this:

Code:
Victor *ap_elevatorDrive;
PIDEncoder *ap_elevatorEncoder;
PIDController *ap_elevatorControl;

Constructor()
{
    ap_elevatorDrive = new Victor(args);
    ap_elevatorEncoder = new PIDEncoder(args);
    ap_elevatorControl = new PIDController(1.0, 0.0, 0.0, ap_elevatorEncoder, ap_elevatorDrive);
}
Then, in your mainloop, you'd call the PIDController's SetSetpoint() method with whatever distance you want the elevator to travel to; the units are wholly dependent on the values returned by PIDEncoder's PidGet() method.

The WPILib User's Guide has a complete example of position control with a PIDController and a potentiometer.

Hope that helped,
-Alexander
Reply With Quote
 


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 18:07.

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