Pages: 1 [2]   Go Down
Author Topic: Saying "Hi!" with my current project  (Read 2115 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 2
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 2
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
   }
 }
}
  

« Last Edit: January 10, 2011, 01:06:55 am by Mr_Manny » Logged

0
Offline Offline
Newbie
*
Karma: 2
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?  smiley-wink :-?


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);
}

« Last Edit: January 10, 2011, 09:43:44 pm by Mr_Manny » Logged

0
Offline Offline
Newbie
*
Karma: 2
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 16, 2011, 01:52:00 pm by Mr_Manny » Logged

Montreal
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Open source opens up possibilities
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Keep up the good work !
Logged

0
Offline Offline
Newbie
*
Karma: 2
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 16, 2011, 07:29:07 pm by Mr_Manny » Logged

Pages: 1 [2]   Go Up
Jump to: