/Modules/Mechanical/WINDGAUGE01A/SW/Data_analyser.ipynb
1,7 → 1,7
{
"metadata": {
"name": "",
"signature": "sha256:2b27dc30afc5801b549b86c718ac60f04cf5f54a281bec76ad61772eab7fb3e7"
"signature": "sha256:2b685229d679e1d41a25fddbfc5abcd92050271aa14c1131a12e709bfacddba1"
},
"nbformat": 3,
"nbformat_minor": 0,
19,7 → 19,7
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"prompt_number": 1
},
{
"cell_type": "code",
31,7 → 31,7
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
"prompt_number": 2
},
{
"cell_type": "code",
50,7 → 50,7
]
}
],
"prompt_number": 4
"prompt_number": 3
},
{
"cell_type": "code",
63,7 → 63,7
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
"prompt_number": 4
},
{
"cell_type": "code",
73,135 → 73,110
"n = 0\n",
"angle = np.zeros((dataset.shape[0]))\n",
"for i in range(dataset.value.shape[0]):\n",
" if abs(dataset.value[i,2] - prev_val) > 300:\n",
" if (dataset.value[i,2] - prev_val) > 300:\n",
" n -= 1\n",
" angle[i] = dataset.value[i,2] + n*360\n",
" prev_val = dataset.value[i,2]\n",
"# elif (dataset.value[i,2] - prev_val) < -300:\n",
"# n -= 1\n",
"# angle[i] = dataset.value[i,2] + n*360\n",
"# prev_val = dataset.value[i,2]\n",
" elif -(dataset.value[i,2] - prev_val) > 300: # compute angular speed in backward direction.\n",
" n += 1\n",
" angle[i] = dataset.value[i,2] - n*360\n",
" prev_val = dataset.value[i,2]\n",
" else:\n",
" angle[i] = dataset.value[i,2] + n*360\n",
" prev_val = dataset.value[i,2]"
" prev_val = dataset.value[i,2]\n",
" "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 55
"prompt_number": 57
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Five point difference numerical calculation. Source: http://mathfun528.blogspot.cz/2011/07/numerical-differentiation.html"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"angle_speed = np.zeros_like(angle)\n",
"\n",
"for i in range(2,angle.shape[0]-2):\n",
" angle_speed[i] = (-angle[i + 2] + 8*angle[i + 1] - 8*angle[i - 1] + angle[i - 2])/12"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 58
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"fig, ax1 = plt.subplots()\n",
"\n",
" ax2 = ax1.twinx()\n",
" ax1.plot(x, y1, 'g-')\n",
" ax2.plot(x, y2, 'b-')\n",
"ax1.set_xlabel('Sample #')\n",
"ax1.set_ylabel('Angle')\n",
"ax2.set_ylabel('Angular speed')\n",
"\n",
" ax1.set_xlabel('X data')\n",
" ax1.set_ylabel('Y1 data', color='g')\n",
" ax2.set_ylabel('Y2 data', color='b')\n",
"\n",
" ax1.plot(dataset.value[:,0], angle,'b',dataset.value[:,0], dataset.value[:,2],'r')\n",
" ax2.plot(dataset.value[1:,0], np.diff(angle, n=1, axis=0),'g')\n",
"ax2.plot(dataset.value[:,0], angle_speed,'g')\n",
"\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "IndentationError",
"evalue": "unexpected indent (<ipython-input-68-85470c16d7f6>, line 3)",
"output_type": "pyerr",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-68-85470c16d7f6>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m ax2 = ax1.twinx()\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unexpected indent\n"
]
}
],
"prompt_number": 68
"outputs": [],
"prompt_number": 59
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"angle.shape"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"output_type": "pyout",
"prompt_number": 63,
"text": [
"(12120,)"
]
}
],
"prompt_number": 63
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dataset.value[:,0].shape"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 57,
"text": [
"(12120,)"
]
}
],
"prompt_number": 57
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dataset.value[:,0].shape"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 60,
"text": [
"(12120,)"
]
}
],
"prompt_number": 60
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"np.diff(angle, n=1, axis=0).shape"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 62,
"text": [
"(12119,)"
]
}
],
"prompt_number": 62
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "code",
/Modules/Mechanical/WINDGAUGE01A/SW/wind_gauge.py
9,6 → 9,7
import time
import datetime
import sys
import numpy as np
from pymlab import config
 
#### Script Arguments ###############################################
64,24 → 65,33
#### Data Logging ###################################################
 
try:
while True:
# for i in range(10):
angle1 = sensor.get_angle(verify = False)
angles = np.zeros(5)
angles[4] = sensor.get_angle(verify = False)
time.sleep(0.1)
angle2 = sensor.get_angle(verify = False)
angles[3] = sensor.get_angle(verify = False)
time.sleep(0.1)
angle3 = sensor.get_angle(verify = False)
angles[2] = sensor.get_angle(verify = False)
time.sleep(0.1)
angles[1] = sensor.get_angle(verify = False)
n = 0
if (angle1 < angle2):
speed = (angle2 - angle1)/0.01
while True:
time.sleep(0.1)
angles[0] = sensor.get_angle(verify = False)
if (angles[0] + n*360 - angles[1]) > 300:
n -= 1
angles[0] = angles[0] + n*360
elif -(angles[0] - n*360 - angles[1]) > 300: # compute angular speed in backward direction.
n += 1
angles[0] = angles[0] - n*360
else:
speed = (360 - angle1 + angle2)/0.01
angles[0] = angles[0] + n*360
speed = (-angles[4] + 8*angles[3] - 8*angles[1] + angles[0])/12
angles = np.roll(angles, 1)
sys.stdout.write("Speed: " + str(speed) +"\t"+ str(angle1) +"\t"+ str(angle2) + "\t\tMagnitude: " + str(sensor.get_magnitude())
+ "\tAGC Value: " + str(sensor.get_agc_value()) + "\tDiagnostics: " + str(sensor.get_diagnostics()) + "\r\n")
sys.stdout.write("Speed: " + str(speed) +"\t"+ str(angles[0]) + "\r\n")
sys.stdout.flush()
time.sleep(0.01)
except KeyboardInterrupt:
sys.exit(0)