Skip to content

Commit 7cf3594

Browse files
committed
mountain pattern algorithm implementation
1 parent 3af0387 commit 7cf3594

File tree

3 files changed

+223
-169
lines changed

3 files changed

+223
-169
lines changed

include/full_coverage_path_planner/common.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ enum
6161
eNodeVisited = true
6262
};
6363

64+
enum
65+
{
66+
point = 0,
67+
east = 1,
68+
west = 2,
69+
north = 3,
70+
south = 4
71+
};
72+
6473
/**
6574
* Find the distance from poi to the closest point in goals
6675
* @param poi Starting point
@@ -124,4 +133,23 @@ void printGrid(std::vector<std::vector<bool> > const& grid);
124133
* @return a list of points that have the given value_to_search
125134
*/
126135
std::list<Point_t> map_2_goals(std::vector<std::vector<bool> > const& grid, bool value_to_search);
136+
137+
/**
138+
* Prints pathNodes in the terminal
139+
*/
140+
void printPathNodes(std::list<gridNode_t> pathNodes);
141+
142+
/**
143+
* returns true only if the desired move is valid
144+
*/
145+
bool validMove(int x2, int y2, int nCols, int nRows,
146+
std::vector<std::vector<bool> > const& grid,
147+
std::vector<std::vector<bool> > const& visited);
148+
149+
/**
150+
* Adds node in (x2, y2) into the list of pathNodes, and marks the node as visited
151+
*/
152+
bool addNodeToList(int x2, int y2, gridNode_t prev, std::list<gridNode_t> pathNodes,
153+
std::vector<std::vector<bool>>& visited);
154+
127155
#endif // FULL_COVERAGE_PATH_PLANNER_COMMON_H

src/common.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,36 @@ std::list<Point_t> map_2_goals(std::vector<std::vector<bool> > const& grid, bool
309309
}
310310
return goals;
311311
}
312+
313+
314+
void printPathNodes(std::list<gridNode_t> pathNodes)
315+
{
316+
for (gridNode_t node : pathNodes) {
317+
std::cout << "(" << node.pos.x << ", " << node.pos.y << ")" << ": " << node.cost << " " << node.he << std::endl;
318+
}
319+
std:: cout << "--------------------------------------" << std::endl;
320+
321+
}
322+
323+
bool validMove(int x2, int y2, int nCols, int nRows,
324+
std::vector<std::vector<bool>> const& grid,
325+
std::vector<std::vector<bool>> const& visited)
326+
{
327+
return (x2 >= 0 && x2 < nCols && y2 >= 0 && y2 < nRows) // path node is within the map
328+
&& (grid[y2][x2] == eNodeOpen && visited[y2][x2] == eNodeOpen); // the path node is unvisited
329+
}
330+
331+
void addNodeToList(int x2, int y2, gridNode_t prev, std::list<gridNode_t>& pathNodes,
332+
std::vector<std::vector<bool>>& visited) {
333+
Point_t new_point = { x2, y2 };
334+
gridNode_t new_node =
335+
{
336+
new_point, // Point: x,y
337+
0, // Cost
338+
0, // Heuristic
339+
};
340+
prev = pathNodes.back();
341+
pathNodes.push_back(new_node);
342+
visited[y2][x2] = eNodeVisited; // Close node
343+
}
344+

0 commit comments

Comments
 (0)