Advertisement
cymplecy

isstracker.py

Apr 23rd, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. import ephem
  2. from array import array
  3. import socket
  4. import time
  5. import sys
  6.  
  7. def sendScratchCommand(cmd):
  8.    n = len(cmd)
  9.    a = array('c')
  10.    a.append(chr((n >> 24) & 0xFF))
  11.    a.append(chr((n >> 16) & 0xFF))
  12.    a.append(chr((n >>  8) & 0xFF))
  13.    a.append(chr(n & 0xFF))
  14.    try:
  15.       PORT = 42001
  16.       HOST = '127.0.0.1'
  17.  
  18.       scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  19.       scratchSock.connect((HOST, PORT))
  20.       #print "data len" , n
  21.       scratchSock.sendall(a.tostring() + cmd)
  22.       time.sleep(0.1)
  23.       scratchSock.shutdown(socket.SHUT_RDWR)
  24.       scratchSock.close()
  25.    except:
  26.       print sys.exc_info()[0]
  27.       print ("Failed to send to Scratch")
  28.      
  29.  
  30.    
  31. observer = ephem.Observer()
  32. observer.lon, observer.lat = '-2.24', '53.48'
  33.  
  34.  
  35. try:
  36.    while True:
  37.       observer.date = ephem.now()   # 12:22:56 EDT
  38.       #print gatech.date
  39.       obj =  ephem.readtle('ISS','1 25544U 98067A   16111.74054971  .00005749  00000-0  93439-4 0  9994',
  40. '2 25544  51.6441 344.5739 0001791  50.1935 345.8459 15.54298106996046'
  41.          )#ephem.Jupiter()
  42.       obj.compute(observer)
  43.       alt = int(( 180 /3.1415926 * float(obj.alt)))
  44.       az = int(( 180 /3.1415926 * float(obj.az)))
  45.       dist = int(obj.range /1000)
  46.       print alt,az,dist
  47.       sendScratchCommand('sensor-update alt ' + str(alt) + ' direction ' + str(az)+ ' dist ' + str(dist))
  48.       time.sleep(1)
  49. except KeyboardInterrupt:
  50.        pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement