changeset 154:869a77d30574

joy
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Thu, 07 Aug 2014 17:56:57 +0200
parents 6d63e4e4542d
children ff5817807016
files joy.py
diffstat 1 files changed, 0 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/joy.py	Thu Aug 07 17:52:45 2014 +0200
+++ b/joy.py	Thu Aug 07 17:56:57 2014 +0200
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import pygame
-import serial
-
-import kubik
-import creep
-
-FPS = 24
-
-
-class Walk(creep.Creep):
-    def __init__(self, robot):
-        super(Walk, self).__init__(robot)
-        self.speed = [0.0, 0.0]
-        self.rotation = 0.0
-        self.gait = ''
-
-    def joy_anim(self):
-        """This animation is for reading user input."""
-        while True:
-            for event in pygame.event.get():
-                if event.type == pygame.QUIT:
-                    raise SystemExit()
-                elif event.type == pygame.JOYBUTTONDOWN:
-                    if event.button == 10:
-                        self.gait = 'forward'
-                    elif event.button == 11:
-                        if self.rotation > 0:
-                            self.gait = 'rotate_left'
-                        else:
-                            self.gait = 'rotate_right'
-                    elif event.button == 0:
-                        serial = self.robot.legs[0].hip.serial
-                        serial.write('0xfd')
-                        sensor = ord(serial.read(1))
-                        print "Sensor value: %d" % sensor
-                    else:
-                        print "Button %d" % event.button
-                elif event.type == pygame.JOYBUTTONUP:
-                    if event.button in (10, 11):
-                        self.gait = ''
-                elif event.type == pygame.JOYAXISMOTION:
-                    if event.axis == 0:
-                        self.speed[0] = event.value
-                        self.rotation = 0.0
-                    elif event.axis == 1:
-                        self.speed[1] = -event.value
-                        self.rotation = 0.0
-                    elif event.axis == 2:
-                        self.robot.shift[2] = event.value * 12
-                    elif event.axis == 3:
-                        self.rotation = event.value
-                        self.speed = [0.0, 0.0]
-            yield
-
-
-
-if __name__ == '__main__':
-    # Initialize PyGame.
-    pygame.display.init()
-    pygame.joystick.init()
-    for joy in range(pygame.joystick.get_count()):
-        pygame.joystick.Joystick(joy).init()
-
-    # Initialize the robot.
-    robot = kubik.Robot(serial.Serial('/dev/rfcomm0', 9600))
-    robot.home()
-    walk = Walk(robot)
-    clock = pygame.time.Clock()
-    robot.run_animations([
-        walk.stomp_anim(),
-        walk.retract_anim(),
-        walk.joy_anim(),
-    ], FPS)