Go Down

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

FilippovM

https://www.youtube.com/watch?v=5druVAvlyxk

FilippovM

Components:
Arduino nano V3,Ultrasonic HC-SR04, Servo, H-Bridge, L293D, L7805.
Robot program:
http://maxim.wf/arduino_code/Robot_compilation.pde

ShockAndAwe

Haha! Great navigation!

I love how crazy it's head spins!

PaulS

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.

The art of getting good answers lies in asking good questions.


oric_dan

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

yes.  I' measuring only several positions (0, 45, 90, 135 180). And servo waits while arduino measuring at these times

Go Up