Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better rot

  • Loading branch information...
commit b6e99d9e4fe55abcee1ab48e186923e1f4fa9ce0 1 parent 71bf2d6
@metaxy authored
Showing with 54 additions and 10 deletions.
  1. +45 −2 code/rotating_cube.py
  2. +9 −8 presentation/pre.tex
View
47 code/rotating_cube.py
@@ -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):
@@ -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()
@@ -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
View
17 presentation/pre.tex
@@ -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
@@ -124,7 +125,7 @@
\end{frame}
\begin{frame}
- \subsection{Gyroskop}
+ \section{Gyroskop}
\frametitle{Gyroskop (Rotationssensoren)}
\begin{block}{Was ist ein Gyroskop}
@@ -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)
@@ -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}
Please sign in to comment.
Something went wrong with that request. Please try again.