View Single Post
  #4   Spotlight this post!  
Unread 18-02-2006, 20:55
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by NextPerception
The code makes the robot overshoot and oscillate back and forth. it takes ten or more seconds to get it to center and this is not very good.

I know there is a way to use a linear or even quadratic formula to increase the speed and to reduce the amount of overshoot instead of what i have i just don't know how to go about programming it. Any help would be vary much appreciated.
Here's a piece of code from the camera software (tracking.c) that implements a simple proportional controller:

-Kevin

Code:
static unsigned char pan_servo_position;
int temp_pan_servo;
int servo_step;
int pan_error;
 
// save the current pan servo PWM value into a local
// integer variable so that we can detect and correct 
// underflow and overflow conditions before we update 
// the pan servo PWM value with a new value
temp_pan_servo = (int)pan_servo_position;
 
// calculate how many image pixels we're away from the
// vertical center line.
pan_error = (int)T_Packet_Data.mx - (int)Tracking_Config_Data.Pan_Target_Pixel;
 
// Are we too far to the left or right of the vertical 
// center line? If so, calculate how far we should step
// the pan servo to reduce the error.
if(pan_error > (int)Tracking_Config_Data.Pan_Allowable_Error)
{
	// calculate how far we need to step the pan servo
	servo_step = pan_error / (int)Tracking_Config_Data.Pan_Gain;
 
	// Due to rounding error in the division calculation above,
	// the step may be calculated as zero, which will make it
	// impossible to converge on the target when x_error is
	// smaller than X_GAIN. To get around this problem, we just 
	// test for the zero case and set the step size to one. 
	if(servo_step == 0)
	{
	 servo_step = 1;
	}
}
else if(pan_error < -1 * (int)Tracking_Config_Data.Pan_Allowable_Error)
{
	// calculate how far we need to step the pan servo
	servo_step = pan_error / (int)Tracking_Config_Data.Pan_Gain;
 
	// Due to rounding error in the division calculation above,
	// the step may be calculated as zero, which will make it
	// impossible to converge on the target when x_error is
	// smaller than X_GAIN. To get around this problem, we just 
	// test for the zero case and set the step size to one. 
	if(servo_step == 0)
	{
	 servo_step = -1;
	}
}
else
{
	// if we've fallen through to here, it means that we're
	// neither too far to the left or too far to the right
	// of the vertical center line of the image and don't 
	// need to move the servo
	servo_step = 0;
}
 
// add the step to the current servo position, taking into
// account the direction set by the user in tracking.h
temp_pan_servo += ((int)Tracking_Config_Data.Pan_Rotation_Sign * servo_step);
 
// check the pan servo PWM value for under/overflow
if(temp_pan_servo < (int)Tracking_Config_Data.Pan_Min_PWM)
{
	temp_pan_servo = (int)Tracking_Config_Data.Pan_Min_PWM;
}
else if(temp_pan_servo > (int)Tracking_Config_Data.Pan_Max_PWM)
{
	temp_pan_servo = (int)Tracking_Config_Data.Pan_Max_PWM;
}
pan_servo_position = (unsigned char)temp_pan_servo;
// update pan servo PWM value
Set_Pan_Servo_Position(pan_servo_position);
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org