From c4395e067140b7bbc40a20c4d8d720d30b096033 Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 11 Mar 2006 12:33:39 +0000 Subject: Ajout de la simulation sur host avec simulation des moteurs. --- n/asserv/src/asserv/Makefile | 4 +- n/asserv/src/asserv/main.c | 5 +- n/asserv/src/asserv/models.host.c | 130 +++++++++++++++++++++++++++++++++ n/asserv/src/asserv/models.host.h | 32 ++++++++ n/asserv/src/asserv/motor_model.c | 88 ---------------------- n/asserv/src/asserv/motor_model.h | 56 -------------- n/asserv/src/asserv/motor_model.host.c | 88 ++++++++++++++++++++++ n/asserv/src/asserv/motor_model.host.h | 56 ++++++++++++++ n/asserv/src/asserv/simu.host.c | 59 ++++++++++++++- n/asserv/src/asserv/simu.host.h | 6 +- n/asserv/src/asserv/taz_model.c | 52 ------------- n/asserv/src/asserv/test_motor_model.c | 25 +++++-- 12 files changed, 392 insertions(+), 209 deletions(-) create mode 100644 n/asserv/src/asserv/models.host.c create mode 100644 n/asserv/src/asserv/models.host.h delete mode 100644 n/asserv/src/asserv/motor_model.c delete mode 100644 n/asserv/src/asserv/motor_model.h create mode 100644 n/asserv/src/asserv/motor_model.host.c create mode 100644 n/asserv/src/asserv/motor_model.host.h delete mode 100644 n/asserv/src/asserv/taz_model.c (limited to 'n/asserv') diff --git a/n/asserv/src/asserv/Makefile b/n/asserv/src/asserv/Makefile index 6fe0762..3dbda13 100644 --- a/n/asserv/src/asserv/Makefile +++ b/n/asserv/src/asserv/Makefile @@ -1,8 +1,8 @@ BASE = ../../../avr PROGS = asserv HOST_PROGS = test_motor_model -asserv_SOURCES = main.c simu.host.c -test_motor_model_SOURCES = test_motor_model.c motor_model.c taz_model.c +asserv_SOURCES = main.c simu.host.c motor_model.host.c models.host.c +test_motor_model_SOURCES = test_motor_model.c motor_model.host.c models.host.c MODULES = proto uart utils test_motor_model_MODULES = CONFIGFILE = avrconfig.h diff --git a/n/asserv/src/asserv/main.c b/n/asserv/src/asserv/main.c index 87124cf..b32f2b1 100644 --- a/n/asserv/src/asserv/main.c +++ b/n/asserv/src/asserv/main.c @@ -36,12 +36,14 @@ # include "timer.avr.c" # include "counter.avr.c" # include "pwm.avr.c" -# include "eeprom.avr.c" #else # include "simu.host.h" #endif #include "pos.c" #include "speed.c" +#ifndef HOST +# include "eeprom.avr.c" +#endif /** Motor control mode: * 0: pwm setup. @@ -82,6 +84,7 @@ main_loop (void); int main (int argc, char **argv) { + avr_init (argc, argv); DDRD = 0x60; /* Pull-ups. */ PORTA = 0xff; diff --git a/n/asserv/src/asserv/models.host.c b/n/asserv/src/asserv/models.host.c new file mode 100644 index 0000000..062b88a --- /dev/null +++ b/n/asserv/src/asserv/models.host.c @@ -0,0 +1,130 @@ +/* models.host.c */ +/* asserv - Position & speed motor control on AVR. {{{ + * + * Copyright (C) 2006 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * 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. + * + * }}} */ +#include "motor_model.host.h" +#include "models.host.h" + +#include +#include + +/* Gloubi model. */ +static const struct motor_t gloubi_model = +{ + /* Motor caracteristics. */ + 407 * M_2_PI / 60, /* Speed constant ((rad/s)/V). */ + 23.4 / 1000, /* Torque constant (N.m/A). */ + 0, /* Bearing friction (N.m/(rad/s)). */ + 2.18, /* Terminal resistance (Ohm). */ + 0.24 / 1000, /* Terminal inductance (H). */ + /* Gearbox caracteristics. */ + 10, /* Gearbox ratio. */ + 0.75, /* Gearbox efficiency. */ + /* Load caracteristics. */ + 4 * 0.02 * 0.02, /* Load (kg.m^2). */ + /* Simulation parameters. */ + 4.444444 / 1000, /* Simulation time step (s). */ + 1000, /* Simulation time step division. */ + /* Simulation current state. */ + 0, /* Current time (not realy used) (s). */ + 0, /* Current input voltage (V). */ + 0, /* Current current (A). */ + 0, /* Current angular speed (o for omega) (rad/s). */ + 0 /* Current theta (th for theta) (rad). */ +}; + +/* Taz model. */ +static const struct motor_t taz_model = +{ + /* Motor caracteristics. */ + 407 * M_2_PI / 60, /* Speed constant ((rad/s)/V). */ + 23.4 / 1000, /* Torque constant (N.m/A). */ + 0, /* Bearing friction (N.m/(rad/s)). */ + 2.18, /* Terminal resistance (Ohm). */ + 0.24 / 1000, /* Terminal inductance (H). */ + /* Gearbox caracteristics. */ + 10, /* Gearbox ratio. */ + 0.75, /* Gearbox efficiency. */ + /* Load caracteristics. */ + 10 * 0.04 * 0.04, /* Load (kg.m^2). */ + /* Simulation parameters. */ + 4.444444 / 1000, /* Simulation time step (s). */ + 1000, /* Simulation time step division. */ + /* Simulation current state. */ + 0, /* Current time (not realy used) (s). */ + 0, /* Current input voltage (V). */ + 0, /* Current current (A). */ + 0, /* Current angular speed (o for omega) (rad/s). */ + 0 /* Current theta (th for theta) (rad). */ +}; + +/* Taz model, with a RE25G and a 1:20.25 ratio gearbox. */ +static const struct motor_t tazg_model = +{ + /* Motor caracteristics. */ + 407 * M_2_PI / 60, /* Speed constant ((rad/s)/V). */ + 40.2 / 1000, /* Torque constant (N.m/A). */ + 0, /* Bearing friction (N.m/(rad/s)). */ + 2.32, /* Terminal resistance (Ohm). */ + 0.24 / 1000, /* Terminal inductance (H). */ + /* Gearbox caracteristics. */ + 20.25, /* Gearbox ratio. */ + 0.75, /* Gearbox efficiency. */ + /* Load caracteristics. */ + 10 * 0.04 * 0.04, /* Load (kg.m^2). */ + /* Simulation parameters. */ + 4.444444 / 1000, /* Simulation time step (s). */ + 1000, /* Simulation time step division. */ + /* Simulation current state. */ + 0, /* Current time (not realy used) (s). */ + 0, /* Current input voltage (V). */ + 0, /* Current current (A). */ + 0, /* Current angular speed (o for omega) (rad/s). */ + 0 /* Current theta (th for theta) (rad). */ +}; + +/* Table of models. */ +static const struct +{ + const char *name; + const struct motor_t *model; +} models[] = { + { "gloubi", &gloubi_model }, + { "taz", &taz_model }, + { "tazg", &tazg_model }, + { 0, 0 } +}; + +/** Get a pointer to a model by name, or return 0. */ +const struct motor_t * +models_get (const char *name) +{ + int i; + for (i = 0; models[i].name; i++) + { + if (strcmp (models[i].name, name) == 0) + return models[i].model; + } + return 0; +} + diff --git a/n/asserv/src/asserv/models.host.h b/n/asserv/src/asserv/models.host.h new file mode 100644 index 0000000..b962b9d --- /dev/null +++ b/n/asserv/src/asserv/models.host.h @@ -0,0 +1,32 @@ +#ifndef models_host_h +#define models_host_h +/* models.host.h */ +/* asserv - Position & speed motor control on AVR. {{{ + * + * Copyright (C) 2006 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * 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. + * + * }}} */ + +/** Get a pointer to a model by name, or return 0. */ +const struct motor_t * +models_get (const char *name); + +#endif /* models_host_h */ diff --git a/n/asserv/src/asserv/motor_model.c b/n/asserv/src/asserv/motor_model.c deleted file mode 100644 index bff5cad..0000000 --- a/n/asserv/src/asserv/motor_model.c +++ /dev/null @@ -1,88 +0,0 @@ -/* motor_model.c - DC motor model. */ -/* asserv - Position & speed motor control on AVR. {{{ - * - * Copyright (C) 2006 Nicolas Schodet - * - * Robot APB Team/Efrei 2006. - * Web: http://assos.efrei.fr/robot/ - * Email: robot AT efrei DOT fr - * - * 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. - * - * }}} */ -#include "common.h" -#include "motor_model.h" - -/** - * Switching to french for all thoses non english speaking people. - * - * Ce fichier permet de modéliser un moteur à courant continue. Il y a deux - * parties, la modélisation électrique et la modélisation mécanique. - * - * On peut trouver de l'aide sur : - * - le site de maxon : http://www.maxonmotor.com/ - * - ici : http://www.mathworks.com/access/helpdesk/help/toolbox/control/getstart/buildmo4.html - * - là : http://iai.eivd.ch/users/mee/Regulation_automatique_anal.htm - * - * Voici ce qui en résulte, des belles équations différentielles : - * u(t) = R i(t) + L di(t)/dt + Ke o(t) - * J do(t)/dt = Kt i(t) - Rf o(t) - * dth(t)/dt = o(t) - * - * Les variables sont décrites dans la structure motor_t. - * - * À cela, il faut ajouter un coef pour le réducteur, je vous laisse ça en - * exercice. - * - * On va résoudre ces belles équadiff numériquement par la méthode d'Euler (il - * est partout celui là). Si vous voulez plus de détail, mailez moi. On arrive - * à : - * - * i(t+h) = i(t) + h (1/L u(t) - R/L i(t) - 1/(Ke L) o(t)) - * o(t+h) = o(t) + h (i_G^2 ro_G)/J (Kt i(t) - Rf o(t)) - * th(t+h) = th(t) + h o(t) - * - * C'est consternant de simplicité non ? - */ - -/** Make a simulation step. */ -void motor_model_step (struct motor_t *m) -{ - double i_, o_, th_; /* New computed values. */ - double h; /* Infinitesimal step... Well, not so infinite. */ - int d; - d = m->d; - h = m->h / d; - /* Make several small steps to increase precision. */ - for (; d; d--) - { - /* Ah, the mistical power of computation. */ - i_ = m->i - + h * (1.0 / m->L * m->u - - m->R / m->L * m->i - - 1.0 / m->Ke / m->L * m->o); - o_ = m->o - + h * m->i_G * m->i_G * m->ro_G / m->J - * (m->Kt * m->i - m->Rf * m->o); - th_ = m->th + h * m->o; - /* Ok, now store this step. */ - m->i = i_; - m->o = o_; - m->th = th_; - } - /* Damn! It's finished yet! */ - m->t += m->h; -} - diff --git a/n/asserv/src/asserv/motor_model.h b/n/asserv/src/asserv/motor_model.h deleted file mode 100644 index a7446e1..0000000 --- a/n/asserv/src/asserv/motor_model.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef motor_model_h -#define motor_model_h -/* motor_model.h - DC motor model. */ -/* asserv - Position & speed motor control on AVR. {{{ - * - * Copyright (C) 2006 Nicolas Schodet - * - * Robot APB Team/Efrei 2006. - * Web: http://assos.efrei.fr/robot/ - * Email: robot AT efrei DOT fr - * - * 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. - * - * }}} */ - -/** Motor and load caracteristics and current data. */ -struct motor_t -{ - /* Motor caracteristics. */ - double Ke; /* Speed constant ((rad/s)/V). */ - double Kt; /* Torque constant (N.m/A). */ - double Rf; /* Bearing friction (N.m/(rad/s)). */ - double R; /* Terminal resistance (Ohm). */ - double L; /* Terminal inductance (H). */ - /* Gearbox caracteristics. */ - double i_G; /* Gearbox ratio. */ - double ro_G;/* Gearbox efficiency. */ - /* Load caracteristics. */ - double J; /* Load (kg.m^2). */ - /* Simulation parameters. */ - double h; /* Simulation time step (s). */ - int d; /* Simulation time step division. */ - /* Simulation current state. */ - double t; /* Current time (not realy used) (s). */ - double u; /* Current input voltage (V). */ - double i; /* Current current (A). */ - double o; /* Current angular speed (o for omega) (rad/s). */ - double th; /* Current theta (th for theta) (rad). */ -}; - -/** Make a simulation step. */ -void motor_model_step (struct motor_t *m); - -#endif /* motor_model_h */ diff --git a/n/asserv/src/asserv/motor_model.host.c b/n/asserv/src/asserv/motor_model.host.c new file mode 100644 index 0000000..1d0855b --- /dev/null +++ b/n/asserv/src/asserv/motor_model.host.c @@ -0,0 +1,88 @@ +/* motor_model.c - DC motor model. */ +/* asserv - Position & speed motor control on AVR. {{{ + * + * Copyright (C) 2006 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * 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. + * + * }}} */ +#include "common.h" +#include "motor_model.host.h" + +/** + * Switching to french for all thoses non english speaking people. + * + * Ce fichier permet de modéliser un moteur à courant continue. Il y a deux + * parties, la modélisation électrique et la modélisation mécanique. + * + * On peut trouver de l'aide sur : + * - le site de maxon : http://www.maxonmotor.com/ + * - ici : http://www.mathworks.com/access/helpdesk/help/toolbox/control/getstart/buildmo4.html + * - là : http://iai.eivd.ch/users/mee/Regulation_automatique_anal.htm + * + * Voici ce qui en résulte, des belles équations différentielles : + * u(t) = R i(t) + L di(t)/dt + Ke o(t) + * J do(t)/dt = Kt i(t) - Rf o(t) + * dth(t)/dt = o(t) + * + * Les variables sont décrites dans la structure motor_t. + * + * À cela, il faut ajouter un coef pour le réducteur, je vous laisse ça en + * exercice. + * + * On va résoudre ces belles équadiff numériquement par la méthode d'Euler (il + * est partout celui là). Si vous voulez plus de détail, mailez moi. On arrive + * à : + * + * i(t+h) = i(t) + h (1/L u(t) - R/L i(t) - 1/(Ke L) o(t)) + * o(t+h) = o(t) + h (i_G^2 ro_G)/J (Kt i(t) - Rf o(t)) + * th(t+h) = th(t) + h o(t) + * + * C'est consternant de simplicité non ? + */ + +/** Make a simulation step. */ +void motor_model_step (struct motor_t *m) +{ + double i_, o_, th_; /* New computed values. */ + double h; /* Infinitesimal step... Well, not so infinite. */ + int d; + d = m->d; + h = m->h / d; + /* Make several small steps to increase precision. */ + for (; d; d--) + { + /* Ah, the mistical power of computation. */ + i_ = m->i + + h * (1.0 / m->L * m->u + - m->R / m->L * m->i + - 1.0 / m->Ke / m->L * m->o); + o_ = m->o + + h * m->i_G * m->i_G * m->ro_G / m->J + * (m->Kt * m->i - m->Rf * m->o); + th_ = m->th + h * m->o; + /* Ok, now store this step. */ + m->i = i_; + m->o = o_; + m->th = th_; + } + /* Damn! It's finished yet! */ + m->t += m->h; +} + diff --git a/n/asserv/src/asserv/motor_model.host.h b/n/asserv/src/asserv/motor_model.host.h new file mode 100644 index 0000000..e3ab615 --- /dev/null +++ b/n/asserv/src/asserv/motor_model.host.h @@ -0,0 +1,56 @@ +#ifndef motor_model_host_h +#define motor_model_host_h +/* motor_model.host.h - DC motor model. */ +/* asserv - Position & speed motor control on AVR. {{{ + * + * Copyright (C) 2006 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * 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. + * + * }}} */ + +/** Motor and load caracteristics and current data. */ +struct motor_t +{ + /* Motor caracteristics. */ + double Ke; /* Speed constant ((rad/s)/V). */ + double Kt; /* Torque constant (N.m/A). */ + double Rf; /* Bearing friction (N.m/(rad/s)). */ + double R; /* Terminal resistance (Ohm). */ + double L; /* Terminal inductance (H). */ + /* Gearbox caracteristics. */ + double i_G; /* Gearbox ratio. */ + double ro_G;/* Gearbox efficiency. */ + /* Load caracteristics. */ + double J; /* Load (kg.m^2). */ + /* Simulation parameters. */ + double h; /* Simulation time step (s). */ + int d; /* Simulation time step division. */ + /* Simulation current state. */ + double t; /* Current time (not realy used) (s). */ + double u; /* Current input voltage (V). */ + double i; /* Current current (A). */ + double o; /* Current angular speed (o for omega) (rad/s). */ + double th; /* Current theta (th for theta) (rad). */ +}; + +/** Make a simulation step. */ +void motor_model_step (struct motor_t *m); + +#endif /* motor_model_host_h */ diff --git a/n/asserv/src/asserv/simu.host.c b/n/asserv/src/asserv/simu.host.c index 5b2b6d4..e7cc4ee 100644 --- a/n/asserv/src/asserv/simu.host.c +++ b/n/asserv/src/asserv/simu.host.c @@ -22,7 +22,14 @@ * Email: * }}} */ #include "common.h" +#include "modules/host/host.h" #include "simu.host.h" +#include "motor_model.host.h" +#include "models.host.h" + +#include +#include +#include /** Simulate some AVR regs. */ uint8_t DDRD, PORTD, PORTA, PORTC, PINA; @@ -40,19 +47,67 @@ int16_t pwm_left, pwm_right; * on port B. */ uint8_t pwm_dir; -/* +AutoDec */ -/* -AutoDec */ +struct motor_t simu_left_model, simu_right_model; + +/** Initialise simulation. */ +static void +simu_init (void) +{ + int argc; + char **argv; + const struct motor_t *m; + host_get_program_arguments (&argc, &argv); + if (argc != 1) + { + fprintf (stderr, "need model name as first argument\n"); + exit (1); + } + m = models_get (argv[0]); + if (!m) + { + fprintf (stderr, "unknown model name: %s\n", argv[0]); + exit (1); + } + simu_left_model = *m; + simu_right_model = *m; +} + +/** Do a simulation step. */ +static void +simu_step (void) +{ + double old_left_th, old_right_th; + /* Convert pwm value into voltage. */ + assert (pwm_left >= -PWM_MAX && pwm_left <= PWM_MAX); + assert (pwm_right >= -PWM_MAX && pwm_right <= PWM_MAX); + simu_left_model.u = (double) pwm_left / PWM_MAX; + simu_right_model.u = (double) pwm_right / PWM_MAX; + /* Make one step. */ + old_left_th = simu_left_model.th; + old_right_th = simu_right_model.th; + motor_model_step (&simu_left_model); + motor_model_step (&simu_right_model); + /* Modifie counters. */ + counter_left_diff = (simu_left_model.th - old_left_th) / M_2_PI * 500 * + simu_left_model.i_G; + counter_left += counter_left_diff; + counter_right_diff = (simu_right_model.th - old_right_th) / M_2_PI * 500 * + simu_right_model.i_G; + counter_right += counter_right_diff; +} /** Initialise the timer. */ void timer_init (void) { + simu_init (); } /** Wait for timer overflow. */ void timer_wait (void) { + simu_step (); } /** Read timer value. Used for performance analysis. */ diff --git a/n/asserv/src/asserv/simu.host.h b/n/asserv/src/asserv/simu.host.h index c2a4934..11f817c 100644 --- a/n/asserv/src/asserv/simu.host.h +++ b/n/asserv/src/asserv/simu.host.h @@ -49,9 +49,9 @@ extern int16_t pwm_left, pwm_right; extern uint8_t pwm_dir; #define EEPROM_KEY 0xa5 -#define eeprom_read_params() -#define eeprom_write_params() -#define eeprom_clear_params() +#define eeprom_read_params() do { } while (0) +#define eeprom_write_params() do { } while (0) +#define eeprom_clear_params() do { } while (0) /* +AutoDec */ diff --git a/n/asserv/src/asserv/taz_model.c b/n/asserv/src/asserv/taz_model.c deleted file mode 100644 index a590029..0000000 --- a/n/asserv/src/asserv/taz_model.c +++ /dev/null @@ -1,52 +0,0 @@ -/* taz_model.c */ -/* asserv - Position & speed motor control on AVR. {{{ - * - * Copyright (C) 2006 Nicolas Schodet - * - * 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. - * - * Contact : - * Web: http://perso.efrei.fr/~schodet/ - * Email: - * }}} */ -#include "motor_model.h" - -#include - -/* Taz model. */ -struct motor_t taz_model = -{ - /* Motor caracteristics. */ - 407 * M_2_PI / 60, /* Speed constant ((rad/s)/V). */ - 23.4 / 1000, /* Torque constant (N.m/A). */ - 0, /* Bearing friction (N.m/(rad/s)). */ - 2.18, /* Terminal resistance (Ohm). */ - 0.24 / 1000, /* Terminal inductance (H). */ - /* Gearbox caracteristics. */ - 10, /* Gearbox ratio. */ - 0.75, /* Gearbox efficiency. */ - /* Load caracteristics. */ - 10 * 0.04 * 0.04, /* Load (kg.m^2). */ - /* Simulation parameters. */ - 4.444444 / 1000, /* Simulation time step (s). */ - 1000, /* Simulation time step division. */ - /* Simulation current state. */ - 0, /* Current time (not realy used) (s). */ - 0, /* Current input voltage (V). */ - 0, /* Current current (A). */ - 0, /* Current angular speed (o for omega) (rad/s). */ - 0 /* Current theta (th for theta) (rad). */ -}; - diff --git a/n/asserv/src/asserv/test_motor_model.c b/n/asserv/src/asserv/test_motor_model.c index a478244..c166999 100644 --- a/n/asserv/src/asserv/test_motor_model.c +++ b/n/asserv/src/asserv/test_motor_model.c @@ -23,12 +23,11 @@ * * }}} */ #include "common.h" -#include "motor_model.h" +#include "motor_model.host.h" +#include "models.host.h" #include -extern struct motor_t taz_model; - void simu (struct motor_t *m, double t) { int i, s; @@ -41,9 +40,25 @@ void simu (struct motor_t *m, double t) } int -main (void) +main (int argc, char **argv) { - struct motor_t *m = &taz_model; + struct motor_t ms; + struct motor_t *m; + const struct motor_t *mr; + /* Check arguments. */ + if (argc != 2) + { + fprintf (stderr, "syntax: %s MODEL\n", argv[0]); + return 1; + } + mr = models_get (argv[1]); + if (!mr) + { + fprintf (stderr, "model unknown\n"); + return 1; + } + ms = *mr; + m = &ms; /* Make a step response simulation. */ printf ("# %10s %12s %12s %12s %12s\n", "t", "u", "i", "omega", "theta"); m->u = 3.0; -- cgit v1.2.3