From 76cb885a1f7a0f4abd0b945863e4fb25858ae0e3 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Wed, 21 Mar 2012 05:14:12 +0000 Subject: confirmed it works, make it look nice git-svn-id: https://svn.spreadspace.org/mur.sat@323 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- tools/photodiodesim/pd_sim.py | 45 +++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'tools/photodiodesim/pd_sim.py') diff --git a/tools/photodiodesim/pd_sim.py b/tools/photodiodesim/pd_sim.py index a5f25b9..0d95522 100755 --- a/tools/photodiodesim/pd_sim.py +++ b/tools/photodiodesim/pd_sim.py @@ -11,13 +11,18 @@ import pylab as pl import scipy.io import re -simduration = 300 #s -simtimestep = 0.1 #s -w_x = np.random.ranf() * np.pi/4 #rad/s -w_y = np.random.ranf() * np.pi/4 #rad/s -w_z = np.random.ranf() * np.pi/4 #rad/s +w_x = np.random.ranf() * np.pi/2 #rad/s +w_y = np.random.ranf() * np.pi/2 #rad/s +w_z = np.random.ranf() * np.pi/2 #rad/s filename_export_mat = "./pd_sim.mat" filename_export_csv = "./pd_sim.csv" +sun = [1,1,1] +numsamples = 1000 +numperiods = 8 + +#calculate simduration so we see numperiods periods of the smalest angular speed +simduration = numperiods*np.pi / min(filter(lambda x: x>0.0,[w_x,w_y,w_z])) if w_x or w_y or w_z else 1.0 #in seconds +simtimestep = simduration / numsamples #s print "Simulation Input:" @@ -42,8 +47,7 @@ sensors = np.matrix([ [0,0,1], [0,0,-1] ]) - -sun= np.matrix([ 1,0,0]) +sun = np.matrix(sun / np.linalg.norm(sun)) def getRotationMatrix(angles): x_angle = angles[0,0] @@ -51,11 +55,11 @@ def getRotationMatrix(angles): z_angle = angles[0,2] return np.matrix([ [1, 0, 0], - [0, np.cos(x_angle), -np.sin(x_angle)], + [0, np.cos(x_angle), -np.sin(x_angle)], [0, np.sin(x_angle), np.cos(x_angle)] ]) * np.matrix([ - [np.cos(y_angle) ,0,np.sin(y_angle)], - [0, 1,0], + [ np.cos(y_angle),0,np.sin(y_angle)], + [ 0, 1,0], [-np.sin(y_angle),0,np.cos(y_angle)] ]) * np.matrix([ [np.cos(z_angle),-np.sin(z_angle),0], @@ -106,12 +110,30 @@ scipy.io.savemat(filename_export_mat, mdict={"legend":legend_names, "senstrace": print "Saving to " + filename_export_csv exportCSV(filename_export_csv, legend_names, simtimeline, senstrace) + +xlabelpos = np.hstack((np.arange(0,simduration, simduration/5),simduration)) +xlabelvalues = ["%.3f" % t for t in xlabelpos] +ylabelpos = [0,0.5,1] +ylabelvalues = [u"0%", u"50%", u"100%"] + +#~ pl.figure() +#~ pl.plot(simtimeline, senstrace) +#~ pl.xticks(xlabelpos,xlabelvalues,rotation=0) +#~ pl.yticks(ylabelpos, ylabelvalues) +#~ pl.xlabel("[s]") +#~ pl.ylabel("[rad]") +#~ pl.legend(legend_names) + pl.figure() for f in range(0,3): fs = 2*f fe = fs + 2 pl.subplot(3,1,f+1) pl.plot(simtimeline, senstrace[:,fs:fe]) + pl.xticks(xlabelpos,xlabelvalues,rotation=0) + pl.yticks(ylabelpos, ylabelvalues) + pl.xlabel("[s]") + pl.ylabel("[Light Intensity]") pl.legend(legend_names[fs:fe]) pl.figure() @@ -120,6 +142,9 @@ spnrows=3 for s in range(0,6): pl.subplot(spnrows,spncols,s+1) pl.plot(simtimeline, senstrace[:,s]) + pl.xticks(xlabelpos,xlabelvalues,rotation=0) + pl.yticks(ylabelpos, ylabelvalues) + pl.ylabel("[Light Intensity]") pl.title(legend_names[s]) pl.show() -- cgit v1.2.3