projects:aerosol_code
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
projects:aerosol_code [2008/03/03 01:01] – laurenceb | projects:aerosol_code [2008/07/19 23:33] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
<code python> | <code python> | ||
- | #!/usr/ | + | #!/media/ |
- | ##!/media/ | + | ##!/usr/bin/python |
+ | |||
import reed_solomon | import reed_solomon | ||
import serial | import serial | ||
Line 15: | Line 16: | ||
TRUE=1 | TRUE=1 | ||
FALSE=0 | FALSE=0 | ||
+ | DEG2RAD=math.pi/ | ||
class updatest: | class updatest: | ||
pass | pass | ||
- | mynumber=" | + | mynumber=" |
default_target_pressure=40 | default_target_pressure=40 | ||
limit=[200, | limit=[200, | ||
Line 25: | Line 27: | ||
Roottwotwomgovercda = (2*9.81*2/ | Roottwotwomgovercda = (2*9.81*2/ | ||
iterations=0 | iterations=0 | ||
+ | Jxpoints=[] | ||
+ | Jypoints=[] | ||
updatestuff=updatest() | updatestuff=updatest() | ||
- | + | ||
- | + | ||
+ | |||
def gps_status(): | def gps_status(): | ||
print ' | print ' | ||
Line 43: | Line 47: | ||
status=FALSE | status=FALSE | ||
return status | return status | ||
+ | |||
def gps_data(): | def gps_data(): | ||
+ | ser_gr.flushInput() | ||
print ' | print ' | ||
gpspos_parts=['' | gpspos_parts=['' | ||
Line 57: | Line 62: | ||
if gpspos_parts[5]==" | if gpspos_parts[5]==" | ||
longitude=-longitude | longitude=-longitude | ||
+ | if gpspos_parts[9]=='': | ||
+ | gpspos_parts[9]=' | ||
altitude=float(gpspos_parts[9]) | altitude=float(gpspos_parts[9]) | ||
#print gpstime, | #print gpstime, | ||
return gpstime, | return gpstime, | ||
+ | |||
def db_stats(): | def db_stats(): | ||
+ | ser_daughter.flushInput() | ||
ser_daughter.write(" | ser_daughter.write(" | ||
V1=ser_daughter.readline() | V1=ser_daughter.readline() | ||
Line 76: | Line 84: | ||
ser_daughter.write(" | ser_daughter.write(" | ||
TS=ser_daughter.readline() | TS=ser_daughter.readline() | ||
- | return V1, | + | return V1[: |
+ | |||
def HV_enable(n): | def HV_enable(n): | ||
stringy=' | stringy=' | ||
ser_daughter.write(stringy) | ser_daughter.write(stringy) | ||
print ser_daughter.readline() | print ser_daughter.readline() | ||
+ | |||
def Set_pressure_target(P): | def Set_pressure_target(P): | ||
ser_daughter.write(' | ser_daughter.write(' | ||
- | + | ||
- | def air_density(alt): | + | def air_density(alt): |
if (alt < 11000.0): | if (alt < 11000.0): | ||
# below 11Km - Troposphere | # below 11Km - Troposphere | ||
Line 102: | Line 110: | ||
return(pres / (0.2869 * (temp + 273.1))) | return(pres / (0.2869 * (temp + 273.1))) | ||
+ | |||
def Updatepredict(Seconds, | def Updatepredict(Seconds, | ||
- | if iterations==0: | ||
- | updatestuff.Predictedn=North | ||
- | updatestuff.Predictede=East | ||
- | updatestuff.Oldeast=East | ||
- | updatestuff.Oldnorth=North | ||
- | updatestuff.Oldaltitude=Altitude | ||
- | updatestuff.Oldseconds=Seconds | ||
Deltae=East-updatestuff.Oldeast | Deltae=East-updatestuff.Oldeast | ||
Deltan=North-updatestuff.Oldnorth | Deltan=North-updatestuff.Oldnorth | ||
Line 116: | Line 117: | ||
Deltat=Seconds-updatestuff.Oldseconds | Deltat=Seconds-updatestuff.Oldseconds | ||
Averagealt=(updatestuff.Oldaltitude+Altitude)/ | Averagealt=(updatestuff.Oldaltitude+Altitude)/ | ||
- | updatestuff.Oldeast=East | ||
- | updatestuff.Oldnorth=North | ||
- | updatestuff.Oldaltitude=Altitude | ||
- | updatestuff.Oldseconds=Seconds | ||
if Deltaa> | if Deltaa> | ||
K=Roottwotwomgovercda*(air_density(Averagealt)**-0.5) | K=Roottwotwomgovercda*(air_density(Averagealt)**-0.5) | ||
Line 127: | Line 124: | ||
K=K/ | K=K/ | ||
print "Layer weighting=", | print "Layer weighting=", | ||
- | K=K+1 | + | updatestuff.Predictedn+=(K+1)*Deltan |
- | updatestuff.Predictedn+=K*Deltan | + | updatestuff.Predictede+=Deltae*( (K*math.cos(((North + updatestuff.Oldnorth)/ |
- | updatestuff.Predictede+=K*Deltae | + | updatestuff.Oldeast=East |
+ | updatestuff.Oldnorth=North | ||
+ | updatestuff.Oldaltitude=Altitude | ||
+ | updatestuff.Oldseconds=Seconds | ||
print " | print " | ||
print " | print " | ||
return updatestuff.Predictedn, | return updatestuff.Predictedn, | ||
- | + | ||
+ | |||
def are_we_inside(gpstime, | def are_we_inside(gpstime, | ||
count=False | count=False | ||
Line 143: | Line 143: | ||
else: | else: | ||
gplus=g+1 | gplus=g+1 | ||
- | if ((Jypoints[g]> | + | if ((Jypoints[g]> |
count=not count | count=not count | ||
+ | print " | ||
print 'we are inside=', | print 'we are inside=', | ||
return count | return count | ||
+ | |||
def load_kml(filepath): | def load_kml(filepath): | ||
xpoints=[] | xpoints=[] | ||
Line 163: | Line 164: | ||
ypoints+=[float(line_split[1])] | ypoints+=[float(line_split[1])] | ||
return xpoints, | return xpoints, | ||
- | + | ||
- | def send_sms(s, | + | def send_sms(s, |
target=str(target) | target=str(target) | ||
- | smscen=str(smscen) | + | if not len(target)==12: |
- | if not (len(target)==12 | + | print " |
- | print " | + | |
return -1 | return -1 | ||
if len(s)> | if len(s)> | ||
Line 189: | Line 189: | ||
Bitstring.append(0) | Bitstring.append(0) | ||
print " | print " | ||
- | stringy=" | + | stringy=" |
- | print stringy | + | #print stringy |
ser_phone.write(stringy) | ser_phone.write(stringy) | ||
- | print ser_phone.readline() | + | print ser_phone.readline() |
- | stringy=" | + | ser_phone.readline() |
- | for g in range(6): | + | print ser_phone.readline() # the "> " is recieved |
- | stringy+=(smscen[2*g+1]) | + | stringy=" |
- | stringy+=(smscen[2*g]) | + | |
- | stringy+="11000C91" | + | |
for g in range(6): | for g in range(6): | ||
stringy+=(target[2*g+1]) | stringy+=(target[2*g+1]) | ||
stringy+=(target[2*g]) | stringy+=(target[2*g]) | ||
- | stringy+=" | + | stringy+=" |
- | stringy+=" | + | stringy+=" |
for G in Bitstring: | for G in Bitstring: | ||
- | stringy+=" | + | stringy+=" |
- | stringy+=chr(026) | + | stringy+=chr(26) #send it |
ser_phone.write(stringy) | ser_phone.write(stringy) | ||
for n in range(4): | for n in range(4): | ||
print ser_phone.readline() | print ser_phone.readline() | ||
- | print stringy | + | # print stringy |
return 0 | return 0 | ||
+ | |||
def get_smscen(): | def get_smscen(): | ||
ser_phone.write(" | ser_phone.write(" | ||
Line 218: | Line 216: | ||
s=s.split('"' | s=s.split('"' | ||
return str(s[1: | return str(s[1: | ||
+ | |||
def cutdown(): | def cutdown(): | ||
- | #ser_gr.write(" | + | ser_gr.write(" |
shutdown() | shutdown() | ||
- | #os.system(" | + | os.system(" |
time.sleep(6) | time.sleep(6) | ||
- | #os.system(" | + | os.system(" |
print " | print " | ||
+ | |||
def shutdown(): | def shutdown(): | ||
HV_enable(0) | HV_enable(0) | ||
Set_pressure_target(0) #pump off | Set_pressure_target(0) #pump off | ||
time.sleep(1) | time.sleep(1) | ||
- | #os.system(" | + | os.system(" |
time.sleep(3) | time.sleep(3) | ||
- | #os.system(" | + | os.system(" |
print " | print " | ||
- | #ser_gr.write(" | + | ser_gr.write(" |
+ | |||
try: | try: | ||
print 'AOPP aerosol experiment running' | print 'AOPP aerosol experiment running' | ||
# | # | ||
log=open(" | log=open(" | ||
- | #ser_gr=serial.Serial('/ | + | ser_gr=serial.Serial('/ |
- | ser_gr=open(" | + | #ser_gr=open(" |
- | #ser_daughter=serial.Serial('/ | + | ser_daughter=serial.Serial('/ |
- | ser_daughter=open(" | + | #ser_daughter=open(" |
- | #ser_phone=serial.Serial('/ | + | ser_phone=serial.Serial('/ |
- | ser_phone=open(" | + | #ser_phone=open(" |
print ' | print ' | ||
- | #ser_gr.write(" | + | ser_gr.write(" |
- | log.write(" | + | #log.write(" |
reed_solomon.setup_rs() | reed_solomon.setup_rs() | ||
- | #ser_gr.write(reed_solomon.encode_string(" | + | ser_gr.write(reed_solomon.encode_string(" |
- | log.write(reed_solomon.encode_string(" | + | #log.write(reed_solomon.encode_string(" |
- | while not gps_status(): | + | # while not gps_status(): |
- | # | + | # ser_gr.write(" |
- | log.write(" | + | #log.write(" |
print 'ok, gps is ready, we are at:' | print 'ok, gps is ready, we are at:' | ||
- | #ser_gr.write(" | + | ser_gr.write(" |
- | log.write(" | + | #log.write(" |
print gps_data() | print gps_data() | ||
print 'now probing daughterboard' | print 'now probing daughterboard' | ||
Line 291: | Line 289: | ||
print ser_phone.readline() | print ser_phone.readline() | ||
print ser_phone.readline() | print ser_phone.readline() | ||
- | smscen=get_smscen() | + | #smscen=get_smscen() |
- | send_sms(" | + | send_sms(" |
- | #ser_daughter.flushinput() | + | ser_daughter.flushInput() |
- | #ser_phone.flushinput() | + | ser_phone.flushInput() |
+ | system_vector=gps_data() | ||
+ | updatestuff.Predictedn=system_vector[1] | ||
+ | updatestuff.Predictede=system_vector[2] | ||
+ | updatestuff.Oldeast=system_vector[2] | ||
+ | updatestuff.Oldnorth=system_vector[1] | ||
+ | updatestuff.Oldaltitude=system_vector[3] | ||
+ | updatestuff.Oldseconds=system_vector[0] | ||
count=0 | count=0 | ||
+ | calibrate=0 | ||
layercounter=0 | layercounter=0 | ||
cut_down='' | cut_down='' | ||
Line 307: | Line 313: | ||
print 'in loop' | print 'in loop' | ||
system_vector=gps_data() | system_vector=gps_data() | ||
- | print system_vector | ||
daughter_board=db_stats() | daughter_board=db_stats() | ||
- | datastring=str(system_vector)+str(daughter_board)+cut_down | + | datastring = ',' |
+ | datastring+=str(daughter_board)+cut_down | ||
+ | print datastring | ||
log.write(datastring+" | log.write(datastring+" | ||
- | #ser_gr.write(reed_solomon.encode_string(callsign+datastring)) | + | ser_gr.write(reed_solomon.encode_string(callsign+datastring)) |
- | log.write(reed_solomon.encode_string(callsign+datastring)) | + | #log.write(reed_solomon.encode_string(callsign+datastring)) |
# | # | ||
#print t | #print t | ||
#print reed_solomon.decode_string(t, | #print reed_solomon.decode_string(t, | ||
if count==2: | if count==2: | ||
- | send_sms(datastring, | + | send_sms(datastring, |
count=0 | count=0 | ||
os.system(" | os.system(" | ||
count+=1 | count+=1 | ||
+ | if calibrate==30: | ||
+ | ser_daughter.write(" | ||
+ | calibrate=0 | ||
+ | calibrate+=1 | ||
if cut_down=='': | if cut_down=='': | ||
if system_vector[3]/ | if system_vector[3]/ | ||
layercounter+=1 | layercounter+=1 | ||
up=Updatepredict(*system_vector) | up=Updatepredict(*system_vector) | ||
+ | log.write(str(up)+" | ||
if not are_we_inside([0], | if not are_we_inside([0], | ||
print " | print " | ||
Line 364: | Line 376: | ||
time.sleep(10) | time.sleep(10) | ||
iterations+=1 | iterations+=1 | ||
+ | |||
finally: | finally: | ||
log.close() | log.close() | ||
- | ser_phone.write(" | + | # ser_phone.write(" |
ser_phone.close() | ser_phone.close() | ||
ser_gr.close() | ser_gr.close() | ||
ser_daughter.close() | ser_daughter.close() | ||
print " | print " |
projects/aerosol_code.1204506070.txt.gz · Last modified: 2008/07/19 23:31 (external edit)