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
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 }
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().
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.
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)
@ Wed, 2011-05-18 20:34
Thanks for info!!
Great ! thanks
Michel, Canada
@ Wed, 2011-05-18 04:30
Info,,
Where do you finf your roboshield ?
Thanks
Michel
@ Wed, 2011-05-18 08:57
Basile gave the answer to
Basile gave the answer to your question.
Thanks
@ Wed, 2011-05-18 08:16
Info...
my guess is that it could be this one.
http://probots.co.in/index.php?main_page=product_info&cPath=55_68&products_id=213
@ Thu, 2011-03-31 15:11
cant your sharp track your
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
@ Thu, 2011-03-31 15:46
Yes
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);
}
@ Mon, 2011-04-18 06:06
Good to see that your
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().
@ Mon, 2011-04-18 08:51
Nice suggestion! I would
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.
@ Mon, 2011-04-18 08:32
ThanksI'll try this code
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)
@ Thu, 2011-03-31 17:18
:)
:)