From: zer0 Date: Sun, 20 Dec 2009 16:48:29 +0000 (+0100) Subject: circles intersection and tourel beacon X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=commitdiff_plain;h=80386d268a58da2be3eeca83f254c980a047b34f;ds=sidebyside circles intersection and tourel beacon --- diff --git a/modules/base/math/geometry/Makefile b/modules/base/math/geometry/Makefile index aa808b6..b905c35 100644 --- a/modules/base/math/geometry/Makefile +++ b/modules/base/math/geometry/Makefile @@ -1,7 +1,7 @@ TARGET = geometry # List C source files here. (C dependencies are automatically generated.) -SRC = vect_base.c lines.c polygon.c +SRC = vect_base.c lines.c polygon.c circles.c ########################################### diff --git a/modules/base/math/geometry/circles.c b/modules/base/math/geometry/circles.c new file mode 100644 index 0000000..09b9af6 --- /dev/null +++ b/modules/base/math/geometry/circles.c @@ -0,0 +1,112 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + +#include + +#include + +#include +#include + +static inline float sq(float x) +{ + return x*x; +} + +uint8_t pt_is_inside_circle(const point_t *p, circle_t *c) +{ + vect_t v; + v.x = p->x - c->x; + v.y = p->y - c->y; + if ((v.x * v.x + v.y * v.y) < (c->r * c->r)) + return 1; + return 0; +} + +/* + * return values: + * 0 dont cross + * 1 one intersection point + * 2 two intersection points + * + * p1, p2 arguments are the crossing points coordinates. Both p1 and + * p2 are dummy for 0 result. When result is 1, p1 and p2 are set to + * the same value. + */ +uint8_t circle_intersect(const circle_t *c1, const circle_t *c2, + point_t *p1, point_t *p2) +{ + circle_t ca, cb; + float a, b, c, d, e; + uint8_t ret = 0; + + /* create circles with same radius, but centered on 0,0 : it + * will make process easier */ + ca.x = 0; + ca.y = 0; + ca.r = c1->r; + cb.x = c2->x - c1->x; + cb.y = c2->y - c1->y; + cb.r = c2->r; + + /* inspired from + http://www.loria.fr/~roegel/notes/note0001.pdf */ + a = 2. * cb.x; + b = 2. * cb.y; + c = sq(cb.x) + sq(cb.y) - sq(cb.r) + sq(ca.r); + d = sq(2. * a * c) - + (4. * (sq(a) + sq(b)) * (sq(c) - sq(b) * sq(ca.r)) ); + + /* no intersection */ + if (d < 0) + return 0; + + if (b == 0) { + /* special case */ + e = sq(cb.r) - sq((2. * c - sq(a)) / (2. * a)); + + /* no intersection */ + if (e < 0) + return 0; + + p1->x = (2. * a * c - sqrt(d)) / (2. * (sq(a) + sq(b))); + p1->y = sqrt(e); + p2->x = p1->x; + p2->y = p1->y; + ret = 1; + } + else { + /* usual case */ + p1->x = (2. * a * c - sqrt(d)) / (2. * (sq(a) + sq(b))); + p1->y = (c - a * p1->x) / b; + p2->x = (2. * a * c + sqrt(d)) / (2. * (sq(a) + sq(b))); + p2->y = (c - a * p2->x) / b; + ret = 2; + } + + /* retranslate */ + p1->x += c1->x; + p1->y += c1->y; + p2->x += c1->x; + p2->y += c1->y; + + return ret; +} diff --git a/modules/base/math/geometry/circles.h b/modules/base/math/geometry/circles.h new file mode 100644 index 0000000..ff3df6e --- /dev/null +++ b/modules/base/math/geometry/circles.h @@ -0,0 +1,47 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + +#ifndef _CIRCLES_H_ +#define _CIRCLES_H_ + +typedef struct _circle { + double x; + double y; + double r; +} circle_t; + +/* return true if a point is in the disc */ +uint8_t pt_is_inside_circle(const point_t *p, circle_t *c); + +/* + * return values: + * 0 dont cross + * 1 one intersection point + * 2 two intersection points + * + * p1, p2 arguments are the crossing points coordinates. Both p1 and + * p2 are dummy for 0 result. When result is 1, p1 and p2 are set to + * the same value. + */ +uint8_t circle_intersect(const circle_t *c1, const circle_t *c2, + point_t *p1, point_t *p2); + +#endif /* _CIRCLES_H_ */ diff --git a/modules/base/math/geometry/lines.c b/modules/base/math/geometry/lines.c index a31834f..09ad1a1 100755 --- a/modules/base/math/geometry/lines.c +++ b/modules/base/math/geometry/lines.c @@ -1,3 +1,24 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + #include #include diff --git a/modules/base/math/geometry/lines.h b/modules/base/math/geometry/lines.h index a6cf421..5ae2394 100755 --- a/modules/base/math/geometry/lines.h +++ b/modules/base/math/geometry/lines.h @@ -1,3 +1,27 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + +#ifndef _LINES_H_ +#define _LINES_H_ + typedef struct _line { double a; double b; @@ -11,10 +35,21 @@ pts2line(const point_t *p1, const point_t *p2, line_t *l); void proj_pt_line(const point_t * p, const line_t * l, point_t * p_out); -uint8_t +/* + * return values: + * 0 dont cross + * 1 cross + * 2 "parallel crossing" + * + * p argument is the crossing point coordinates (dummy for 0 or 2 + * result) + */ +uint8_t intersect_line(const line_t *l1, const line_t *l2, point_t *p); uint8_t intersect_segment(const point_t *s1, const point_t *s2, const point_t *t1, const point_t *t2, point_t *p); + +#endif /* _LINES_H_ */ diff --git a/modules/base/math/geometry/polygon.c b/modules/base/math/geometry/polygon.c index d62179c..9eef11e 100755 --- a/modules/base/math/geometry/polygon.c +++ b/modules/base/math/geometry/polygon.c @@ -1,3 +1,24 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + #include #include #include diff --git a/modules/base/math/geometry/polygon.h b/modules/base/math/geometry/polygon.h index 83468d8..d5c717c 100755 --- a/modules/base/math/geometry/polygon.h +++ b/modules/base/math/geometry/polygon.h @@ -1,3 +1,24 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + #ifndef _POLYGON_H_ #define _POLYGON_H_ diff --git a/modules/base/math/geometry/vect_base.c b/modules/base/math/geometry/vect_base.c index f36724c..2fb8563 100755 --- a/modules/base/math/geometry/vect_base.c +++ b/modules/base/math/geometry/vect_base.c @@ -1,16 +1,37 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + #include #include #include /* Return scalar product */ -int32_t +float vect_pscal(vect_t *v, vect_t *w) { return v->x * w->x + v->y * w->y; } /* Return Z of vectorial product */ -int32_t +float vect_pvect(vect_t *v, vect_t *w) { return v->x*w->y - v->y*w->x; @@ -20,7 +41,7 @@ vect_pvect(vect_t *v, vect_t *w) int8_t vect_pscal_sign(vect_t *v, vect_t *w) { - int32_t z; + float z; z = vect_pscal(v, w); if (z==0) return 0; @@ -31,13 +52,27 @@ vect_pscal_sign(vect_t *v, vect_t *w) int8_t vect_pvect_sign(vect_t *v, vect_t *w) { - int32_t z; + float z; z = vect_pvect(v, w); if (z==0) return 0; return z>0?1:-1; } +float norm(float x1, float y1, float x2, float y2) +{ + float x = x2 - x1; + float y = y2 - y1; + return sqrt(x*x + y*y); +} + +float pt_norm(point_t *p1, point_t *p2) +{ + float x = p2->x - p1->x; + float y = p2->y - p1->y; + return sqrt(x*x + y*y); +} + /* norm of a vector */ float vect_norm(vect_t *v) @@ -45,11 +80,9 @@ vect_norm(vect_t *v) return sqrt(v->x*v->x+v->y*v->y); } - - void vect_rot_trigo(vect_t *v) { - int32_t s; + float s; s = v->x; v->x= -v->y; @@ -58,7 +91,7 @@ void vect_rot_trigo(vect_t *v) void vect_rot_retro(vect_t *v) { - int32_t s; + float s; s = v->x; v->x= v->y; @@ -68,7 +101,7 @@ void vect_rot_retro(vect_t *v) float vect_get_angle(vect_t *v, vect_t *w) { - int32_t ps; + float ps; float n; ps = vect_pscal(v, w); @@ -76,3 +109,11 @@ float vect_get_angle(vect_t *v, vect_t *w) return acos((float)ps/n); } + +void vect_resize(vect_t *v, float l) +{ + float old_l = vect_norm(v); + float x = v->x, y = v->y; + v->x = x * l / old_l; + v->y = y * l / old_l; +} diff --git a/modules/base/math/geometry/vect_base.h b/modules/base/math/geometry/vect_base.h index b9dda3f..b511e07 100755 --- a/modules/base/math/geometry/vect_base.h +++ b/modules/base/math/geometry/vect_base.h @@ -1,21 +1,43 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + +#ifndef _VECT_BASE_H_ +#define _VECT_BASE_H_ + typedef struct _vect_t { - int32_t x; - int32_t y; -}vect_t; + float x; + float y; +} vect_t; typedef struct _point_t { - int32_t x; - int32_t y; -}point_t; - + float x; + float y; +} point_t; - /* Return scalar product */ -int32_t +float vect_pscal(vect_t *v, vect_t *w); /* Return Z of vectorial product */ -int32_t +float vect_pvect(vect_t *v, vect_t *w); /* Return scalar product */ @@ -27,8 +49,13 @@ int8_t vect_pvect_sign(vect_t *v, vect_t *w); /* norm of a vector */ +float norm(float x1, float y1, float x2, float y2); +float pt_norm(point_t *p1, point_t *p2); float vect_norm(vect_t *v); void vect_rot_trigo(vect_t *v); void vect_rot_retro(vect_t *v); float vect_get_angle(vect_t *v, vect_t *w); - + +void vect_resize(vect_t *v, float l); + +#endif /* _VECT_BASE_H_ */ diff --git a/projects/microb2010/tests/tourel_beacon/.config b/projects/microb2010/tests/tourel_beacon/.config new file mode 100644 index 0000000..9a16be2 --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/.config @@ -0,0 +1,252 @@ +# +# Automatically generated by make menuconfig: don't edit +# + +# +# Hardware +# +# CONFIG_MCU_AT90S2313 is not set +# CONFIG_MCU_AT90S2323 is not set +# CONFIG_MCU_AT90S3333 is not set +# CONFIG_MCU_AT90S2343 is not set +# CONFIG_MCU_ATTINY22 is not set +# CONFIG_MCU_ATTINY26 is not set +# CONFIG_MCU_AT90S4414 is not set +# CONFIG_MCU_AT90S4433 is not set +# CONFIG_MCU_AT90S4434 is not set +# CONFIG_MCU_AT90S8515 is not set +# CONFIG_MCU_AT90S8534 is not set +# CONFIG_MCU_AT90S8535 is not set +# CONFIG_MCU_AT86RF401 is not set +# CONFIG_MCU_ATMEGA103 is not set +# CONFIG_MCU_ATMEGA603 is not set +# CONFIG_MCU_AT43USB320 is not set +# CONFIG_MCU_AT43USB355 is not set +# CONFIG_MCU_AT76C711 is not set +# CONFIG_MCU_ATMEGA8 is not set +# CONFIG_MCU_ATMEGA48 is not set +# CONFIG_MCU_ATMEGA88 is not set +# CONFIG_MCU_ATMEGA8515 is not set +# CONFIG_MCU_ATMEGA8535 is not set +# CONFIG_MCU_ATTINY13 is not set +# CONFIG_MCU_ATTINY2313 is not set +# CONFIG_MCU_ATMEGA16 is not set +# CONFIG_MCU_ATMEGA161 is not set +# CONFIG_MCU_ATMEGA162 is not set +# CONFIG_MCU_ATMEGA163 is not set +# CONFIG_MCU_ATMEGA165 is not set +# CONFIG_MCU_ATMEGA168 is not set +# CONFIG_MCU_ATMEGA169 is not set +# CONFIG_MCU_ATMEGA32 is not set +# CONFIG_MCU_ATMEGA323 is not set +# CONFIG_MCU_ATMEGA325 is not set +# CONFIG_MCU_ATMEGA3250 is not set +# CONFIG_MCU_ATMEGA64 is not set +# CONFIG_MCU_ATMEGA645 is not set +# CONFIG_MCU_ATMEGA6450 is not set +CONFIG_MCU_ATMEGA128=y +# CONFIG_MCU_ATMEGA1281 is not set +# CONFIG_MCU_AT90CAN128 is not set +# CONFIG_MCU_AT94K is not set +# CONFIG_MCU_AT90S1200 is not set +# CONFIG_MCU_ATMEGA2560 is not set +# CONFIG_MCU_ATMEGA256 is not set +CONFIG_QUARTZ=16000000 + +# +# Generation options +# +# CONFIG_OPTM_0 is not set +# CONFIG_OPTM_1 is not set +# CONFIG_OPTM_2 is not set +# CONFIG_OPTM_3 is not set +CONFIG_OPTM_S=y +CONFIG_MATH_LIB=y +# CONFIG_FDEVOPEN_COMPAT is not set +# CONFIG_NO_PRINTF is not set +# CONFIG_MINIMAL_PRINTF is not set +CONFIG_STANDARD_PRINTF=y +# CONFIG_ADVANCED_PRINTF is not set +# CONFIG_FORMAT_IHEX is not set +# CONFIG_FORMAT_SREC is not set +CONFIG_FORMAT_BINARY=y + +# +# Base modules +# +# CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set +# CONFIG_MODULE_FIXED_POINT is not set +# CONFIG_MODULE_VECT2 is not set +CONFIG_MODULE_GEOMETRY=y +# CONFIG_MODULE_SCHEDULER is not set +# CONFIG_MODULE_SCHEDULER_STATS is not set +# CONFIG_MODULE_SCHEDULER_CREATE_CONFIG is not set +# CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set +CONFIG_MODULE_SCHEDULER_TIMER0=y +# CONFIG_MODULE_SCHEDULER_MANUAL is not set +# CONFIG_MODULE_TIME is not set +# CONFIG_MODULE_TIME_CREATE_CONFIG is not set +# CONFIG_MODULE_TIME_EXT is not set +# CONFIG_MODULE_TIME_EXT_CREATE_CONFIG is not set + +# +# Communication modules +# +# CONFIG_MODULE_UART is not set +# CONFIG_MODULE_UART_9BITS is not set +# CONFIG_MODULE_UART_CREATE_CONFIG is not set +# CONFIG_MODULE_SPI is not set +# CONFIG_MODULE_SPI_CREATE_CONFIG is not set +# CONFIG_MODULE_I2C is not set +# CONFIG_MODULE_I2C_MASTER is not set +# CONFIG_MODULE_I2C_MULTIMASTER is not set +# CONFIG_MODULE_I2C_CREATE_CONFIG is not set +# CONFIG_MODULE_MF2_CLIENT is not set +# CONFIG_MODULE_MF2_CLIENT_USE_SCHEDULER is not set +# CONFIG_MODULE_MF2_CLIENT_CREATE_CONFIG is not set +# CONFIG_MODULE_MF2_SERVER is not set +# CONFIG_MODULE_MF2_SERVER_CREATE_CONFIG is not set + +# +# Hardware modules +# +# CONFIG_MODULE_TIMER is not set +# CONFIG_MODULE_TIMER_CREATE_CONFIG is not set +# CONFIG_MODULE_TIMER_DYNAMIC is not set +# CONFIG_MODULE_PWM is not set +# CONFIG_MODULE_PWM_CREATE_CONFIG is not set +# CONFIG_MODULE_PWM_NG is not set +# CONFIG_MODULE_ADC is not set +# CONFIG_MODULE_ADC_CREATE_CONFIG is not set + +# +# IHM modules +# +# CONFIG_MODULE_MENU is not set +# CONFIG_MODULE_VT100 is not set +# CONFIG_MODULE_RDLINE is not set +# CONFIG_MODULE_RDLINE_CREATE_CONFIG is not set +# CONFIG_MODULE_RDLINE_KILL_BUF is not set +# CONFIG_MODULE_RDLINE_HISTORY is not set +# CONFIG_MODULE_PARSE is not set +# CONFIG_MODULE_PARSE_NO_FLOAT is not set + +# +# External devices modules +# +# CONFIG_MODULE_LCD is not set +# CONFIG_MODULE_LCD_CREATE_CONFIG is not set +# CONFIG_MODULE_MULTISERVO is not set +# CONFIG_MODULE_MULTISERVO_CREATE_CONFIG is not set +# CONFIG_MODULE_AX12 is not set +# CONFIG_MODULE_AX12_CREATE_CONFIG is not set + +# +# Brushless motor drivers (you should enable pwm modules to see all) +# +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_CREATE_CONFIG is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE_CREATE_CONFIG is not set + +# +# Encoders (you need comm/spi for encoders_spi) +# +# CONFIG_MODULE_ENCODERS_MICROB is not set +# CONFIG_MODULE_ENCODERS_MICROB_CREATE_CONFIG is not set +# CONFIG_MODULE_ENCODERS_EIRBOT is not set +# CONFIG_MODULE_ENCODERS_EIRBOT_CREATE_CONFIG is not set +# CONFIG_MODULE_ENCODERS_SPI is not set +# CONFIG_MODULE_ENCODERS_SPI_CREATE_CONFIG is not set + +# +# Robot specific modules +# +# CONFIG_MODULE_ROBOT_SYSTEM is not set +# CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT is not set +# CONFIG_MODULE_POSITION_MANAGER is not set +# CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE is not set +# CONFIG_MODULE_TRAJECTORY_MANAGER is not set +# CONFIG_MODULE_BLOCKING_DETECTION_MANAGER is not set +# CONFIG_MODULE_OBSTACLE_AVOIDANCE is not set +# CONFIG_MODULE_OBSTACLE_AVOIDANCE_CREATE_CONFIG is not set + +# +# Control system modules +# +# CONFIG_MODULE_CONTROL_SYSTEM_MANAGER is not set +# CONFIG_MODULE_PID is not set +# CONFIG_MODULE_PID_CREATE_CONFIG is not set +# CONFIG_MODULE_RAMP is not set +# CONFIG_MODULE_QUADRAMP is not set +# CONFIG_MODULE_QUADRAMP_DERIVATE is not set +# CONFIG_MODULE_BIQUAD is not set + +# +# Radio devices +# +# CONFIG_MODULE_CC2420 is not set +# CONFIG_MODULE_CC2420_CREATE_CONFIG is not set + +# +# Crypto modules +# +# CONFIG_MODULE_AES is not set +# CONFIG_MODULE_AES_CTR is not set +# CONFIG_MODULE_MD5 is not set +# CONFIG_MODULE_MD5_HMAC is not set +# CONFIG_MODULE_RC4 is not set + +# +# Encodings modules +# +# CONFIG_MODULE_BASE64 is not set +# CONFIG_MODULE_HAMMING is not set + +# +# Debug modules +# +# CONFIG_MODULE_DIAGNOSTIC is not set +# CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set +CONFIG_MODULE_ERROR=y +CONFIG_MODULE_ERROR_CREATE_CONFIG=y + +# +# Programmer options +# +CONFIG_AVRDUDE=y +# CONFIG_AVARICE is not set + +# +# Avrdude +# +# CONFIG_AVRDUDE_PROG_FUTURELEC is not set +# CONFIG_AVRDUDE_PROG_ABCMINI is not set +# CONFIG_AVRDUDE_PROG_PICOWEB is not set +# CONFIG_AVRDUDE_PROG_SP12 is not set +# CONFIG_AVRDUDE_PROG_ALF is not set +# CONFIG_AVRDUDE_PROG_BASCOM is not set +# CONFIG_AVRDUDE_PROG_DT006 is not set +# CONFIG_AVRDUDE_PROG_PONY_STK200 is not set +CONFIG_AVRDUDE_PROG_STK200=y +# CONFIG_AVRDUDE_PROG_PAVR is not set +# CONFIG_AVRDUDE_PROG_BUTTERFLY is not set +# CONFIG_AVRDUDE_PROG_AVR910 is not set +# CONFIG_AVRDUDE_PROG_STK500 is not set +# CONFIG_AVRDUDE_PROG_AVRISP is not set +# CONFIG_AVRDUDE_PROG_BSD is not set +# CONFIG_AVRDUDE_PROG_DAPA is not set +# CONFIG_AVRDUDE_PROG_JTAG1 is not set +# CONFIG_AVRDUDE_PROG_AVR109 is not set +CONFIG_AVRDUDE_PORT="/dev/parport0" +CONFIG_AVRDUDE_BAUDRATE=19200 + +# +# Avarice +# +CONFIG_AVARICE_PORT="/dev/ttyS0" +CONFIG_AVARICE_DEBUG_PORT=1234 +CONFIG_AVARICE_PROG_MKI=y +# CONFIG_AVARICE_PROG_MKII is not set +# CONFIG_AVRDUDE_CHECK_SIGNATURE is not set diff --git a/projects/microb2010/tests/tourel_beacon/.config.old b/projects/microb2010/tests/tourel_beacon/.config.old new file mode 100644 index 0000000..0a9b697 --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/.config.old @@ -0,0 +1,252 @@ +# +# Automatically generated by make menuconfig: don't edit +# + +# +# Hardware +# +# CONFIG_MCU_AT90S2313 is not set +# CONFIG_MCU_AT90S2323 is not set +# CONFIG_MCU_AT90S3333 is not set +# CONFIG_MCU_AT90S2343 is not set +# CONFIG_MCU_ATTINY22 is not set +# CONFIG_MCU_ATTINY26 is not set +# CONFIG_MCU_AT90S4414 is not set +# CONFIG_MCU_AT90S4433 is not set +# CONFIG_MCU_AT90S4434 is not set +# CONFIG_MCU_AT90S8515 is not set +# CONFIG_MCU_AT90S8534 is not set +# CONFIG_MCU_AT90S8535 is not set +# CONFIG_MCU_AT86RF401 is not set +# CONFIG_MCU_ATMEGA103 is not set +# CONFIG_MCU_ATMEGA603 is not set +# CONFIG_MCU_AT43USB320 is not set +# CONFIG_MCU_AT43USB355 is not set +# CONFIG_MCU_AT76C711 is not set +# CONFIG_MCU_ATMEGA8 is not set +# CONFIG_MCU_ATMEGA48 is not set +# CONFIG_MCU_ATMEGA88 is not set +# CONFIG_MCU_ATMEGA8515 is not set +# CONFIG_MCU_ATMEGA8535 is not set +# CONFIG_MCU_ATTINY13 is not set +# CONFIG_MCU_ATTINY2313 is not set +# CONFIG_MCU_ATMEGA16 is not set +# CONFIG_MCU_ATMEGA161 is not set +# CONFIG_MCU_ATMEGA162 is not set +# CONFIG_MCU_ATMEGA163 is not set +# CONFIG_MCU_ATMEGA165 is not set +# CONFIG_MCU_ATMEGA168 is not set +# CONFIG_MCU_ATMEGA169 is not set +# CONFIG_MCU_ATMEGA32 is not set +# CONFIG_MCU_ATMEGA323 is not set +# CONFIG_MCU_ATMEGA325 is not set +# CONFIG_MCU_ATMEGA3250 is not set +# CONFIG_MCU_ATMEGA64 is not set +# CONFIG_MCU_ATMEGA645 is not set +# CONFIG_MCU_ATMEGA6450 is not set +CONFIG_MCU_ATMEGA128=y +# CONFIG_MCU_ATMEGA1281 is not set +# CONFIG_MCU_AT90CAN128 is not set +# CONFIG_MCU_AT94K is not set +# CONFIG_MCU_AT90S1200 is not set +# CONFIG_MCU_ATMEGA2560 is not set +# CONFIG_MCU_ATMEGA256 is not set +CONFIG_QUARTZ=16000000 + +# +# Generation options +# +# CONFIG_OPTM_0 is not set +# CONFIG_OPTM_1 is not set +# CONFIG_OPTM_2 is not set +# CONFIG_OPTM_3 is not set +CONFIG_OPTM_S=y +CONFIG_MATH_LIB=y +# CONFIG_FDEVOPEN_COMPAT is not set +# CONFIG_NO_PRINTF is not set +# CONFIG_MINIMAL_PRINTF is not set +CONFIG_STANDARD_PRINTF=y +# CONFIG_ADVANCED_PRINTF is not set +CONFIG_FORMAT_IHEX=y +# CONFIG_FORMAT_SREC is not set +# CONFIG_FORMAT_BINARY is not set + +# +# Base modules +# +# CONFIG_MODULE_CIRBUF is not set +# CONFIG_MODULE_CIRBUF_LARGE is not set +# CONFIG_MODULE_FIXED_POINT is not set +# CONFIG_MODULE_VECT2 is not set +CONFIG_MODULE_GEOMETRY=y +# CONFIG_MODULE_SCHEDULER is not set +# CONFIG_MODULE_SCHEDULER_STATS is not set +# CONFIG_MODULE_SCHEDULER_CREATE_CONFIG is not set +# CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set +CONFIG_MODULE_SCHEDULER_TIMER0=y +# CONFIG_MODULE_SCHEDULER_MANUAL is not set +# CONFIG_MODULE_TIME is not set +# CONFIG_MODULE_TIME_CREATE_CONFIG is not set +# CONFIG_MODULE_TIME_EXT is not set +# CONFIG_MODULE_TIME_EXT_CREATE_CONFIG is not set + +# +# Communication modules +# +# CONFIG_MODULE_UART is not set +# CONFIG_MODULE_UART_9BITS is not set +# CONFIG_MODULE_UART_CREATE_CONFIG is not set +# CONFIG_MODULE_SPI is not set +# CONFIG_MODULE_SPI_CREATE_CONFIG is not set +# CONFIG_MODULE_I2C is not set +# CONFIG_MODULE_I2C_MASTER is not set +# CONFIG_MODULE_I2C_MULTIMASTER is not set +# CONFIG_MODULE_I2C_CREATE_CONFIG is not set +# CONFIG_MODULE_MF2_CLIENT is not set +# CONFIG_MODULE_MF2_CLIENT_USE_SCHEDULER is not set +# CONFIG_MODULE_MF2_CLIENT_CREATE_CONFIG is not set +# CONFIG_MODULE_MF2_SERVER is not set +# CONFIG_MODULE_MF2_SERVER_CREATE_CONFIG is not set + +# +# Hardware modules +# +# CONFIG_MODULE_TIMER is not set +# CONFIG_MODULE_TIMER_CREATE_CONFIG is not set +# CONFIG_MODULE_TIMER_DYNAMIC is not set +# CONFIG_MODULE_PWM is not set +# CONFIG_MODULE_PWM_CREATE_CONFIG is not set +# CONFIG_MODULE_PWM_NG is not set +# CONFIG_MODULE_ADC is not set +# CONFIG_MODULE_ADC_CREATE_CONFIG is not set + +# +# IHM modules +# +# CONFIG_MODULE_MENU is not set +# CONFIG_MODULE_VT100 is not set +# CONFIG_MODULE_RDLINE is not set +# CONFIG_MODULE_RDLINE_CREATE_CONFIG is not set +# CONFIG_MODULE_RDLINE_KILL_BUF is not set +# CONFIG_MODULE_RDLINE_HISTORY is not set +# CONFIG_MODULE_PARSE is not set +# CONFIG_MODULE_PARSE_NO_FLOAT is not set + +# +# External devices modules +# +# CONFIG_MODULE_LCD is not set +# CONFIG_MODULE_LCD_CREATE_CONFIG is not set +# CONFIG_MODULE_MULTISERVO is not set +# CONFIG_MODULE_MULTISERVO_CREATE_CONFIG is not set +# CONFIG_MODULE_AX12 is not set +# CONFIG_MODULE_AX12_CREATE_CONFIG is not set + +# +# Brushless motor drivers (you should enable pwm modules to see all) +# +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_CREATE_CONFIG is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE is not set +# CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE_CREATE_CONFIG is not set + +# +# Encoders (you need comm/spi for encoders_spi) +# +# CONFIG_MODULE_ENCODERS_MICROB is not set +# CONFIG_MODULE_ENCODERS_MICROB_CREATE_CONFIG is not set +# CONFIG_MODULE_ENCODERS_EIRBOT is not set +# CONFIG_MODULE_ENCODERS_EIRBOT_CREATE_CONFIG is not set +# CONFIG_MODULE_ENCODERS_SPI is not set +# CONFIG_MODULE_ENCODERS_SPI_CREATE_CONFIG is not set + +# +# Robot specific modules +# +# CONFIG_MODULE_ROBOT_SYSTEM is not set +# CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT is not set +# CONFIG_MODULE_POSITION_MANAGER is not set +# CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE is not set +# CONFIG_MODULE_TRAJECTORY_MANAGER is not set +# CONFIG_MODULE_BLOCKING_DETECTION_MANAGER is not set +# CONFIG_MODULE_OBSTACLE_AVOIDANCE is not set +# CONFIG_MODULE_OBSTACLE_AVOIDANCE_CREATE_CONFIG is not set + +# +# Control system modules +# +# CONFIG_MODULE_CONTROL_SYSTEM_MANAGER is not set +# CONFIG_MODULE_PID is not set +# CONFIG_MODULE_PID_CREATE_CONFIG is not set +# CONFIG_MODULE_RAMP is not set +# CONFIG_MODULE_QUADRAMP is not set +# CONFIG_MODULE_QUADRAMP_DERIVATE is not set +# CONFIG_MODULE_BIQUAD is not set + +# +# Radio devices +# +# CONFIG_MODULE_CC2420 is not set +# CONFIG_MODULE_CC2420_CREATE_CONFIG is not set + +# +# Crypto modules +# +# CONFIG_MODULE_AES is not set +# CONFIG_MODULE_AES_CTR is not set +# CONFIG_MODULE_MD5 is not set +# CONFIG_MODULE_MD5_HMAC is not set +# CONFIG_MODULE_RC4 is not set + +# +# Encodings modules +# +# CONFIG_MODULE_BASE64 is not set +# CONFIG_MODULE_HAMMING is not set + +# +# Debug modules +# +# CONFIG_MODULE_DIAGNOSTIC is not set +# CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set +CONFIG_MODULE_ERROR=y +CONFIG_MODULE_ERROR_CREATE_CONFIG=y + +# +# Programmer options +# +CONFIG_AVRDUDE=y +# CONFIG_AVARICE is not set + +# +# Avrdude +# +# CONFIG_AVRDUDE_PROG_FUTURELEC is not set +# CONFIG_AVRDUDE_PROG_ABCMINI is not set +# CONFIG_AVRDUDE_PROG_PICOWEB is not set +# CONFIG_AVRDUDE_PROG_SP12 is not set +# CONFIG_AVRDUDE_PROG_ALF is not set +# CONFIG_AVRDUDE_PROG_BASCOM is not set +# CONFIG_AVRDUDE_PROG_DT006 is not set +# CONFIG_AVRDUDE_PROG_PONY_STK200 is not set +CONFIG_AVRDUDE_PROG_STK200=y +# CONFIG_AVRDUDE_PROG_PAVR is not set +# CONFIG_AVRDUDE_PROG_BUTTERFLY is not set +# CONFIG_AVRDUDE_PROG_AVR910 is not set +# CONFIG_AVRDUDE_PROG_STK500 is not set +# CONFIG_AVRDUDE_PROG_AVRISP is not set +# CONFIG_AVRDUDE_PROG_BSD is not set +# CONFIG_AVRDUDE_PROG_DAPA is not set +# CONFIG_AVRDUDE_PROG_JTAG1 is not set +# CONFIG_AVRDUDE_PROG_AVR109 is not set +CONFIG_AVRDUDE_PORT="/dev/parport0" +CONFIG_AVRDUDE_BAUDRATE=19200 + +# +# Avarice +# +CONFIG_AVARICE_PORT="/dev/ttyS0" +CONFIG_AVARICE_DEBUG_PORT=1234 +CONFIG_AVARICE_PROG_MKI=y +# CONFIG_AVARICE_PROG_MKII is not set +# CONFIG_AVRDUDE_CHECK_SIGNATURE is not set diff --git a/projects/microb2010/tests/tourel_beacon/Makefile b/projects/microb2010/tests/tourel_beacon/Makefile new file mode 100644 index 0000000..6d5d8e2 --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/Makefile @@ -0,0 +1,21 @@ +TARGET = main + +# repertoire des modules +AVERSIVE_DIR =../..# VALUE, absolute or relative path : example ../.. # + +# List C source files here. (C dependencies are automatically generated.) +SRC = $(TARGET).c + +# List Assembler source files here. +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# care about how the name is spelled on its command-line. +ASRC = + +######################################## + +-include .aversive_conf +include $(AVERSIVE_DIR)/mk/aversive_project.mk diff --git a/projects/microb2010/tests/tourel_beacon/error_config.h b/projects/microb2010/tests/tourel_beacon/error_config.h new file mode 100644 index 0000000..2e1288a --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/error_config.h @@ -0,0 +1,31 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2005) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: error_config.h,v 1.4.6.1 2006-11-26 21:06:03 zer0 Exp $ + * + */ + +#ifndef _ERROR_CONFIG_ +#define _ERROR_CONFIG_ + +/** enable the dump of the comment */ +#define ERROR_DUMP_TEXTLOG + +/** enable the dump of filename and line number */ +#define ERROR_DUMP_FILE_LINE + +#endif diff --git a/projects/microb2010/tests/tourel_beacon/graph.py b/projects/microb2010/tests/tourel_beacon/graph.py new file mode 100644 index 0000000..23193b7 --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/graph.py @@ -0,0 +1,229 @@ +import sys, re, math +import numpy as np +import matplotlib +import matplotlib.path as mpath +import matplotlib.patches as mpatches +import matplotlib.pyplot as plt +from matplotlib.patches import Arrow, Circle, Wedge, Polygon +from matplotlib.collections import PatchCollection +from numpy.random import randn +import pylab +import popen2, random + +Path = mpath.Path +FLOAT = "([-+]?[0-9]*\.?[0-9]+)" +INT = "([-+]?[0-9][0-9]*)" +RANDOM_ERROR = 0.3 # deg +beacons = [ (0.0, 1050.0), (3000.0, 0.0), (3000.0, 2100.0) ] + +def build_poly(ptlist): + polydata = [] + polydata.append((Path.MOVETO, (ptlist[0]))) + for pt in ptlist[1:]: + polydata.append((Path.LINETO, (pt))) + polydata.append((Path.CLOSEPOLY, (ptlist[0]))) + codes, verts = zip(*polydata) + poly = mpath.Path(verts, codes) + x, y = zip(*poly.vertices) + return x,y + +def build_path(ptlist): + polydata = [] + polydata.append((Path.MOVETO, (ptlist[0]))) + for pt in ptlist[1:]: + polydata.append((Path.LINETO, (pt))) + codes, verts = zip(*polydata) + poly = mpath.Path(verts, codes) + x, y = zip(*poly.vertices) + return x,y + +def get_angle(ref, b): + """get angle from robot point of view (ref) of beacon 'b'""" + a = math.atan2(b[1]-ref[1], b[0]-ref[0]) + ea = (math.pi/180.) * RANDOM_ERROR * random.random() + ea = random.choice([ea, -ea]) + return a + ea, ea + + alpha = math.atan2(a[1]-ref[1], a[0]-ref[0]) + beta = math.atan2(b[1]-ref[1], b[0]-ref[0]) + gamma = beta-alpha + if gamma < 0: + gamma = gamma + 2*math.pi + return gamma + error, error + +def dist(p1, p2): + return math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) + +def graph(filename, real_x, real_y): + + real_pt = (real_x, real_y) + + # display beacons + patches = [] + for b in beacons: + patches += [ Circle((b[0], b[1]), 40, alpha=0.4) ] + + patches += [ Circle((real_x, real_y), 20, alpha=0.4, facecolor="red") ] + + # process angles from robot position + a0,ea0 = get_angle((real_x, real_y), beacons[0]) + a1,ea1 = get_angle((real_x, real_y), beacons[1]) + a2,ea2 = get_angle((real_x, real_y), beacons[2]) + text = "a0 = %2.2f (%+2.2f deg)\n"%(a0, ea0*(180./math.pi)) + text += "a1 = %2.2f (%+2.2f deg)\n"%(a1, ea1*(180./math.pi)) + text += "a2 = %2.2f (%+2.2f deg)\n"%(a2, ea2*(180./math.pi)) + + a01 = a1-a0 + if a01 < 0: + a01 += 2*math.pi + a12 = a2-a1 + if a12 < 0: + a12 += 2*math.pi + a20 = a0-a2 + if a20 < 0: + a20 += 2*math.pi + + cmd = "./main angle2pos %f %f %f"%(a01, a12, a20) + o,i = popen2.popen2(cmd) + i.close() + s = o.read(1000000) + o.close() + + open(filename + ".txt", "w").write(s) + + if len(s) == 1000000: + gloupix() + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.set_title("Erreur de position en mm lorsqu'on ajoute une erreur de mesure\n" + "d'angle aleatoire comprise entre - %1.1f et %1.1f deg"%(RANDOM_ERROR, + RANDOM_ERROR)) + + # area + x,y = build_poly([(0,0), (3000,0), (3000,2100), (0,2100)]) + ax.plot(x, y, 'g-') + + for l in s.split("\n"): + m = re.match("circle: x=%s y=%s r=%s"%(FLOAT, FLOAT, FLOAT), l) + if m: + x,y,r = (float(m.groups()[0]), float(m.groups()[1]), float(m.groups()[2])) + print x,y,r + patches += [ Circle((x, y), r, facecolor="none") ] + m = re.match("p%s: x=%s y=%s"%(INT, FLOAT, FLOAT), l) + if m: + n,x,y = (float(m.groups()[0]), float(m.groups()[1]), float(m.groups()[2])) + if (n == 0): + patches += [ Circle((x, y), 20, alpha=0.4, facecolor="yellow") ] + result_pt = (x, y) + text += l + "\n" + + p = PatchCollection(patches, cmap=matplotlib.cm.jet, match_original=True) + + # text area, far from the point + l = [(800., 1800.), (800., 500.), (1500., 1800.), (1500., 500.), + (2200., 1800.), (2200., 500.)] + l.sort(cmp=lambda p1,p2: (dist(p1,real_pt) 2cm (pour un deplacement\n" + 'a %2.2f m/s vers %d deg et une periode tourelle = %d ms)'%(speed, angle_deg, period)) + +#do_random_test() +#do_graph_2d_simple_error() +do_graph_2d_move_error() diff --git a/projects/microb2010/tests/tourel_beacon/main.c b/projects/microb2010/tests/tourel_beacon/main.c new file mode 100644 index 0000000..38ab0a7 --- /dev/null +++ b/projects/microb2010/tests/tourel_beacon/main.c @@ -0,0 +1,343 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#define POS_ACCURACY 10.0 /* 1 cm accuracy max */ +#ifndef HOST_VERSION +#define printf(args...) do {} while(0) +#endif + +static int dprint = 0; +#define dprintf(args...) if (dprint) printf(args) + +const point_t beacon0 = { 0, 1050 }; +const point_t beacon1 = { 3000, 0 }; +const point_t beacon2 = { 3000, 2100 }; + +/* Fill the 2 circles pointer given as parameter, each of those cross + * both beacons b1 and b2. From any point of these circles (except b1 + * and b2), we see b1 and b2 with the angle of a_rad (which must be + * positive). Return 0 on success. + * + * l + * <-------------------------> + * + * b1 O b2 + * +----------------------------+ + * ,' \\ | /|'\ + * / \ \ | ^ / | ` + * / \ \ a___ | | d / | `. + * / \ \ / | v / | \ + * | \ \ | / | | + * | \ \ | / | | + * | \ \|/ | | + * | \ * C | | + * | \ | .' + * | \ | | + * | \ | .' + * \ \ a____| / + * \ \ / | ,' + * ` \ | / + * '. \ | ,' + * '-. \ |_,' + * '-._ _,*' + * '`--......---' R (the robot) + * + */ +int8_t angle_to_circles(circle_t *c1, circle_t *c2, + const point_t *b1, const point_t *b2, + double a_rad) +{ + point_t O; + vect_t v; + float l, d; + + /* reject negative or too small angles */ + if (a_rad <= 0.01) + return -1; + + /* get position of O */ + O.x = (b1->x + b2->x) / 2; + O.y = (b1->y + b2->y) / 2; + + /* get the length l */ + v.x = b2->x - b1->x; + v.y = b2->y - b1->y; + l = vect_norm(&v); + + /* distance from O to the center of the circle */ + /* XXX div by 0 when pi */ + d = l / (2 * tan(a_rad)); + + /* get the circle c1 */ + vect_rot_trigo(&v); + vect_resize(&v, d); + if (c1) { + c1->x = O.x + v.x; + c1->y = O.y + v.y; + c1->r = norm(b1->x, b1->y, c1->x, c1->y); + } + + /* get the circle c2 */ + if (c2) { + c2->x = O.x - v.x; + c2->y = O.y - v.y; + c2->r = norm(b1->x, b1->y, c1->x, c1->y); + } + + return 0; +} + +/* get the position of the robot from the angle of the 3 beacons */ +int8_t angles_to_posxy(point_t *pos, double a01, double a12, double a20) +{ + circle_t c01, c12, c20; + point_t dummy_pt, p1, p2, p3; + + dprintf("a01 = %2.2f\n", a01); + dprintf("a12 = %2.2f\n", a12); + dprintf("a20 = %2.2f\n", a20); + + if (angle_to_circles(&c01, NULL, &beacon0, &beacon1, a01)) + return -1; + dprintf("circle: x=%2.2f y=%2.2f r=%2.2f\n", c01.x, c01.y, c01.r); + + if (angle_to_circles(&c12, NULL, &beacon1, &beacon2, a12)) + return -1; + dprintf("circle: x=%2.2f y=%2.2f r=%2.2f\n", c12.x, c12.y, c12.r); + + if (angle_to_circles(&c20, NULL, &beacon2, &beacon0, a20)) + return -1; + dprintf("circle: x=%2.2f y=%2.2f r=%2.2f\n", c20.x, c20.y, c20.r); + + if (circle_intersect(&c01, &c12, &p1, &dummy_pt) == 0) + return -1; + if (circle_intersect(&c12, &c20, &p2, &dummy_pt) == 0) + return -1; + if (circle_intersect(&c20, &c01, &dummy_pt, &p3) == 0) + return -1; + + dprintf("p1: x=%2.2f y=%2.2f\n", p1.x, p1.y); + dprintf("p2: x=%2.2f y=%2.2f\n", p2.x, p2.y); + dprintf("p3: x=%2.2f y=%2.2f\n", p3.x, p3.y); + + /* if (norm(p1.x, p1.y, p2.x, p2.y) > POS_ACCURACY || */ + /* norm(p2.x, p2.y, p3.x, p3.y) > POS_ACCURACY || */ + /* norm(p3.x, p3.y, p1.x, p1.y) > POS_ACCURACY) */ + /* return -1; */ + + pos->x = (p1.x + p2.x + p3.x) / 3.0; + pos->y = (p1.y + p2.y + p3.y) / 3.0; + + return 0; +} + +/* get the angles of beacons from xy pos */ +int8_t posxy_to_angles(point_t pos, double *a01, double *a12, + double *a20, int err_num, float err_val) +{ + double a0, a1, a2; + + a0 = atan2(beacon0.y-pos.y, beacon0.x-pos.x); + a1 = atan2(beacon1.y-pos.y, beacon1.x-pos.x); + a2 = atan2(beacon2.y-pos.y, beacon2.x-pos.x); + + if (err_num == 0 || err_num == 3) + a0 += (err_val * M_PI/180.); + if (err_num == 1 || err_num == 3) + a1 += (err_val * M_PI/180.); + if (err_num == 2 || err_num == 3) + a2 += (err_val * M_PI/180.); + + *a01 = a1-a0; + if (*a01 < 0) + *a01 += M_PI*2; + *a12 = a2-a1; + if (*a12 < 0) + *a12 += M_PI*2; + *a20 = a0-a2; + if (*a20 < 0) + *a20 += M_PI*2; + + return 0; +} + +int8_t process_move_error(double x, double y, double speed, + double period, double angle, double *err) +{ + double a01, a12, a20; + point_t pos, tmp; + double a0, a1, a2; + vect_t u,v; + point_t pos2, pos3; + + pos.x = x; + pos.y = y; + + /* from start to destination */ + v.x = cos(angle) * speed * period; + v.y = sin(angle) * speed * period; + + /* first process real pos */ + posxy_to_angles(pos, &a01, &a12, &a20, -1, 0); + + /* vector covered during measure of a0 and a1 */ + u.x = v.x * a01 / (2*M_PI); + u.y = v.y * a01 / (2*M_PI); + pos2.x = pos.x + u.x; + pos2.y = pos.y + u.y; + + /* vector covered during measure of a1 and a2 */ + u.x = v.x * a12 / (2*M_PI); + u.y = v.y * a12 / (2*M_PI); + pos3.x = pos2.x + u.x; + pos3.y = pos2.y + u.y; + + dprintf("p0: x=%2.2f y=%2.2f\n", pos.x, pos.y); + dprintf("p1: x=%2.2f y=%2.2f\n", pos2.x, pos2.y); + dprintf("p2: x=%2.2f y=%2.2f\n", pos3.x, pos3.y); + + a0 = atan2(beacon0.y-pos.y, beacon0.x-pos.x); + a1 = atan2(beacon1.y-pos2.y, beacon1.x-pos2.x); + a2 = atan2(beacon2.y-pos3.y, beacon2.x-pos3.x); + + a01 = a1-a0; + if (a01 < 0) + a01 += M_PI*2; + a12 = a2-a1; + if (a12 < 0) + a12 += M_PI*2; + a20 = a0-a2; + if (a20 < 0) + a20 += M_PI*2; + + if (angles_to_posxy(&tmp, a01, a12, a20)) + return -1; + *err = pt_norm(&tmp, &pos); + if (*err > 50.) /* saturate error to 5cm */ + *err = 50.; + return 0; +} + +/* whole process is around 3ms on atmega128 at 16Mhz */ +int main(int argc, char **argv) +{ + double a01, a12, a20; + point_t pos, tmp; + const char *mode = "nothing"; + +#ifdef HOST_VERSION + if (argc < 2) { + printf("bad args\n"); + return -1; + } + mode = argv[1]; +#else + mode = "angle2pos"; + argc = 5; + a01 = 1.65; + a12 = 2.12; + a20 = 2.53; +#endif + + if (argc == 5 && strcmp(mode, "angle2pos") == 0) { +#ifdef HOST_VERSION + dprint = 1; + a01 = atof(argv[2]); + a12 = atof(argv[3]); + a20 = atof(argv[4]); +#endif + if (angles_to_posxy(&pos, a01, a12, a20) < 0) + return -1; + printf("p0: x=%2.2f y=%2.2f\n", pos.x, pos.y); + return 0; + } + + if (argc == 4 && strcmp(mode, "simple_error") == 0) { + int x, y; + int err_num; + double err_val_deg; + double err; + + err_num = atof(argv[2]); /* which beacon sees an error */ + err_val_deg = atof(argv[3]); /* how many degrees of error */ + + for (x=0; x<300; x++) { + for (y=0; y<210; y++) { + pos.x = x*10; + pos.y = y*10; + posxy_to_angles(pos, &a01, &a12, &a20, + err_num, err_val_deg); + if (angles_to_posxy(&tmp, a01, a12, a20)) + continue; + err = pt_norm(&tmp, &pos); + if (err > 50.) /* saturate error to 5cm */ + err = 50.; + printf("%d %d %2.2f\n", x, y, err); + } + } + return 0; + } + + if ((argc == 5 || argc == 7) + && strcmp(argv[1], "move_error") == 0) { + int x, y; + double angle, speed, period, err; + + speed = atof(argv[2]); /* speed in m/s ( = mm/ms) */ + period = atof(argv[3]); /* period of turret in ms */ + angle = atof(argv[4]); /* direction of moving */ + if (argc == 7) { + dprint = 1; + process_move_error(atof(argv[5]), atof(argv[6]), + speed, period, angle, &err); + printf("%2.2f %2.2f %2.2f\n", atof(argv[5]), + atof(argv[6]), err); + return 0; + } + + for (x=0; x<300; x++) { + for (y=0; y<210; y++) { + pos.x = x*10; + pos.y = y*10; + if (process_move_error(pos.x, pos.y, + speed, period, angle, + &err) < 0) + continue; + printf("%d %d %2.2f\n", x, y, err); + } + } + return 0; + } + + printf("bad args\n"); + return -1; +}