Camera for turning
I am using a combination of the camera and a gyro to turn until the camera is lined up with the green light. With the code I'm using the robot just rotates back and forth and will never stop. Is there a better way to accomplish this. Here is the code:
Camera_Handler();
Servo_Track();
temp_gyro = Get_Gyro_Angle();
tracking_state = Get_Tracking_State();
printf("gyro_angle = %d\r\n", (int)temp_gyro);
if(capture == 0 && tracking_state == CAMERA_ON_TARGET )
{
goal_angle = ((((int)PAN_SERVO - 124) * 65)/124);
capture = 1;
}
milliradian_goal = ((goal_angle * 3.1415 * 1000)/180);
if(capture == 1)
{
if((milliradian_goal - 60) < temp_gyro)
{
pwm03 = pwm06 = 150; //Turns robot left
pwm04 = pwm05 = 150;
}
if(temp_gyro < milliradian_goal + 60)
{
pwm03 = pwm06 = 104; //Turns robot right
pwm04 = pwm05 = 104;
}
if(((milliradian_goal + 60) >= temp_gyro) && (temp_gyro >= (milliradian_goal - 60)))
{
pwm03 = pwm06 = 127;
pwm04 = pwm05 = 127;
capture = 2;
}
}
|