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/02 10:00] – 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 | ||
- | mynumber=" | + | DEG2RAD=math.pi/ |
+ | class updatest: | ||
+ | pass | ||
+ | mynumber=" | ||
default_target_pressure=40 | default_target_pressure=40 | ||
- | start_altitude=200 | + | limit=[200,10000, |
- | limit=[10000, | + | max_flight_time=7000 |
callsign=" | callsign=" | ||
logname=" | logname=" | ||
- | Roottwomgovercda | + | Roottwotwomgovercda |
iterations=0 | iterations=0 | ||
+ | Jxpoints=[] | ||
+ | Jypoints=[] | ||
updatestuff=updatest() | updatestuff=updatest() | ||
- | + | ||
- | class updatest: | + | |
- | pass | + | |
def gps_status(): | def gps_status(): | ||
print ' | print ' | ||
- | gpspos_parts[0]='' | + | gpspos_parts=['' |
while not gpspos_parts[0]==' | while not gpspos_parts[0]==' | ||
gpspos=ser_gr.readline() | gpspos=ser_gr.readline() | ||
+ | print " | ||
gpspos_parts = gpspos.split(',' | gpspos_parts = gpspos.split(',' | ||
- | if ((gpspos_parts[6]==' | + | if ((gpspos_parts[6]==' |
print 'GPS fix' , gpspos_parts[6] , 'ie valid' | print 'GPS fix' , gpspos_parts[6] , 'ie valid' | ||
- | gpsstatus=TRUE | + | status=TRUE |
else: | else: | ||
print 'GPS fix' , gpspos_parts[6] , 'ie not valid' | print 'GPS fix' , gpspos_parts[6] , 'ie not valid' | ||
status=FALSE | status=FALSE | ||
return status | return status | ||
+ | |||
def gps_data(): | def gps_data(): | ||
+ | ser_gr.flushInput() | ||
print ' | print ' | ||
- | gpspos_parts[0]='' | + | gpspos_parts=['' |
while not gpspos_parts[0]==' | while not gpspos_parts[0]==' | ||
gpspos=ser_gr.readline() | gpspos=ser_gr.readline() | ||
gpspos_parts = gpspos.split(',' | gpspos_parts = gpspos.split(',' | ||
gpstime=3600*float(gpspos_parts[1][0: | gpstime=3600*float(gpspos_parts[1][0: | ||
- | latitude=float(gpspos_parts[2][0: | + | latitude=float(gpspos_parts[2][0: |
if gpspos_parts[3]==" | if gpspos_parts[3]==" | ||
latitude=-latitude | latitude=-latitude | ||
Line 55: | 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, | ||
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 72: | Line 83: | ||
PD=ser_daughter.readline() | PD=ser_daughter.readline() | ||
ser_daughter.write(" | ser_daughter.write(" | ||
- | TS=ser_daugher.readline() | + | TS=ser_daughter.readline() |
- | return V1,V2,V3,IC,VB,PD,TS | + | 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): | ||
+ | if (alt < 11000.0): | ||
+ | # below 11Km - Troposphere | ||
+ | temp = 15.04 - (0.00649 * alt) | ||
+ | pres = 101.29 *(((temp + 273.1) / 288.08)**5.256) | ||
+ | else: | ||
+ | if (alt < 25000.0): | ||
+ | # between 11Km and 25Km - lower Stratosphere | ||
+ | temp = -56.46 | ||
+ | pres = 22.65 * math.exp(1.73 - ( 0.000157 * alt)) | ||
+ | else: | ||
+ | # above 25Km - upper Stratosphere | ||
+ | temp = -131.21 + (0.00299 * alt) | ||
+ | pres = 2.488 *(((temp + 273.1) / 216.6)**-11.388) | ||
+ | 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 96: | 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=Roottwomgovercda*0.90909*math.exp(Averagealt/20869) #we now have the velocity of decent | + | K=Roottwotwomgovercda*(air_density(Averagealt)**-0.5) #we now have the velocity of decent |
print " | print " | ||
K=Deltaa/ | K=Deltaa/ | ||
Line 107: | 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 | ||
- | for g in range(len(Jxpoints)-1): | + | print " |
+ | for g in range(len(Jxpoints)): | ||
if g==len(Jxpoints)-1: | if g==len(Jxpoints)-1: | ||
gplus=0 | gplus=0 | ||
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 142: | 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 168: | 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(" |
ser_phone.readline() | ser_phone.readline() | ||
s=ser_phone.readline() | s=ser_phone.readline() | ||
s=s.split('"' | s=s.split('"' | ||
return str(s[1: | return str(s[1: | ||
+ | |||
def cutdown(): | def cutdown(): | ||
ser_gr.write(" | ser_gr.write(" | ||
Line 205: | Line 224: | ||
os.system(" | os.system(" | ||
print " | print " | ||
+ | |||
def shutdown(): | def shutdown(): | ||
HV_enable(0) | HV_enable(0) | ||
Line 215: | Line 234: | ||
print " | print " | ||
ser_gr.write(" | ser_gr.write(" | ||
+ | |||
try: | try: | ||
print 'AOPP aerosol experiment running' | print 'AOPP aerosol experiment running' | ||
- | log=open("/ | + | #log=open("/ |
+ | log=open(" | ||
ser_gr=serial.Serial('/ | ser_gr=serial.Serial('/ | ||
+ | # | ||
ser_daughter=serial.Serial('/ | ser_daughter=serial.Serial('/ | ||
+ | # | ||
ser_phone=serial.Serial('/ | ser_phone=serial.Serial('/ | ||
+ | # | ||
print ' | print ' | ||
ser_gr.write(" | ser_gr.write(" | ||
+ | # | ||
reed_solomon.setup_rs() | reed_solomon.setup_rs() | ||
ser_gr.write(reed_solomon.encode_string(" | ser_gr.write(reed_solomon.encode_string(" | ||
- | while not gps_status: | + | # |
- | ser_gr.write(" | + | # while not gps_status(): |
+ | # ser_gr.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(" | ||
- | print gps_data | + | # |
+ | print gps_data() | ||
print 'now probing daughterboard' | print 'now probing daughterboard' | ||
print db_stats() | print db_stats() | ||
Line 236: | Line 263: | ||
HV_enable(1) | HV_enable(1) | ||
print 'HV1 on, probing board' | print 'HV1 on, probing board' | ||
+ | time.sleep(1) | ||
print db_stats() | print db_stats() | ||
print ' | print ' | ||
for x in [2,3]: | for x in [2,3]: | ||
- | time.sleep(1) | ||
HV_enable(x) | HV_enable(x) | ||
- | print 'HV channel' | + | time.sleep(1) |
+ | print 'HV channel' | ||
HV_enable(0) | HV_enable(0) | ||
print 'ok, now testing the pump @ 20%' | print 'ok, now testing the pump @ 20%' | ||
Line 249: | Line 277: | ||
time.sleep(1) | time.sleep(1) | ||
Set_pressure_target(0) | Set_pressure_target(0) | ||
+ | print ' | ||
for i in range(6): | for i in range(6): | ||
print db_stats() | print db_stats() | ||
Line 254: | Line 283: | ||
print ' | print ' | ||
print ' | print ' | ||
- | Jxpoints, | + | Jxpoints, |
print Jxpoints, | print Jxpoints, | ||
print ' | print ' | ||
- | ser_phone.write(" | + | ser_phone.write(" |
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() | ||
+ | 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='' | ||
system_vector=gps_data() | system_vector=gps_data() | ||
maxaltitude=system_vector[3] | maxaltitude=system_vector[3] | ||
- | print 'ok launch the fucking | + | startuptime=system_vector[0] |
+ | HV=0 | ||
+ | pump=FALSE | ||
+ | print 'ok launch the balloon' | ||
while 1: | while 1: | ||
print 'in loop' | print 'in loop' | ||
- | iterations+=1 | ||
system_vector=gps_data() | system_vector=gps_data() | ||
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)) | ||
+ | # | ||
+ | # | ||
+ | #print 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 system_vector[3]/ | + | if calibrate==30: |
- | layercounter+=1 | + | ser_daughter.write(" |
- | if not are_we_inside([0]+Updatepredict(system_vector)+[0]): #update and check against the polygon | + | calibrate=0 |
- | print " | + | calibrate+=1 |
- | log.write(" | + | if cut_down=='': |
+ | if system_vector[3]/ | ||
+ | layercounter+=1 | ||
+ | up=Updatepredict(*system_vector) | ||
+ | log.write(str(up)+" | ||
+ | if not are_we_inside([0], | ||
+ | print " | ||
+ | log.write(" | ||
+ | cutdown() | ||
+ | cut_down=' | ||
+ | if system_vector[0]-startuptime> | ||
+ | print "time cutdown" | ||
+ | log.write(" | ||
cutdown() | cutdown() | ||
- | cut_down=' | + | cut_down=' |
- | if system_vector[0]-startuptime> | + | #if daughter_board[4]< |
- | print "time cutdown" | + | # print " |
- | log.write(" | + | # log.write(" |
- | cutdown() | + | # cutdown() |
- | cut_down=' | + | # cut_down=' |
- | if daughter_board[4]< | + | if system_vector[3]-maxaltitude< |
- | print " | + | print " |
- | log.write(" | + | log.write(" |
- | cutdown() | + | shutdown() |
- | cut_down=' | + | cut_down=' |
- | if system_vector[3]-maxaltitude< | + | |
- | print " | + | |
- | log.write(" | + | |
- | shutdown() | + | |
- | cut_down=' | + | |
if system_vector[3]> | if system_vector[3]> | ||
maxaltitude=system_vector[3] | maxaltitude=system_vector[3] | ||
- | if system_vector[3]> | + | if system_vector[3]> |
print ' | print ' | ||
HV_enable(1) | HV_enable(1) | ||
Set_pressure_target(default_target_pressure) | Set_pressure_target(default_target_pressure) | ||
log.write(" | log.write(" | ||
- | if system_vector[3]> | + | pump=TRUE |
- | if system_vector[3]< | + | HV=1 |
- | HV_enable(2) | + | if system_vector[3]> |
- | log.write(" | + | HV_enable(2) |
- | else: | + | log.write(" |
- | HV_enable(3) | + | HV=2 |
- | log.write(" | + | if system_vector[3]> |
- | time.sleep(10) | + | HV_enable(3) |
+ | log.write(" | ||
+ | HV=3 | ||
+ | time.sleep(10) | ||
+ | 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.1204452047.txt.gz · Last modified: 2008/07/19 23:31 (external edit)