summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--digital/io/src/Makefile5
-rw-r--r--digital/io/src/avrconfig.h2
-rw-r--r--digital/io/src/eeprom.avr.c (renamed from digital/io/src/eeprom.c)2
-rw-r--r--digital/io/src/gutter_cb.c2
-rw-r--r--digital/io/src/main.c14
-rw-r--r--digital/io/src/servo.avr.c (renamed from digital/io/src/servo.c)2
-rw-r--r--digital/io/src/simu.host.c153
-rw-r--r--digital/io/src/simu.host.h52
-rw-r--r--digital/io/src/test/gutter/main.c2
-rw-r--r--host/inter/inter_node.py23
10 files changed, 249 insertions, 8 deletions
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index e263479b..7a82e78d 100644
--- a/digital/io/src/Makefile
+++ b/digital/io/src/Makefile
@@ -1,6 +1,7 @@
BASE = ../../avr
-AVR_PROGS = io
-io_SOURCES = main.c asserv.c servo.c eeprom.c trap.c sharp.c \
+PROGS = io
+io_SOURCES = main.c asserv.c servo.avr.c eeprom.avr.c trap.c sharp.c \
+ simu.host.c \
fsm.c getsamples.c getsamples_fsm.c getsamples_cb.c \
gutter_fsm.c gutter_cb.c
MODULES = proto uart twi utils adc
diff --git a/digital/io/src/avrconfig.h b/digital/io/src/avrconfig.h
index e7555acb..27a550c0 100644
--- a/digital/io/src/avrconfig.h
+++ b/digital/io/src/avrconfig.h
@@ -59,7 +59,7 @@
/** In HOST compilation:
* - STDIO: use stdin/out.
* - PTS: use pseudo terminal. */
-#define AC_UART0_HOST_DRIVER PTS
+#define AC_UART0_HOST_DRIVER STDIO
/** Same thing for secondary port. */
#define AC_UART1_PORT -1
#define AC_UART1_BAUDRATE 115200
diff --git a/digital/io/src/eeprom.c b/digital/io/src/eeprom.avr.c
index c1685a09..b16130c6 100644
--- a/digital/io/src/eeprom.c
+++ b/digital/io/src/eeprom.avr.c
@@ -1,4 +1,4 @@
-/* eeprom.c */
+/* eeprom.avr.c */
/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
*
* Copyright (C) 2008 Dufour Jérémy
diff --git a/digital/io/src/gutter_cb.c b/digital/io/src/gutter_cb.c
index 30166929..336ae404 100644
--- a/digital/io/src/gutter_cb.c
+++ b/digital/io/src/gutter_cb.c
@@ -37,7 +37,7 @@
fsm_branch_t
gutter__START__ok (void)
{
- asserv_go_to_gutter();
+ asserv_go_to_the_wall();
return gutter_next (START, ok);
}
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index 7f0fc6eb..bab667e4 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -31,13 +31,17 @@
/* AVR include, non HOST */
#ifndef HOST
# include "main_timer.avr.h"
+# include "switch.h" /* Manage switches (jack, color selector) */
#endif /* HOST */
+#include "simu.host.h"
+
#include "asserv.h" /* Functions to control the asserv board */
-#include "switch.h" /* Manage switches (jack, color selector) */
#include "eeprom.h" /* Parameters loaded/stored in the EEPROM */
#include "trap.h" /* Trap module (trap_* functions) */
+#include "io.h"
+
/**
* Initialize the main and all its subsystems.
*/
@@ -135,6 +139,12 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
* - 1b: pwm high time value (position).
*/
servo_set_high_time (args[0], args[1]);
+ break;
+
+ case c ('S', 0):
+ /* Report switch states. */
+ proto_send1b ('S', switch_get_color () << 1 | switch_get_jack ());
+ break;
/* EEPROM command */
case c ('e', 1):
@@ -165,6 +175,8 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
int
main (int argc, char **argv)
{
+ avr_init (argc, argv);
+
/* Initialize the main and its subsystems */
main_init ();
diff --git a/digital/io/src/servo.c b/digital/io/src/servo.avr.c
index 0d2b2580..c2603c6e 100644
--- a/digital/io/src/servo.c
+++ b/digital/io/src/servo.avr.c
@@ -1,4 +1,4 @@
-/* servo.c */
+/* servo.avr.c */
/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
*
* Copyright (C) 2008 Dufour Jérémy
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
new file mode 100644
index 00000000..cc9155bd
--- /dev/null
+++ b/digital/io/src/simu.host.c
@@ -0,0 +1,153 @@
+/* simu.host.c - Host simulation. */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2008 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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 "simu.host.h"
+
+#include "servo.h"
+
+#include "modules/utils/utils.h"
+#include "modules/host/host.h"
+#include "modules/host/mex.h"
+
+enum
+{
+ MSG_SIMU_IO_JACK = 0xb0,
+ MSG_SIMU_IO_COLOR = 0xb1,
+ MSG_SIMU_IO_SERVO = 0xb2,
+};
+
+/** Requested servo position. */
+uint8_t servo_high_time_[SERVO_NUMBER];
+
+/** Current servo position. */
+uint8_t servo_high_time_current_[SERVO_NUMBER];
+
+/** Servo speed is about 120 ms for 60 degrees. This means about 360 ms for
+ * the full swing. */
+#define SERVO_SPEED (int) ((256 / (360.0 / 4.4444)) + 0.5)
+
+/** Initialise simulation. */
+void
+simu_init (void)
+{
+ mex_node_connect ();
+}
+
+/** Make a simulation step. */
+void
+simu_step (void)
+{
+ int i;
+ mex_msg_t *m;
+ /* Update servos. */
+ for (i = 0; i < SERVO_NUMBER; i++)
+ {
+ if (UTILS_ABS (servo_high_time_current_[i] - servo_high_time_[i]) <
+ SERVO_SPEED)
+ servo_high_time_current_[i] = servo_high_time_[i];
+ else if (servo_high_time_current_[i] < servo_high_time_[i])
+ servo_high_time_current_[i] += SERVO_SPEED;
+ else
+ servo_high_time_current_[i] -= SERVO_SPEED;
+ }
+ /* Send servos. */
+ m = mex_msg_new (MSG_SIMU_IO_SERVO);
+ for (i = 0; i < SERVO_NUMBER; i++)
+ mex_msg_push (m, "B", servo_high_time_current_[i]);
+ mex_node_send (m);
+}
+
+void
+servo_init (void)
+{
+}
+
+void
+servo_set_high_time (uint8_t servo, uint8_t high_time)
+{
+ servo_high_time_[servo] = high_time;
+}
+
+uint8_t
+servo_get_high_time (uint8_t servo)
+{
+ return servo_high_time_[servo];
+}
+
+void
+switch_init (void)
+{
+}
+
+uint8_t
+switch_get_color (void)
+{
+ mex_msg_t *m = mex_msg_new (MSG_SIMU_IO_COLOR);
+ m = mex_node_request (m);
+ uint8_t r;
+ mex_msg_pop (m, "B", &r);
+ mex_msg_delete (m);
+ return r;
+}
+
+uint8_t
+switch_get_jack (void)
+{
+ mex_msg_t *m = mex_msg_new (MSG_SIMU_IO_JACK);
+ m = mex_node_request (m);
+ uint8_t r;
+ mex_msg_pop (m, "B", &r);
+ mex_msg_delete (m);
+ return r;
+}
+
+void
+main_timer_init (void)
+{
+ simu_init ();
+}
+
+void
+main_timer_wait (void)
+{
+ mex_node_wait_date (mex_node_date () + 4);
+ simu_step ();
+}
+
+void
+eeprom_load_param (void)
+{
+}
+
+void
+eeprom_save_param (void)
+{
+}
+
+void
+eeprom_clear_param (void)
+{
+}
+
diff --git a/digital/io/src/simu.host.h b/digital/io/src/simu.host.h
new file mode 100644
index 00000000..7d2be4fa
--- /dev/null
+++ b/digital/io/src/simu.host.h
@@ -0,0 +1,52 @@
+#ifndef simu_host_h
+#define simu_host_h
+/* simu.host.h - Host simulation. */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2008 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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.
+ *
+ * }}} */
+
+#ifdef HOST
+
+/** Hooked, initialise the host simulation. */
+void
+main_timer_init (void);
+
+/** Hooked, as before, wait for the next iteration. */
+void
+main_timer_wait (void);
+
+/** Hooked, do nothing. */
+void
+switch_init (void);
+
+/** Hooked, request via mex. */
+uint8_t
+switch_get_color (void);
+
+/** Hooked, request via mex. */
+uint8_t
+switch_get_jack (void);
+
+#endif /* defined (HOST) */
+
+#endif /* simu_host_h */
diff --git a/digital/io/src/test/gutter/main.c b/digital/io/src/test/gutter/main.c
index 38e4c3ea..37eefbda 100644
--- a/digital/io/src/test/gutter/main.c
+++ b/digital/io/src/test/gutter/main.c
@@ -111,7 +111,7 @@ trap_close_rear_panel(void)
}
void
-asserv_go_to_gutter (void)
+asserv_go_to_the_wall (void)
{
printf ("Go to gutter\n");
}
diff --git a/host/inter/inter_node.py b/host/inter/inter_node.py
index 14be6908..131df874 100644
--- a/host/inter/inter_node.py
+++ b/host/inter/inter_node.py
@@ -29,6 +29,7 @@ if __name__ == '__main__':
from inter import Inter
from Tkinter import *
from mex.node import Node
+from mex.msg import Msg
class InterNode (Inter):
"""Inter, coupled with a mex Node."""
@@ -37,11 +38,18 @@ class InterNode (Inter):
# period.
TICK = 900.0
+ IO_JACK = 0xb0
+ IO_COLOR = 0xb1
+ IO_SERVO = 0xb2
+
def __init__ (self):
Inter.__init__ (self)
self.node = Node ()
self.node.register (0xa0, self.handle_asserv_0)
self.node.register (0xa8, self.handle_asserv_8)
+ self.node.register (self.IO_JACK, self.handle_IO_JACK)
+ self.node.register (self.IO_COLOR, self.handle_IO_COLOR)
+ self.node.register (self.IO_SERVO, self.handle_IO_SERVO)
self.tk.createfilehandler (self.node, READABLE, self.read)
self.step_after = None
@@ -102,6 +110,21 @@ class InterNode (Inter):
self.actuatorview.arm.angle = float (a) / 1024
self.update (self.actuatorview.arm)
+ def handle_IO_JACK (self, msg):
+ m = Msg (self.IO_JACK)
+ m.push ('B', self.jackVar.get ())
+ self.node.response (m)
+
+ def handle_IO_COLOR (self, msg):
+ m = Msg (self.IO_COLOR)
+ m.push ('B', self.colorVar.get ())
+ self.node.response (m)
+
+ def handle_IO_SERVO (self, msg):
+ for t in self.actuatorview.rear.traps:
+ t.pos = float (msg.pop ('B')[0]) / 255
+ self.update (self.actuatorview.rear)
+
if __name__ == '__main__':
import mex.hub
import mex.forked