changeset 132:afaac497dfe7

steps
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 12 Jul 2014 12:02:13 +0000
parents 6617b34e4047
children 6cfedf4dc1b7
files creep.py kubik.py rotate.py
diffstat 3 files changed, 42 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/creep.py	Wed Jul 09 21:29:58 2014 +0000
+++ b/creep.py	Sat Jul 12 12:02:13 2014 +0000
@@ -1,6 +1,6 @@
 import kubik
 
-STRIDE = 45
+STRIDE = 42
 SPEED = 3
 SWING = 24
 SWING_SPEED = 4
@@ -8,14 +8,14 @@
 HEIGHT = -35
 STEP = -5
 OVERLAP = 1
-FPS = 6
+FPS = 36
 
 
-def swing(robot):
+def _swing(robot, delay, steps):
     for i in range(delay):
         yield
     pause = STRIDE / SPEED + 3 - SWING * 2 / SWING_SPEED
-    while True:
+    for step in range(steps):
         for i in range(pause):
             yield
         for i in range(-SWING, SWING, SWING_SPEED):
@@ -28,10 +28,10 @@
             yield
 
 
-def creep(leg, side, delay, robot):
+def _creep(leg, side, delay, steps):
     for i in range(delay):
         yield
-    while True:
+    for step in range(steps):
         leg.move_to((None, None, STEP))
         for i in range(4):
             yield
@@ -44,15 +44,20 @@
             yield
 
 
+def creep(robot, steps):
+    delay = (2 * STRIDE / SPEED + 6) / 4
+    animations = [
+        _swing(robot, 0, steps),
+        _creep(robot.legs[0], 1, delay * 0 + OVERLAP, steps),
+        _creep(robot.legs[1], 1, delay * 1 - OVERLAP, steps),
+        _creep(robot.legs[3], -1, delay * 2 + OVERLAP, steps),
+        _creep(robot.legs[2], -1, delay * 3 - OVERLAP, steps),
+    ]
+    return animations
+
+
 if __name__ == '__main__':
     robot = kubik.Robot()
     robot.home()
-    delay = (2 * STRIDE / SPEED + 6) / 4
-    animations = [
-        swing(robot),
-        creep(robot.legs[0], 1, delay * 0 + OVERLAP, robot),
-        creep(robot.legs[1], 1, delay * 1 - OVERLAP, robot),
-        creep(robot.legs[3], -1, delay * 2 + OVERLAP, robot),
-        creep(robot.legs[2], -1, delay * 3 - OVERLAP, robot),
-    ]
+    animations = creep(robot, 10)
     robot.run_animations(animations, FPS)
--- a/kubik.py	Wed Jul 09 21:29:58 2014 +0000
+++ b/kubik.py	Sat Jul 12 12:02:13 2014 +0000
@@ -143,7 +143,7 @@
                 KneeServo(m, 5, reverse=True, trim=-200),
                 AnkleServo2(m, 3, reverse=True, trim=-400, center=1500 * 4),
                 True),
-            Leg(HipServo(m, 7, reverse=True, trim=150),
+            Leg(HipServo(m, 7, reverse=False, trim=-150),
                 KneeServo(m, 8, trim=100),
                 AnkleServo1(m, 6, trim=0, center=1500 * 4),
                 True),
--- a/rotate.py	Wed Jul 09 21:29:58 2014 +0000
+++ b/rotate.py	Sat Jul 12 12:02:13 2014 +0000
@@ -1,22 +1,22 @@
 import kubik
 
 
-STRIDE = 10
-SPEED = 1
+STRIDE = -20
+SPEED = -1
 SWING = 18
 SWING_SPEED = 3
 STEP = -10
 HEIGHT = -35
-OVERLAP = 1
-FPS = 12
+OVERLAP = -3
+FPS = 36
 
 
-def swing(robot, (dx, dy), delay=0):
+def _swing(robot, (dx, dy), delay, steps):
     for i in range(delay):
         yield
     pause = STRIDE / SPEED + 3 - SWING * 2 / SWING_SPEED
     first = True
-    while True:
+    for step in range(steps):
         for i in range(pause):
             yield
         for i in range(-SWING, SWING, SWING_SPEED):
@@ -33,11 +33,11 @@
 
 
 
-def rotate(leg, side, delay):
+def _rotate(leg, side, delay, steps):
     for i in range(delay):
         yield
     first = True
-    while True:
+    for step in range(steps):
         leg.move_to((None, None, STEP))
         for i in range(4):
             yield
@@ -55,16 +55,21 @@
             yield
 
 
+def rotate(robot, steps):
+    delay = (2 * STRIDE / SPEED + 6) / 4
+    animations = [
+        _swing(robot, (-1, 0), 0 * delay, steps),
+#        swing(robot, (0, 1), 1 * delay, steps),
+        _rotate(robot.legs[0], 1, 0 * delay + OVERLAP, steps),
+        _rotate(robot.legs[1], -1, 1 * delay - OVERLAP, steps),
+        _rotate(robot.legs[3], -1, 2 * delay + OVERLAP, steps),
+        _rotate(robot.legs[2], 1, 3 * delay - OVERLAP, steps),
+    ]
+    return animations
+
+
 if __name__ == '__main__':
     robot = kubik.Robot()
     robot.home()
-    delay = (2 * STRIDE / SPEED + 6) / 4
-    animations = [
-        swing(robot, (-1, 0), 0 * delay),
-#        swing(robot, (0, 1), 1 * delay),
-        rotate(robot.legs[0], 1, 0 * delay + OVERLAP),
-        rotate(robot.legs[1], -1, 1 * delay - OVERLAP),
-        rotate(robot.legs[3], -1, 2 * delay + OVERLAP),
-        rotate(robot.legs[2], 1, 3 * delay - OVERLAP),
-    ]
+    animations = rotate(robot, 10)
     robot.run_animations(animations, FPS)