summaryrefslogtreecommitdiffhomepage
path: root/host
diff options
context:
space:
mode:
authorNicolas Schodet2008-04-04 13:03:03 +0200
committerNicolas Schodet2008-04-04 13:03:03 +0200
commit7724570ce164859bd7f7fd8ff16b9e7fab17eb58 (patch)
treec176d5500634cea1c237e4da6c00ba943efe8a2f /host
parent19c735ed14a22f0d295505a2aceb4ab545cadd51 (diff)
* host/inter:
- added robot arm and rear servos.
Diffstat (limited to 'host')
-rw-r--r--host/inter/inter.py93
1 files changed, 88 insertions, 5 deletions
diff --git a/host/inter/inter.py b/host/inter/inter.py
index 52104f0b..8071bcba 100644
--- a/host/inter/inter.py
+++ b/host/inter/inter.py
@@ -1,7 +1,7 @@
from Tkinter import *
from drawable import *
-from math import pi
+from math import pi, cos, sin
class Robot (Drawable):
"""The robot."""
@@ -90,7 +90,7 @@ class Table (Drawable):
class TableView (DrawableCanvas):
"""This class handle the view of the table and every items inside it."""
- WIDTH = 3000 + 2 * 22 + 2 * 80 + 2 * 250 + 2 * 10
+ WIDTH = 3000 + 2 * 22 + 2 * 80 + 2 * 50 + 2 * 10
HEIGHT = 2100 + 2 * 22 + 2 * 80 + 2 * 10
XORIGIN = -3000 / 2
YORIGIN = -2100 / 2
@@ -109,6 +109,84 @@ class TableView (DrawableCanvas):
self.table.draw ()
self.robot.draw ()
+class Arm (Drawable):
+ """The robot arm."""
+
+ def draw (self):
+ self.reset ()
+ self.draw_arc ((0, 0), 0.45, start = 7 * pi / 12, extent = 10 * pi / 12,
+ style = 'arc', outline = '#808080')
+ self.draw_arc ((0, 0), 0.45, start = -5 * pi / 12, extent = 10 * pi / 12,
+ style = 'arc', outline = '#808080')
+ self.trans_scale (0.4)
+ self.trans_rotate (self.angle)
+ self.draw_line ((0, 0), (0, -1))
+ self.draw_line ((0, 0), (cos (pi / 6), sin (pi / 6)))
+ self.draw_line ((0, 0), (-cos (pi / 6), sin (pi / 6)))
+
+class Servo:
+ """Servo motor."""
+
+ def __init__ (self, coord, l, start, extent):
+ self.coord = coord
+ self.l = l
+ self.start = start
+ self.extent = extent
+ self.pos = 0
+
+ def draw (self, d):
+ d.draw_arc (self.coord, self.l, start = self.start,
+ extent = self.extent, style = 'arc', outline = '#808080')
+ a = self.start + self.pos * self.extent
+ d.draw_line (self.coord, (self.coord[0] + cos (a),
+ self.coord[1] + sin (a)))
+
+
+class Rear (Drawable):
+ """Rear actuators."""
+
+ def __init__ (self, onto):
+ Drawable.__init__ (self, onto)
+ self.traps = [
+ Servo ((-2.5, -1), 1, 0, pi/2),
+ Servo ((-1.5, -0.9), 1, 0, pi/2),
+ Servo ((-0.5, -0.8), 1, 0, pi/2),
+ Servo ((0.5, -0.8), 1, pi, -pi/2),
+ Servo ((1.5, -0.9), 1, pi, -pi/2),
+ Servo ((-2.5, 1.3), 1, -pi/6, pi/3),
+ ]
+
+ def draw (self):
+ self.reset ()
+ self.trans_scale (0.9/5)
+ for i in self.traps:
+ i.draw (self)
+ self.draw_line ((-0.5, 1.5), (-0.5, 0.5), (-2.5, 0.2),
+ fill = '#808080')
+ self.draw_line ((-2.5, -1.2), (-2.5, -2.3), (2.5, -2.3), (2.5, 0.2),
+ (0.5, 0.5), (0.5, 1.5), fill = '#808080')
+ for i in (-1.5, -0.5, 0.5, 1.5):
+ self.draw_line ((i, -2.3), (i, -2), fill = '#808080')
+
+class ActuatorView (DrawableCanvas):
+ """This class handle the view of the actuators inside the robot."""
+
+ def __init__ (self, master = None):
+ DrawableCanvas.__init__ (self, 1, 2, 0, 0, master,
+ borderwidth = 1, relief = 'sunken', background = 'white')
+ self.configure (width = 120, height = 240)
+ self.arm_drawable = Drawable (self)
+ self.arm_drawable.trans_translate ((0, 0.5))
+ self.arm = Arm (self.arm_drawable)
+ self.arm.angle = pi / 6
+ self.rear_drawable = Drawable (self)
+ self.rear_drawable.trans_translate ((0, -0.5))
+ self.rear = Rear (self.rear_drawable)
+
+ def draw (self):
+ self.arm.draw ()
+ self.rear.draw ()
+
class Application (Frame):
def __init__ (self, master = None):
@@ -117,10 +195,15 @@ class Application (Frame):
self.createWidgets ()
def createWidgets (self):
- self.quitButton = Button (self, text = 'Quit', command = self.quit)
- self.quitButton.pack (side = 'right', anchor = 'n')
+ self.rightFrame = Frame (self)
+ self.rightFrame.pack (side = 'right', fill = 'y')
+ self.quitButton = Button (self.rightFrame, text = 'Quit', command = self.quit)
+ self.quitButton.pack (side = 'top')
+ self.actuatorview = ActuatorView (self.rightFrame)
+ self.actuatorview.pack (side = 'bottom', fill = 'x')
+
self.tableview = TableView (self)
- self.tableview.pack (expand = 1, fill = 'both')
+ self.tableview.pack (expand = True, fill = 'both')
app = Application()
app.mainloop()