Local Path Planning Using virtual Potential Field in Python

Nerd For Tech
Published in
5 min readMar 2, 2021


In this article, I will show you how you can write a python code for planing the path of a robot using potential fields of obstacle and the goal.


The autonomous navigation of a robot relies on the robot's ability to achieve its goal, avoiding obstacles in the environment. In some cases, the robot has complete knowledge of its environment and plans its movement based on it. In general, the robot only has an idea about the goal and should reach it using its sensors to gather information about the environment.

Local path planning should be performed in real-time, and it takes priority over the high-level plans. Therefore, it is sometimes called real-time obstacle avoidance.

One of the local path planning methods is the potential field method. It is an attractive method because of its elegance and simplicity [1]. However, using this method, the robot can easily fall into a local minimum. Therefore, additional efforts are needed to avoid this situation.

The Potential Field Method

The idea of a potential field is taken from nature. For instance, a charged particle navigating a magnetic field or a small ball rolling in a hill. The idea is that depending on the strength of the field or the hill's slope, the particle or the ball can arrive at the source of the field, the magnet, or the valley in this example.

In robotics, we can simulate the same effect by creating an artificial potential field that will attract the robot to the goal.

By designing an adequate potential field, we can make the robot exhibit simple behaviors.

For instance, let's assume that there is no obstacle in the environment and that the robot should seek this goal. In conventional planning, one should calculate the robot's relative position to the goal and then apply the suitable forces that will drive the robot to the goal.

In the potential field approach, we create an attractive field going inside the goal. The potential field is defined across the entire free space, and in each time step, we calculate the potential field at the robot position and then calculate the induced force by this field. The robot then should move according to this force.

The following figure illustrates this concept:

Fig:1 Potential Field of the Goal

We can also define another behavior that allows the robot to avoid obstacles. We make each obstacle generate a repulsive field around it. If the robot approaches the obstacle, a repulsive force will act on it, pushing it away from the obstacle.

Potential Field of the Obstacle

The two behaviors, seeking and avoiding, can be combined by combining the two potential fields; the robot then can follow the force induced by the new field to reach the goal while avoiding the obstacle:

Formulas used:

For the Goal’s potential field

For the Obstacles’ potential field

Let's Code it.

Plotting the attractive potential of the Goal same a Fig1.


Now let's plot the repulsive potential of the obstacle.


Now let’s combine the goal and obstacle’s potential field. First, I will assume that both obstacle and goal are at the origin and how its field looks.

And the results are:

Both goal and obstacle are overlapping.

The following code will plot the potential field if the goal and obstacle are at a different place:


Now we have to find a path from origin to the goal avoiding the obstacle; for this, I have used a stream plot and given the starting points as (0,0)


Now Let’s push the limits further; what I will do now is I will increase the number of obstacles from 1 to 10. The size and location of the obstacle vary randomly.

Now let's see the plots.

The results are very appropriate; our robot reaches the goal of avoiding the obstacle very efficiently except for the 6 obstacle case; the reason this is that, if you see the graph carefully, you will find that there is an obstacle very close to the origin, because of this the attractive field of the goal is not enough to cancel out the repulsive potential of the obstacle, So it is stuck at the origin. In mathematical terms, you can say that the robot is stuck in the local minima.

Find the whole code here:



Nerd For Tech

Backbencher and Not Successful, but reluctant to give up.