summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-21 00:33:59 +0100
committerNicolas Schodet2013-03-21 00:33:59 +0100
commit32c28a77698a34f7fb5f0499553db05321afa9b5 (patch)
tree75a8495742044c21763bf2009c522d2e5cee76f7
parent8e5af42aae242f6391d4b2aaef6df156dbd60bcb (diff)
digital/io-hub/src: add general and playground definitions
-rw-r--r--digital/io-hub/src/apbirthday/main.cc4
-rw-r--r--digital/io-hub/src/common-cc/debug.host.hh34
-rw-r--r--digital/io-hub/src/common-cc/defs.hh72
-rw-r--r--digital/io-hub/src/common-cc/playground.hh86
4 files changed, 196 insertions, 0 deletions
diff --git a/digital/io-hub/src/apbirthday/main.cc b/digital/io-hub/src/apbirthday/main.cc
index f6f244f7..bea4ceec 100644
--- a/digital/io-hub/src/apbirthday/main.cc
+++ b/digital/io-hub/src/apbirthday/main.cc
@@ -24,12 +24,16 @@
#include "ucoolib/arch/arch.hh"
#include "ucoolib/common.hh"
#include "robot.hh"
+#include "defs.hh"
extern "C" {
#define ANGFSM_NAME AI
#include "angfsm.h"
}
+/// Global team color.
+TeamColor team_color = TEAM_COLOR_UNKNOWN;
+
int
main (int argc, const char **argv)
{
diff --git a/digital/io-hub/src/common-cc/debug.host.hh b/digital/io-hub/src/common-cc/debug.host.hh
new file mode 100644
index 00000000..e64dff45
--- /dev/null
+++ b/digital/io-hub/src/common-cc/debug.host.hh
@@ -0,0 +1,34 @@
+#ifndef debug_host_hh
+#define debug_host_hh
+// io-hub - Modular Input/Output. {{{
+//
+// Copyright (C) 2013 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.
+//
+// }}}
+
+/// Assert only on host, for costly asserts.
+#ifdef TARGET_host
+# define host_assert ucoo::assert
+#else
+# define host_assert(x)
+#endif
+
+#endif // debug_host_hh
diff --git a/digital/io-hub/src/common-cc/defs.hh b/digital/io-hub/src/common-cc/defs.hh
new file mode 100644
index 00000000..4475b299
--- /dev/null
+++ b/digital/io-hub/src/common-cc/defs.hh
@@ -0,0 +1,72 @@
+#ifndef defs_hh
+#define defs_hh
+// io-hub - Modular Input/Output. {{{
+//
+// Copyright (C) 2013 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.
+//
+// }}}
+
+/// General purpose definitions.
+
+extern "C" {
+#include "modules/math/geometry/geometry.h"
+#include "modules/math/geometry/vect.h"
+}
+
+/// Position with an angle.
+struct Position
+{
+ /// Cartesian position in millimeters, (0, 0) is at bottom left.
+ vect_t v;
+ /// Angle, counter-clockwise, [0, 1), f0.16.
+ /// For example, 0x8000 means 0.5, which means 180 degrees.
+ uint16_t a;
+};
+
+/// Convert degrees to an angle usable in Position.
+#define POSITION_A_DEG(a) G_ANGLE_UF016_DEG (a)
+
+/// Moving direction.
+enum Direction
+{
+ /// No direction or unknown.
+ DIRECTION_NONE,
+ /// Forward direction, along the robot X axis.
+ DIRECTION_FORWARD,
+ /// Backward direction, opposite to the robot X axis.
+ DIRECTION_BACKWARD,
+};
+
+/// Team color, determine the start zone side.
+enum TeamColor
+{
+ /// Start on the right side, every coordinates are mirrored.
+ TEAM_COLOR_RIGHT = 0,
+ /// Start on the left side.
+ TEAM_COLOR_LEFT = 1,
+ /// Initial value, should never be read.
+ TEAM_COLOR_UNKNOWN = 2
+};
+
+/// Current team color, sampled early during the setup stage.
+extern TeamColor team_color;
+
+#endif // defs_hh
diff --git a/digital/io-hub/src/common-cc/playground.hh b/digital/io-hub/src/common-cc/playground.hh
new file mode 100644
index 00000000..e8abfc40
--- /dev/null
+++ b/digital/io-hub/src/common-cc/playground.hh
@@ -0,0 +1,86 @@
+#ifndef playground_hh
+#define playground_hh
+// io-hub - Modular Input/Output. {{{
+//
+// Copyright (C) 2013 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 "defs.hh"
+#include "debug.host.hh"
+
+/// Define playground constants and tools.
+
+/// Playground width, mm.
+static const int pg_width = 3000;
+
+/// Playground length, mm.
+static const int pg_length = 2000;
+
+/// Distance to playground borders for general movements, mm.
+static const int pg_border_distance = 250;
+
+/// Return mirror X coordinate, using a horizontal symmetry.
+#define PG_MIRROR_X(x) (pg_width - (x))
+
+/// Return X coordinate, applying symmetry according to team color.
+static inline int
+pg_x (int x)
+{
+ host_assert (team_color != TEAM_COLOR_UNKNOWN);
+ return team_color ? x : PG_MIRROR_X (x);
+}
+
+/// Same as pg_y, but for Y coordinate. Actually nothing is done, there is no
+/// symmetry.
+static inline int
+pg_y (int y)
+{
+ return y;
+}
+
+/// Return an angle, applying symmetry according to team color. Takes degrees
+/// as input.
+static inline uint16_t
+pg_a_deg (double a)
+{
+ host_assert (team_color != TEAM_COLOR_UNKNOWN);
+ return team_color ? POSITION_A_DEG (a) : POSITION_A_DEG (180 - a);
+}
+
+/// Position applying symmetry according to color. Takes degrees for angle.
+static inline Position pg_position_deg (int x, int y, double a)
+{
+ host_assert (team_color != TEAM_COLOR_UNKNOWN);
+ if (team_color)
+ return (Position) { { (int16_t) x, (int16_t) y },
+ POSITION_A_DEG (a) };
+ else
+ return (Position) { { (int16_t) PG_MIRROR_X (x), (int16_t) y },
+ POSITION_A_DEG (180 - a) };
+}
+
+/// Vector applying symmetry according to color.
+static inline vect_t pg_vect (int x, int y)
+{
+ return (vect_t) { (int16_t) pg_x (x), (int16_t) pg_y (y) };
+}
+
+#endif // playground_hh