# Formula for decision making when in contact with an obstacle using Arduino

I am currently working on an obstacle avoidance robot project and I have seen numerous algorithms for obstacle avoidance a very good example is this Obstacle avoidance algorithm [Editor's note: by user3880651], but unfortunately non of those algorithm works with Arduino so upon my research I found this blog

and in there the author talks about an effective way to avoid obstacles and even has a formula he uses for avoiding obstacles at different positions e.g (Front and sides) but doesn't really explain how he got the formula so I was wondering if anyone as an effective formula or algorithm for obstacle avoidance that works with Arduino thanks for your help in advance

• I'm not voting to close this because it is Arduino based, but I think you might get a better (but more generic) response on the robotics forum, but don't mention 'Arduino' otherwise it will get bounced back to here :) Good luck Apr 5, 2017 at 12:16
• As there's the code given in the blog, you may try reverse engineer it to understand the principles? Apr 5, 2017 at 19:06
• Both links posted are 100% about Arduinos. You asked for an algorithm, an several were given. An algorithm is not code; it's a method. Is your duty to implement that method in C, Java, Perl, Assembler or whatever is your language of choice.
– user31481
Nov 2, 2017 at 16:10
• Possible duplicate of Obstacle avoidance algorithm
– user31481
Nov 2, 2017 at 16:12

The algorithm mentioned in the blog uses a Fuzzy Logic Controller to perform obstacle avoidance. You can read up more on fuzzy logic here: https://www.calvin.edu/~pribeiro/othrlnks/Fuzzy/home.htm

newMotorSPD_L = basicVelocity + urgMotor_L + (urgTurn_R/4) - (urgTurn_L/2) + 60; newMotorSPD_R = basicVelocity + urgMotor_R + (urgTurn_L/4) - (urgTurn_R/2) + 60;

Based on the code, the formula is basically made up of variables with different weight/ratio.

basicVelocity is the default moving velocity of the robot when there is no obstacle or wall detected.

urgMotor_L/urgMotor_R is the ouput of the controller for frontal object detection/avoidance by getting the difference between the left and right ultrasonic sensor.

(urgTurn_R/4) - (urgTurn_L/2) is probably the left/right bias?

+60 at the end is probably to offset the error of the motor. (Assuming all other variable are 0, the robot should be still at 60 for their case?)

To simplify what the formula does, it can be shown using this graph:

Obstacle avoidance doesn't really have any practical use unless it works alongside a goal finding algorithm.

Take a look here for a simple introduction (and a few modifications) to this excellent paper on goal finding with obstacle avoidance.

You can also experiment with the python code (add obstacles, change positions of goal and start points, and step through the decision process). Keep in mind that in this code, sensor inputs are also simulated and so the code is much more complex than that would actually need to be deployed on a robot with real world sensors.