The following is to hopefully describe where I am at and the issue I have.
I have been building an Arduino based robot for the last year or so. All has
been working quite well until I wanted to use a digital sensor to work in close
range, 4 to 6 inches, situations. I am aware that the Sharp GP2Y0D810Z0F w/Pololu
carrier will not give an exact distance, rather if an object is not in its range
will give a HIGH or a LOW when an object is sensed.
Using the following code I get what I see are expected results…
This gives me:
void loop() {
Serial.print("Digital Signal 6:");
Serial.println(digitalRead(6), BIN);
= the following output:
Digital Signal 6:1 - when the sharp s810 sensor does not see anything
Digital Signal 6:0 - when the sensor sees an object in the appropriate range.
My intent is to use the above data, if a sensor 6, 7, OR 8 (or how many sensors
I am using) that outputs a LOW means an object in its range and execute some
arduino code to direct my robot to avoid a the obsticle, nothing if the output is a HIGH.
Well, I am sure that you are saying “so what is your issue?”
The issue is I must be missing some code that I do not understand. I wish to be able to
do what I can do with my analog ir sensors, for example:
#include <SharpIR.h>
SharpIR sensorA1( SharpIR::GP2Y0A41SK0F, A1); // 4 cm to 30cm
SharpIR sensorA8( SharpIR::GP2Y0A41SK0F, A8); // 4 cm to 30cm
SharpIR sensorA4( SharpIR::GP2Y0A21YK0F, A4); // 10cm to 80cm
void setup()
{
Serial.begin( 9600 ); //Enable the serial comunication
}
void loop()
{
delay(200);
int distanceA4 = sensorA4.getDistance();
Serial.println(distanceA4);
delay(200);
int distanceA1 = sensorA1.getDistance();
Serial.println(distanceA1);
delay(200);
int distanceA8 = sensorA8.getDistance();
Serial.println(distanceA8);
if (distanceA4 >= 50) {
FASTFORWARD(); //Move quickly when no object or wall is close
}
else if (distanceA4 >= 20) {
SLOWFORWARD(); //Cut speed when object/wall is close
}
else if (distanceA1 > distanceA8) {
CCW(); //rotate left to avoid object
delay(4320); //180 degrees continue 'till next sensed object
}
else if (distanceA8 > distanceA1) {
CW(); //rotate right to avoid object
delay(4320); //180 degrees continue 'till next sensed object
}
I know there are some code pieces missing here, but this snipet of code works
perfectly running a group of 3 Omni wheels giving my bot very precisemovement.
NOW comes my ignorance, I have no idea how to code the results given
by the s810 sensors into proper movement instructions for the short range issues
I am attempting to address!!
Oh, and please don’t just suggest I use a different sensor. I have invested in
12 - sharp GP2Y0D810Z0F sensors with matching carriers at $114.24. They should
work, I just cannot figure the code. Well, actually, they do work but my thinking cap is
kind of busted concerning the correct code. ;-(
Thankyou for listening to my ramblings.