View Single Post
  #1   Spotlight this post!  
Unread 31-01-2009, 09:07
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Autonomous PID movement

Hi,

For autonomous mode I'm able to find the target and calculate a setpoint to turn to, but I'm not sure I'm actually using PID control correctly. Here is what I'm doing in pseudo code

Code:
class PIDCameraSource : public PIDSource
{
public:
	PIDCameraSource() : source_( 0.0f ) {
	}
	
	virtual Double PIDGet() {
		return source_;
	}
	
	void SetSource( Double source ) {
		source_ = source;
	}
	
private:
	Double source_;
};

class PIDCameraOutput : public PIDOutput
{
public:
	PIDCameraOutput() : output_( 0.0 ) {
	}
	
	virtual void PIDWrite( Float output ) {
		output_ = output;
	}
	
	Float GetOutput() const {
		return output_;
	}
	
private:
	Float output_;
};


static int currentDriveX_ = 0; // really a member variable, not a static

if( TargetFound ) {
    pidSource_.SetSource( currentDriveX_ ); // pidSource_ is a member variables
    pidController_.SetSetpoint( normalize_x_center_of_mass ); // as well pidController_
}

robotDrive_.Drive( speed, (currentDriveX_ = pidOutput_.GetOutput()) ); //  speed calculate elsewhere
Basically, my source is just my last PID output. Is that wrong? Obviously there is not direct 1-to-1 relationship between the a turn curve and the values actually sent to the two drive motors for tank control, but should I still try to calculate what the turn curve is from the two motors or is what I have sufficient?

Also, what's the best to go about getting the PID constants right? I seem to be having a hard time calculating something that works and I'm not sure if it's because I'm just using PID control wrong, or if my constants are just to far off.