summaryrefslogtreecommitdiff
path: root/n/asserv/src
diff options
context:
space:
mode:
Diffstat (limited to 'n/asserv/src')
-rw-r--r--n/asserv/src/asserv/Makefile9
-rw-r--r--n/asserv/src/asserv/counter.avr.c (renamed from n/asserv/src/asserv/counter.c)2
-rw-r--r--n/asserv/src/asserv/eeprom.avr.c (renamed from n/asserv/src/asserv/eeprom.c)0
-rw-r--r--n/asserv/src/asserv/main.c12
-rw-r--r--n/asserv/src/asserv/pwm.avr.c (renamed from n/asserv/src/asserv/pwm.c)2
-rw-r--r--n/asserv/src/asserv/simu.host.c94
-rw-r--r--n/asserv/src/asserv/simu.host.h92
-rw-r--r--n/asserv/src/asserv/taz_model.c52
-rw-r--r--n/asserv/src/asserv/test_motor_model.c37
-rw-r--r--n/asserv/src/asserv/timer.avr.c (renamed from n/asserv/src/asserv/timer.c)15
10 files changed, 271 insertions, 44 deletions
diff --git a/n/asserv/src/asserv/Makefile b/n/asserv/src/asserv/Makefile
index d618c0a..6fe0762 100644
--- a/n/asserv/src/asserv/Makefile
+++ b/n/asserv/src/asserv/Makefile
@@ -1,10 +1,8 @@
BASE = ../../../avr
PROGS = asserv
HOST_PROGS = test_motor_model
-asserv_SOURCES = main.c
-test_motor_model_SOURCES = test_motor_model.c motor_model.c
-DOC =
-EXTRACTDOC =
+asserv_SOURCES = main.c simu.host.c
+test_motor_model_SOURCES = test_motor_model.c motor_model.c taz_model.c
MODULES = proto uart utils
test_motor_model_MODULES =
CONFIGFILE = avrconfig.h
@@ -14,7 +12,4 @@ AVR_MCU = atmega128
# -Os : size
OPTIMIZE = -O2
-DEFS =
-LIBS =
-
include $(BASE)/make/Makefile.gen
diff --git a/n/asserv/src/asserv/counter.c b/n/asserv/src/asserv/counter.avr.c
index c4135b4..0dd59f4 100644
--- a/n/asserv/src/asserv/counter.c
+++ b/n/asserv/src/asserv/counter.avr.c
@@ -1,4 +1,4 @@
-/* counter.c */
+/* counter.avr.c */
/* asserv - Position & speed motor control on AVR. {{{
*
* Copyright (C) 2005 Nicolas Schodet
diff --git a/n/asserv/src/asserv/eeprom.c b/n/asserv/src/asserv/eeprom.avr.c
index 34770bb..34770bb 100644
--- a/n/asserv/src/asserv/eeprom.c
+++ b/n/asserv/src/asserv/eeprom.avr.c
diff --git a/n/asserv/src/asserv/main.c b/n/asserv/src/asserv/main.c
index f56c662..87124cf 100644
--- a/n/asserv/src/asserv/main.c
+++ b/n/asserv/src/asserv/main.c
@@ -32,12 +32,16 @@
#include "misc.h"
/* This is implementation include. */
-#include "timer.c"
-#include "counter.c"
-#include "pwm.c"
+#ifndef HOST
+# 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"
-#include "eeprom.c"
/** Motor control mode:
* 0: pwm setup.
diff --git a/n/asserv/src/asserv/pwm.c b/n/asserv/src/asserv/pwm.avr.c
index 50f4842..773cfef 100644
--- a/n/asserv/src/asserv/pwm.c
+++ b/n/asserv/src/asserv/pwm.avr.c
@@ -1,4 +1,4 @@
-/* pwm.c */
+/* pwm.avr.c */
/* asserv - Position & speed motor control on AVR. {{{
*
* Copyright (C) 2005 Nicolas Schodet
diff --git a/n/asserv/src/asserv/simu.host.c b/n/asserv/src/asserv/simu.host.c
new file mode 100644
index 0000000..5b2b6d4
--- /dev/null
+++ b/n/asserv/src/asserv/simu.host.c
@@ -0,0 +1,94 @@
+/* simu.host.c */
+/* {{{
+ *
+ * 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: <contact@ni.fr.eu.org>
+ * }}} */
+#include "common.h"
+#include "simu.host.h"
+
+/** Simulate some AVR regs. */
+uint8_t DDRD, PORTD, PORTA, PORTC, PINA;
+
+/** Overall counter values. */
+uint16_t counter_left, counter_right;
+/** Counter differences since last update.
+ * Maximum of 9 significant bits, sign included. */
+int16_t counter_left_diff, counter_right_diff;
+
+/** PWM values, this is an error if absolute value is greater than the
+ * maximum. */
+int16_t pwm_left, pwm_right;
+/** PWM reverse direction, only set pwm dir bits or you will get weird results
+ * on port B. */
+uint8_t pwm_dir;
+
+/* +AutoDec */
+/* -AutoDec */
+
+/** Initialise the timer. */
+void
+timer_init (void)
+{
+}
+
+/** Wait for timer overflow. */
+void
+timer_wait (void)
+{
+}
+
+/** Read timer value. Used for performance analysis. */
+uint8_t
+timer_read (void)
+{
+ return 0;
+}
+
+/** Initialize the counters. */
+void
+counter_init (void)
+{
+}
+
+/** Update overall counter values and compute diffs. */
+void
+counter_update (void)
+{
+}
+
+/** Restart counting. */
+void
+counter_restart (void)
+{
+}
+
+/** Initialise PWM generator. */
+void
+pwm_init (void)
+{
+}
+
+/** Update the hardware PWM values. */
+void
+pwm_update (void)
+{
+}
+
diff --git a/n/asserv/src/asserv/simu.host.h b/n/asserv/src/asserv/simu.host.h
new file mode 100644
index 0000000..c2a4934
--- /dev/null
+++ b/n/asserv/src/asserv/simu.host.h
@@ -0,0 +1,92 @@
+#ifndef simu_host_h
+#define simu_host_h
+/* simu.host.h */
+/* 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: <contact@ni.fr.eu.org>
+ * }}} */
+
+/** Simulate some AVR regs. */
+extern uint8_t DDRD, PORTD, PORTA, PORTC, PINA;
+
+/** Overall counter values. */
+extern uint16_t counter_left, counter_right;
+/** Counter differences since last update.
+ * Maximum of 9 significant bits, sign included. */
+extern int16_t counter_left_diff, counter_right_diff;
+
+/** Define the direction output for left motor. */
+#define PWM_LEFT_DIR 3
+/** Define the direction output for right motor. */
+#define PWM_RIGHT_DIR 2
+
+/** Define the absolute maximum PWM value. */
+#define PWM_MAX 0x3ff
+
+/** PWM values, this is an error if absolute value is greater than the
+ * maximum. */
+extern int16_t pwm_left, pwm_right;
+/** PWM reverse direction, only set pwm dir bits or you will get weird results
+ * on port B. */
+extern uint8_t pwm_dir;
+
+#define EEPROM_KEY 0xa5
+#define eeprom_read_params()
+#define eeprom_write_params()
+#define eeprom_clear_params()
+
+/* +AutoDec */
+
+/** Initialise the timer. */
+void
+timer_init (void);
+
+/** Wait for timer overflow. */
+void
+timer_wait (void);
+
+/** Read timer value. Used for performance analysis. */
+uint8_t
+timer_read (void);
+
+/** Initialize the counters. */
+void
+counter_init (void);
+
+/** Update overall counter values and compute diffs. */
+void
+counter_update (void);
+
+/** Restart counting. */
+void
+counter_restart (void);
+
+/** Initialise PWM generator. */
+void
+pwm_init (void);
+
+/** Update the hardware PWM values. */
+void
+pwm_update (void);
+
+/* -AutoDec */
+
+#endif /* simu_host_h */
diff --git a/n/asserv/src/asserv/taz_model.c b/n/asserv/src/asserv/taz_model.c
new file mode 100644
index 0000000..a590029
--- /dev/null
+++ b/n/asserv/src/asserv/taz_model.c
@@ -0,0 +1,52 @@
+/* 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: <contact@ni.fr.eu.org>
+ * }}} */
+#include "motor_model.h"
+
+#include <math.h>
+
+/* 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 14bab66..a478244 100644
--- a/n/asserv/src/asserv/test_motor_model.c
+++ b/n/asserv/src/asserv/test_motor_model.c
@@ -25,33 +25,9 @@
#include "common.h"
#include "motor_model.h"
-#include <math.h>
#include <stdio.h>
-/* Our robot model. */
-struct motor_t taz =
-{
- /* 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). */
-};
+extern struct motor_t taz_model;
void simu (struct motor_t *m, double t)
{
@@ -67,12 +43,13 @@ void simu (struct motor_t *m, double t)
int
main (void)
{
+ struct motor_t *m = &taz_model;
/* Make a step response simulation. */
printf ("# %10s %12s %12s %12s %12s\n", "t", "u", "i", "omega", "theta");
- taz.u = 3.0;
- printf ("%12f %12f %12f %12f %12f\n", taz.t, taz.u, taz.i, taz.o, taz.th);
- simu (&taz, 1.0);
- taz.u = 0.0;
- simu (&taz, 1.0);
+ m->u = 3.0;
+ printf ("%12f %12f %12f %12f %12f\n", m->t, m->u, m->i, m->o, m->th);
+ simu (m, 1.0);
+ m->u = 0.0;
+ simu (m, 1.0);
return 0;
}
diff --git a/n/asserv/src/asserv/timer.c b/n/asserv/src/asserv/timer.avr.c
index e91d8a8..dcad74d 100644
--- a/n/asserv/src/asserv/timer.c
+++ b/n/asserv/src/asserv/timer.avr.c
@@ -1,4 +1,4 @@
-/* timer.c */
+/* timer.avr.c */
/* asserv - Position & speed motor control on AVR. {{{
*
* Copyright (C) 2005 Nicolas Schodet
@@ -24,6 +24,19 @@
* }}} */
/* +AutoDec */
+
+/** Initialise the timer. */
+static inline void
+timer_init (void);
+
+/** Wait for timer overflow. */
+static inline void
+timer_wait (void);
+
+/** Read timer value. Used for performance analysis. */
+static inline uint8_t
+timer_read (void);
+
/* -AutoDec */
/** Initialise the timer. */