Alan Johnstone
Posts: 45
Joined: Tue Jan 08, 2013 4:35 pm

Finding Info on libraries

Fri Feb 08, 2013 10:20 am

This is a general question about where to look for documentation for libraries.
I have just attached a GPS card to my RPi and I have got it going by searching the intenet for examples.
But that only tells me how one peson did it and gives me very little about what else is available.

As an example I am using

"gps.gps.data.fix.latitude "

to get the latitude and similar for the other types of data.

I can find no documentation of the "fix" class or struct.

I have discovered using

dir(gps)

and

help(gps)

that there is lots of other stuff in gps including time

help(gps.time)

but nothing at all about fix

So the question is how do you find out about all the possibilities of a library module?

Alan

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Finding Info on libraries

Fri Feb 08, 2013 10:57 am

Just a thought, but have you tried
pydoc libraryname from the Pi's prompt?

It sometimes gives you some useful info
Alex Eames RasPi.TV, RasP.iO

User avatar
metachris
Posts: 96
Joined: Wed Feb 06, 2013 1:52 pm
Location: Vienna, Austria

Re: Finding Info on libraries

Fri Feb 08, 2013 2:17 pm

The Python command 'help(...)' shows the same info as 'pydoc'. If you don't find enough information in there its most likely a badly documented module and you'll need to take a look at the source. Both the help/pydoc commands show you the filename of the module at the very top.

Edit: Found the git repository link for you: http://git.savannah.gnu.org/cgit/gpsd.g ... gps/gps.py
pythonhosted.org/RPIO

Alan Johnstone
Posts: 45
Joined: Tue Jan 08, 2013 4:35 pm

Re: Finding Info on libraries

Fri Feb 08, 2013 2:54 pm

Thanks for that. I can now see why I could not see fix as member of data.

It is sad that such a wonderful module is not better documented.

Just in case anybody is interested the code below ( basterdized from something I found on the internet) accesses the GPS data that is read in a thread
as it must be. The calls to get the data are within locks so there will be no clashes and the code closes using ctrl-c I have tried to make sure that gpsd is properly loaded at the top but I do not know much about subprocesses (and many other things!)

Code: Select all

import os
import gps
import time
import threading
import copy
from pickle import *
# reload spi drivers to prevent spi failures
import subprocess
try:
  kill_gpsd   = subprocess.Popen('sudo killall gpsd', shell=True, stdout=subprocess.PIPE)
except:
  pass # throws an error if it is not open already
reopen_gpsd = subprocess.Popen('sudo gpsd /dev/ttyUSB0  -F /var/run/gpsd.sock', shell=True, stdout=subprocess.PIPE)
time.sleep(3)



class GetData(threading.Thread):
  def __init__(self,lock):

    threading.Thread.__init__(self)

tryGPS.py
 self.data  = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
    self.event = threading.Event()
    self.lock  = lock

  def stopThread(self):
    self.event.set()

  def stopped(self):
    return self.event.isSet()

  def run(self):
    while not self.stopped():

     self.lock.acquire()
     self.data.next() # grap data
     self.lock.release()



def main():
  os.system('clear')
  lock=threading.Lock()   # create the lock
  gpsData = GetData(lock) # create the thread and give it the lock
 try:
    gpsData.start() # start it up
    outFile=open("outside.file",'w')
    while True:

      os.system('clear')

      lock.acquire()
      print gpsData.data.fix
      theData = copy.copy(gpsData.data.fix)
      lock.release()

      print
      print ' GPS reading'
      print '----------------------------------------'
      print 'latitude    ' , theData.latitude
      print 'longitude   ' , theData.longitude
      print 'time        ' , theData.time
      print 'altitude (m)' , theData.altitude
      print 'eps         ' , theData.eps
      print 'epx         ' , theData.epx
      print 'epv         ' , theData.epv
 print 'ept         ' , theData.ept
      print 'speed (m/s) ' , theData.speed
      print 'climb       ' , theData.climb
      print 'track       ' , theData.track
      print 'mode        ' , theData.mode

      position=[theData.latitude,theData.longitude]
      dump(position,outFile)

      time.sleep(5) #wait for a while

  except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
    print "\nKilling Thread..."
    lock.acquire()
    gpsData.stopThread()
    lock.release()

    gpsData.join() # wait for the thread to finish what it's doing
  print "Done.\nExiting."
  outFile.close()


main()




Return to “Python”