This class was introduced earlier, though I have made some minor code changes. It takes a keepout map and uses A* (A-star) algorithm to create the lowest cost path between two points; cost is obtained from the pixel values of keepout map. As a grid cell is rectangular, we will end up with the "staircase" like route, smoothing it is not part of what AStarGrid class should do. We will address it later.
Here is a route produced by a sample "main" function of the class. This function is only being called if you run the file directly, either as python3 AStarGrid.py, or by clicking the "run" icon in vscode.
Note also, that the code has a problem (I will eventually fix it, I hope). If you run it the first way, you need to provide a different path in
... while if you run it from terminal, the path will depend on the current working directory. And if you click "debug" icon, you will have to provide yet another path. It is because each of these ways to start a program assumes a different cwd, and the path I provide is relative. The fix (that I will eventually do) should figure out the cwd and build the path dynamically.
Here is the heavily commented code. Note a non-obviois detail: when we ask the "main" program to plot a path, we provide numbers of cells, not coordinates. In descendant classes, we will introduce gridToCell and cellToGrid convertions, so we can use coordinates in meters.