SWARM ROBOTICS urgent help

hi.i am 4th year ece stude ,i m working on my SWARM ROBTICS project.

In my Project i use arduino board,dc motor and HC-SRO4 ultrasonic sensor.my first task is to perform square loop which is completed,my second task is too perform square loop with obstacle detection (mean when obstacle is present in ur path it should be detect it nd avoide it and the follow a same contiuos path)

i tried this program but it check obstacle in only corner site no in path so plz help me

https://mail-attachment.googleuserconte … o&sadssc=1

#define trigPin 3
#define echoPin 2
void setup() { 
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT); 
pinMode(4,  OUTPUT);
pinMode(5,  OUTPUT);
}
void f()
{
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void turn()
{
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void loop() {
  int duration;float distance;
  digitalWrite(trigPin,HIGH);
  delay(1000);
  digitalWrite(trigPin,LOW);
  duration=pulseIn(echoPin,HIGH);
  distance=(duration/2)/29.1;
  Serial.print(distance);
  Serial.println("cm ");
  delay(100);
 if (distance <= 25)
 {
digitalWrite(9, LOW);
digitalWrite(10,LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(500);
turn();
delay(750);
}
else
{
 f();
 delay(4000);
 turn();
 delay(750);
}
}

The kiss of death for any posting title is to include the word “urgent”. Another significant negative is asking for help on homework.

With that said, what do you think your program does and what does it actually do?

If you were my student, you would get a failing grade on this program. There is not a single comment. How are we supposed to know how you connected the Arduino? What pins go to what devices? Also very poor choice of names. Subroutines should be given verb like names (TurnRight, stop, SelfDestruct) not something like ‘f’.

So document your program, think what your real questions are (rather than generic ‘help’), and try again.

Another good word that’ll throw out practically any chance of help is “plz”.

If you can be lazy enough to skip 3 characters, I’ll be even more lazy and not read the rest of it.

That and lack of punctuation, bad spelling, the words “student”, “x Year”, and so on…

He even had the time to use bold type and italics… But couldn’t spend 30 seconds on spell check.

I was less impressed by a lack of a good description of what the problem is.

Aside from trying to translate this;

it check obstacle in only corner site no in path

into English, it doesn't say what happened, what was expected to happen, what tests were done to figure out the problem. And as said above, the code is uncommented and leaves the casual reader guessing how it's supposed to work. For example I might guess that the turn() function does a 90 turn. OK but if that's the case then when it's called when distance <= 25 (I again have to guess this is the obstacle avoidance), I don't see code for a series of following turns to get back on the original path. Also it would seem to check for obstacles all the time, not just in the "corners" as indicated by the problem "description" above.

To think that the OP is a fourth year engineering student certainly inspires confidence in the educational system.

jremington:
To think that the OP is a fourth year engineering student certainly inspires confidence in the educational system.

Maybe their "years" are equal to our days?

And who could forget this guy:

https://forum.sparkfun.com/viewtopic.ph … ct#p140496

To be fair to the OP in this case, he’s just a befuddled student who hasn’t tried very hard.

The other poster was a fraud who deserved to be reported to the scholarship authorities.

Very true, but reading this post certainly reminded me of that old chestnut.

This just reinforces the need to read the “how to ask a good question” FAQ (http://www.catb.org/~esr/faqs/smart-questions.html) to not fall victim of asking questions that violate the good manners of being a proper net citizen.

Guess it wasn’t that URGENT after all.

I also don’t get the difficulty… if he managed to do the first part of the project (going in a square), he should be able to do the second part. All the second part requires is programming another path, an ‘obstacle avoiding’ path to implement whenever the obstacle sensor goes off…

if (pathclear)

do square

else ()

do obstacle avoid square