From e29194cf2afec5d37583804d21c8049c6ab91b44 Mon Sep 17 00:00:00 2001 From: Olivier Lanneluc Date: Sat, 13 Apr 2013 01:38:40 +0200 Subject: Add prepare_score and get_score --- digital/io-hub/src/common-cc/path.cc | 65 +++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'digital/io-hub/src/common-cc/path.cc') diff --git a/digital/io-hub/src/common-cc/path.cc b/digital/io-hub/src/common-cc/path.cc index 78011eb3..f6b58f63 100644 --- a/digital/io-hub/src/common-cc/path.cc +++ b/digital/io-hub/src/common-cc/path.cc @@ -27,6 +27,7 @@ #include "bot.hh" #include "robot.hh" #include "playground.hh" +#include "playground_2013.hh" extern "C" { #include "modules/math/fixed/fixed.h" @@ -34,7 +35,7 @@ extern "C" { #include "modules/utils/utils.h" } -#define PATH_DEBUG 1 +#define PATH_DEBUG 1 #ifdef HOST #include "../../digital/ai/src/common/debug.host.h" @@ -63,19 +64,18 @@ Path::Path() : void Path::reset() { vect_t nul = {0,0}; - vect_t cake = {pg_width>>1, pg_length}; /* Reset everything */ DPRINTF( "Path reset\n"); obstacles_nb = 0; - points_nb = PATH_FIXED_POINTS_NB; + points_nb = PATH_RESERVED_POINTS_NB; points[PATH_POINT_SRC_IDX] = nul; points[PATH_POINT_DST_IDX] = nul; next_node = 0; escape_factor = 0; /* Declare the cake as an obstacle */ - add_obstacle(cake, 500 + BOT_SIZE_SIDE, 0, PATH_CAKE_POINTS_NB); + add_obstacle(pg_cake_pos, pg_cake_radius + BOT_SIZE_SIDE * 4 / 3, 0, PATH_CAKE_POINTS_NB); } void Path::add_obstacle(const vect_t &c, const int r, const int factor, const int num) @@ -105,7 +105,7 @@ void Path::add_obstacle(const vect_t &c, const int r, const int factor, const in (fixed_mul_f824(rot_b,rot_b) >> 16) + (1L<<8) ); fact_r += 1; /* To counter rounding operations */ - fact_r += 13; /* Add 10% margin */ + //fact_r += 13; /* Add 10% margin */ /* First point is at the relative position (r;0) */ x = ((r * fact_r) >> 8); @@ -137,11 +137,11 @@ void Path::add_obstacle(const vect_t &c, const int r, const int factor, const in #ifdef HOST // Plot obstacle points - robot->hardware.simu_report.pos( &points[PATH_FIXED_POINTS_NB], points_nb-PATH_FIXED_POINTS_NB, PATH_PLOT_ID); + robot->hardware.simu_report.pos( &points[PATH_RESERVED_POINTS_NB], points_nb-PATH_RESERVED_POINTS_NB, PATH_PLOT_ID); #if 0 // Draw the last obstacle points[points_nb] = points[points_nb - num]; - robot->hardware.simu_report.path( &points[points_nb - num], points_nb + 1); + robot->hardware.simu_report.path( &points[points_nb - num], num + 1); #endif #endif } @@ -205,28 +205,38 @@ bool Path::get_next(vect_t &p) return path_found; } -vect_t& Path::get_point(uint8_t index) +vect_t& Path::get_point_vect(const uint8_t index) { + //assert(index validated w=%u\n", weight); neighbors[neighbors_nb].node = i; - neighbors[neighbors_nb].weight = (uint16_t)UTILS_MIN(weight,0xFFFF); + neighbors[neighbors_nb].weight = weight; neighbors_nb++; } else @@ -256,7 +267,7 @@ uint8_t Path::find_neighbors(uint8_t cur_point, struct astar_neighbor_t *neighbo #if PATH_DEBUG DPRINTF("\tFound %u neighbors: ", neighbors_nb); - for(i=0;ipath.get_point(node); - DPRINTF("AC_ASTAR_NEIGHBOR_CALLBACK node=%u (%u;%u)\n", node, node_v.x, node_v.y); + vect_t point_v = robot->path.get_point_vect(node); + DPRINTF("AC_ASTAR_NEIGHBOR_CALLBACK node=%u (%u;%u)\n", node, point_v.x, point_v.y); #endif return robot->path.find_neighbors(node, neighbors); } @@ -277,9 +302,9 @@ AC_ASTAR_NEIGHBOR_CALLBACK (uint8_t node, struct astar_neighbor_t *neighbors) extern "C" uint16_t AC_ASTAR_HEURISTIC_CALLBACK (uint8_t node) { - vect_t node_a = robot->path.get_point(node); - vect_t node_b = robot->path.get_point(PATH_POINT_SRC_IDX); - int16_t dist = distance_point_point(&node_a, &node_b); + vect_t point_a = robot->path.get_point_vect(node); + vect_t point_b = robot->path.get_point_vect(PATH_POINT_SRC_IDX); + int16_t dist = distance_point_point(&point_a, &point_b); DPRINTF("Heuristic node=%u dist=%u\n", node, dist); return dist; } -- cgit v1.2.3