summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorOlivier Lanneluc2013-04-16 01:25:40 +0200
committerNicolas Schodet2013-04-27 00:19:46 +0200
commit89880e703e7b92e2b50c4a72d69f7fa12400bc14 (patch)
tree2eff4f32f40d60947450c769cec1ccf5d5eb45d3 /digital
parent2a01637d453ffcfbc3bb182ec2bef13d25e82781 (diff)
Use int instead of mixed int8/int16 for indexes, uint16 for positions
Diffstat (limited to 'digital')
-rw-r--r--digital/io-hub/src/common-cc/path.cc16
-rw-r--r--digital/io-hub/src/common-cc/path.hh34
2 files changed, 24 insertions, 26 deletions
diff --git a/digital/io-hub/src/common-cc/path.cc b/digital/io-hub/src/common-cc/path.cc
index 2672426f..63ea7d96 100644
--- a/digital/io-hub/src/common-cc/path.cc
+++ b/digital/io-hub/src/common-cc/path.cc
@@ -81,7 +81,7 @@ void Path::reset()
add_obstacle(pg_cake_pos, pg_cake_radius, PATH_CAKE_POINTS_NB);
}
-void Path::add_obstacle(const vect_t &c, int r, int num)
+void Path::add_obstacle(const vect_t &c, uint16_t r, int num)
{
uint32_t rot_a, rot_b, nr;
uint32_t x, y, nx;
@@ -144,7 +144,7 @@ void Path::add_obstacle(const vect_t &c, int r, int num)
#endif
}
-void Path::obstacle(int index, const vect_t &c, int r, int f)
+void Path::obstacle(int index, const vect_t &c, uint16_t r, int f)
{
add_obstacle(c, r, PATH_OBSTACLES_POINTS_NB);
}
@@ -165,7 +165,7 @@ void Path::compute(int escape)
escape_factor = escape;
/* Call the A* algorithm */
- path_found = (bool)astar(astar_nodes, PATH_NODES_NB, PATH_POINT_DST_IDX, PATH_POINT_SRC_IDX);
+ path_found = (bool)astar(astar_nodes, PATH_POINTS_NB, PATH_POINT_DST_IDX, PATH_POINT_SRC_IDX);
if (path_found)
{
/* Store next node to go to */
@@ -174,8 +174,8 @@ void Path::compute(int escape)
#if PATH_DEBUG
/* Log and display the path found */
vect_t path[PATH_POINTS_NB];
- uint8_t node = PATH_POINT_SRC_IDX;
- uint8_t path_nb = 0;
+ int node = PATH_POINT_SRC_IDX;
+ int path_nb = 0;
DPRINTF(">> Path found: ");
while(node!=PATH_POINT_DST_IDX)
@@ -203,7 +203,7 @@ bool Path::get_next(vect_t &p)
return path_found;
}
-vect_t& Path::get_point_vect(const uint8_t index)
+vect_t& Path::get_point_vect(const int index)
{
//assert(index<points_nb);
return points[index];
@@ -219,9 +219,9 @@ int Path::get_point_index(const vect_t& point)
return -1;
}
-uint8_t Path::find_neighbors(uint8_t cur_point, struct astar_neighbor_t *neighbors)
+int Path::find_neighbors(int cur_point, struct astar_neighbor_t *neighbors)
{
- uint8_t neighbors_nb = 0;
+ int neighbors_nb = 0;
/* Parse all nodes */
for(int i=0; i<points_nb; i++)
diff --git a/digital/io-hub/src/common-cc/path.hh b/digital/io-hub/src/common-cc/path.hh
index 37f1c77d..53bae657 100644
--- a/digital/io-hub/src/common-cc/path.hh
+++ b/digital/io-hub/src/common-cc/path.hh
@@ -47,20 +47,20 @@ class Path
/** Reset path computation, remove every obstacles */
void reset(void);
/** Set a moving obstacle position, radius and factor*/
- void obstacle(int index, const vect_t &c, int r, int f = 0);
+ void obstacle(int index, const vect_t &c, uint16_t r, int f = 0);
/** Set path source and destination */
void endpoints(const vect_t &src, const vect_t &dst);
/** Compute path with the given escape factor */
void compute(int escape = 0);
/** Return a point vector by index */
- vect_t& get_point_vect(const uint8_t index);
+ vect_t& get_point_vect(const int index);
/** Return a point index */
int get_point_index(const vect_t& point);
/** Get next point in computed path, return false if none
(no path found or last point given yet) */
bool get_next(vect_t &p);
/** Find all neighbors of a given node, fill the astar_neighbor structure */
- uint8_t find_neighbors(uint8_t node, struct astar_neighbor_t *neighbors);
+ int find_neighbors(int node, struct astar_neighbor_t *neighbors);
/** Prepare score computation for the given source, with given escape factor */
void prepare_score(const vect_t &src, int escape = 0);
/** Return score for a given destination, using a previous preparation
@@ -69,39 +69,37 @@ class Path
private:
/** Add an obstacle on the field */
- void add_obstacle(const vect_t &c, int r, int num);
+ void add_obstacle(const vect_t &c, uint16_t r, int nodes);
/** Number of possible obstacles. */
- static const uint8_t PATH_OBSTACLES_NB = (4+1/*cake*/);
+ static const int PATH_OBSTACLES_NB = (4+1/*cake*/);
/** Number of points per standard obstacle. */
- static const uint8_t PATH_OBSTACLES_POINTS_NB = 8;
+ static const int PATH_OBSTACLES_POINTS_NB = 8;
/** Number of points for the cake */
- static const uint8_t PATH_CAKE_POINTS_NB = 14;
+ static const int PATH_CAKE_POINTS_NB = 14;
/** Number of reserved points for the 2 endpoints */
- static const uint8_t PATH_RESERVED_POINTS_NB = 2;
+ static const int PATH_RESERVED_POINTS_NB = 2;
/** Number of points. */
- static const uint8_t PATH_POINTS_NB = (PATH_RESERVED_POINTS_NB +
- (PATH_OBSTACLES_NB * PATH_OBSTACLES_POINTS_NB) +
- (PATH_CAKE_POINTS_NB - PATH_OBSTACLES_POINTS_NB));
- /** Number of nodes. */
- static const uint8_t PATH_NODES_NB = PATH_POINTS_NB;
+ static const int PATH_POINTS_NB = (PATH_RESERVED_POINTS_NB +
+ (PATH_OBSTACLES_NB * PATH_OBSTACLES_POINTS_NB) +
+ (PATH_CAKE_POINTS_NB - PATH_OBSTACLES_POINTS_NB));
/** Borders, any point outside borders is eliminated. */
- const int16_t border_xmin, border_ymin, border_xmax, border_ymax;
+ const uint16_t border_xmin, border_ymin, border_xmax, border_ymax;
/** Escape factor, 0 if none. */
int escape_factor;
/** List of obstacles. */
path_obstacle_t obstacles[PATH_OBSTACLES_NB];
/** Number of obstacles */
- uint8_t obstacles_nb;
+ int obstacles_nb;
/** List of navigation points coordonates */
vect_t points[PATH_POINTS_NB];
/** Number of navigation points */
- uint8_t points_nb;
+ int points_nb;
/** List of nodes used for A*. */
- struct astar_node_t astar_nodes[PATH_NODES_NB];
+ struct astar_node_t astar_nodes[PATH_POINTS_NB];
/** Which node to look at for next step. */
- uint8_t next_node;
+ int next_node;
/** TRUE when a path has been found */
bool path_found;
};