Mercurial > ukubik
changeset 85:ea63674fe408
Fine tune accel readings
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 12 Oct 2014 12:39:26 +0200 |
| parents | 3c6798ab41ba |
| children | e0fc40139163 |
| files | robot.py show_accel.py |
| diffstat | 2 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/robot.py Sun Oct 12 12:39:17 2014 +0200 +++ b/robot.py Sun Oct 12 12:39:26 2014 +0200 @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import itertools +import math import pygame @@ -64,6 +65,12 @@ sensors[6], # temperature ] + def get_attitude(self): + ((ax, ay, az), (gx, gy, gz), tmp) = self.get_accel() + roll = math.degrees(math.atan2(ay, az)) + pitch = math.degrees(math.atan(ay / math.sqrt(ax ** 2 + az ** 2))) + return (roll, pitch), (gx/ 16384, gy / 16384, gz / 16384) + def get_battery(self): return float(self.legs[0].hip.get_battery() - self.battery_min) / (self.battery_max - self.battery_min)
--- a/show_accel.py Sun Oct 12 12:39:17 2014 +0200 +++ b/show_accel.py Sun Oct 12 12:39:26 2014 +0200 @@ -15,6 +15,8 @@ def circle(self, screen, (x, y, z), c, m): x = m + int((x * m) / 16384) y = m + int((y * m) / 16384) + if z < 0: + c /= 2 z = max(2, int(abs(z * m) / 16384)) pygame.draw.circle(screen, c, (x, y), z, 2) @@ -23,6 +25,8 @@ xsize, ysize = screen.get_size() while True: accel, gyro, temp = robot.get_accel() + accel = accel[1], accel[0], accel[2] + gyro = gyro[1], gyro[2], gyro[0] screen.fill(0x000000) self.circle(screen, accel, 0xff0000, 100) self.circle(screen, gyro, 0x00ff00, 100)
