Defines | |
#define | _ISOC99_SOURCE |
#define | _XOPEN_SOURCE |
Functions | |
int | getPathLength (int xstart, int ystart, int xgoal, int ygoal) |
void | GraphCell2XY (GraphMapCell *c, int *x, int *y) |
Returns X and Y index of a graph cell identified by a pointer. | |
A* Implementation Functions | |
This functions have not a meaning in A* algorithm, but are needed for implementation. | |
void | initGraphStructure (void) |
Init Graph structure with default values. | |
A* related functions | |
This functions have a meaning in theorical A*. | |
float | cFunction (int x1, int y1, int x2, int y2) |
Calculates the lenght of edge connecting two points. | |
void | calculateMapHeuristic (int xgoal, int ygoal) |
Calculates Map Heuristic values. | |
float | calculateCost (int x1, int y1, int x2, int y2) |
Calculates the cost of moving from the first cell to the second cell. | |
A* Main function | |
| |
int | aAlgorithm (double xstart_real, double ystart_real, double xgoal_real, double ygoal_real, GraphMapCell **original_path) |
Search the shortest path between two points. | |
Path simplifier functions | |
| |
PathPoint * | newPathPoint (PathPoint *last, float x, float y) |
Put the REAL coordonates (X,Y) in a list of points. | |
void | calc_line (float x1, float y1, float x2, float y2, Line *l) |
Calc line parameters from two points. | |
float | calc_dist (Line *l, float x, float y) |
Calc the distance between a line and a point. | |
int | path_simplifier (PathPoint *path, int nbpoints, PathPoint *first_point, double *angle) |
Simplify a given path. | |
Queue functions | |
This functions implements a queue needed by other functions. | |
int | queueIsEmpty (NodeQueue *q) |
Tests if a queue is empty. | |
void | pushNode (NodeQueue *q, int x, int y) |
Push a node into the queue in a FIFO mode. | |
void | pushNodeLast (NodeQueue *q, int x, int y) |
Push a node into the queue in a LIFO mode. | |
int | popNode (NodeQueue *q, Node *n) |
Pop the first node of the queue. | |
void | printQueue (NodeQueue *q) |
Print the queue. | |
NodeQueue * | newQueue (void) |
Init queue values. | |
int | delQueue (NodeQueue *q) |
Free queue memory. | |
int | isInQueue (NodeQueue *q, int x, int y) |
Finds out if the node (X,Y) is in the queue. | |
void | drainQueue (NodeQueue *q) |
Free memory allocated in the queue. | |
A* Constants | |
| |
#define | SQRT2 M_SQRT2 |
Root square of two. | |
#define | WALL_COST 1000 |
Cost of jumping a wall. |
PathPlaner is composed of three sublibraries or modules:
#define _ISOC99_SOURCE |
#define _XOPEN_SOURCE |
#define SQRT2 M_SQRT2 |
Root square of two.
#define WALL_COST 1000 |
Cost of jumping a wall.
int aAlgorithm | ( | double | xstart_real, | |
double | ystart_real, | |||
double | xgoal_real, | |||
double | ygoal_real, | |||
GraphMapCell ** | original_path | |||
) |
Search the shortest path between two points.
xstart_real | Coordonate X of the start point | |
ystart_real | Coordonate Y of the start point | |
xgoal_real | Coordonate X of the goal point | |
ygoal_real | Coordonate Y of the goal point | |
original_path | [out] Pointer to the first map cell of the path is stored here. Use GraphMapCell.next to traverse the found path. |
This is an implementation of A* Algorithm (Algorithm 24, p531) defined in the book "Principles of Robot Motion" by H. Choset&others
prioritySet : Set of nodes to process order by heuristic distance
nbest : Best node to reach the goal
Init graph structure with default values.
Calculate Heuristic distances.
Initial values : put start node in queue.
Expand nbest :for all x E Star(nbest) that are not in C
REPEAT until the queue is empty.
Pick nbest from prioritySet and remove
add to processed
IF nbest == goal ; EXIT
Expand nbest :for all x E Star(nbest) that are not in C
IF is not in Priorityset add to prioritySet.
ELSE update backpointer to point to nbest.
float calc_dist | ( | Line * | l, | |
float | x, | |||
float | y | |||
) |
Calc the distance between a line and a point.
l | A pointer to line parameters | |
x | Coordonate X of the point | |
y | Coordonate Y of the point |
If it is a hotizontal line, the distance is the difference between y coordonate and b parameter.
If it is a vertical line, the distance is the difference between x coordonate and b parameter.
If it is a oblicuous line, the distance is .
void calc_line | ( | float | x1, | |
float | y1, | |||
float | x2, | |||
float | y2, | |||
Line * | l | |||
) |
Calc line parameters from two points.
x1 | Coordonate X of the first point | |
y1 | Coordonate Y of the first point | |
x2 | Coordonate X of the second point | |
y2 | Coordonate Y of the second point | |
l | A pointer to line parameters |
Returns parameters of a line : a1 * x + a2 * y = b
float calculateCost | ( | int | x1, | |
int | y1, | |||
int | x2, | |||
int | y2 | |||
) |
Calculates the cost of moving from the first cell to the second cell.
x1 | Coordonate X of the first cell | |
y1 | Coordonate Y of the first cell | |
x2 | Coordonate X of the second cell | |
y2 | Coordonate Y of the second cell |
void calculateMapHeuristic | ( | int | xgoal, | |
int | ygoal | |||
) |
Calculates Map Heuristic values.
xgoal | Coordonate X of the goal | |
ygoal | Coordonate Y of the goal |
This function calculates the map heuristic values (the distance to the goal that is supoused to be the shortest).
The chosen method has been the euclidean distance. The distance between a point of the grid and the goal
is
.
Another method explained in the book is coded but not used.It is called Brushfire algorithm. (section 4.3.2 of the book)
float cFunction | ( | int | x1, | |
int | y1, | |||
int | x2, | |||
int | y2 | |||
) |
Calculates the lenght of edge connecting two points.
x1 | Coordonate X of the first cell | |
y1 | Coordonate Y of the first cell | |
x2 | Coordonate X of the second cell | |
y2 | Coordonate Y of the second cell |
int delQueue | ( | NodeQueue * | q | ) |
Free queue memory.
q | Queue |
void drainQueue | ( | NodeQueue * | q | ) |
Free memory allocated in the queue.
q | Queue |
int getPathLength | ( | int | xstart, | |
int | ystart, | |||
int | xgoal, | |||
int | ygoal | |||
) |
void GraphCell2XY | ( | GraphMapCell * | c, | |
int * | x, | |||
int * | y | |||
) |
Returns X and Y index of a graph cell identified by a pointer.
[in] | c | Pointer to the cell in question. |
[out] | x | Cell's X index. |
[out] | y | Cell's Y index. |
void initGraphStructure | ( | void | ) |
Init Graph structure with default values.
int isInQueue | ( | NodeQueue * | q, | |
int | x, | |||
int | y | |||
) |
Finds out if the node (X,Y) is in the queue.
q | Queue | |
x | Coordonate X of a cell | |
y | Coordonate Y of a cell |
Put the REAL coordonates (X,Y) in a list of points.
last | Last point of the points list | |
x | Coordonate X of the first cell | |
y | Coordonate Y of the first cell |
NodeQueue* newQueue | ( | void | ) |
Init queue values.
Simplify a given path.
path | A pointer to a list of points of the original path | |
nbpoints | Number of points of the original path | |
first_point | [out] A pointer to the list of points of simplest path | |
angle | [out] Angle of the last line |
This is an algorithm who tries to simplify the path given by A* Algorithm (
In pseudo-code:
first_index = 0; last_index = nbpoints; step = (last_index - first_index)/2 WHILE (the first index less than nbpoints ) Calc the line FOR all the points between path[first_index] and path[last_index] calc the distance betwen the point and the line Take the max_error END FOR IF max_error less than ACCEPTABLE_ERROR THEN The line is part of the simple path. first_index = last_index last_index = last_index + step ELSE reduce last_index step = (last_index - first_index)/2 last_index = last_index - step; END IF END WHILE
Pop the first node of the queue.
q | Queue | |
n | Pointer to a node |
void printQueue | ( | NodeQueue * | q | ) |
Print the queue.
q | Queue |
void pushNode | ( | NodeQueue * | q, | |
int | x, | |||
int | y | |||
) |
Push a node into the queue in a FIFO mode.
q | Queue | |
x | Coordonate X of a cell | |
y | Coordonate Y of a cell |
void pushNodeLast | ( | NodeQueue * | q, | |
int | x, | |||
int | y | |||
) |
Push a node into the queue in a LIFO mode.
q | Queue | |
x | Coordonate X of a cell | |
y | Coordonate Y of a cell |
int queueIsEmpty | ( | NodeQueue * | q | ) |
Tests if a queue is empty.
q | A queue |