Skip to content

Commit

Permalink
better rot
Browse files Browse the repository at this point in the history
  • Loading branch information
metaxy committed Mar 26, 2012
1 parent 71bf2d6 commit b6e99d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
47 changes: 45 additions & 2 deletions code/rotating_cube.py
Expand Up @@ -6,6 +6,35 @@
"""
import sys, math, pygame
from operator import itemgetter
import serial
import inspect
import numpy as np
from math import *


class IMU:
ser = serial.Serial(2, 115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=1, timeout=1, xonxoff=True)

def start(this):
this.ser.flush()
this.ser.write('+'.encode('latin1'))

def parse(this,a):
return float(a.replace('+',''))

def read(this):
this.ser.flush()
list = str(this.ser.readline(), encoding='utf8' ).split(' ')
time = this.parse(list[0])
v = [this.parse(list[3]),this.parse(list[4]),this.parse(list[5])]
theta = [this.parse(list[8]),this.parse(list[9]),this.parse(list[10])]
acc=[this.parse(list[13]),this.parse(list[14]),this.parse(list[15])]

return [time,v,theta,acc]

def close(this):
print "Closing IMU"
this.ser.close()

class Point3D:
def __init__(self, x = 0, y = 0, z = 0):
Expand Down Expand Up @@ -75,10 +104,20 @@ def __init__(self, win_width = 640, win_height = 480):
self.angle = 60

def run(self):
try:
imu = IMU()
imu.start()
except:
imu.close();
print "Failed to open IMU"
return

""" Main Loop """
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print "Quitting"
imu.close()
pygame.quit()
sys.exit()

Expand All @@ -87,10 +126,14 @@ def run(self):

# It will hold transformed vertices.
t = []

try:
time,v,theta,acc = imu.read()
except:
print "Failed to read IMU"
continue
for v in self.vertices:
# Rotate the point around X axis, then around Y axis, and finally around Z axis.
r = v.rotateX(self.angle).rotateY(self.angle).rotateZ(self.angle)
r = v.rotateX(theta[0]).rotateY(theta[1]).rotateZ(theta[2])
# Transform the point from 3D to 2D
p = r.project(self.screen.get_width(), self.screen.get_height(), 256, 4)
# Put the point in the list of transformed vertices
Expand Down
17 changes: 9 additions & 8 deletions presentation/pre.tex
Expand Up @@ -65,16 +65,17 @@
\end{frame}

\begin{frame}
\subsection{Acceleromter}
\section{Acceleromter}
\frametitle{Accelerometer (Beschleunigungssensoren)}
\begin{block}{Prinzip}
Messung der aufgrund von Trägheitskräften resultierende Beschleunigung
\end{block}
Anwendung:
\begin{itemize}
\item Messung von (linearen) Beschleunigungen
\item Sensorik in digitalen Kameras
\item Positionsbestimmung
\item Seismographen
\item Schutz vor Head-Crash bei Festplatten
\end{itemize}
\begin{figure}
\subfigure{\includegraphics[width=0.49\textwidth, height=0.4\textheight,keepaspectratio=true]{images/acc2.jpg}}\hfil
Expand Down Expand Up @@ -124,7 +125,7 @@
\end{frame}

\begin{frame}
\subsection{Gyroskop}
\section{Gyroskop}
\frametitle{Gyroskop (Rotationssensoren)}

\begin{block}{Was ist ein Gyroskop}
Expand Down Expand Up @@ -203,10 +204,7 @@
\end{enumerate}
\end{frame}

\begin{frame}
\frametitle{Stable Platform Systems}
\includegraphics[scale=0.55]{images/gimbal.png} \cite{King98}
\end{frame}


\begin{frame}
Vollkardanisch kreiselstabilisierte (Stabile Plattform)
Expand Down Expand Up @@ -310,5 +308,8 @@

\end{frame}


\begin{frame}
\frametitle{Stable Platform Systems}\cite{King98}
\includegraphics[scale=0.55]{images/gimbal.png}
\end{frame}
\end{document}

0 comments on commit b6e99d9

Please sign in to comment.