From 43fed3a07ab4626a2961b850ffbb08734359e86e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 17 Jun 2008 22:57:09 +0200 Subject: * digital/io/src: - make path independent of playground. --- digital/io/src/main.c | 4 +++- digital/io/src/path.c | 19 +++++++++++++------ digital/io/src/path.h | 3 ++- digital/io/src/test_path.c | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'digital/io') diff --git a/digital/io/src/main.c b/digital/io/src/main.c index a24e7e14..05fb68b5 100644 --- a/digital/io/src/main.c +++ b/digital/io/src/main.c @@ -47,6 +47,7 @@ #include "gutter.h" /* gutter_generate_wait_finished_event */ #include "sharp.h" /* sharp module */ #include "path.h" /* path module */ +#include "playground.h" #include "io.h" @@ -142,7 +143,8 @@ main_init (void) /* Switch module */ switch_init (); /* Path module */ - path_init (); + path_init (PG_BORDER_DISTANCE, PG_BORDER_DISTANCE, + PG_WIDTH - PG_BORDER_DISTANCE, PG_HEIGHT - PG_BORDER_DISTANCE); /* Start the top FSM */ top_start (); /* Sharp module */ diff --git a/digital/io/src/path.c b/digital/io/src/path.c index cf3167c4..a41a2d4e 100644 --- a/digital/io/src/path.c +++ b/digital/io/src/path.c @@ -25,7 +25,6 @@ #include "common.h" #include "path.h" -#include "playground.h" #include "simu.host.h" #include "modules/math/fixed/fixed.h" @@ -71,6 +70,8 @@ struct path_obstacle_t /** Path finding context. */ struct path_t { + /** Borders, any point outside borders is eliminated. */ + int16_t border_xmin, border_ymin, border_xmax, border_ymax; /** Complex number used to position obstacles points. * The obstacles points are placed evenly on a circle around the center * point. Complex multiplication is used to make a point rotate around @@ -94,8 +95,14 @@ struct path_t path; /** Initialise path finder. */ void -path_init (void) +path_init (int16_t border_xmin, int16_t border_ymin, + int16_t border_xmax, int16_t border_ymax) { + /** Save borders. */ + path.border_xmin = border_xmin; + path.border_ymin = border_ymin; + path.border_xmax = border_xmax; + path.border_ymax = border_ymax; /** Complex number of modulus 1 and rotation angle. */ path.rot_a = fixed_cos_f824 (PATH_OBSTACLES_POINTS_ANGLE); path.rot_b = fixed_sin_f824 (PATH_OBSTACLES_POINTS_ANGLE); @@ -131,10 +138,10 @@ path_compute_points (void) path.points[p].x = path.obstacles[i].x + (uint16_t) x; path.points[p].y = path.obstacles[i].y + (uint16_t) y; /* Check it is in playground. */ - if (path.points[p].x > PG_BORDER_DISTANCE - && path.points[p].y > PG_BORDER_DISTANCE - && path.points[p].x < PG_WIDTH - PG_BORDER_DISTANCE - && path.points[p].y < PG_HEIGHT - PG_BORDER_DISTANCE) + if (path.points[p].x >= path.border_xmin + && path.points[p].y >= path.border_ymin + && path.points[p].x < path.border_xmax + && path.points[p].y < path.border_ymax) /* Accept point. */ p++; } diff --git a/digital/io/src/path.h b/digital/io/src/path.h index aea50f40..cf19ec3d 100644 --- a/digital/io/src/path.h +++ b/digital/io/src/path.h @@ -27,7 +27,8 @@ /** Initialise path finder. */ void -path_init (void); +path_init (int16_t border_xmin, int16_t border_ymin, + int16_t border_xmax, int16_t border_ymax); /** Setup end points (source and destination coordinates). */ void diff --git a/digital/io/src/test_path.c b/digital/io/src/test_path.c index 3d25e0b7..e16e5c6f 100644 --- a/digital/io/src/test_path.c +++ b/digital/io/src/test_path.c @@ -33,7 +33,7 @@ path_print_graph (void); int main (void) { - path_init (); + path_init (0, 0, 3000, 2100); path_endpoints (300, 1000, 1200, 1000); path_obstacle (0, 600, 930, 100, 1); path_obstacle (1, 900, 1070, 100, 1); -- cgit v1.2.3