j'ai monté un Raspberry sur un gros Amel c'est vraiment sympa comme engin j’ai fait un petit programme en python qui montre la position des satellites gps dans le ciel et permet de mettre le pi a l'heure car il n'a pas de conservation de la date une foi éteint et l'heure est utile pour un autre programme que j’ai fait pour établir une courbe de pression (celui de open c.p.n. ne marchait pas et je ne sait pas pourquoi il y avait une : "erreur de type de capteur")
il le lancer et l’arrêter avant de lancer open c.p.n. il faut insister plusieurs foi pour fermer le programme c'est encore un brouillon mais ca marche bien et c'est rigolo de voir les satelites
voila le code il vaut nettement mieux le voir avec un éditeur text pour le python (coloration et formatage python)
edit oups le forum me transforme une ligne de code en smileys mais c'est pas grave car c'est une ligne commentarisee donc sans importance pour le fonctionnement du software
edit bis je ne connaissait ni le python ni le nmea ni la com port gps donc please soyez indulgent
*************************************************************************************************************************************
# ******************************************************************** # gps tracking by alexander voivoditch 14 05 2016 # # # there is also a time keeper device built with reading gps nmea sentences through usb # # #************************************************************************************************************************** # here are the NMEA sentences produced by this usb gps/glonas dongle #************************************************************************************************************************** # # example read fom the dongle : $GPGGA,022824.00,4319.86622,N,00522.97280,E,1,07,1.14,68.8,M,47.7,M,,*65 # # And here is a translation from an helpfile in open plotter: # # # spliting at the comas $GPGGA,022824.00, 4319.86622,N, 00522.97280,E, 1, 07, # translate to $GPGGA ident 02h28m24s.00s, 43deg19min.86622sec,N, 005deg22min.97280sec,E, 1GPS fix, 07 satellites, # # 1.14, 68.8,M, 47.7,M, ,*65 # 1.14 m Dilution of precision , 68.8,M alt, 47.7, Mgeoide diff, ,*65 parity check, xor result of all the line terms # # # # gps dongle txt visible at begin of data sending mostly dongle builder infos #**************************************************************************** # # $GPTXT,01,01,02,u-blox ag - www.u-blox.com*50 # # $GPTXT,01,01,02,HW UBX-G70xx 00070000 *77 # # $GPTXT,01,01,02,ROM CORE 1.00 (59842) Jun 27 2012 17:43:52*59 # # $GPTXT,01,01,02,PROTVER 14.00*1E # # $GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20 # # $GPTXT,01,01,02,ANTSTATUS=OK*3B # # $GPTXT,01,01,02,LLC FFFFFFFF-FFFFFFFD-FFFFFFFF-FFFFFFFF-FFFFFFF9*53 # # standard datas output example all the nmea sentence produced ar present #************************************************************************ # # # GPGGA,022922.00,4319.86431,N,00522.97225,E,1,05,1.48,51.2,M,47.7,M,,*66 # # GPGLL,4319.86431,N,00522.97225,E,022922.00,A,A*69 # # GPRMC,022923.00,A,4319.86428,N,00522.97229,E,0.039,,030616,,,A*7D # # GPVTG,,T,,M,0.039,N,0.072,K,A*2C # # GPGSA,A,3,07,02,09,23,06, ,3.50,1.48,3.18*08 # # GPGLL,4319.86431,N,00522.97225,E,022922.00,A,A*69 # # GPGSV,3,3,10,26,06,042,,30,20,186,14*77 # # # # # GPGGA Global Positioning System Fix Data, Time, Latitude/Longitude, nbr sat, hz dilution, alt # gpgll Geographic Position - Latitude/Longitude, time # GPRMC Recommended Minimum Navigation Information, - Latitude/Longitude, time, vel, over ground, date, dd mm yy, # GPVTG VTG - Track made good, and Ground speed, # GPGSA GPS DOP and active satellites sat ids # GPGSV Satellites in view elev azim # # $GPGSV,3,1,10,02,31,089,20,06,16,045,,12,57,053,29,14,38,284,13*77 # $GPGSV, 3, 1 ,10 ,02 ,31 ,089 # $GPGSV, 3 message in this group ,1 st mess of group ,10,nbr sat in view 02 satellite PRN number, 31 elev deg,089 azim deg # # #
#************************************************************************************************************************** #**************************************** BEGIN MAIN ********************************************************************** #**************************************************************************************************************************
import time import subprocess # for an eventual auto computer shut down import turtle # for postscript file writing (curve saving) import serial # for reading port /dev/ttyACM0 on thi pi import subprocess # for an eventual auto time import os # for giving order as command line such as ***os.system('sudo date --set="%s"' % dateformated)***
# ************************************************************************************************************************ # *********************************** sys time and date init ************************************************************ # ************************************************************************************************************************
nmeasentance = "" nmea_id1 = "$GPRMC" nmea_id2 = "$GPGGA" nmea_date = "" nmea_time = ""
lat = "" lon = "" timeread=0 dateread=0 dateorg= [] timeorg= [] timesorted= [] dateformated= "" timeformated= ""
nbr_sat=0 sat_id="" sat_data = []
mainloopa=0 mainloopb=0
letters_nbr=0 # debug nbr of chars in the nmea sentance k=0 ;
#********************************************************************************************************************* #*********** setting sys time and date on good track because pi does not have time keeper device ********************* #******************* THE PAART OF THEINSTRUCTIONS DEALING WITH GPS (at the begining) ****************************** #******************* may not work if gps is busy elswhere with opencpn for an example ****************************** #*********************************************************************************************************************
#********************************************************************************************************************* #********************* serial port readding one sentence up to stop bit ***************************************** #*********************************************************************************************************************
ser = serial.Serial( port='/dev/ttyACM0', # port adress baudrate = 9600, # port transit speed parity=serial.PARITY_NONE, # parity check y/n stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 )
counter=0 letters_nbr=0
#******************************************************************************************************************** #**** when serial readding done, sentence identification and if good ones found then do spliting,and formating **** #************* work on $GPRMC or $GPGGA while anny one or both havent been worked out yet *********************** #****************** if both have been worked continue direct to pressure and temp ****************************** #********************************************************************************************************************
while (mainloopa==0)or(mainloopb==0): # $GPRMC or $GPGGA while anny one or both havent been worked out yet # $GPGGA is used for time 1st loop $GPRMC is used for date 2nd loop nmeasentance=ser.readline() # reading serial through a call nmea_id1 = nmeasentance.split(",") # nmeasentance is splited on each commas
neededData1 = (nmea_id1[0]) # neededData1 this is the *first* nmea word --> source and format #print neededData1 # debug
if (neededData1 == "$GPGGA")and(timeread==0): # if $GPGGA and not worked on it before else check 2nd loop neededData2 = (nmea_id1[1]) # this is the *second word* of nmeasentance.split (nmea_id1) nmea_time=neededData2
for k in range (6): timeorg.append(nmea_time[k]) # organized list time append the 6 numbers #print k # debug k=0
#timeformated= adding the : separators between the 2 numbers blocks hh:mm:ss timeformated=((timeorg[0])+(timeorg[1])+":"+(timeorg[2])+(timeorg[3])+":"+(timeorg[4])+(timeorg[5]))
#print timeformated # debug timeorg=[] timeread=timeread+1 mainloopa=mainloopa+1 # increment to set this job as done
if neededData1 == "$GPRMC": # if $GPRMC and not worked on it before else check the while #print nmea_id1 # debug neededData1 = (nmea_id1[3], nmea_id1[4], nmea_id1[5], nmea_id1[6], nmea_id1[9] ) lat =(nmea_id1[3]+nmea_id1[4]) lon =(nmea_id1[5]+nmea_id1[6]) nmea_date=(nmea_id1[9])
for k in range (6): dateorg.append(nmea_date[k])
dateformated=((dateorg[4])+(dateorg[5])+(dateorg[2])+(dateorg[3])+(dateorg[0])+(dateorg[1])+" "+(timeformated)) dateorg= [] #print timeformated #ok but format is lost before the print it is in fact : dateformated="060711 05:12:01" #print dateformated #ok but format is lost before the print it is in fact : dateformated="060711 05:12:01"
timesorted= []
timeformated="063722"
if (dateread==0)and(timeread==1) : #os.system('sudo date --set="%s"' % dateformated) # keep comented for computer with time keeper device such as cmos battery
dateformated= [] # needed dateread=dateread+1 # needed mainloopb=mainloopb+1 # needed
#********************************************************************************************************************* #*********** now the time should be set so we can begine the satelites tracking ************************************** #*********************************************************************************************************************
#**************************************************************************************************************** #**************************************************************************************************************** #**************************************************************************************************************** #****************** ********************************** #****************** drawing the graph with the little turtle application ********************************** #****************** ********************************** #**************************************************************************************************************** #**************************************************************************************************************** #**************************************************************************************************************** from turtle import * # import all from turtle
#******************************************************************************************************************* #****************************************** windows title **************************************************** #*******************************************************************************************************************
title("gps checking app by Alexander Voivoditch") # set window title
#********************************************************************* #testing the presence of bg file else soft is blocked if bg is absent #*********************************************************************
try: fp=open('landscape.gif',"r") bgpic('landscape.gif') fp.close() except: up() pencolor('red') goto(-330,270) write ("background picture file not found rendering white background") pencolor('blue') print" " print"*********************************" print"background picture file not found" print"*********************************" print" "
#******************************************************************************************************************* #**************************** drawing the and graph and sats ************************************************* #*******************************************************************************************************************
tracer(20) # tracer(n,d) truly refresh evry n frame d=delay between fames, can be ignored
sat_count = 0 nbr_undo = 0 while 1: # while 1: always on main loop the reticle should be out but have # to find a way to refresh sats and trace but not the reticle
#******************************************************************************************************************* #**************************** drawing the graph reticle ******************************************************* #*******************************************************************************************************************
#print turtle.pos() # debug goto(0,0)
turtle.speed(0) # the fastest slowest is 1 to fast 10 and fastest 0 hideturtle() # hide the turtle ht()
up() # no trace goto(-10,0) # fix at graph tail (will draw to graph corner) down() # trace no center cross goto( 10,0) up()
up() # no trace goto(0,-10) # fix at graph tail (will draw to graph corner) down() # trace no center cross goto(0,10) up()
pencolor('red')
goto(0,270) write ("360", font=("Arial", 12, "bold")) # write cardinal point with ofset to be out of graph
goto(280,0) write ("90", font=("Arial", 12, "bold")) # write cardinal point with ofset to be out of graph
goto(0,-260) write ("180", font=("Arial", 12, "bold")) # write cardinal point with ofset to be out of graph
goto(-300,0) write ("270", font=("Arial", 12, "bold")) # write cardinal point with ofset to be out of graph
goto(0,0) up() # no trace width(3) # trace width pencolor('orange') goto(0,-270) # begin the circle at botom setheading(0) # important else the circle is drawn from here (0,-270) but to a wrong direction down() circle (270) up()
width(1) # trace width
t=10 k=0 complete_list = [] # init inthdg =0 intforward =0
goto(0,0) k=0
turtle.shape('circle') turtle.shapesize(0.3,0.3) pencolor('blue')
#******************************************************************************************************************* #******************** drawing the sats and refreshing the screen ********************************************** #*******************************************************************************************************************
nmeasentance=ser.readline() # reading serial through a call nmea_id1 = nmeasentance.split(",") # nmeasentance is splited on each commas neededData1 = (nmea_id1[0]) # neededData1 this is the *first* nmea word --> source and format
if neededData1 == "$GPGSV": # if $GPGSV (the nmeasentance we are looking for) nbr_sat = (nmea_id1[3]) # 4 but 1 ofset due to start at 0 goto(-260,260) # out of circle top left write ("nbr sat "+nbr_sat) # display "nbr sat "+ value #print nbr_sat # debug #nbr_sat = (0) # reset to 0 after display goto(0,0) # very important else turtle heading and range can start from sat number
complete_list=nmea_id1 # list format
#print (complete_list) # debug very useful #print " " complete_list.pop() # get rid of the last one '28*75\r\n' (parity check line break etc) complete_list.pop(0) # get rid of the first one sentence id complete_list.pop(0) # get rid of the new first one mesage number complete_list.pop(0) # get rid of the new first one mesage rank complete_list.pop(0) # get rid of the new first one number of sat in view
lnght=len(complete_list) # number of ellements in the list # print ("lnght") # print (lnght)
# turtle.setundobuffer(300) # Set or disable undobuffer integer only
while k< (lnght-3): k=k+3 # increment by 3 because need sat id (PRN number), # elev (00,90) azimut (000,359)true north #print ("k+3") # debug #print (k) # debug
if (complete_list[(k-1)]) == '': # if $GPGSV (the nmeasentance we are looking for) inthdg=0 else :inthdg=int (complete_list[(k-1)]) # (k-1) because we avoid the unused (SNR in dB) disphdg=inthdg+90 # +90--> 0 apear at E90 on turtle graph coordinates setheading(disphdg) # set turtle heading intforward=int (complete_list[(k-2)]) # (k-2) because before inthdg dispforward=int (90-intforward) # 90 is zenith (center of circle) 0 is perimeter forward(dispforward*3) # (90-value) give a crude conversion *3 1/2 dia = 270 # move turtle ahead along heading
sat_id=(complete_list[(k-3)]) # (k-3) because before intforward write (sat_id) # writing sat id need somthing less persistant stamp() # turtle impression to mark sat position goto(0,0) # back to center for an other sat sat_count = sat_count+1 #print "sat count" #print (sat_count) #print " " #print "nbr sat" #print (nbr_sat)
if sat_count == int (nbr_sat)+1 : #nbr_undo = sat_count*3 sat_count = 0 #print "sat count" time.sleep(2) clear()
complete_list.pop(k) # pop (erase) the unused list element (SNR in dB) complete_list.append(0) # 0 to compensate poped items #print ("k poped") # debug #print (k) # debug #print (complete_list) # debug
#print (k) # debug #print (" ") # debug goto(0,0) k=0 # reset to 0 complete_list=[] # reset empty for a new line scan
# $GPGSV,3,1,10,02,31,089,20,06,16,045,,12,57,053,29,14,38,284,13*77 # $GPGSV, 3, 1, ,10 # $GPGSV, 3 message in this group ,1 st mess of group ,10,nbr sat in view # # ,02 ,31 ,089 ,20 ,06 ,16 ,045 # 02 sat PRN number, 31 elev deg, 089 azim deg ,20 snr db sat ,06 PRN number ,16 elev deg ,045 azim deg
#lat =(nmea_id1[3]+nmea_id1[4]) #lon =(nmea_id1[5]+nmea_id1[6]) #nmea_date=(nmea_id1[9]) #for k in range (6): # dateorg.append(nmea_date[k]) # dateformated=((dateorg[4])+(dateorg[5])+(dateorg[6])) #dateorg= [] #print timeformated #ok but format is lost before the print it is in fact : dateformated="060711 05:12:01" #print dateformated #ok but format is lost before the print it is in fact : dateformated="060711 05:12:01"
#end of indent does not go farther |