summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--host/simu/model/distance_sensor_trig.py65
-rw-r--r--host/simu/model/table_eurobot2013.py3
-rw-r--r--host/simu/robots/apbirthday/model/bag.py5
-rw-r--r--host/simu/robots/apbirthday/view/bag.py3
4 files changed, 76 insertions, 0 deletions
diff --git a/host/simu/model/distance_sensor_trig.py b/host/simu/model/distance_sensor_trig.py
new file mode 100644
index 00000000..7d22ebab
--- /dev/null
+++ b/host/simu/model/distance_sensor_trig.py
@@ -0,0 +1,65 @@
+# simu - Robot simulation. {{{
+#
+# 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.
+#
+# }}}
+"""Sensopart FT20RA."""
+from utils.observable import Observable
+from simu.model.distance_sensor import DistanceSensor
+
+class DistanceSensorTrig (Observable, DistanceSensor):
+
+ RANGE = 100
+
+ def __init__ (self, link, scheduler, table, pos, angle, into = None,
+ level = 0, exclude = None, factor = 1):
+ Observable.__init__ (self)
+ DistanceSensor.__init__ (self, table, pos, angle, self.RANGE, into,
+ level, exclude)
+ self.factor = factor
+ self.link = link
+ self.scheduler = scheduler
+ self.value = None
+ self.evaluate ()
+ self.register (self.__update)
+
+ def evaluate (self):
+ # Compute real distance.
+ DistanceSensor.evaluate (self)
+ # Convert to sensor voltage.
+ d = self.distance
+ if self.distance is None:
+ d = self.RANGE
+ if d < 22.5:
+ self.value = -0.014 * d * d + 0.41 * d + 7
+ else:
+ self.value = -0.657 + 220.431 / d
+ self.value *= 0.1 * self.factor
+ # Update observers.
+ self.notify ()
+ # Prepare next update.
+ self.scheduler.schedule (self.scheduler.date
+ + int (self.scheduler.tick * 0.03), self.evaluate)
+
+ def __update (self):
+ self.link.value = self.value
+ self.link.notify ()
+
diff --git a/host/simu/model/table_eurobot2013.py b/host/simu/model/table_eurobot2013.py
index 5fb663f4..c0d8b27d 100644
--- a/host/simu/model/table_eurobot2013.py
+++ b/host/simu/model/table_eurobot2013.py
@@ -57,6 +57,8 @@ class Table (simu.model.table.Table):
colors = ([ False ] + colors_r[0:3] + [ None, None, None, None ]
+ colors_r[3:6] + [ True ])
add_candle_circle ((1500, 2000), 450, pi + pi / 24, pi / 12, colors, 2)
+ cake = RoundObstacle (500, 0)
+ cake.pos = (1500, 2000)
# Glasses.
self.glasses = [ ]
def add_glass (pos):
@@ -108,6 +110,7 @@ class Table (simu.model.table.Table):
add_gifts ((1800, 0))
add_gifts ((2400, 0))
# Add everything to obstacles.
+ self.obstacles.append (cake)
self.obstacles += self.candles
self.obstacles += self.glasses
self.obstacles += self.cherries
diff --git a/host/simu/robots/apbirthday/model/bag.py b/host/simu/robots/apbirthday/model/bag.py
index ce2c8667..2c026740 100644
--- a/host/simu/robots/apbirthday/model/bag.py
+++ b/host/simu/robots/apbirthday/model/bag.py
@@ -25,6 +25,7 @@
from simu.model.switch import Switch
from simu.model.position import Position
from simu.model.round_obstacle import RoundObstacle
+from simu.model.distance_sensor_trig import DistanceSensorTrig
from simu.model.distance_sensor_sensopart import DistanceSensorSensopart
from simu.model.pneumatic_cylinder import PneumaticCylinder
from simu.robots.apbirthday.model.cake_arm import CakeArm
@@ -51,6 +52,10 @@ class Bag:
DistanceSensorSensopart (link_bag.adc_dist[3], scheduler, table,
(-83, -120), pi, (self.position, ), 4),
]
+ self.cake_front = DistanceSensorTrig (link_bag.adc_cake_front,
+ scheduler, table, (80, 136), pi / 2, (self.position, ), 0)
+ self.cake_back = DistanceSensorTrig (link_bag.adc_cake_back,
+ scheduler, table, (-66, 139), pi / 2, (self.position, ), 0)
self.cake_arm = CakeArm (table, self.position,
PneumaticCylinder (
link_bag.cake_arm_in,
diff --git a/host/simu/robots/apbirthday/view/bag.py b/host/simu/robots/apbirthday/view/bag.py
index a5d733e1..6a9e2d3d 100644
--- a/host/simu/robots/apbirthday/view/bag.py
+++ b/host/simu/robots/apbirthday/view/bag.py
@@ -23,6 +23,7 @@
# }}}
"""APBirthday bag of views."""
from simu.view.switch import Switch
+from simu.view.distance_sensor import DistanceSensor
from simu.view.distance_sensor_us import DistanceSensorUS
from simu.view.pos_report import PosReport
from simu.robots.apbirthday.view.robot import Robot
@@ -36,5 +37,7 @@ class Bag:
self.robot = Robot (table, model_bag.position, model_bag.cake_arm)
self.distance_sensor = [DistanceSensorUS (self.robot, ds)
for ds in model_bag.distance_sensor]
+ self.cake_front = DistanceSensor (self.robot, model_bag.cake_front)
+ self.cake_back = DistanceSensor (self.robot, model_bag.cake_back)
self.pos_report = PosReport (table, model_bag.pos_report)