Пример #1
0
def gpsread():
  while True:
    try:
    report = session.next()
    if report['class'] == 'TPV':
      if hasattr(report, 'lat'):
	lat = report.lat
      if hasattr(report, 'lon'):
	lon = report.lon
      if hasattr(report, 'track'):
	track = report.track
      if hasattr(report, 'speed'):
	speed = report.speed * gps.MPS_TO_KPH
      loc = lat, lon
  except KeyError:
    pass
  except KeyboardInterrupt:
    quit()
  except StopIteration:
    session = None
    print "GPSD has terminated"
    
def gotoloc(destination):
  while repeat:
    distto = dist(loc, destination)
    repeat = 1
    if (distto > changedistance)
      steer = heading(loc, destination)
      steer = steer - track
      if (steer > 30)
	steer = 30
      if (steer < -30)
	steer = -30
      steer(steer)
      throttle(throttle)
    else if (distto < changedistance)
      repeat = 0
      return('done: ' + destination);
     
    
while True:
  dest = path.readline()
  if dest == 'end':
    throttle(0)
    steer(0)
    break
  dest = strip(dest)
  dest = split(dest, ':')
  gotoloc(dest)
  
    
if __name__ == '__main__':
  gpsproc = Process(target=gpsread)
  gpsproc.start()
  gpsproc.join()
Пример #2
0
def gotoloc(destination):
  while repeat:
    distto = dist(loc, destination)
    repeat = 1
    if (distto > changedistance)
      steer = heading(loc, destination)
      steer = steer - track
      if (steer > 30)
	steer = 30
      if (steer < -30)
	steer = -30
      steer(steer)
      throttle(throttle)
    else if (distto < changedistance)
      repeat = 0
      return('done: ' + destination);