View Single Post
  #6   Spotlight this post!  
Unread 17-04-2006, 11:02
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: How to end an auto mode after gyro gets out of deadband

Code:
#define KP		1
#define KI		0
#define KD		0
#define WANTED_HEADING	0
#define WANTED_OUTPUT_SPEED		80 //-127 to 127
#define SHOOTING_DEADBAND		20 //4 degree deadband. 20 tenths of a degree = 2 degrees. -2 to 2 = 4 total degrees.

cur_heading = Get_Gyro_Angle();

error = WANTED_HEADING - cur_heading; //if you want the robot to drive straight in auto mode, line up robot, then turn on. cur_heading will be 0 and 0-0=0.
sumError += error;
dError = last_error - error;

if(sumError > 100){
	sumError = 100;
}else if(sumError < -100){
	sumError = -100;
}

//Calculate individual outputs
pOut = error * KP; //proportional gain
iOut = sumError * KI; //integral gain
dOut = dError * KD; //differential gain

//Add for total PID output signal
pidOut = pOut + iOut + dOut;

//limit pidOUT so total output value is in range (0,254)
if(pidOut > 126){
	pidOut = 126;
}else if(pidOut < -127){
	pidOut = -127;
}

//To drive straight, subtract output from either side of the drivebase..
//this should work if pwm01 is left side and pwm02 is right side.
pmw01 = 127 + WANTED_OUTPUT SPEED - pidOut;
pwm02 = 127 + WANTED_OUTPUT SPEED + pidOut;

//Lastly, do other stuff.
if(error >= -SHOOTING_DEADBAND && error <= SHOOTING_DEADBAND){
	Shoot(); //Put whatever you want the robot to "do" here.
}
This will utilize a PID feedback control system to steer and control the shooting of your robot.

This will work the best, but you must know how to tune this piece of code to work with your robot. If you choose to follow this road, please read (in full) this page:
http://www.embedded.com/2000/0010/0010feat3.htm
(it wasnt loading for me.. heres the google cached page)

and this CD paper: http://www.chiefdelphi.com/media/papers/1823?