summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2012-03-27 01:02:35 +0200
committerNicolas Schodet2012-03-27 01:02:35 +0200
commit2e74c3d0afcb7552295032b9292e65d8d688117e (patch)
tree91e063ef83a194511bf90d2a2470704d2296fc7a /digital
parentf4de6d5292e305e2729687e345f5c2d97121652d (diff)
digital/io-hub/src/guybrush: add outputs
Diffstat (limited to 'digital')
-rw-r--r--digital/io-hub/src/guybrush/Makefile1
-rw-r--r--digital/io-hub/src/guybrush/main.c19
-rw-r--r--digital/io-hub/src/guybrush/output_defs.h51
-rw-r--r--digital/io-hub/src/guybrush/simu.host.c5
-rw-r--r--digital/io-hub/src/guybrush/simu.host.h2
5 files changed, 76 insertions, 2 deletions
diff --git a/digital/io-hub/src/guybrush/Makefile b/digital/io-hub/src/guybrush/Makefile
index 535fba17..74423423 100644
--- a/digital/io-hub/src/guybrush/Makefile
+++ b/digital/io-hub/src/guybrush/Makefile
@@ -7,6 +7,7 @@ io_hub_SOURCES = main.c top.c \
radar_defs.c radar.c path.c move.c \
init.c fsm.host.c fsm_AI_gen.avr.c fsm_queue.c \
contact.avr.c contact.host.c \
+ output.c output.host.c \
twi_master.c asserv.c mimot.c \
chrono.c timer.avr.c simu.host.c
# Modules needed for IO.
diff --git a/digital/io-hub/src/guybrush/main.c b/digital/io-hub/src/guybrush/main.c
index 92f9c33b..5daa2a30 100644
--- a/digital/io-hub/src/guybrush/main.c
+++ b/digital/io-hub/src/guybrush/main.c
@@ -39,6 +39,7 @@
#include "twi_master.h"
#include "contact.h"
+#include "output.h"
#include "radar.h"
#define FSM_NAME AI
@@ -99,6 +100,7 @@ main_init (void)
twi_master_init ();
/* IO modules. */
contact_init ();
+ output_init ();
usdist_init ();
/* AI modules. */
path_init ();
@@ -243,6 +245,23 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
break;
/* Stats commands.
* - b: interval between stats. */
+ case c ('o', 5):
+ /* Set/clear outputs.
+ * - 1d: mask.
+ * - 1b: 01 to set, 00 to clear. */
+ {
+ uint32_t mask = v8_to_v32 (args[0], args[1], args[2], args[3]);
+ if (args[4] == 0)
+ output_clear (mask);
+ else if (args[4] == 1)
+ output_set (mask);
+ else
+ {
+ proto_send0 ('?');
+ return;
+ }
+ }
+ break;
case c ('A', 1):
/* Position stats. */
main_stats_asserv_ = main_stats_asserv_cpt_ = args[0];
diff --git a/digital/io-hub/src/guybrush/output_defs.h b/digital/io-hub/src/guybrush/output_defs.h
new file mode 100644
index 00000000..c24bbd9c
--- /dev/null
+++ b/digital/io-hub/src/guybrush/output_defs.h
@@ -0,0 +1,51 @@
+#ifndef output_defs_h
+#define output_defs_h
+/* output_defs.h */
+/* guybrush - Eurobot 2012 AI. {{{
+ *
+ * Copyright (C) 2012 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.
+ *
+ * }}} */
+
+#define OUTPUT_PNEUM_OPEN A, 6
+#define OUTPUT_UPPER_CLAMP_OPEN C, 1
+#define OUTPUT_UPPER_CLAMP_OUT C, 3
+#define OUTPUT_UPPER_CLAMP_IN C, 5
+#define OUTPUT_UPPER_CLAMP_DOWN C, 2
+#define OUTPUT_UPPER_CLAMP_UP C, 4
+#define OUTPUT_DOOR_OPEN C, 7
+#define OUTPUT_DOOR_CLOSE C, 6
+#define OUTPUT_LOWER_CLAMP_1_OPEN A, 5
+#define OUTPUT_LOWER_CLAMP_2_OPEN F, 5
+
+#define OUTPUT_LIST \
+ OUTPUT (OUTPUT_PNEUM_OPEN, 0) \
+ OUTPUT (OUTPUT_UPPER_CLAMP_OPEN, 0) \
+ OUTPUT (OUTPUT_UPPER_CLAMP_OUT, 0) \
+ OUTPUT (OUTPUT_UPPER_CLAMP_IN, 0) \
+ OUTPUT (OUTPUT_UPPER_CLAMP_DOWN, 0) \
+ OUTPUT (OUTPUT_UPPER_CLAMP_UP, 0) \
+ OUTPUT (OUTPUT_DOOR_OPEN, 0) \
+ OUTPUT (OUTPUT_DOOR_CLOSE, 0) \
+ OUTPUT (OUTPUT_LOWER_CLAMP_1_OPEN, 0) \
+ OUTPUT (OUTPUT_LOWER_CLAMP_2_OPEN, 0) \
+
+#endif /* output_defs_h */
diff --git a/digital/io-hub/src/guybrush/simu.host.c b/digital/io-hub/src/guybrush/simu.host.c
index 6e523228..46c2a8fd 100644
--- a/digital/io-hub/src/guybrush/simu.host.c
+++ b/digital/io-hub/src/guybrush/simu.host.c
@@ -23,6 +23,7 @@
*
* }}} */
#include "common.h"
+#include "output.h"
#include "simu.host.h"
#include "modules/utils/utils.h"
@@ -33,7 +34,7 @@
#include "io.h"
/** AVR registers. */
-uint8_t PORTA, DDRA, PINA, PINE, PINF;
+uint8_t PORTA, PORTC, PORTF, DDRA, DDRC, DDRF, PINA, PINE, PINF;
/** Message types. */
uint8_t simu_mex_pos_report;
@@ -59,12 +60,14 @@ simu_init (void)
mex_node_register (mtype, simu_adc_handle, 0);
simu_mex_pos_report = mex_node_reservef ("%s:pos-report", mex_instance);
simu_mex_path = mex_node_reservef ("%s:path", mex_instance);
+ output_host_init ();
}
/** Make a simulation step. */
void
simu_step (void)
{
+ output_host_update ();
}
void
diff --git a/digital/io-hub/src/guybrush/simu.host.h b/digital/io-hub/src/guybrush/simu.host.h
index a419e857..d2b0da91 100644
--- a/digital/io-hub/src/guybrush/simu.host.h
+++ b/digital/io-hub/src/guybrush/simu.host.h
@@ -28,7 +28,7 @@
#ifdef HOST
-extern uint8_t PORTA, DDRA, PINA, PINE, PINF;
+extern uint8_t PORTA, PORTC, PORTF, DDRA, DDRC, DDRF, PINA, PINE, PINF;
/** Send general purpose positions to indicate computation results.
* - pos: array of positions to report.