summaryrefslogtreecommitdiff
path: root/digital/ai/tools
diff options
context:
space:
mode:
authorNicolas Schodet2012-03-26 01:01:02 +0200
committerNicolas Schodet2012-03-26 01:01:02 +0200
commitb205ee5bcb6adacf9b23448bf17ee0ff8bd16ae3 (patch)
tree6bdd15258808a9c10a327d5ffeaba9dd661ccdb0 /digital/ai/tools
parentc912f3edd803e4d8e6664e360590a0a538fbc7e5 (diff)
digital/{ai, io-hub}, host/simu/robots: add guybrush
Still use robospierre parameters for asserv and mimot
Diffstat (limited to 'digital/ai/tools')
-rw-r--r--digital/ai/tools/guybrush.py46
-rw-r--r--digital/ai/tools/test_simu.py3
-rw-r--r--digital/ai/tools/test_simu_control_guybrush.py72
3 files changed, 121 insertions, 0 deletions
diff --git a/digital/ai/tools/guybrush.py b/digital/ai/tools/guybrush.py
new file mode 100644
index 00000000..d5124e9b
--- /dev/null
+++ b/digital/ai/tools/guybrush.py
@@ -0,0 +1,46 @@
+import asserv
+import asserv.init
+import mimot
+import mimot.init
+import io_hub
+import io_hub.init
+
+from proto.popen_io import PopenIO
+import math
+
+class Robot:
+ """Guybrush robot instance."""
+
+ import simu.model.table_eurobot2012 as table_model
+ import simu.view.table_eurobot2012 as table_view
+
+ import simu.robots.guybrush.link.bag as robot_link
+ import simu.robots.guybrush.model.bag as robot_model
+ import simu.robots.guybrush.view.bag as robot_view
+
+ robot_start_pos = {
+ False: (300, 2000 - 200, math.radians (180)),
+ True: (3000 - 300, 2000 - 200, math.radians (0))
+ }
+
+ client_nb = 3
+
+ def __init__ (self, proto_time, instance = 'robot0'):
+ self.instance = instance
+ def proto (proto_class, cmd, init):
+ cmd = [ s.format (instance = instance) for s in cmd ]
+ return proto_class (PopenIO (cmd), proto_time, **init)
+ asserv_cmd = ('../../asserv/src/asserv/asserv.host',
+ '-i{instance}:asserv0', '-m9', 'robospierre')
+ mimot_cmd = ('../../mimot/src/dirty/dirty.host',
+ '-i{instance}:mimot0', '-m9', 'robospierre')
+ io_hub_cmd = ('../../io-hub/src/guybrush/io_hub.host',
+ '-i{instance}:io0')
+ self.asserv = proto (asserv.Proto, asserv_cmd,
+ asserv.init.host['robospierre'])
+ self.mimot = proto (mimot.Proto, mimot_cmd,
+ mimot.init.host['robospierre'])
+ self.io = proto (io_hub.ProtoGuybrush, io_hub_cmd,
+ io_hub.init.host['guybrush'])
+ self.protos = (self.asserv, self.mimot, self.io)
+
diff --git a/digital/ai/tools/test_simu.py b/digital/ai/tools/test_simu.py
index 1b804e22..c5655f87 100644
--- a/digital/ai/tools/test_simu.py
+++ b/digital/ai/tools/test_simu.py
@@ -128,6 +128,9 @@ def run (default_robot, test_class = TestSimu):
elif options.robot == 'robospierre':
import robospierre
robot = robospierre.Robot
+ elif options.robot == 'guybrush':
+ import guybrush
+ robot = guybrush.Robot
else:
parser.error ("unknown robot")
app = test_class (robot, options.robot_nb)
diff --git a/digital/ai/tools/test_simu_control_guybrush.py b/digital/ai/tools/test_simu_control_guybrush.py
new file mode 100644
index 00000000..9170b838
--- /dev/null
+++ b/digital/ai/tools/test_simu_control_guybrush.py
@@ -0,0 +1,72 @@
+# io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+#
+# 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.
+#
+# }}}
+from test_simu import TestSimu, run
+from Tkinter import *
+import math
+
+class TestSimuControl (TestSimu):
+ """Interface with extra control."""
+
+ def __init__ (self, robot_class, *args):
+ TestSimu.__init__ (self, robot_class, *args, color_switch = False)
+ self.io = self.robots[0].io
+ self.asserv = self.robots[0].asserv
+ self.mimot = self.robots[0].mimot
+ self.robot_model = self.robots[0].model
+
+ def create_widgets (self):
+ TestSimu.create_widgets (self)
+ self.control_frame = Frame (self)
+ self.control_frame.pack (side = 'left', before = self.table_view,
+ fill = 'y')
+ self.backward_var = IntVar ()
+ self.backward_button = Checkbutton (self.control_frame,
+ text = 'Backward', variable = self.backward_var)
+ self.backward_button.pack ()
+ self.goto_var = IntVar ()
+ self.goto_button = Checkbutton (self.control_frame,
+ text = 'Goto FSM', variable = self.goto_var)
+ self.goto_button.pack ()
+ self.table_view.bind ('<1>', self.move)
+ self.table_view.bind ('<3>', self.orient)
+
+ def move (self, ev):
+ pos = self.table_view.screen_coord ((ev.x, ev.y))
+ if self.goto_var.get ():
+ self.io.goto (pos[0], pos[1], self.backward_var.get ())
+ else:
+ self.asserv.goto (pos[0], pos[1], self.backward_var.get ())
+
+ def orient (self, ev):
+ x, y = self.table_view.screen_coord ((ev.x, ev.y))
+ robot_pos = self.robot_model.position.pos
+ if robot_pos is not None:
+ a = math.atan2 (y - robot_pos[1], x - robot_pos[0])
+ self.asserv.goto_angle (a)
+
+ def change_color (self, *dummy):
+ pass
+
+if __name__ == '__main__':
+ run ('guybrush', TestSimuControl)