Arduino obstacle avoiding robot problem code!!

Hi all, I built a robot with Arduino avoiding obstacles. Not being very good at programming, I found a code online and I adapted to my “needs”. Despite all the problems persist …
1- The robot turns just right, I suspect that the problem is this: in checkpath () is if (curDist> curDist) that is never checked and maxAngle is never set to remain at 0.
I tried in every way but I can not remedy.
2- Although there is no obstacle in front, sometimes the robot goes back … I run checkCourse () but I do not understand why …
These are the issues that I would solve … I trust in you I desperately need help! Thanks in advance to all! I attach the code.

Components used:
Arduino Uno
motor shield L293D
hc-SR04 ultrasonic sensor
servo motor
4 Dc motors
2 x 4 battery pack

APC_4_ROBOT.ino (10.1 KB)

I have not downloaded your code but if you really have

if (curDist> curDist)

in your program then I am not surprised that it does not work the way you want. Under what circumstances would this test ever be true ?

I can not fix it, do not know what to put in the place of curDist

up

kingterminetor: I can not fix it, do not know what to put in the place of curDist

Do you understand what the problem is with the code at the moment ? What is the code trying to establish at that point ? It is comparing two distances. What are those two distances ? One of them may well be curDist, which from its name sounds like the current distance. When was it current and what will have changed that it might be compared with ? It is likely that there was a previous distance measurement that it should be compared with. Is there such a thing ?