zunächst einmal: ich bin ein Anfänger in Python und ganz besonders mit matplotlib

Also: Im Zuge eines Projektes mit einem zweiarmigen Roboteraufbau habe ich ein kleines Programm geschrieben, was aus den Positionsdaten der einzelnen Gelenke auslesen soll, was für eine Bewegung gemacht wurde.
Dazu werden die Daten für jeden Arm jeweils in einer Matrix geordnet nach Gelenken eingelesen, die aktuelle Positionen mit denen vor t Samples verglichen und überprüft, ob die Differenz einen Schwellwert (hier provisorisch ein Bruchteil der jeweiligen Standardabweichung) übersteigt. Die maximale Auslenkung entscheidet dann darüber, welche "Bewegung" gerade gemacht wird. Das Programm ist noch nicht besonders schick, aber es tut, was es soll (also da erstmal nicht kritisieren

Vielen Dank schon einmal!
(PS: verwende Python 2.7, falls das für matplotlib von Bedeutung ist)
Code: Alles auswählen
import numpy as np
import matplotlib.pyplot as plt
from copy import deepcopy
#####
J_309_310 = [13, 5]
J_409_410 = [7, 5]
fig1 = plt.figure()
plt.plot([10, 10, 10, 10, 10, 10, 11, 13, 14, 14, 14, 13, 14, 14, 14, 14, 13, 9, 7, 6, 6, 6, 7, 6, 6, 6, 6, 7], # Koordinaten der Gelenke
[7, 9, 11, 13, 16, 17, 15, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 15, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5], 'ko',
markerfacecolor='w', markersize=15)
plt.axis([0, 20, 0, 22])
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.ion()
plt.show()
#####
input1 = np.load('/Users/neckardt/Documents/joints1.npy')
input2 = np.load('/Users/neckardt/Documents/joints2.npy')
arm1 = deepcopy(input1)
arm2 = deepcopy(input2)
t = 50
mv1 = []
for i in range(0, len(arm1[:, 1])):
mv1 += [np.std(arm1[i, :])]
mv1 = np.asarray(mv1)
mv1 /= 5.5
mv2 = []
for i in range(0, len(arm2[:, 1])):
mv2 += [np.std(arm2[i, :])]
mv2 = np.asarray(mv2)
mv2 /= 5.5
#####
for i in range(2206 + t, len(arm1[5, :])):
array1 = np.amax(abs(arm1[:, i] - arm1[:, i - t]))
array2 = np.amax(abs(arm2[:, i] - arm2[:, i - t]))
if array1 > array2:
ind = np.argmax(abs(arm1[:, i] - arm1[:, i - t]))
else:
ind = np.argmax(abs(arm2[:, i] - arm2[:, i - t]))
if abs(arm1[ind, i] - arm1[ind, i - t]) >= mv1[ind] and abs(arm2[ind, i] - arm2[ind, i - t]) >= mv2[ind]:
# Beide Arme
plt.plot([J_309_310[0]], [J_309_310[1]], 'go', markersize=15)
plt.plot([J_409_410[0]], [J_309_310[1]], 'go', markersize=15)
elif abs(arm1[ind, i] - arm1[ind, i - t]) >= mv1[ind]:
# nur linker Arm
plt.plot([J_409_410[0]], [J_409_410[1]], 'ko', markerfacecolor='w', markersize=15)
plt.plot([J_309_310[0]], [J_309_310[1]], 'go', markersize=15)
elif abs(arm2[ind, i] - arm2[ind, i - t]) >= mv2[ind]:
# nur rechter Arm
plt.plot([J_309_310[0]], [J_409_410[1]], 'ko', markerfacecolor='w', markersize=15)
plt.plot([J_409_410[0]], [J_309_310[1]], 'go', markersize=15)
else:
print "{0:00}. -".format(i)
plt.plot([J_309_310[0]], [J_309_310[1]], 'ko', markerfacecolor='w', markersize=15)
plt.plot([J_409_410[0]], [J_409_410[1]], 'ko', markerfacecolor='w', markersize=15)
plt.draw()