|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#7
|
|||
|
|||
|
Re: WPILib PID controller object
We've just coded this last night and hope to try it tonight. You need to derive your own class from the PIDSource class. In PIDSource.h, notice that there is one method defined:
virtual double PIDGet() = 0; This is what's known as a pure virtual method; There is no default implementation This means you can't create a PIDSource object, only one derived from it with this method overridden with your own. The code looks something like this: // .h file #include <WPILib.h> class MyPIDSource : public PIDSource { public: double PIDGet(); } // .cpp file #include "MyPIDSource.h" double MyPIDSource: IDGet(){ double pidSourceValue; // calculate 'double' value that you want compared to the set point // feel free to format it the same as you expect with your set point pidSourceValue = ... // return value return pidSourceValue; } Before you create your controller object, you must create an instance of your class. Pass this pointer as a parameter to PIDController for the PIDSource arg. Now, every 50 ms (assuming you've started it going), the PIDController will read the PID source, compare the value to the set point, do it's PID calculations, and write the new value to the PID output device. With our setup, we are turning a turret that has a camera mounted on it to track the vision target. My PID Source uses the X component of the Particle report to get the error value. So our set point is permanently set to 0 (centered in the camera). But we have to take into account the position of the turret with respect to our two end stops. As we get closer to one of our stops (as read from our 10 turn pot attached to the turret gears) we have to supply a smaller number until it gets to 0 at the end, assuming we're driving it in that direction. We can also disable our 'auto tracking' by just returning a 0, and allow manual control by just passing back the z component of a joystick to represent the value. It's actually quite powerful. I'll let you know how it works. Hope this helped... Steve |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| void* pointer to object in C++ | byteit101 | C/C++ | 6 | 14-01-2009 17:15 |
| UI Board Object Specs | 3DWolf | Control System | 2 | 10-12-2008 16:13 |
| Demo: Simple robot arm with a PID controller | mtomczak | Programming | 1 | 17-01-2008 02:17 |
| rangefinding/object detection | sciguy125 | Electrical | 14 | 13-01-2008 20:36 |
| Object Enablers | SherryG | Inventor | 1 | 07-04-2006 10:01 |