Go Down

Topic: Noob project - motion tracker (Read 505 times) previous topic - next topic

TerraBytes

Hi all,
I have just embarked on my first Arduino project for an artwork.

I want to build a pair of robot eyes that will pan left-right and back again continuously.  When a 'person' is sighted the eyes should pause in their tracking and another process be triggered to indicate aquisition, i.e. to flash some Leds, before resuming panning to look for other 'people'.

I'm trying to keep this as simple as possible for now however would eventually like to build it up to track an object so that if it moves the eyes move to keep it in sight.

I have a Diecimila to use for the time being (though could get a different board if necessary), a couple of servos and a single IR proximity sensor which I plan to have between the eyes and panning at the same rate (as the eyes).

I can get the servo panning, and I can get the input from the sensor, however I'm a little stuck on how to implement the 'interrupt' operation.

Any advice would be much appreciated!

AWOL

Quote
however I'm a little stuck on how to implement the 'interrupt' operation.

Tell us what you think you need an interrupt for.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DPontes11

I'm not quite sure if the Arduino will work well with an external interrupt, I once tried and realized that the Arduino is kinda limited in this aspect.

Therefore, I would suggest something along the lines of, while the servo is going left to right, you would test the values (with an analogRead) read by the IR sensor. When (and if) this value would go over a certain threshold (defined by you), the Arduino would stop the panning and flash the leds, as you said.

It would then resume the panning and detecting... I would just give it a certain minimum amount of time (let's say 10seconds) between each time it would actuate the leds, because otherwise it would just be constantly detecting the same person and lighting up the leds.

Here's some code of my suggestion:
Code: [Select]


int IRthreshold = 300;
const int pinIN = 0;
const int pinLED = 13;
const int pinSERVO = 6;

void setup()
{
  pinMode(pinLED, OUTPUT);
  pinMode(pinSERVO, OUTPUT);
}

void loop()
{
  moveServo()
  {
    // This function makes the servo go left to right [u]one step at a time[/u];
    // It cannot be stuck inside just going left to right;
  }

  if(analogRead(pinIN) >= IRthreshold)  // Detects someone
  {
    digitalWrite(pinLED, HIGH);
    delay(2000);  //  Led turned on for 2 seconds
    digitalWrite(pinLED, LOW);
  }
}


Now, this might not be the best way to do what you wanted, but it works :) And, because of the delay(), it will not move the servo until the led is turned off.

To secure the fact that it won't detect another person for, let's say, 10 seconds, you need to use the Time.h library. But first see if this code makes sense...

AWOL

Quote
I'm not quite sure if the Arduino will work well with an external interrupt, I once tried and realized that the Arduino is kinda limited in this aspect. 

That's a pretty sweeping damnation - would you care to expand on it, please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DPontes11

Well, on second thought, never mind that sentence. I mixed up internal and external interrupts, and what I meant was that, as far as I know, you can't use internal interrupts that react to software values (a given value threshold or time).

And, in this case, since the IR sensor would be constantly outputting a value different than zero, I'm not sure as to how one would go about using the IR sensor with an interrupt... Hence, my pulling solution. I've used it in my programs, and it never gave me any problems :)

Go Up