The example Alexander gave is probably a little simpler but here is a class we are working on to represent the elevator controller. Basically this class inherits from PIDController (it "is" a PIDController) and contains the victor and encoder objects that are required for PIDOputput and PIDSource. It is still under construction but it compiles and illustrates the concept I think. Also, our team is hosting an open source project for our development efforts on google code (
http://code.google.com/p/first-team63/). Can't guarantee when/what will get posted here but I will try to keep it updated as we make progress. Here the elevator class as it stands now:
ElevatorController.h:
Code:
#include "PIDController.h"
#include "Victor.h"
#include "PIDEncoder.h"
class ElevatorController : public PIDController
{
public:
ElevatorController(float p, float i, float d,float period = 0.05);
~ElevatorController();
void SetHeight(double dHeight);
private:
Victor *motorController;
PIDEncoder *encoder;
};
ElevatorController.cpp:
Code:
#include "ElevatorController.h"
ElevatorController::ElevatorController(float p, float i, float d, float period)
: PIDController(p,i,d,this->encoder, this->motorController, period)
{
this->encoder = new PIDEncoder(1, 1, 1, 1, false, CounterBase::k1X); //pass proper parameters here later
this->motorController = new Victor(1,1); //and here
this->PIDController::SetInputRange(0.0,0.0);//and here
}
ElevatorController::~ElevatorController()
{
}
void ElevatorController::SetHeight(double dHeight)
{
this->PIDController::Reset();
this->PIDController::SetSetpoint(dHeight);
this->PIDController::Enable();
}