From a62e936645808b33558168bd2225c96ad388740c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 19 Apr 2011 23:50:18 +0200 Subject: host/simu: add table for Eurobot 2011 --- host/simu/model/table_eurobot2011.py | 83 ++++++++++++++++++++++++ host/simu/view/table_eurobot2011.py | 120 +++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 host/simu/model/table_eurobot2011.py create mode 100644 host/simu/view/table_eurobot2011.py (limited to 'host/simu') diff --git a/host/simu/model/table_eurobot2011.py b/host/simu/model/table_eurobot2011.py new file mode 100644 index 00000000..c9c1d193 --- /dev/null +++ b/host/simu/model/table_eurobot2011.py @@ -0,0 +1,83 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2009 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. +# +# }}} +"""Table model for Eurobot 2011.""" +import simu.model.table +from random import randrange +from simu.model.round_obstacle import RoundObstacle + +class Table (simu.model.table.Table): + + def __init__ (self, cards = None): + simu.model.table.Table.__init__ (self) + # Draw cards. + if cards is None: + cards = [ randrange (20) for i in xrange (3) ] + self.cards = cards + def pos (card): + king_pos = card // 4 + queen_pos = card % 4 + if queen_pos >= king_pos: + queen_pos += 1 + return (king_pos, queen_pos) + # Well, this is a boring write only code which create every elements. + self.pawns = [ ] + # Put pawns in green zones. + green_pos = pos (cards[0]) + for i in xrange (5): + if i == green_pos[0]: + kind = 'king' + elif i == green_pos[1]: + kind = 'queen' + else: + kind = 'pawn' + pawn = RoundObstacle (100, 1) + pawn.pos = (200, 10 + 280 * (5 - i)) + pawn.kind = kind + self.pawns.append (pawn) + pawn = RoundObstacle (100, 1) + pawn.pos = (3000 - 200, 10 + 280 * (5 - i)) + pawn.kind = kind + self.pawns.append (pawn) + # Put pawns in playing zone. + kind = 'pawn' + for j in xrange (2): + play_pos = pos (cards[2 - j]) + for i in xrange (5): + if i in play_pos: + pawn = RoundObstacle (100, 1) + pawn.pos = (1500 - 350 * (1 + j), 350 * (5 - i)) + pawn.kind = kind + self.pawns.append (pawn) + pawn = RoundObstacle (100, 1) + pawn.pos = (1500 + 350 * (1 + j), 350 * (5 - i)) + pawn.kind = kind + self.pawns.append (pawn) + # Put center pawn. + kind = 'pawn' + pawn = RoundObstacle (100, 1) + pawn.pos = (1500, 350 * 3) + pawn.kind = kind + self.pawns.append (pawn) + # Add everything to obstacles. + self.obstacles += self.pawns diff --git a/host/simu/view/table_eurobot2011.py b/host/simu/view/table_eurobot2011.py new file mode 100644 index 00000000..64cb66d8 --- /dev/null +++ b/host/simu/view/table_eurobot2011.py @@ -0,0 +1,120 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2009 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. +# +# }}} +"""Eurobot 2011 table.""" +from simu.inter.drawable import Drawable +from simu.utils.trans_matrix import TransMatrix +from math import pi + +RED = '#cc0000' +BLUE = '#0000cc' +GREEN = '#006b00' +BLACK = '#181818' +YELLOW = '#cccc00' + +class Pawn (Drawable): + + def __init__ (self, onto, model): + Drawable.__init__ (self, onto) + self.model = model + self.model.register (self.__notified) + self.__notified () + + def __notified (self): + self.pos = self.model.pos + self.update () + + def draw (self): + self.reset () + if self.pos: + self.trans_translate (self.pos) + r = self.model.radius + self.draw_circle ((0, 0), r, fill = YELLOW) + if self.model.kind == 'king': + a = 0.1 * r + b = 0.5 * r + self.draw_line ((a, b), (a, a), (b, a), (b, -a), (a, -a), + (a, -b), (-a, -b), (-a, -a), (-b, -a), (-b, a), + (-a, a), (-a, b), (a, b)) + elif self.model.kind == 'queen': + self.draw_circle ((0, 0), 0.5 * r) + self.draw_circle ((0, 0), 0.4 * r) + Drawable.draw (self) + +class Table (Drawable): + """The table and its elements.""" + + def __init__ (self, onto, model): + Drawable.__init__ (self, onto) + self.model = model + for e in model.pawns: + Pawn (self, e) + + def draw_both (self, primitive, *args, **kargs): + """Draw a primitive on both sides.""" + primitive (*args, **kargs) + primitive (*((3000 - x, y) for x, y in args), **kargs) + + def draw (self): + # Redraw. + self.reset () + # Table. + self.draw_rectangle ((-22, -22), (3000 + 22, 2100 + 22), fill = BLACK) + self.draw_rectangle ((0, 0), (3000, 2100), fill = BLACK) + self.draw_both (self.draw_rectangle, (0, 0), (400, 2100 - 400 - 22), fill = GREEN) + self.draw_rectangle ((0, 2100 - 400), (400, 2100), fill = RED) + self.draw_rectangle ((0, 2100 - 400 - 22), (400, 2100 - 400), fill = RED) + self.draw_rectangle ((3000, 2100 - 400), (3000 - 400, 2100), fill = BLUE) + self.draw_rectangle ((3000, 2100 - 400 - 22), (3000 - 400, 2100 - 400), fill = BLUE) + self.draw_rectangle ((1500 - 3 * 350, 0), (1500 + 3 * 350, 2100), fill = BLUE) + for i in xrange (-3, 3): + for j in xrange (0, 6): + if (i + j) % 2: + self.draw_rectangle ((1500 + i * 350, j * 350), + (1850 + i * 350, 350 + j * 350), fill = RED) + # Bonus. + for i, j in ((0, 0), (1, 2), (1, 4)): + self.draw_circle ((1500 - 175 - i * 350, 175 + j * 350), 50, fill = BLACK) + self.draw_circle ((1500 + 175 + i * 350, 175 + j * 350), 50, fill = BLACK) + # Protected zones. + self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 0), (1500 - 350, 120), fill = BLACK) + self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 120), (1500 - 3 * 350 + 22, 120 + 130), fill = BLACK) + self.draw_both (self.draw_rectangle, (1500 - 350, 120), (1500 - 350 - 22, 120 + 130), fill = BLACK) + self.draw_both (self.draw_rectangle, (1500 - 350, 120 + 130), (1500 - 350 - 20, 350), fill = BLACK) + self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 350 - 20), (1500 - 350, 350), fill = BLACK) + # Axes. + self.draw_line ((0, 200), (0, 0), (200, 0), arrow = 'both') + # Beacons. + self.draw_both (self.draw_rectangle, (-22, 2100 + 22), (-22 - 80, 2100 + 22 + 80), fill = BLACK) + self.draw_both (self.draw_rectangle, (-22, 1050 - 40), (-22 - 80, 1050 + 40), fill = BLACK) + self.draw_both (self.draw_rectangle, (-22, -80 - 22), (-22 - 80, -22), fill = BLACK) + # Children. + Drawable.draw (self) + +if __name__ == '__main__': + from simu.inter.inter import Inter + import simu.model.table_eurobot2011 as model + app = Inter () + m = model.Table () + Table (app.table_view, m) + app.mainloop () -- cgit v1.2.3 From b0ef2ecc8467319f27fd5de45c0bc9906013147b Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 28 Apr 2011 22:08:31 +0200 Subject: host/simu: add transformation matrix push/pop --- host/simu/inter/drawable.py | 2 ++ host/simu/utils/trans_matrix.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'host/simu') diff --git a/host/simu/inter/drawable.py b/host/simu/inter/drawable.py index bcf1823f..af7c62a2 100644 --- a/host/simu/inter/drawable.py +++ b/host/simu/inter/drawable.py @@ -43,6 +43,8 @@ class Drawable: self.trans_translate = self.__trans_matrix.translate self.trans_scale = self.__trans_matrix.scale self.trans_identity = self.__trans_matrix.identity + self.trans_push = self.__trans_matrix.push + self.trans_pop = self.__trans_matrix.pop self.__children = [ ] self.children = self.__children self.__onto.__children.append (self) diff --git a/host/simu/utils/trans_matrix.py b/host/simu/utils/trans_matrix.py index 99ffe707..12bc7b35 100644 --- a/host/simu/utils/trans_matrix.py +++ b/host/simu/utils/trans_matrix.py @@ -47,6 +47,7 @@ class TransMatrix: self.matrix = m else: self.matrix = self.IDENTITY + self.stack = [ ] def identity (self): """Set to identity. @@ -163,6 +164,25 @@ class TransMatrix: vl = sqrt (v[0] ** 2 + v[1] ** 2) return vl + def push (self): + """Save the current value to be poped later. + + >>> a = TransMatrix () + >>> a.translate ((2, 3)); a + ((1, 0), (0, 1), (2, 3)) + >>> a.push () + >>> a.scale (2); a + ((2, 0), (0, 2), (4, 6)) + >>> a.pop () + >>> a + ((1, 0), (0, 1), (2, 3)) + """ + self.stack.append (self.matrix) + + def pop (self): + """Restore saved value, see push.""" + self.matrix = self.stack.pop () + def __repr__ (self): return self.matrix.__repr__ () -- cgit v1.2.3 From 6abca0d890c2040e77eeaadf675cc4804196a0f0 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 28 Apr 2011 22:09:30 +0200 Subject: host/simu/view/table_eurobot2011: clearer colors --- host/simu/view/table_eurobot2011.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'host/simu') diff --git a/host/simu/view/table_eurobot2011.py b/host/simu/view/table_eurobot2011.py index 64cb66d8..5e67b9e7 100644 --- a/host/simu/view/table_eurobot2011.py +++ b/host/simu/view/table_eurobot2011.py @@ -26,9 +26,9 @@ from simu.inter.drawable import Drawable from simu.utils.trans_matrix import TransMatrix from math import pi -RED = '#cc0000' -BLUE = '#0000cc' -GREEN = '#006b00' +RED = '#d42626' +BLUE = '#2626d4' +GREEN = '#268126' BLACK = '#181818' YELLOW = '#cccc00' -- cgit v1.2.3 From 022a832d4d7ea01ea888f47ba7ca1cc1536b74d1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 28 Apr 2011 22:10:16 +0200 Subject: host/simu/view/table_eurobot2011: move pawn drawing to function --- host/simu/view/table_eurobot2011.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'host/simu') diff --git a/host/simu/view/table_eurobot2011.py b/host/simu/view/table_eurobot2011.py index 5e67b9e7..787c9359 100644 --- a/host/simu/view/table_eurobot2011.py +++ b/host/simu/view/table_eurobot2011.py @@ -32,6 +32,18 @@ GREEN = '#268126' BLACK = '#181818' YELLOW = '#cccc00' +def draw_pawn (d, radius, kind): + d.draw_circle ((0, 0), radius, fill = YELLOW) + if kind == 'king': + a = 0.1 * radius + b = 0.5 * radius + d.draw_line ((a, b), (a, a), (b, a), (b, -a), (a, -a), (a, -b), + (-a, -b), (-a, -a), (-b, -a), (-b, a), (-a, a), (-a, b), + (a, b)) + elif kind == 'queen': + d.draw_circle ((0, 0), 0.5 * radius) + d.draw_circle ((0, 0), 0.4 * radius) + class Pawn (Drawable): def __init__ (self, onto, model): @@ -48,17 +60,7 @@ class Pawn (Drawable): self.reset () if self.pos: self.trans_translate (self.pos) - r = self.model.radius - self.draw_circle ((0, 0), r, fill = YELLOW) - if self.model.kind == 'king': - a = 0.1 * r - b = 0.5 * r - self.draw_line ((a, b), (a, a), (b, a), (b, -a), (a, -a), - (a, -b), (-a, -b), (-a, -a), (-b, -a), (-b, a), - (-a, a), (-a, b), (a, b)) - elif self.model.kind == 'queen': - self.draw_circle ((0, 0), 0.5 * r) - self.draw_circle ((0, 0), 0.4 * r) + draw_pawn (self, self.model.radius, self.model.kind) Drawable.draw (self) class Table (Drawable): -- cgit v1.2.3 From de2a1e81eef5054725ae218afaf51dc8e06dedd0 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 28 Apr 2011 22:57:03 +0200 Subject: host/simu/view: remove useless import --- host/simu/view/table_eurobot2010.py | 1 - host/simu/view/table_eurobot2011.py | 1 - 2 files changed, 2 deletions(-) (limited to 'host/simu') diff --git a/host/simu/view/table_eurobot2010.py b/host/simu/view/table_eurobot2010.py index 2ef8de1f..4beb8be8 100644 --- a/host/simu/view/table_eurobot2010.py +++ b/host/simu/view/table_eurobot2010.py @@ -23,7 +23,6 @@ # }}} """Eurobot 2010 table.""" from simu.inter.drawable import Drawable -from simu.utils.trans_matrix import TransMatrix from math import pi GREEN = '#00ad00' diff --git a/host/simu/view/table_eurobot2011.py b/host/simu/view/table_eurobot2011.py index 787c9359..f0a65ce1 100644 --- a/host/simu/view/table_eurobot2011.py +++ b/host/simu/view/table_eurobot2011.py @@ -23,7 +23,6 @@ # }}} """Eurobot 2011 table.""" from simu.inter.drawable import Drawable -from simu.utils.trans_matrix import TransMatrix from math import pi RED = '#d42626' -- cgit v1.2.3 From 9c9f35753489cba5a61816104ac294857be20941 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 29 Apr 2011 20:35:20 +0200 Subject: host/simu: transpose transformation matrix, reverse transformation order This is better because transformations can be built incrementally from the container to the contained. This use the same semantic as OpenGL. --- host/inter/inter.py | 2 +- host/simu/inter/inter.py | 2 +- host/simu/inter/test/test_drawable.py | 4 ++-- host/simu/model/distance_sensor.py | 2 +- host/simu/robots/aquajim/model/sorter.py | 2 +- host/simu/robots/aquajim/view/robot.py | 2 +- host/simu/robots/giboulee/view/robot.py | 2 +- host/simu/robots/marcel/model/loader.py | 4 ++-- host/simu/robots/marcel/view/loader.py | 2 +- host/simu/robots/marcel/view/robot.py | 2 +- host/simu/utils/trans_matrix.py | 31 ++++++++++++++++++------------- host/simu/view/table_eurobot2009.py | 2 +- 12 files changed, 31 insertions(+), 26 deletions(-) (limited to 'host/simu') diff --git a/host/inter/inter.py b/host/inter/inter.py index 3f1effd4..f097f955 100644 --- a/host/inter/inter.py +++ b/host/inter/inter.py @@ -33,8 +33,8 @@ class Robot (Drawable): def draw (self): self.reset () if self.angle is not None: - self.trans_rotate (self.angle) self.trans_translate (self.pos) + self.trans_rotate (self.angle) self.draw_polygon ((115, 30), (170, 85), (150, 127), (130, 145), (-25, 200), (-70, 200), (-70, -200), (-25, -200), (130, -145), (150, -127), (170, -85), (115, -30)) diff --git a/host/simu/inter/inter.py b/host/simu/inter/inter.py index b8a889e5..8623885f 100644 --- a/host/simu/inter/inter.py +++ b/host/simu/inter/inter.py @@ -58,8 +58,8 @@ class ActuatorView (DrawableCanvas): self.resize (1, self.size, 0, self.size / 2) self.configure (width = self.UNIT, height = self.UNIT * self.size) d = Drawable (self) - d.trans_scale (1.0 / width) d.trans_translate ((0, - self.size + ratio / 2)) + d.trans_scale (1.0 / width) return d class Inter (Frame): diff --git a/host/simu/inter/test/test_drawable.py b/host/simu/inter/test/test_drawable.py index b977d36e..a9c1bfef 100644 --- a/host/simu/inter/test/test_drawable.py +++ b/host/simu/inter/test/test_drawable.py @@ -49,9 +49,9 @@ class App (DrawableCanvas): # Real user should reset at each redraw. self.after (500, self.animate) self.test.draw () - self.test.trans_rotate (-pi/12) - self.test.trans_translate ((10, 10)) self.test.trans_scale (1.05) + self.test.trans_translate ((10, 10)) + self.test.trans_rotate (-pi/12) self.i += 1 if self.i == 10: self.test.reset () diff --git a/host/simu/model/distance_sensor.py b/host/simu/model/distance_sensor.py index 3dc83f45..bdc8531d 100644 --- a/host/simu/model/distance_sensor.py +++ b/host/simu/model/distance_sensor.py @@ -46,8 +46,8 @@ class DistanceSensor: if i.pos is None: self.distance = None return - m.rotate (i.angle) m.translate (i.pos) + m.rotate (i.angle) pos, target = m.apply (pos, target) # Find intersection. i = self.table.intersect (pos, target, level = self.level, diff --git a/host/simu/robots/aquajim/model/sorter.py b/host/simu/robots/aquajim/model/sorter.py index e7b69761..93ff5e2a 100644 --- a/host/simu/robots/aquajim/model/sorter.py +++ b/host/simu/robots/aquajim/model/sorter.py @@ -58,8 +58,8 @@ class Sorter (Observable): for i in self.into: if i.pos is None: return None - m.rotate (i.angle) m.translate (i.pos) + m.rotate (i.angle) return m.apply (pos) def __arm_motor_notified (self): diff --git a/host/simu/robots/aquajim/view/robot.py b/host/simu/robots/aquajim/view/robot.py index ad613bba..aefe2170 100644 --- a/host/simu/robots/aquajim/view/robot.py +++ b/host/simu/robots/aquajim/view/robot.py @@ -42,8 +42,8 @@ class Robot (simu.inter.drawable.Drawable): """Draw the robot.""" self.reset () if self.pos is not None: - self.trans_rotate (self.angle) self.trans_translate (self.pos) + self.trans_rotate (self.angle) # Draw robot body. self.draw_polygon ((150, 155), (-90, 155), (-150, 70), (-150, -70), (-90, -155), (150, -155)) diff --git a/host/simu/robots/giboulee/view/robot.py b/host/simu/robots/giboulee/view/robot.py index ab1ffc6d..42ebe6fb 100644 --- a/host/simu/robots/giboulee/view/robot.py +++ b/host/simu/robots/giboulee/view/robot.py @@ -42,8 +42,8 @@ class Robot (simu.inter.drawable.Drawable): """Draw the robot.""" self.reset () if self.pos is not None: - self.trans_rotate (self.angle) self.trans_translate (self.pos) + self.trans_rotate (self.angle) # Draw robot body. self.draw_polygon ((115, 30), (170, 85), (150, 127), (130, 145), (-25, 200), (-70, 200), (-70, -200), (-25, -200), diff --git a/host/simu/robots/marcel/model/loader.py b/host/simu/robots/marcel/model/loader.py index 0270ce79..ae1caa7d 100644 --- a/host/simu/robots/marcel/model/loader.py +++ b/host/simu/robots/marcel/model/loader.py @@ -159,8 +159,8 @@ class Loader (Observable): # If gate is high, drop elements. if self.load and self.gate_angle > self.GATE_STROKE / 2: m = TransMatrix () - m.rotate (self.robot_position.angle) m.translate (self.robot_position.pos) + m.rotate (self.robot_position.angle) pos = m.apply ((-250, 0)) for e in self.load: e.pos = pos @@ -177,9 +177,9 @@ class Loader (Observable): return elements # Matrix to transform an obstacle position into robot coordinates. m = TransMatrix () + m.rotate (-self.robot_position.angle) m.translate ((-self.robot_position.pos[0], -self.robot_position.pos[1])) - m.rotate (-self.robot_position.angle) # Look up elements. # This could be used if clamp blocking is handled or elements are # pushed: diff --git a/host/simu/robots/marcel/view/loader.py b/host/simu/robots/marcel/view/loader.py index 5bda5d5b..d4ed336e 100644 --- a/host/simu/robots/marcel/view/loader.py +++ b/host/simu/robots/marcel/view/loader.py @@ -67,8 +67,8 @@ class Loader (Drawable): (300, 25 + 25 * i + (150 - 20 * i) * ratio)) if self.model.elevator_height is not None: self.trans_identity () - self.trans_rotate (-self.model.elevator_angle) self.trans_translate ((-100, -100 + self.model.elevator_height)) + self.trans_rotate (-self.model.elevator_angle) # Draw clamp load. if self.model.clamp_load: elements = self.model.clamp_load diff --git a/host/simu/robots/marcel/view/robot.py b/host/simu/robots/marcel/view/robot.py index 4e2135f2..67d505a2 100644 --- a/host/simu/robots/marcel/view/robot.py +++ b/host/simu/robots/marcel/view/robot.py @@ -52,8 +52,8 @@ class Robot (simu.inter.drawable.Drawable): """Draw the robot.""" self.reset () if self.pos is not None: - self.trans_rotate (self.angle) self.trans_translate (self.pos) + self.trans_rotate (self.angle) # Draw robot body. self.draw_polygon ((120, 155), (-95, 155), (-160, 90), (-160, -90), (-95, -155), (120, -155)) diff --git a/host/simu/utils/trans_matrix.py b/host/simu/utils/trans_matrix.py index 12bc7b35..1b582e1b 100644 --- a/host/simu/utils/trans_matrix.py +++ b/host/simu/utils/trans_matrix.py @@ -27,8 +27,13 @@ from math import sin, cos, sqrt, atan2 class TransMatrix: """Define a matrix to be used for transformations on the plane. - This is a "special" kind of matrix, because the last column is omitted as - it is always (0, 0, 1).""" + This is a "special" kind of matrix, because the last line is omitted as + it is always (0, 0, 1). + + First index is column, last index is line. + + Transformations are done from the last added to the first added, so that + it can be incrementally constructed for objects contained in others.""" IDENTITY = ((1, 0), (0, 1), (0, 0)) @@ -65,7 +70,7 @@ class TransMatrix: >>> from math import pi >>> a = TransMatrix () >>> a.rotate (pi / 3); a # doctest: +ELLIPSIS - ((0.5..., 0.866...), (-0.866..., 0.5...), (0.0, 0.0)) + ((0.5..., 0.866...), (-0.866..., 0.5...), (0, 0)) """ s = sin (angle) c = cos (angle) @@ -98,17 +103,17 @@ class TransMatrix: >>> a = TransMatrix ((1, 0), (0, 1), (1, 0)) >>> b = TransMatrix ((0, 1), (1, 0), (0, 1)) >>> a *= b; a - ((0, 1), (1, 0), (0, 2)) + ((0, 1), (1, 0), (1, 1)) """ s = self.matrix o = other.matrix self.matrix = ( - (s[0][0] * o[0][0] + s[0][1] * o[1][0], - s[0][0] * o[0][1] + s[0][1] * o[1][1]), - (s[1][0] * o[0][0] + s[1][1] * o[1][0], - s[1][0] * o[0][1] + s[1][1] * o[1][1]), - (s[2][0] * o[0][0] + s[2][1] * o[1][0] + o[2][0], - s[2][0] * o[0][1] + s[2][1] * o[1][1] + o[2][1])) + (s[0][0] * o[0][0] + s[1][0] * o[0][1], + s[0][1] * o[0][0] + s[1][1] * o[0][1]), + (s[0][0] * o[1][0] + s[1][0] * o[1][1], + s[0][1] * o[1][0] + s[1][1] * o[1][1]), + (s[0][0] * o[2][0] + s[1][0] * o[2][1] + s[2][0], + s[0][1] * o[2][0] + s[1][1] * o[2][1] + s[2][1])) return self def apply (self, *args): @@ -121,9 +126,9 @@ class TransMatrix: ((20, 40), (21, 42)) """ r = tuple ( - (i[0] * self.matrix[0][0] + i[1] * self.matrix[1][0] + (self.matrix[0][0] * i[0] + self.matrix[1][0] * i[1] + self.matrix[2][0], - i[0] * self.matrix[0][1] + i[1] * self.matrix[1][1] + self.matrix[0][1] * i[0] + self.matrix[1][1] * i[1] + self.matrix[2][1]) for i in args) if len (args) == 1: @@ -172,7 +177,7 @@ class TransMatrix: ((1, 0), (0, 1), (2, 3)) >>> a.push () >>> a.scale (2); a - ((2, 0), (0, 2), (4, 6)) + ((2, 0), (0, 2), (2, 3)) >>> a.pop () >>> a ((1, 0), (0, 1), (2, 3)) diff --git a/host/simu/view/table_eurobot2009.py b/host/simu/view/table_eurobot2009.py index 5e2d6db5..282b25a5 100644 --- a/host/simu/view/table_eurobot2009.py +++ b/host/simu/view/table_eurobot2009.py @@ -113,8 +113,8 @@ class Table (Drawable): ((3000 - 40, 1050 + ds), pi, GREEN), ): dtm = TransMatrix () - dtm.rotate (dangle) dtm.translate (dpos) + dtm.rotate (dangle) if dpos[1] == 40: a = 55 else: -- cgit v1.2.3 From 4909f63bea2598489a5895f9bbe1e2622093caa1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 30 Apr 2011 20:45:16 +0200 Subject: digital/io/tools, host/simu: add robospierre --- digital/io/tools/io/io.py | 2 +- digital/io/tools/robospierre.py | 39 +++++ digital/io/tools/test_simu.py | 3 + digital/io/tools/test_simu_control.py | 108 -------------- digital/io/tools/test_simu_control_marcel.py | 108 ++++++++++++++ digital/io/tools/test_simu_control_robospierre.py | 101 +++++++++++++ host/simu/robots/robospierre/__init__.py | 0 host/simu/robots/robospierre/link/__init__.py | 0 host/simu/robots/robospierre/link/bag.py | 35 +++++ host/simu/robots/robospierre/model/__init__.py | 0 host/simu/robots/robospierre/model/bag.py | 57 +++++++ host/simu/robots/robospierre/model/clamp.py | 172 ++++++++++++++++++++++ host/simu/robots/robospierre/view/__init__.py | 0 host/simu/robots/robospierre/view/bag.py | 48 ++++++ host/simu/robots/robospierre/view/clamp.py | 172 ++++++++++++++++++++++ host/simu/robots/robospierre/view/robot.py | 111 ++++++++++++++ 16 files changed, 847 insertions(+), 109 deletions(-) create mode 100644 digital/io/tools/robospierre.py delete mode 100644 digital/io/tools/test_simu_control.py create mode 100644 digital/io/tools/test_simu_control_marcel.py create mode 100644 digital/io/tools/test_simu_control_robospierre.py create mode 100644 host/simu/robots/robospierre/__init__.py create mode 100644 host/simu/robots/robospierre/link/__init__.py create mode 100644 host/simu/robots/robospierre/link/bag.py create mode 100644 host/simu/robots/robospierre/model/__init__.py create mode 100644 host/simu/robots/robospierre/model/bag.py create mode 100644 host/simu/robots/robospierre/model/clamp.py create mode 100644 host/simu/robots/robospierre/view/__init__.py create mode 100644 host/simu/robots/robospierre/view/bag.py create mode 100644 host/simu/robots/robospierre/view/clamp.py create mode 100644 host/simu/robots/robospierre/view/robot.py (limited to 'host/simu') diff --git a/digital/io/tools/io/io.py b/digital/io/tools/io/io.py index 87471bbd..375ad38d 100644 --- a/digital/io/tools/io/io.py +++ b/digital/io/tools/io/io.py @@ -53,7 +53,7 @@ class Proto: self.proto.send ('s', 'BB', servo, high_time) def pwm_set (self, value, timer): - self.proto.send ('w', 'Hh', value, timer) + self.proto.send ('w', 'hH', value, timer) def loader (self, command): self.proto.send ('c', 'c', command) diff --git a/digital/io/tools/robospierre.py b/digital/io/tools/robospierre.py new file mode 100644 index 00000000..948faa8c --- /dev/null +++ b/digital/io/tools/robospierre.py @@ -0,0 +1,39 @@ +import simu.model.table_eurobot2011 +import simu.view.table_eurobot2011 + +import simu.robots.robospierre.link.bag +import simu.robots.robospierre.model.bag +import simu.robots.robospierre.view.bag + +import asserv +import asserv.init +import mimot +import mimot.init +import io +import io.init + +from proto.popen_io import PopenIO +import math + +class Robot: + + def __init__ (self, proto_time): + self.table_model = simu.model.table_eurobot2011 + self.table_view = simu.view.table_eurobot2011 + self.robot_link = simu.robots.robospierre.link.bag + self.robot_model = simu.robots.robospierre.model.bag + self.robot_view = simu.robots.robospierre.view.bag + asserv_cmd = ('../../asserv/src/asserv/asserv.host', '-m9', 'marcel') + mimot_cmd = ('../../mimot/src/dirty/dirty.host', '-m9', 'marcel') + io_cmd = ('../src/io.host') + self.asserv = asserv.Proto (PopenIO (asserv_cmd), proto_time, + **asserv.init.host) + self.mimot = mimot.Proto (PopenIO (mimot_cmd), proto_time, + **mimot.init.host) + self.io = io.Proto (PopenIO (io_cmd), proto_time, + **io.init.host) + self.robot_start_pos = { + False: (700, 2100 - 250, math.radians (-270)), + True: (3000 - 700, 2100 - 250, math.radians (-270)) + } + diff --git a/digital/io/tools/test_simu.py b/digital/io/tools/test_simu.py index 36a5cb1b..80008bb9 100644 --- a/digital/io/tools/test_simu.py +++ b/digital/io/tools/test_simu.py @@ -138,6 +138,9 @@ def run (default_robot, test_class = TestSimu): if options.robot == 'marcel': import marcel robot = marcel.Robot + elif options.robot == 'robospierre': + import robospierre + robot = robospierre.Robot else: parser.error ("unknown robot") app = test_class (robot) diff --git a/digital/io/tools/test_simu_control.py b/digital/io/tools/test_simu_control.py deleted file mode 100644 index 2a43b7bb..00000000 --- a/digital/io/tools/test_simu_control.py +++ /dev/null @@ -1,108 +0,0 @@ -# io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{ -# -# Copyright (C) 2009 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): - TestSimu.__init__ (self, robot_class) - - 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.clamp_var = IntVar () - self.clamp_button = Checkbutton (self.control_frame, text = 'Clamp', - indicatoron = False, - variable = self.clamp_var, command = self.clamp_command) - self.clamp_button.pack () - self.elevator_var = IntVar () - self.elevator_button = Checkbutton (self.control_frame, - text = 'Elevator', indicatoron = False, - variable = self.elevator_var, command = self.elevator_command) - self.elevator_button.pack () - self.gate_var = IntVar () - self.gate_button = Checkbutton (self.control_frame, - text = 'Gate', indicatoron = False, - variable = self.gate_var, command = self.gate_command) - self.gate_button.pack () - self.loader_up_button = Button (self.control_frame, - text = 'Loader up', padx = 0, pady = 0, - command = self.loader_up_command) - self.loader_up_button.pack () - self.loader_down_button = Button (self.control_frame, - text = 'Loader down', padx = 0, pady = 0, - command = self.loader_down_command) - self.loader_down_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)) - self.asserv.goto (pos[0], pos[1]) - - 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 clamp_command (self): - if self.clamp_var.get (): - self.mimot.clamp ('a0', 0x60, 0x100) - self.mimot.clamp ('a1', 0x60, 0x100) - else: - self.mimot.goto_pos ('a0', 0) - self.mimot.goto_pos ('a1', 0) - - def elevator_command (self): - if self.elevator_var.get (): - pos = 7089 - else: - pos = 0 - self.asserv.goto_pos ('a0', pos) - - def gate_command (self): - if self.gate_var.get (): - pos = -0x1d6b - else: - pos = 0 - self.asserv.goto_pos ('a1', pos) - - def loader_up_command (self): - self.io.loader ('u') - - def loader_down_command (self): - self.io.loader ('d') - - def change_color (self, *dummy): - pass - -if __name__ == '__main__': - run ('marcel', TestSimuControl) diff --git a/digital/io/tools/test_simu_control_marcel.py b/digital/io/tools/test_simu_control_marcel.py new file mode 100644 index 00000000..2a43b7bb --- /dev/null +++ b/digital/io/tools/test_simu_control_marcel.py @@ -0,0 +1,108 @@ +# io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{ +# +# Copyright (C) 2009 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): + TestSimu.__init__ (self, robot_class) + + 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.clamp_var = IntVar () + self.clamp_button = Checkbutton (self.control_frame, text = 'Clamp', + indicatoron = False, + variable = self.clamp_var, command = self.clamp_command) + self.clamp_button.pack () + self.elevator_var = IntVar () + self.elevator_button = Checkbutton (self.control_frame, + text = 'Elevator', indicatoron = False, + variable = self.elevator_var, command = self.elevator_command) + self.elevator_button.pack () + self.gate_var = IntVar () + self.gate_button = Checkbutton (self.control_frame, + text = 'Gate', indicatoron = False, + variable = self.gate_var, command = self.gate_command) + self.gate_button.pack () + self.loader_up_button = Button (self.control_frame, + text = 'Loader up', padx = 0, pady = 0, + command = self.loader_up_command) + self.loader_up_button.pack () + self.loader_down_button = Button (self.control_frame, + text = 'Loader down', padx = 0, pady = 0, + command = self.loader_down_command) + self.loader_down_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)) + self.asserv.goto (pos[0], pos[1]) + + 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 clamp_command (self): + if self.clamp_var.get (): + self.mimot.clamp ('a0', 0x60, 0x100) + self.mimot.clamp ('a1', 0x60, 0x100) + else: + self.mimot.goto_pos ('a0', 0) + self.mimot.goto_pos ('a1', 0) + + def elevator_command (self): + if self.elevator_var.get (): + pos = 7089 + else: + pos = 0 + self.asserv.goto_pos ('a0', pos) + + def gate_command (self): + if self.gate_var.get (): + pos = -0x1d6b + else: + pos = 0 + self.asserv.goto_pos ('a1', pos) + + def loader_up_command (self): + self.io.loader ('u') + + def loader_down_command (self): + self.io.loader ('d') + + def change_color (self, *dummy): + pass + +if __name__ == '__main__': + run ('marcel', TestSimuControl) diff --git a/digital/io/tools/test_simu_control_robospierre.py b/digital/io/tools/test_simu_control_robospierre.py new file mode 100644 index 00000000..9da57196 --- /dev/null +++ b/digital/io/tools/test_simu_control_robospierre.py @@ -0,0 +1,101 @@ +# io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{ +# +# Copyright (C) 2011 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.""" + + ELEVATION_STROKE = 0x3b0b + + ROTATION_STROKE = 0x11c6 + + def __init__ (self, robot_class): + TestSimu.__init__ (self, robot_class) + + 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.clamp_var = IntVar () + self.clamp_var.set (1) + self.clamp_button = Checkbutton (self.control_frame, text = 'Clamp', + indicatoron = False, + variable = self.clamp_var, command = self.clamp_command) + self.clamp_button.pack () + self.elevation_up_button = Button (self.control_frame, + text = 'Elevation up', padx = 0, pady = 0, + command = self.elevation_up_command) + self.elevation_up_button.pack () + self.elevation_down_button = Button (self.control_frame, + text = 'Elevation down', padx = 0, pady = 0, + command = self.elevation_down_command) + self.elevation_down_button.pack () + self.rotation_cw_button = Button (self.control_frame, + text = 'Rotation cw', padx = 0, pady = 0, + command = self.rotation_cw_command) + self.rotation_cw_button.pack () + self.rotation_ccw_button = Button (self.control_frame, + text = 'Rotation ccw', padx = 0, pady = 0, + command = self.rotation_ccw_command) + self.rotation_ccw_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)) + self.asserv.goto (pos[0], pos[1]) + + 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 clamp_command (self): + if self.clamp_var.get (): + self.io.pwm_set (-0x7fff, 255) + else: + self.io.pwm_set (0x7fff, 255) + + def elevation_up_command (self): + self.mimot.speed_pos ('a0', self.ELEVATION_STROKE / 2) + + def elevation_down_command (self): + self.mimot.speed_pos ('a0', -self.ELEVATION_STROKE / 2) + + def rotation_cw_command (self): + self.mimot.speed_pos ('a1', self.ROTATION_STROKE / 2) + + def rotation_ccw_command (self): + self.mimot.speed_pos ('a1', -self.ROTATION_STROKE / 2) + + def change_color (self, *dummy): + pass + +if __name__ == '__main__': + run ('robospierre', TestSimuControl) diff --git a/host/simu/robots/robospierre/__init__.py b/host/simu/robots/robospierre/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/host/simu/robots/robospierre/link/__init__.py b/host/simu/robots/robospierre/link/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/host/simu/robots/robospierre/link/bag.py b/host/simu/robots/robospierre/link/bag.py new file mode 100644 index 00000000..2760aec0 --- /dev/null +++ b/host/simu/robots/robospierre/link/bag.py @@ -0,0 +1,35 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre bag of links.""" +import io.mex +import asserv.mex +import mimot.mex + +class Bag: + + def __init__ (self, node): + self.asserv = asserv.mex.Mex (node) + self.io = io.mex.Mex (node) + self.mimot = mimot.mex.Mex (node) + diff --git a/host/simu/robots/robospierre/model/__init__.py b/host/simu/robots/robospierre/model/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/host/simu/robots/robospierre/model/bag.py b/host/simu/robots/robospierre/model/bag.py new file mode 100644 index 00000000..e6810e18 --- /dev/null +++ b/host/simu/robots/robospierre/model/bag.py @@ -0,0 +1,57 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre bag of models.""" +from simu.model.switch import Switch +from simu.model.position import Position +from simu.model.motor_basic import MotorBasic +from simu.model.distance_sensor_sensopart import DistanceSensorSensopart +from simu.robots.robospierre.model.clamp import Clamp +from math import pi + +class Bag: + + def __init__ (self, scheduler, table, link_bag): + self.jack = Switch (link_bag.io.jack) + self.color_switch = Switch (link_bag.io.color_switch) + self.contact = [ Switch (contact) for contact in link_bag.io.contact ] + self.position = Position (link_bag.asserv.position) + self.clamping_motor = MotorBasic (link_bag.io.pwm[0], scheduler, + 2 * pi, 0, pi) + self.clamp = Clamp (table, self.position, link_bag.mimot.aux[0], + link_bag.mimot.aux[1], self.clamping_motor) + self.distance_sensor = [ + DistanceSensorSensopart (link_bag.io.adc[0], scheduler, table, + (20, -20), -pi * 10 / 180, (self.position, ), 2), + DistanceSensorSensopart (link_bag.io.adc[1], scheduler, table, + (20, 20), pi * 10 / 180, (self.position, ), 2), + DistanceSensorSensopart (link_bag.io.adc[2], scheduler, table, + (-20, 20), pi - pi * 10 / 180, (self.position, ), 2), + DistanceSensorSensopart (link_bag.io.adc[3], scheduler, table, + (-20, -20), pi + pi * 10 / 180, (self.position, ), 2), + ] + link_bag.io.adc[4].value = 0 + link_bag.io.adc[5].value = 0 + self.path = link_bag.io.path + self.pos_report = link_bag.io.pos_report + diff --git a/host/simu/robots/robospierre/model/clamp.py b/host/simu/robots/robospierre/model/clamp.py new file mode 100644 index 00000000..ff27a7ea --- /dev/null +++ b/host/simu/robots/robospierre/model/clamp.py @@ -0,0 +1,172 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre clamp.""" +from utils.observable import Observable +from simu.utils.trans_matrix import TransMatrix +from math import pi, cos, sin + +class Slot: + """Slot which can contain a pawn.""" + + def __init__ (self, x, y, z, side): + self.x = x + self.y = y + self.z = z + self.side = side + self.pawn = None + +class Clamp (Observable): + + ELEVATION_STROKE = 120.0 + ELEVATION_MOTOR_STROKE = 120.0 * 5.0 / 6.0 + + ROTATION_STROKE = pi + ROTATION_MOTOR_STROKE = pi * 115.0 / 12.0 + + CLAMPING_STROKE = 10 + CLAMPING_MOTOR_STROKE = pi + + BAY_OFFSET = 150 + BAY_ZOFFSET = 60 + + SLOT_FRONT_BOTTOM = 0 + SLOT_FRONT_MIDDLE = 1 + SLOT_FRONT_TOP = 2 + SLOT_BACK_BOTTOM = 3 + SLOT_BACK_MIDDLE = 4 + SLOT_BACK_TOP = 5 + SLOT_SIDE = 6 + + def __init__ (self, table, robot_position, elevation_motor, + rotation_motor, clamping_motor): + Observable.__init__ (self) + self.table = table + self.robot_position = robot_position + self.elevation_motor = elevation_motor + self.rotation_motor = rotation_motor + self.clamping_motor = clamping_motor + self.slots = ( + Slot (self.BAY_OFFSET, 0, 0 * self.BAY_ZOFFSET, 0), + Slot (self.BAY_OFFSET, 0, 1 * self.BAY_ZOFFSET, 0), + Slot (self.BAY_OFFSET, 0, 2 * self.BAY_ZOFFSET, 0), + Slot (-self.BAY_OFFSET, 0, 0 * self.BAY_ZOFFSET, 1), + Slot (-self.BAY_OFFSET, 0, 1 * self.BAY_ZOFFSET, 1), + Slot (-self.BAY_OFFSET, 0, 2 * self.BAY_ZOFFSET, 1), + Slot (0, self.BAY_OFFSET, 2 * self.BAY_ZOFFSET, None)) + self.load = None + self.robot_position.register (self.__robot_position_notified) + self.elevation_motor.register (self.__elevation_notified) + self.rotation_motor.register (self.__rotation_notified) + self.clamping_motor.register (self.__clamping_notified) + + def __robot_position_notified (self): + # Update bottom slots. + changed = False + for sloti in (self.SLOT_FRONT_BOTTOM, self.SLOT_BACK_BOTTOM): + slot = self.slots[sloti] + if slot.pawn is None: + p = self.__get_floor_elements (slot.side) + if p is not None: + slot.pawn = p + p.pos = None + p.notify () + changed = True + if changed: + self.notify () + + def __elevation_notified (self): + if self.elevation_motor.angle is None: + self.elevation = None + else: + # Update elevation. + self.elevation = (self.elevation_motor.angle + * self.ELEVATION_STROKE / self.ELEVATION_MOTOR_STROKE) + self.notify () + + def __rotation_notified (self): + if self.rotation_motor.angle is None: + self.rotation = None + else: + # Update rotation. + self.rotation = (self.rotation_motor.angle * self.ROTATION_STROKE + / self.ROTATION_MOTOR_STROKE) + self.notify () + + def __clamping_notified (self): + if self.clamping_motor.angle is None: + self.clamping = None + else: + # Update clamping. + self.clamping = (self.clamping_motor.angle * self.CLAMPING_STROKE + / self.CLAMPING_MOTOR_STROKE) + if self.clamping == 0 and self.load is None: + # Load an element. + slot = self.__get_clamp_slot () + if slot: + self.load, slot.pawn = slot.pawn, self.load + elif self.clamping == self.CLAMPING_STROKE \ + and self.load is not None: + # Unload an element. + slot = self.__get_clamp_slot () + if slot and slot.pawn is None: + self.load, slot.pawn = slot.pawn, self.load + self.notify () + + def __get_floor_elements (self, side): + """Return an elements in front (side = 0) or in back (side = 1) of the + robot, on the floor.""" + if self.robot_position.pos is None: + return None + # Matrix to transform an obstacle position into robot coordinates. + m = TransMatrix () + m.rotate (-self.robot_position.angle) + m.translate ((-self.robot_position.pos[0], + -self.robot_position.pos[1])) + # Look up elements. + xoffset = (self.BAY_OFFSET, -self.BAY_OFFSET)[side] + xmargin = 20 + ymargin = 50 + for o in self.table.obstacles: + if o.level == 1 and o.pos is not None: + pos = m.apply (o.pos) + if (pos[0] > xoffset - xmargin + and pos[0] < xoffset + xmargin + and pos[1] > -ymargin and pos[1] < ymargin): + return o + return None + + def __get_clamp_slot (self): + """Return the slot in which the clamp is.""" + if self.rotation is None or self.elevation is None: + return None + margin = 10 + x = cos (self.rotation) * self.BAY_OFFSET + y = sin (self.rotation) * self.BAY_OFFSET + for slot in self.slots: + if abs (slot.z - self.elevation) < margin \ + and abs (slot.x - x) < margin \ + and abs (slot.y - y) < margin: + return slot + return None + diff --git a/host/simu/robots/robospierre/view/__init__.py b/host/simu/robots/robospierre/view/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/host/simu/robots/robospierre/view/bag.py b/host/simu/robots/robospierre/view/bag.py new file mode 100644 index 00000000..361c79d3 --- /dev/null +++ b/host/simu/robots/robospierre/view/bag.py @@ -0,0 +1,48 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre bag of views.""" +from simu.view.switch import Switch +from simu.view.distance_sensor_us import DistanceSensorUS +from simu.view.path import Path +from simu.view.pos_report import PosReport +from simu.robots.robospierre.view.robot import Robot +from simu.robots.robospierre.view.clamp import ClampTop, ClampSide + +class Bag: + + def __init__ (self, table, actuator_view, sensor_frame, model_bag): + self.jack = Switch (sensor_frame, model_bag.jack, 'Jack') + self.color_switch = Switch (sensor_frame, model_bag.color_switch, + 'Color') + self.robot = Robot (table, model_bag.position, model_bag.clamp) + self.clamp = ( + ClampTop (actuator_view.add_view (ClampTop.width, + ClampTop.height), model_bag.clamp), + ClampSide (actuator_view.add_view (ClampSide.width, + ClampSide.height), model_bag.clamp)) + self.distance_sensor = [DistanceSensorUS (self.robot, ds) + for ds in model_bag.distance_sensor] + self.path = Path (table, model_bag.path) + self.pos_report = PosReport (table, model_bag.pos_report) + diff --git a/host/simu/robots/robospierre/view/clamp.py b/host/simu/robots/robospierre/view/clamp.py new file mode 100644 index 00000000..bd5f6dab --- /dev/null +++ b/host/simu/robots/robospierre/view/clamp.py @@ -0,0 +1,172 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre clamp.""" +from simu.inter.drawable import Drawable +from simu.utils.trans_matrix import TransMatrix +from math import pi, sin, cos + +from simu.view.table_eurobot2011 import YELLOW, draw_pawn + +DGREY = '#404040' +GREY = '#808080' +BLACK = '#000000' + +class ClampTop (Drawable): + + width = 420 + height = 420 + + def __init__ (self, onto, model): + Drawable.__init__ (self, onto) + self.model = model + self.model.register (self.__notified) + + def __notified (self): + self.update () + + def draw (self): + self.reset () + # Draw base from top. + self.trans_rotate (pi) + self.draw_arc ((0, 0), 190, start = pi * 35 / 180, + extent = pi * 110 / 180, style = 'arc', + outline = GREY) + self.draw_arc ((0, 0), 190, start = pi + pi * 35 / 180, + extent = pi * 110 / 180, style = 'arc', + outline = GREY) + self.draw_arc ((150, 0), 110, start = pi / 2, + extent = pi, style = 'arc', outline = GREY) + self.draw_arc ((-150, 0), 110, start = 3 * pi / 2, + extent = pi, style = 'arc', outline = GREY) + self.draw_arc ((0, 150), 100, start = pi, + extent = pi, style = 'arc', outline = GREY, dash = (2, 3)) + self.draw_line ((-40, 0), (40, 0), fill = GREY, arrow = 'last') + # Draw slots. + for slot in self.model.slots: + if slot.pawn is not None: + self.trans_push () + self.trans_scale (1 - slot.z / 1000.0) + self.trans_translate ((slot.x, slot.y)) + draw_pawn (self, slot.pawn.radius, slot.pawn.kind) + self.trans_pop () + # Draw clamp. + if self.model.rotation is not None: + self.trans_rotate (self.model.rotation) + # Fixed side. + self.draw_line ((0, 3), (47, 3)) + self.draw_arc ((150, 0), 103, start = pi / 2, extent = pi / 2, + style = 'arc') + # Pawn. + load = self.model.load + if load is not None: + self.trans_push () + self.trans_translate ((150, 0)) + draw_pawn (self, load.radius, load.kind) + self.trans_pop () + # Mobile side. + self.trans_rotate (-self.model.clamping / 43) + self.draw_line ((0, -3), (47, -3)) + self.draw_arc ((150, 0), 103, start = pi, extent = pi / 2, + style = 'arc') + +class ClampSide (Drawable): + + width = 420 + height = 370 + + def __init__ (self, onto, model): + Drawable.__init__ (self, onto) + self.model = model + self.model.register (self.__notified) + + def __notified (self): + self.update () + + def draw_pawn (self, pos, pawn): + if pawn is not None: + self.trans_push () + self.trans_translate (pos) + self.draw_rectangle ((-100, 0), (100, 50), fill = YELLOW) + if pawn.kind == 'king': + self.draw_polygon ((-50, 50), (-10, 170), (-50, 170), (-50, 190), + (-10, 190), (-10, 230), (10, 230), (10, 190), (50, 190), + (50, 170), (5, 170), (50, 50), fill = YELLOW, + outline = BLACK) + elif pawn.kind == 'queen': + self.draw_polygon ((-50, 50), (-10, 180), (10, 180), (50, 50), + fill = YELLOW, outline = BLACK) + self.draw_circle ((0, 180), 50, fill = YELLOW) + self.trans_pop () + + def draw (self): + self.reset () + # Draw base from side. + self.trans_translate ((0, -165)) + self.draw_line ((-150, 0), (150, 0), fill = GREY) + self.draw_line ((-20, 60), (20, 60), fill = GREY) + self.draw_line ((-20, 120), (20, 120), fill = GREY) + self.draw_line ((0, 0), (0, 330), fill = GREY) + # Draw slots. + for slot in self.model.slots: + if slot.pawn is not None: + self.draw_pawn ((-slot.x, slot.z), slot.pawn) + # Draw clamp. + if self.model.rotation is not None: + self.trans_translate ((0, self.model.elevation)) + m = TransMatrix () + m.rotate (pi + self.model.rotation) + # 2D projection of a 3D circular clamp. + ltip = m.apply ((150, 103))[0] + lbase = m.apply ((47, 0))[0] + lcenter = m.apply ((150, 0))[0] + m.rotate (- self.model.clamping / 43) + rtip = m.apply ((150, -103))[0] + rbase = m.apply ((47, 0))[0] + rcenter = m.apply ((150, 0))[0] + s, c = sin (self.model.rotation), cos (self.model.rotation) + dattr = dict (outline = BLACK, fill = DGREY) + attr = dict (outline = BLACK, fill = GREY) + if c >= 0: + if s >= 0: + self.draw_rectangle ((lbase, 10), (lcenter + 103, 40), **dattr) + self.draw_rectangle ((rtip, 10), (rbase, 40), **dattr) + self.draw_pawn ((lcenter, 0), self.model.load) + self.draw_rectangle ((ltip, 10), (lcenter + 103, 40), **attr) + else: + self.draw_rectangle ((rtip, 10), (rcenter + 103, 40), **dattr) + self.draw_pawn ((lcenter, 0), self.model.load) + self.draw_rectangle ((ltip, 10), (lbase, 40), **attr) + self.draw_rectangle ((rbase, 10), (rcenter + 103, 40), **attr) + else: + if s >= 0: + self.draw_rectangle ((lbase, 10), (ltip, 40), **dattr) + self.draw_rectangle ((rbase, 10), (rcenter - 103, 40), **dattr) + self.draw_pawn ((lcenter, 0), self.model.load) + self.draw_rectangle ((rtip, 10), (rcenter - 103, 40), **attr) + else: + self.draw_rectangle ((ltip, 10), (lcenter - 103, 40), **dattr) + self.draw_pawn ((lcenter, 0), self.model.load) + self.draw_rectangle ((lbase, 10), (lcenter - 103, 40), **attr) + self.draw_rectangle ((rbase, 10), (rtip, 40), **attr) + diff --git a/host/simu/robots/robospierre/view/robot.py b/host/simu/robots/robospierre/view/robot.py new file mode 100644 index 00000000..c0f6624c --- /dev/null +++ b/host/simu/robots/robospierre/view/robot.py @@ -0,0 +1,111 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2011 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. +# +# }}} +"""Robospierre robot view.""" +import simu.inter.drawable +from math import pi + +from simu.view.table_eurobot2011 import draw_pawn + +COLOR_ROBOT = '#000000' +COLOR_CLAMP = '#606060' +COLOR_AXES = '#202040' + +class Robot (simu.inter.drawable.Drawable): + + def __init__ (self, onto, position_model, clamp_model): + """Construct and make connections.""" + simu.inter.drawable.Drawable.__init__ (self, onto) + self.position_model = position_model + self.position_model.register (self.__position_notified) + self.clamp_model = clamp_model + self.clamp_model.register (self.__clamp_notified) + + def __position_notified (self): + """Called on position modifications.""" + self.pos = self.position_model.pos + self.angle = self.position_model.angle + self.update () + + def __clamp_notified (self): + """Called on clamp modifications.""" + self.update () + + def draw (self): + """Draw the robot.""" + self.reset () + if self.pos is not None: + self.trans_translate (self.pos) + self.trans_rotate (self.angle) + # Draw slots. + for slot in self.clamp_model.slots: + if slot.pawn is not None: + self.trans_push () + self.trans_scale (1 - slot.z / 1000.0) + self.trans_translate ((slot.x, slot.y)) + draw_pawn (self, slot.pawn.radius, slot.pawn.kind) + self.trans_pop () + # Draw clamp. + if self.clamp_model.rotation is not None: + self.trans_push () + # Fixed side. + self.trans_rotate (self.clamp_model.rotation) + self.draw_arc ((150, 0), 103, start = pi / 2, extent = pi / 2, + style = 'arc', outline = COLOR_CLAMP) + # Draw load. + load = self.clamp_model.load + if load: + self.trans_push () + self.trans_translate ((150, 0)) + draw_pawn (self, load.radius, load.kind) + self.trans_pop () + # Mobile side. + self.trans_rotate (- self.clamp_model.clamping / 47) + self.draw_arc ((150, 0), 103, start = pi, extent = pi / 2, + style = 'arc', outline = COLOR_CLAMP) + # Done. + self.trans_pop () + # Draw robot body. + self.draw_polygon ((0, 190), (150, 110), (95, 95), (55, 55), + (40, -0), (55, -55), (95, -95), (150, -110), (0, -190), + (-150, -110), (-95, -95), (-55, -55), (-40, -0), + (-55, 55), (-95, 95), (-150, 110), (0, 190), + fill = COLOR_ROBOT) + self.draw_arc ((0, 0), 190, start = pi * 35 / 180, + extent = pi * 110 / 180, style = 'chord', + outline = COLOR_ROBOT, fill = COLOR_ROBOT) + self.draw_arc ((0, 0), 190, start = pi + pi * 35 / 180, + extent = pi * 110 / 180, style = 'chord', + outline = COLOR_ROBOT, fill = COLOR_ROBOT) + # Draw Robot axis. + self.draw_line ((-50, 0), (50, 0), fill = COLOR_AXES, + arrow = 'last') + # Draw Robot wheels. + f = 221 # Wheel spacing + wr = 60 / 2 # Wheel radius + self.draw_line ((0, +f / 2), (0, -f / 2), fill = COLOR_AXES) + self.draw_line ((-wr, f / 2), (+wr, f / 2), fill = COLOR_AXES) + self.draw_line ((-wr, -f / 2), (+wr, -f / 2), fill = COLOR_AXES) + # Extends. + simu.inter.drawable.Drawable.draw (self) + -- cgit v1.2.3 From 8ed9fb23f3ab93374d9bcbe6560e84c6c1de1b2a Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 7 May 2011 00:30:10 +0200 Subject: digital/{ai,io-hub}, host/simu: use io-hub for simu --- digital/ai/tools/robospierre.py | 10 +++++----- digital/ai/tools/test_simu_control_robospierre.py | 4 ++-- digital/io-hub/src/robospierre/main.c | 1 + host/simu/robots/robospierre/link/bag.py | 4 ++-- host/simu/robots/robospierre/model/bag.py | 23 +++++++++++------------ host/simu/robots/robospierre/view/bag.py | 2 -- 6 files changed, 21 insertions(+), 23 deletions(-) (limited to 'host/simu') diff --git a/digital/ai/tools/robospierre.py b/digital/ai/tools/robospierre.py index 23fb19a3..59023184 100644 --- a/digital/ai/tools/robospierre.py +++ b/digital/ai/tools/robospierre.py @@ -9,8 +9,8 @@ import asserv import asserv.init import mimot import mimot.init -import io -import io.init +import io_hub +import io_hub.init from proto.popen_io import PopenIO import math @@ -25,13 +25,13 @@ class Robot: self.robot_view = simu.robots.robospierre.view.bag asserv_cmd = ('../../asserv/src/asserv/asserv.host', '-m9', 'marcel') mimot_cmd = ('../../mimot/src/dirty/dirty.host', '-m9', 'marcel') - io_cmd = ('../../io/src/io.host') + io_hub_cmd = ('../../io-hub/src/robospierre/io_hub.host') self.asserv = asserv.Proto (PopenIO (asserv_cmd), proto_time, **asserv.init.host) self.mimot = mimot.Proto (PopenIO (mimot_cmd), proto_time, **mimot.init.host) - self.io = io.Proto (PopenIO (io_cmd), proto_time, - **io.init.host) + self.io = io_hub.Proto (PopenIO (io_hub_cmd), proto_time, + **io_hub.init.host) self.robot_start_pos = { False: (700, 2100 - 250, math.radians (-270)), True: (3000 - 700, 2100 - 250, math.radians (-270)) diff --git a/digital/ai/tools/test_simu_control_robospierre.py b/digital/ai/tools/test_simu_control_robospierre.py index 9da57196..5300918a 100644 --- a/digital/ai/tools/test_simu_control_robospierre.py +++ b/digital/ai/tools/test_simu_control_robospierre.py @@ -78,9 +78,9 @@ class TestSimuControl (TestSimu): def clamp_command (self): if self.clamp_var.get (): - self.io.pwm_set (-0x7fff, 255) + self.io.pwm_set_timed (0, -0x3ff, 255, 0) else: - self.io.pwm_set (0x7fff, 255) + self.io.pwm_set_timed (0, 0x3ff, 255, 0) def elevation_up_command (self): self.mimot.speed_pos ('a0', self.ELEVATION_STROKE / 2) diff --git a/digital/io-hub/src/robospierre/main.c b/digital/io-hub/src/robospierre/main.c index bbc9bdb9..980ab138 100644 --- a/digital/io-hub/src/robospierre/main.c +++ b/digital/io-hub/src/robospierre/main.c @@ -60,6 +60,7 @@ main_init (void) sei (); /* Main timer */ timer_init (); + timer_wait (); /* TWI communications */ asserv_init (); mimot_init (); diff --git a/host/simu/robots/robospierre/link/bag.py b/host/simu/robots/robospierre/link/bag.py index 2760aec0..ac68889a 100644 --- a/host/simu/robots/robospierre/link/bag.py +++ b/host/simu/robots/robospierre/link/bag.py @@ -22,7 +22,7 @@ # # }}} """Robospierre bag of links.""" -import io.mex +import io_hub.mex import asserv.mex import mimot.mex @@ -30,6 +30,6 @@ class Bag: def __init__ (self, node): self.asserv = asserv.mex.Mex (node) - self.io = io.mex.Mex (node) + self.io_hub = io_hub.mex.Mex (node) self.mimot = mimot.mex.Mex (node) diff --git a/host/simu/robots/robospierre/model/bag.py b/host/simu/robots/robospierre/model/bag.py index e6810e18..ce55f997 100644 --- a/host/simu/robots/robospierre/model/bag.py +++ b/host/simu/robots/robospierre/model/bag.py @@ -32,26 +32,25 @@ from math import pi class Bag: def __init__ (self, scheduler, table, link_bag): - self.jack = Switch (link_bag.io.jack) - self.color_switch = Switch (link_bag.io.color_switch) - self.contact = [ Switch (contact) for contact in link_bag.io.contact ] + self.color_switch = Switch (link_bag.io_hub.contact[0]) + self.jack = Switch (link_bag.io_hub.contact[1]) + self.contact = [ Switch (contact) + for contact in link_bag.io_hub.contact[2:] ] self.position = Position (link_bag.asserv.position) - self.clamping_motor = MotorBasic (link_bag.io.pwm[0], scheduler, + self.clamping_motor = MotorBasic (link_bag.io_hub.pwm[0], scheduler, 2 * pi, 0, pi) self.clamp = Clamp (table, self.position, link_bag.mimot.aux[0], link_bag.mimot.aux[1], self.clamping_motor) self.distance_sensor = [ - DistanceSensorSensopart (link_bag.io.adc[0], scheduler, table, + DistanceSensorSensopart (link_bag.io_hub.adc[0], scheduler, table, (20, -20), -pi * 10 / 180, (self.position, ), 2), - DistanceSensorSensopart (link_bag.io.adc[1], scheduler, table, + DistanceSensorSensopart (link_bag.io_hub.adc[1], scheduler, table, (20, 20), pi * 10 / 180, (self.position, ), 2), - DistanceSensorSensopart (link_bag.io.adc[2], scheduler, table, + DistanceSensorSensopart (link_bag.io_hub.adc[2], scheduler, table, (-20, 20), pi - pi * 10 / 180, (self.position, ), 2), - DistanceSensorSensopart (link_bag.io.adc[3], scheduler, table, + DistanceSensorSensopart (link_bag.io_hub.adc[3], scheduler, table, (-20, -20), pi + pi * 10 / 180, (self.position, ), 2), ] - link_bag.io.adc[4].value = 0 - link_bag.io.adc[5].value = 0 - self.path = link_bag.io.path - self.pos_report = link_bag.io.pos_report + for adc in link_bag.io_hub.adc[4:]: + adc.value = 0 diff --git a/host/simu/robots/robospierre/view/bag.py b/host/simu/robots/robospierre/view/bag.py index 361c79d3..0b5a85ad 100644 --- a/host/simu/robots/robospierre/view/bag.py +++ b/host/simu/robots/robospierre/view/bag.py @@ -43,6 +43,4 @@ class Bag: ClampSide.height), model_bag.clamp)) self.distance_sensor = [DistanceSensorUS (self.robot, ds) for ds in model_bag.distance_sensor] - self.path = Path (table, model_bag.path) - self.pos_report = PosReport (table, model_bag.pos_report) -- cgit v1.2.3