Modifications

Sauter à la navigation Sauter à la recherche
1 971 octets ajoutés ,  24 juillet 2013 à 20:05
Page créée avec « {{RASP-GPS-ULTIME-NAV}} {{bloc-etroit|text=Maintenant que avez un GPS et état de marche et '''gpsd''' fonctionnant avec lui, il est temps de faire quelque-chose avec ces do... »
{{RASP-GPS-ULTIME-NAV}}

{{bloc-etroit|text=Maintenant que avez un GPS et état de marche et '''gpsd''' fonctionnant avec lui, il est temps de faire quelque-chose avec ces données!

Le plus facile pour démarrer est d'utiliser [[Pi-WebIde|WebIDE]] et un peu de code Python pour accéder à gpsd.

Créez un nouveau fichier dans WebIDE, ajoutez et exécutez ensuite le code suivant:}}

<nowiki>import gps

# Ecouter sur le port 2947 (gpsd) de localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
try:
report = session.next()
# Attendre après une information 'TPV' et afficher l'heure
# Pour voir toutes les données, décommentez la ligne ci-dessous
# print report
if report['class'] == 'TPV':
if hasattr(report, 'time'):
print report.time
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD est arrete (has terminated)"</nowiki>

Vous devriez voir quelque-chose de similaire à ceci (avec une mise-à-jour toutes les secondes):

[[Fichier:RASP-GPS-ULTIME-Utiliser-01.png]]

Looking for position data rather than just the timestamp? Essentially, all you have to do is parse the 'report' data following the example above.

To see what data is available, you can uncomment the 'print report' line, and then just look at the different values and class names and pick and choose whatever you want.

For example, you could use the following code to get the current speed using the TPV class:

<nowiki> if report['class'] == 'TPV':
if hasattr(report, 'speed'):
print report.speed * gps.MPS_TO_KPH</nowiki>

That's it! It's pretty painless, and now it's up to you to figure out what you want to do with you latitude, longitude, date and time, speed, altitude, etc.!

{{RASP-GPS-ULTIME-TRAILER}}
29 917

modifications

Menu de navigation