From 75cc934b072310f22c5fe349168e5e4cdc231c4c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 28 Mar 2013 23:28:13 +0100 Subject: host/simu/robots/apbirthday: add cake arm simulation Still need color sensors simulation. --- host/simu/robots/apbirthday/view/bag.py | 2 +- host/simu/robots/apbirthday/view/robot.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'host/simu/robots/apbirthday/view') diff --git a/host/simu/robots/apbirthday/view/bag.py b/host/simu/robots/apbirthday/view/bag.py index dfea21fa..7956e5f2 100644 --- a/host/simu/robots/apbirthday/view/bag.py +++ b/host/simu/robots/apbirthday/view/bag.py @@ -32,7 +32,7 @@ class 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) + 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] diff --git a/host/simu/robots/apbirthday/view/robot.py b/host/simu/robots/apbirthday/view/robot.py index 398d34c8..cb489fb0 100644 --- a/host/simu/robots/apbirthday/view/robot.py +++ b/host/simu/robots/apbirthday/view/robot.py @@ -29,11 +29,13 @@ COLOR_AXES = '#202040' class Robot (simu.inter.drawable.Drawable): - def __init__ (self, onto, position_model): + def __init__ (self, onto, position_model, cake_arm_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.cake_arm_model = cake_arm_model + self.cake_arm_model.register (self.update) def __position_notified (self): """Called on position modifications.""" @@ -59,6 +61,16 @@ class Robot (simu.inter.drawable.Drawable): 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) + # Draw arm. + m = self.cake_arm_model + f = m.arm_cyl.pos + for x, y, pos in ((m.far_x, m.far_y, m.far_cyl.pos), + (m.near_x, m.near_y, m.near_cyl.pos)): + e = (y - 140) * f + 140 + gray = pos * 0x40 + fill = '#%02x%02x%02x' % (gray, gray, gray) + self.draw_polygon ((x - 20, 140), (x - 20, e), (x + 20, e), + (x + 20, 140), fill = fill) # Extends. simu.inter.drawable.Drawable.draw (self) -- cgit v1.2.3