Let's Make Robots!

Object tracker

Kawal's picture
Tracks the object

Few details about building

Servo

Two sharps

Arduino uno and roboshield

Acrylic strips

Sensors mounted

Completed work

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Canadian Robot's picture

Great ! thanks 

 

Michel, Canada

Canadian Robot's picture

Where do you finf your roboshield ?

Thanks

Michel

Kawal's picture

Basile gave the answer to your question.

Thanks

basile's picture

cant your sharp track your hand at any farther distance? just curious. Also, please post the code, it looks different from your forum post. Very well done, no jerky movements, it is slick

Kawal's picture

Yes the sharp can track my hand at the farther distance than shown in the video.

Code:

#include <Servo.h>
int sharp1 = 0;             // right sensor analogue pin
int sharp2 = 1;            // left sensor analogue pin
int leftdist = 0;           // variable to store left sensor reading
int rightdist = 0;        // variable to store right sensor reading
int headpin = 8;       // pin to which servo is connected
int pos = 90;          // center position for servo

Servo head;      // create a servo object

void setup() {
  head.attach(headpin);
  head.write(pos);         //center the servo
}

void loop() {
  delay(10);
  rightdist = analogRead(sharp1);
  leftdist = analogRead(sharp2);
  if (rightdist < 600 && leftdist < 600) faceforward();
  if (rightdist < 600 && leftdist < 400) faceright();
  if (leftdist < 600 && rightdist < 400) faceleft();
  head.write(pos);
}

void faceright() {
  pos = pos + 1;      //  adding 5 to the servo command(i even tried with 1 instead of 5)
  }
void faceleft() {
  pos = pos - 1;     //  subtracting 5 from the servo command(i even tried with 1 instead of 5)
  }
  void faceforward () {
  head.write(pos);
  }

TeleFox's picture

Good to see that your tracker has improved a lot =)
If you make the following adjustment, your tracking code should be even more responsive:

void loop() {
  delay(10);
  rightdist = analogRead(sharp1);
  leftdist = analogRead(sharp2);
  if (rightdist < 600 && leftdist < 600) {
    if (rightdist > leftdist) faceright();
    else if (leftdist > rightdist) faceleft();
  }
  head.write(pos);
}

There is actually no need for the faceforward() function, as you're already performing head.write(pos); at the end of every loop.
Also, since you have only 'if' comparisons and no 'else if' or 'else' comparisons, when leftdist and rightdist are both < 400, you actually end up calling faceforward() then faceright() then faceleft() and then writing with head.write(pos) after that, all in the same iteration of loop().

Lasrin's picture

Nice suggestion!  I would love to see video on how this changes the response.  I still haven't recieved my sharps yet.. :(  I'll be playing with this soon enough.

Kawal's picture

Thanks

I'll try this code .

and yeah i had figured it out earlier that there was no need to put faceforward() function but i was too lazy to change the code and test it again because of my arduino IDE.(see the forum post here maybe you can give a solution)

 

Lasrin's picture

:)