Go Down

Topic: Saying "Hi!" with my current project (Read 2432 times) previous topic - next topic

Dale Emery

Looks pretty cool.  Nice work on the base - looks 'manufactured'.  The IR thing will do what - scan around?  Detect motion?

I'm very interested in your driver strategy.  I've found that the 1-degree steps are pretty coarse.  So I'm trying microseconds from about 650 to 2400 (seems to concur with Federico - but I'm not sure I understand it yet).
This is a couple bits from my code: 1st is servo 1, second is servo 2, third is time interval in ms:

{650, 1000, 2000}, //650 is about the limit for ccw rotation

 {2600, 1290, 1000}, //2600 is around the limit for cw rotation

Mr_Manny

The basic idea is to make a very primitive "motion tracker" using simple IR phototransistors.
Of course, it will basically just rotate until both sensors have relatively equal readings. What will keep it from being jittery, is defining a deadband in the code. Other than that, it basically does a +1 or -1 left or right..
I am not using PWM, just calling out, or calculating out the angle of the servo 0-180 degrees using the Arduino library.
I will share code here after I do a test with the sensors mounted on the 1st servo.

Mr_Manny

#17
Jan 10, 2011, 01:41 am Last Edit: Jan 10, 2011, 07:06 am by Mr_Manny Reason: 1
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:

Quote

/*
  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 Servo

int 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 Point

int 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 out

int minPos = 10;           //Min Position
int maxPos = 170;          //Max Position

float 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 = Right
 
 if (errorAVG < (deadband * -1))
 {
   return 1;
 }
 else
 {
   if (errorAVG > deadband)
   {
     return -1;
   }
   else
   {
     //Do not move within deadband
     return 0;
   }
 }
}
  


Mr_Manny

#18
Jan 11, 2011, 03:22 am Last Edit: Jan 11, 2011, 03:43 am by Mr_Manny Reason: 1
So, I tried a different sketch, and it works more predictably.
I need to go over my adapted code, and find the problem.
When I run this sketch, the tracker seems to have exagerated jitter/oscillation randomly.

Maybe somebody can spot the problem ?  ;) :-?


EDIT: Ok, maybe it needs a center position to start:

Quote

void setup()
{
ServoHorz.attach(servoX);
ServoHorz.write(minPos);  //Quick Initialization before start
ServoHorz.write(maxPos);
ServoHorz.write(output);
delay(2000);
}


Mr_Manny

#19
Jan 16, 2011, 01:40 am Last Edit: Jan 16, 2011, 07:52 pm by Mr_Manny Reason: 1
I just received my Sensor Shield V4.0, and it is going to make my testing easier.
Pretty neat, just what I needed. I also bought a new pair of IR phototransistors to change the wiring setup a little, and now I can solder a standard servo cable to the sensor.

Diastro

Looks awesome!!
Great idea to do the 3d design then do the real concept!!


Keep up the good work !

Mr_Manny

#21
Jan 16, 2011, 11:49 pm Last Edit: Jan 17, 2011, 01:29 am by Mr_Manny Reason: 1
Small Update. Here is testing of the X axis.
Sorry about the soundtrack, you might want to mute.

[media]http://www.youtube.com/watch?v=pyfZz7aYMw8[/media]

The test involves a lamp above and a white plastic sphere for reflection.

Go Up