Mercurial > ukubik
changeset 83:9f37e5f03a20
Show the values from accelerometer
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 11 Oct 2014 17:27:32 +0200 |
| parents | 49e3d06ed7c8 |
| children | 3c6798ab41ba |
| files | show_accel.py |
| diffstat | 1 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/show_accel.py Sat Oct 11 17:27:32 2014 +0200 @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import pygame +import serial +import math + +import kubik +import joy + + +FPS = 50 + + +class Walk(joy.Walk): + def circle(self, screen, (x, y, z), c, m): + x = m + int((x * m) / 16384) + y = m + int((y * m) / 16384) + z = max(2, int(abs(z * m) / 16384)) + pygame.draw.circle(screen, c, (x, y), z, 2) + + def accel_anim(self): + screen = pygame.display.get_surface() + xsize, ysize = screen.get_size() + while True: + accel, gyro, temp = robot.get_accel() + screen.fill(0x000000) + self.circle(screen, accel, 0xff0000, 100) + self.circle(screen, gyro, 0x00ff00, 100) + pygame.display.update() + yield + + +if __name__ == '__main__': + # Initialize PyGame. + pygame.display.init() + window = pygame.display.set_mode((200, 200)) + 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', 115200)) + robot.home() + walk = Walk(robot) + clock = pygame.time.Clock() + robot.run_animations([ + walk.stomp_anim(), + walk.retract_anim(), + walk.joy_anim(), + walk.accel_anim(), + ], FPS)
