# Potential field algorithm implementation

I'm studying robotics at the university and as a practice, I have to implement potential field in the simulator (I'm going to use ROS and Gazebo).

I'm having troubles about how to implement it, especially in the data structures that I'm going to need. By the way, I'm going to do it with C++.

If I have understand it well, goal attracts the robot and obstacles repel it. So, the first thing I need is:

1. A map with the obstacles, and goal location.

I will also need a function that computes the force between the robot's current location and goal, taking repelling force into consideration.

With the map and the previous function, I will move the robot to goal location.

Do you think I need something else?

I am assuming you need a force field mapping of a two-dimensional space.

You will need an array to hold the goals, unless there is only one. You will need an array to hold the obstacles. Both of these arrays must be two-dimensional to contain the coordinates of the locations.

You will need an algorithm that, for a given point in your space, sums the attractors and repulsors to come up with a vector force at that location in your field. You can do a vector summation - add all of the $$F \cos \theta$$ terms and all of the $$F \sin \theta$$ terms. This algorithm likely contains some factor based on the distance between locations. You might start by using a negative coefficient times the gravity equation for obstacles, and a positive coefficient for goals. This becomes more difficult to do when the obstacles are larger than point masses. You can play with the value of the coefficients to change the magnitude of the force field.

You will (probably, depending on the assignment) need a method to loop through the x and y coordinates of your space, computing the vector force for each location. If this is required, you will need to store this data.

Finally, you may need a way to display the force vectors. You can do this by displaying scaled lines in the direction of each vector, although your instructor may want some other representation.

Hopefully this will get you past your stuck point.

• Thanks for your answer. I think I will get a vector (with a magnitude and direction), because they are forces. How can I get this vector? In other words, what is the formula to compute that vector? Aug 4, 2019 at 7:28