From d3c6012abe3b59ba88c8c83b2ffcb467b472f00d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 7 Apr 2010 23:51:42 +0200 Subject: digital/io, host/simu: add position report tool --- host/simu/robots/marcel/model/bag.py | 1 + host/simu/robots/marcel/view/bag.py | 2 ++ host/simu/view/pos_report.py | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 host/simu/view/pos_report.py (limited to 'host/simu') diff --git a/host/simu/robots/marcel/model/bag.py b/host/simu/robots/marcel/model/bag.py index ab4814e0..563a16b4 100644 --- a/host/simu/robots/marcel/model/bag.py +++ b/host/simu/robots/marcel/model/bag.py @@ -47,4 +47,5 @@ class Bag: 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/marcel/view/bag.py b/host/simu/robots/marcel/view/bag.py index e8666749..75f7ff50 100644 --- a/host/simu/robots/marcel/view/bag.py +++ b/host/simu/robots/marcel/view/bag.py @@ -25,6 +25,7 @@ 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.marcel.view.robot import Robot class Bag: @@ -37,4 +38,5 @@ class Bag: 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/view/pos_report.py b/host/simu/view/pos_report.py new file mode 100644 index 00000000..2103997f --- /dev/null +++ b/host/simu/view/pos_report.py @@ -0,0 +1,47 @@ +# simu - Robot simulation. {{{ +# +# Copyright (C) 2010 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. +# +# }}} +"""Display general purpose position reports.""" +from simu.inter.drawable import Drawable + +class PosReport (Drawable): + + def __init__ (self, onto, model): + Drawable.__init__ (self, onto) + self.model = model + self.model.register (self.__notified) + self.__colors = ('red', 'blue', 'green', 'yellow') + + def __notified (self): + self.update () + + def draw (self): + self.reset () + for id in self.model.pos.iterkeys (): + for p in self.model.pos[id]: + s = 20 + self.draw_line ( + (p[0] - s, p[1] - s), (p[0] + s, p[1] + s), + (p[0] - s, p[1] + s), (p[0] + s, p[1] - s), + (p[0] - s, p[1] - s), fill = self.__colors[id]) + -- cgit v1.2.3