# Navigation Potential fields algorithm [closed]

I am working with a raspberry pi which has some positional sensors and I manage it from my mobile with an app I am developing. Now I am trying to understand how to implement this algorithm to code, but I don't really know how to start, so I would be really great if someone can help me with some starting code or similar because I cant find this algorithm implementation.

• What literature have you read about the topic? What was presented in the papers that you didn't understand? Apr 18 '17 at 13:10
• Welcome to Robotics diego, but I'm afraid that questions asking for code are off-topic because there are many ways to solve any given coding problem. We prefer practical, answerable questions based on actual problems that you face, so please try to include what you want to achieve, what you tried, what you saw & what you expected to see. Please take a look at How to Ask, tour and the Robotics question checklist for advice on writing a good question. Apr 19 '17 at 10:06

I have studied this algorithm couple months before and i'll give you my thoughts about it.

You should really start by defining the positions of your sensor. Their position is crucial for good working algorithm. I will continue with an imaginary example robot which has a circular shape. Then i placed 8 sensors on its edge with 45degree gap. Each sensor read will return only the distance to the nearest target if in detectable range else a 0. You can represent each vector as like this: $$\vec {V}_{direction} = - \phi$$ Since you want to move away from the obstacle.

$$\vec {V}_{magnitute} = c$$

But there is an important part in here. You have 3 policies to choose from when evaluating the sensor values:

1. Constant Magnitude

This profile has some important problems. It causes jerky motion on the perimeter of potential field so i dont recommend it.

1. Linear Dropoff

This profile says that the magnitude of vector decreases linearly with the distance. So if you double the distance, your magnitude cuts to the half.

3.Exponential Dropoff

This profile seems to be the best suit for most of the cases. Your magnitude decreases linearly with the square of the distance ie. if you double the distance your magnitude will be %25 of the original magnitude.

After the policy select, its really easy. You read the sensors, you evaluate its values according to selected policy then for each vector you obtained(in our example 8) you sum them as vectors. The vector you obtained has everything you need:

• Its magnitude is your motors base speed.

• Its direction is the measure of angle you should turn.

I will give one last example about the functions and the program flow.

I will have a simple linear dropoff potential field which will only turn the opposite way of the obstacle. In this case i only have my front sensor.

$$\vec{V}_{direction} = -180$$ $$\vec{V}_{magnitude} = \begin {cases}d \gt D,&0 \\ d \lt D,& \frac {(D - d)}{D}\end {cases}$$

Where D is the max distance you sense.

vector repulsive(double d, double D)                {
if (d <= D) {
outputVector.direction =   -180;
outputVector.magnitude = (D-d)/D;}
else {
outputVector.direction=0.0
outputVector.magnitude=0.0
}
return    outputVector;
}


This part is the sensing part which is so simple. You can build upon this by changing the policy and reading more sensors.