summaryrefslogtreecommitdiff
path: root/host/simu/robots
diff options
context:
space:
mode:
Diffstat (limited to 'host/simu/robots')
-rw-r--r--host/simu/robots/apbirthday/link/bag.py2
-rw-r--r--host/simu/robots/apbirthday/model/bag.py3
-rw-r--r--host/simu/robots/apbirthday/model/cannon.py27
-rw-r--r--host/simu/robots/apbirthday/view/robot.py3
4 files changed, 31 insertions, 4 deletions
diff --git a/host/simu/robots/apbirthday/link/bag.py b/host/simu/robots/apbirthday/link/bag.py
index f27f65fa..52c5c75f 100644
--- a/host/simu/robots/apbirthday/link/bag.py
+++ b/host/simu/robots/apbirthday/link/bag.py
@@ -34,7 +34,7 @@ class Bag:
self.asserv = asserv.mex.Mex (node, '%s:asserv0' % instance,
aux_nb = 0)
self.io_hub = io_hub.mex.Mex (node, '%s:io0' % instance, gpios = True,
- adc_channels = True)
+ adc_channels = True, potentiometer = True)
for gpio in io_hub.apbirthday.gpios:
setattr (self, gpio, MexGpio (self.io_hub.gpios, gpio))
adc_channels = self.io_hub.adc_channels
diff --git a/host/simu/robots/apbirthday/model/bag.py b/host/simu/robots/apbirthday/model/bag.py
index bbf5438e..c7330598 100644
--- a/host/simu/robots/apbirthday/model/bag.py
+++ b/host/simu/robots/apbirthday/model/bag.py
@@ -82,6 +82,7 @@ class Bag:
link_bag.cherry_plate_clamp,
scheduler, 0., 1., 10., 10., 0.),
(Switch (link_bag.cherry_plate_left_contact),
- Switch (link_bag.cherry_plate_right_contact)))
+ Switch (link_bag.cherry_plate_right_contact)),
+ link_bag.io_hub.potentiometer)
self.pos_report = link_bag.io_hub.pos_report
diff --git a/host/simu/robots/apbirthday/model/cannon.py b/host/simu/robots/apbirthday/model/cannon.py
index 74810fd6..4fc78fd8 100644
--- a/host/simu/robots/apbirthday/model/cannon.py
+++ b/host/simu/robots/apbirthday/model/cannon.py
@@ -25,22 +25,29 @@
from utils.observable import Observable
from simu.utils.trans_matrix import TransMatrix
from simu.utils.vector import vector
+import random
+from math import pi
class Cannon (Observable):
+ # TODO: update distance with real robot.
+ cannon_hit = (1000, 80)
+
def __init__ (self, table, robot_position,
- arm_cyl, clamp_cyl, contacts):
+ arm_cyl, clamp_cyl, contacts, pot):
Observable.__init__ (self)
self.table = table
self.robot_position = robot_position
self.arm_cyl = arm_cyl
self.clamp_cyl = clamp_cyl
self.contacts = contacts
+ self.pot = pot
self.plate = None
self.cherries = [ ]
self.robot_position.register (self.__robot_position_notified)
self.arm_cyl.register (self.__arm_notified)
self.clamp_cyl.register (self.__arm_notified)
+ self.pot.register (self.__pot_notified)
def __robot_position_notified (self):
if self.robot_position.pos is None:
@@ -82,8 +89,24 @@ class Cannon (Observable):
elif (self.plate is not None and self.plate.cherries and
self.arm_cyl.pos < .1):
# Load cherries.
- self.cherries = self.plate.cherries
+ self.cherries.extend (self.plate.cherries)
self.plate.cherries = [ ]
+ self.__pot_notified ()
+ self.notify ()
+
+ def __pot_notified (self):
+ if self.cherries and self.pot.wiper[0] > 0.5:
+ m = TransMatrix ()
+ m.translate (self.robot_position.pos)
+ m.rotate (self.robot_position.angle)
+ hit = vector (*m.apply (self.cannon_hit))
+ for c in self.cherries:
+ c.pos = hit + vector.polar (random.uniform (-pi, pi),
+ random.uniform (0, 50))
+ c.notify ()
+ self.table.cherries.cherries.extend (self.cherries)
+ self.table.cherries.notify ()
+ self.cherries = [ ]
self.notify ()
def __plate_drop_point (self):
diff --git a/host/simu/robots/apbirthday/view/robot.py b/host/simu/robots/apbirthday/view/robot.py
index e4153232..9675aff5 100644
--- a/host/simu/robots/apbirthday/view/robot.py
+++ b/host/simu/robots/apbirthday/view/robot.py
@@ -27,6 +27,7 @@ from simu.view.table_eurobot2013 import PINK, colors
COLOR_ROBOT = '#000000'
COLOR_AXES = '#202040'
+COLOR_CANNON = '#808080'
class Robot (simu.inter.drawable.Drawable):
@@ -69,6 +70,8 @@ class Robot (simu.inter.drawable.Drawable):
# Draw robot body.
self.draw_polygon ((102, 140), (102, -140), (-108, -140),
(-108, 70), (-58, 140), fill = COLOR_ROBOT)
+ self.draw_circle ((70, self.cannon_model.cannon_hit[1]), 20,
+ fill = COLOR_CANNON)
# Draw Robot axis.
self.draw_line ((-50, 0), (50, 0), fill = COLOR_AXES,
arrow = 'last')