Here's my updated camera search code. So, if anyone has any insights I'd appreciate it.
Code:
//turn the turret to the right for a specified
//number of loops if direction is equal to 1
if (direction == 1)
{
pwm12 = 255;
loop_number++;
//when it reaches the end of the time,
//change tilt value, change direction
//and reset loop counter
if (loop_number > 50)
{
if(temp_tilt_servo >= (int)Tracking_Config_Data.Tilt_Max_PWM)
{
temp_tilt_servo = (int)Tracking_Config_Data.Tilt_Min_PWM;
}
else
{
// step the tilt servo to its next destination
temp_tilt_servo += (int)Tracking_Config_Data.Tilt_Search_Step_Size;
// make sure its new position isn't beyond
// the maximum value set in tracking.h
if(temp_tilt_servo >= (int)Tracking_Config_Data.Tilt_Max_PWM)
{
temp_tilt_servo = (int)Tracking_Config_Data.Tilt_Max_PWM;
}
}
direction = 0;
loop_number = 0;
}
}
//turn the turret to the left for a specified
//number of loops if direction is equal to 0
else if (direction == 0)
{
pwm12 = 0;
loop_number++;
//when it reaches the end of the time,
//change tilt value, change direction
//and reset loop counter
if (loop_number > 50)
{
if(temp_tilt_servo >= (int)Tracking_Config_Data.Tilt_Max_PWM)
{
temp_tilt_servo = (int)Tracking_Config_Data.Tilt_Min_PWM;
}
else
{
// step the tilt servo to its next destination
temp_tilt_servo += (int)Tracking_Config_Data.Tilt_Search_Step_Size;
// make sure its new position isn't beyond
// the maximum value set in tracking.h
if(temp_tilt_servo >= (int)Tracking_Config_Data.Tilt_Max_PWM)
{
temp_tilt_servo = (int)Tracking_Config_Data.Tilt_Max_PWM;
}
}
direction = 1;
loop_number = 0;
}
}
//if direction isn't left or right
//there is a code error and the
//motor is set to neutral
// else
// pwm12 = 127;
}
// update the pan and tilt servo PWM value
//PAN_SERVO = (unsigned char)temp_pan_servo;
TILT_SERVO = (unsigned char)temp_tilt_servo;
}
}
}
}