Go Down

### Topic: My robot with ultrasonic sensor (Read 5054 times)previous topic - next topic

#### FilippovM

#1
##### Oct 23, 2012, 10:23 pm
Components:
Arduino nano V3,Ultrasonic HC-SR04, Servo, H-Bridge, L293D, L7805.
Robot program:
http://maxim.wf/arduino_code/Robot_compilation.pde

#### ShockAndAwe

#2
##### Oct 30, 2012, 06:26 pm

I love how crazy it's head spins!

#### PaulS

#3
##### Oct 31, 2012, 11:52 am
Code: [Select]
`   if(dist_f>=25)   {    a:    motion('f',180,135,t);    dist_135=sonar();    front_motion(t);    motion('f',135,90,t);      dist_f=sonar();    front_motion(t);    motion('f',90,45,t);    dist_45=sonar();    front_motion(t);    motion('f',45,0,t);    dist_r=sonar();    front_motion(t);    motion('f',0,45,t);    dist_45=sonar();    front_motion(t);    motion('f',45,90,t);    dist_f=sonar();    front_motion(t);    motion('f',90,135,t);    dist_135=sonar();    front_motion(t);    motion('f',135,180,t);    dist_l=sonar();    front_motion(t);    if (dist_f>=25)    goto a;    }`
This should be a while loop, so you can loose the silly goto.

Some arrays and for loops() would greatly shorted the code.

#4
Thanks

#### oric_dan

#5
##### Dec 17, 2012, 05:14 am
Is it this platform?  http://www.robotshop.com/dfrobot-mobile-tank-base-1.html

Do you think you are getting good readings with panning the sonar so fast?

#### FilippovM

#6
##### Dec 23, 2012, 11:10 pm
yes.  I' measuring only several positions (0, 45, 90, 135 180). And servo waits while arduino measuring at these times

Go Up