View Single Post
  #9   Spotlight this post!  
Unread 24-01-2011, 15:09
sircedric4's Avatar
sircedric4 sircedric4 is offline
Registered User
AKA: Darren
no team (The SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Lousiana
Posts: 245
sircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond repute
Re: Encoder as PIDSource

Quote:
Originally Posted by Alexander Meyer View Post
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:

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
This did help, I have read the example you mention in the User's Guide and finally got it to mostly work with a potentiometer last year, but didn't know how to get it to work with an encoder. jwakeman's sub-class was apparantly the magic I needed, and I wasn't sure how to use it. Between your post and his I should be able to beat it into submission now.

Our goal this week is to get some sort of prototype setup so we can work on encoders since they have become mandatory for us this year with the design we want. Thanks everyone.

(P.S. I will read that tutorial you hyperlinked since I still have a hard time figuring out when to use *, &, ::, ., -> and all the other heiroglyphics in C++. If there was one simple use throughout for calling classes and such I could get it. The Getting Started with C++ guide from the FIRST website made an attempt to explain these differences in pointers and references and I am getting closer, but it could do with some full sample code examples instead of just snippets)
Reply With Quote