The objective of this task is to implement the logic of the Gradient Path Planning algorithm.
The GPP consists of selecting a destination and finding the shortest path to it. To do so, I have decided to implement GPP navigation algorithm following the next steps:
SET VALUES:
First of all, to start setting the values it is necessary to get the map image (which is made of 400x400 pixels), the target converted from the world into the map coordinates as the world is made of 500x500 pixels and the car coordinates also converted from the world into the map.
As in opencv white is 255 and black is 0 , it is easy to increment values from 0 rather than decrementing values so, I have decided that the new map will have inverted weights : when in the original map there is a black pixel, now it is white and viceversa. To fill the map values, I have created a grid of 400x400 pixels filled with 0's (black) .
To initially fill the grid, I use the logic explained before: if a pixel from the map is black, in the grid will be white and viceversa. Then, to set cells securities to avoid car going closer to walls, I have set 3 cells with values around 255 to simulate walls. I know it would be easier to set those values different but I was not able to mix those values with the algorithm that creates the path.
After initially setting the values that I am going to work with, it is time to set the values for the path.
I start the bidimensional list from the target with an init weight of 0; then, I get the shortest distance from the values that are inside of the list and iterate along its neighbours and if one of them is 0, set the new value with is its distance + cell value. If you reach to the car position in the map, means that it is the end of the wave.
Not to forget that, it is not recommended to just finish in the car pose, so around -20 to 20 pixels to the car and if those cells have 0 value, set them to 255 to make easier the creation of the path.
I show the grid with the wave and bounds.
CREATE PATH:
I have obtained again the car coordinates in the map and I take from the grid the neighbours of the car pose and check the ones with the minimum distance and so, I insert them into the list used for the path. It stops when it reaches to the target.
Now, the path obtained is backwards due to its first pose is the target so it is necessary to invert it. I show the path (which is green by default) to have a visual guide.
I tried to fix that in intersections, in the path appears peaks and I found it impossible to fix it. The only thing I could do is increasing the security cells to decrease the size of the peak.
NAVIGATION:
I have created a function used for eliminating duplicates in the array to avoid bad navigation.
The navigation logic I have decided to implement is the following:
Until the car does not arrive to the target, I subtract each coord point with I the car coordinate in the map and that differences I store them and set some cases: ahead, back, ahead-right, ahead-left, center-right, center-left, back-left, back-right.
Down below you can see what I am trying to explain:
CONCLUSION:
I know it works but I wish it would go faster.
VIDEO:
Down below you can find a video which its speed is modified from 1x to 2x because the video was too long and I could not save that. Sorry about the inconveniences.
- Complete planification:
I hope you liked it!

.jpg)
.jpg)
.jpg)



.jpg)
.jpg)
