Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ephem
- from array import array
- import socket
- import time
- import sys
- def sendScratchCommand(cmd):
- n = len(cmd)
- a = array('c')
- a.append(chr((n >> 24) & 0xFF))
- a.append(chr((n >> 16) & 0xFF))
- a.append(chr((n >> 8) & 0xFF))
- a.append(chr(n & 0xFF))
- try:
- PORT = 42001
- HOST = '127.0.0.1'
- scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- scratchSock.connect((HOST, PORT))
- #print "data len" , n
- scratchSock.sendall(a.tostring() + cmd)
- time.sleep(0.1)
- scratchSock.shutdown(socket.SHUT_RDWR)
- scratchSock.close()
- except:
- print sys.exc_info()[0]
- print ("Failed to send to Scratch")
- observer = ephem.Observer()
- observer.lon, observer.lat = '-2.24', '53.48'
- try:
- while True:
- observer.date = ephem.now() # 12:22:56 EDT
- #print gatech.date
- obj = ephem.readtle('ISS','1 25544U 98067A 16111.74054971 .00005749 00000-0 93439-4 0 9994',
- '2 25544 51.6441 344.5739 0001791 50.1935 345.8459 15.54298106996046'
- )#ephem.Jupiter()
- obj.compute(observer)
- alt = int(( 180 /3.1415926 * float(obj.alt)))
- az = int(( 180 /3.1415926 * float(obj.az)))
- dist = int(obj.range /1000)
- print alt,az,dist
- sendScratchCommand('sensor-update alt ' + str(alt) + ' direction ' + str(az)+ ' dist ' + str(dist))
- time.sleep(1)
- except KeyboardInterrupt:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement