I got it wired up for a full test with the IR sensors mounted on the turret, but the results were less than encouraging.
Possibly my sensors need amplification, or my wiring is just shorting.
The axis is not responsive unless I shine bright light on it, and sometimes jittery.
EDIT: I think it is a fault phototransistor. Only one sensor activates the slew.
Here is the code I adapted:
/*
Base Coding For Arduino Motion Tracker Using IR Sensors
Adapted by Mr_Manny from code by Dave Auld
Original Url: http://www.codeproject.com/KB/system/ArduinoLightTrack.aspx
*/#include <Servo.h>
// Define Pins To Be used
int pin_L = 5; //Left Sensor Pin
int pin_R = 4; //Right Sensor Pin
int servoX = 11; //Pin For The Horizontal Servoint leftValue = 0; //The left Sensor Value
int rightValue = 0; //The right Sensor Value
int error =0; //The Deviation between the 2 sensors
int errorAVG = 0; //Error Average - Rolling 2 Pointint deadband = 10; //Range for which to do nothing with output 10 = -10 to +10
//Servo Declarations
Servo ServoHorz; //Make a Servo object
int Position = 45; //Position to write outint minPos = 10; //Min Position
int maxPos = 170; //Max Positionfloat output = (maxPos - minPos) /2; //Start Position, Try 90deg Later
void setup()
{
ServoHorz.attach(servoX);
}void loop()
{
//Read Sensors And Calculate
leftValue = analogRead(pin_L);
rightValue = analogRead(pin_R);//Calculate
error = leftValue - rightValue;
errorAVG = (errorAVG + error) / 2;float newOutput = output + getTravel();
if (newOutput > maxPos)
{
newOutput = maxPos;
}
else
{
if (newOutput < minPos)
{
newOutput = minPos;
}
}
//Output Writing
ServoHorz.write(newOutput);
output = newOutput;
}int getTravel()
{
// -1 = Left; +1 = Rightif (errorAVG < (deadband * -1))
{
return 1;
}
else
{
if (errorAVG > deadband)
{
return -1;
}
else
{
//Do not move within deadband
return 0;
}
}
}