OrbitTracker


This project just as this webpage are still under development...

This project was inspired by the Orbit Tracker made by Grady Hillhouse of the youtube channel Practical Engineering: https://practical.engineering/blog/2016/1/20/international-space-station-orbit-tracker-and-pointer


3D printed parts: https://www.thingiverse.com/thing:3415423

Source code

#trackOrbit.py
import ephem
import requests
import json
import math
import time

Pi = True;

 import stepperAzi
 import stepperAlt
 from Adafruit_CharLCD import Adafruit_CharLCD




#Initiate LCD
lcd = Adafruit_CharLCD(rs = 21,en=20,d4=24,d5=25,d6=12,d7=16,cols=16,lines=2)
lcd.clear()
lcd.message('Prep orbital\n Tracking') #\n is new line

#StepperAzi
stepsTakenAzi = 0
stepsPerRev = 512

stepsTakenAlt = 0


#Stepper Freedom of motion checks
lcd.clear()
lcd.message('Initialize Alt\n Stepper') #\n is new line
#Stepper
stepsTakenAlt = 128
stepsToTakeAlt = 128
stepsTakenAlt = 256 
if stepsToTakeAlt > 0:
    stepperAlt.clockwise(5,abs(stepsToTakeAlt))
else:
    stepperAlt.counterclockwise(5,abs(stepsToTakeAlt))

stepsToTakeAlt = -128
stepsTakenAlt = 128
if stepsToTakeAlt > 0:
    stepperAlt.clockwise(5,abs(stepsToTakeAlt))
else:
    stepperAlt.counterclockwise(5,abs(stepsToTakeAlt))

     
lcd.clear()
lcd.message('Prep orbital\n Tracking')

degrees_per_radian = 180.0 / math.pi

#site used to obtain gps coordinate from ip adress
send_url = 'http://api.ipstack.com/82.72.6.91?access_key=6be639c4197395ae3a024f6467b38b50&format=1'  
r = requests.get(send_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']


#Get most recent TLE from: https://www.celestrak.com/NORAD/elements/stations.txt
celestrack = requests.get("https://celestrak.com/NORAD/elements/stations.txt")
trackedBody = celestrack.text.splitlines()[0]
TLE1 = celestrack.text.splitlines()[1]
TLE2 = celestrack.text.splitlines()[2]
iss = ephem.readtle(trackedBody, TLE1,TLE2)



gatech = ephem.Observer()
gatech.lon, gatech.lat = lon/degrees_per_radian, lat/degrees_per_radian #Set gps coordinates for observer in radian
gatech.elevation = 5 # elevation of observer
    
print(gatech.date)
print('latitude:',lat,' longitude:',lon) # prints the lattitude and longitude of the observer

#lcd.clear()
#lcdstring = 'Lat:' + str(lat) + '\nLon:'+ str(lon)
#lcd.message(lcdstring)

while True:

    gatech = ephem.Observer()
    gatech.lon, gatech.lat = lon/degrees_per_radian, lat/degrees_per_radian #Set gps coordinates for observer in radian
    gatech.elevation = 5 # elevation of observer
    
    iss.compute(gatech) #All angles returned are in radians!
    
    issAzi = round(iss.az * degrees_per_radian,2)
    issAlt = round(iss.alt * degrees_per_radian,2)
    
    #Stepper
    stepsAzimuth = math.floor((iss.az * degrees_per_radian/360)*stepsPerRev*2.875)  
    stepsToTakeAzi= stepsAzimuth - stepsTakenAzi
    stepsTakenAzi = stepsTakenAzi + stepsToTakeAzi
    if stepsToTakeAzi < 0:
        stepperAzi.clockwise(5,abs(stepsToTakeAzi))
    else:
        stepperAzi.counterclockwise(5,abs(stepsToTakeAzi))
       
    augmentedAlt = issAlt+90  #Makes sure you don't have to work with negatives

    stepsToTakeAlt = math.floor((augmentedAlt/180)*256 - stepsTakenAlt)  #Altitude percentage times step raange
    stepsTakenAlt = stepsTakenAlt + stepsToTakeAlt

    if stepsToTakeAlt > 0:#Moves stepper altitude
        stepperAlt.clockwise(5,abs(stepsToTakeAlt))
    else:
        stepperAlt.counterclockwise(5,abs(stepsToTakeAlt))
       
    #Print in Python Shell    
    print('iss: altitude: %4.1f deg azimuth: %5.1f deg' %(issAlt , issAzi) ,gatech.date,'stepsTakenAzi: 
	      %4.1f stepsToTakeAzi: %4.1F ' %(stepsTakenAzi,stepsToTakeAzi) ,'stepsTakeAlt:  %4.1f   
		  stepsToTakeAlt: %5.1f' %(stepsTakenAlt,stepsToTakeAlt)) 

    #Print on LCD Screen
    lcd.clear()
    lcdstring = 'ISS Azi:' + str(issAzi) + '\nAlt:'+ str(issAlt)
    lcd.message(lcdstring)
    #lcd.message('ISS (Zarya)\n Azi{}'.format(issAzi).'Alt{}'.format(issAlt))




    time.sleep(1.0)
#stepperAzi.py
import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
coil_A_1_pin = 6 # pink
coil_A_2_pin = 13 # orange
coil_B_1_pin = 19 # blue
coil_B_2_pin = 26 # yellow

# adjust if different
StepCount = 8
Seq    = [0,0,0,0,0,0,0,0] #Initializes vector
Seq[0] = [0,1,0,0]
Seq[1] = [0,1,0,1]
Seq[2] = [0,0,0,1]
Seq[3] = [1,0,0,1]
Seq[4] = [1,0,0,0]
Seq[5] = [1,0,1,0]
Seq[6] = [0,0,1,0]
Seq[7] = [0,1,1,0]
 

GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
 

 
def setStep(w1, w2, w3, w4):
    GPIO.output(coil_A_1_pin, w1)
    GPIO.output(coil_A_2_pin, w2)
    GPIO.output(coil_B_1_pin, w3)
    GPIO.output(coil_B_2_pin, w4)
 
def counterclockwise(delay, steps):
    for i in list(range(steps)):
        for j in list(range(StepCount)):
            setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
            time.sleep(delay/1000)
 
def clockwise(delay, steps):
    for i in list(range(steps)):
        for j in list(reversed(range(StepCount))):
            setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
            time.sleep(delay/1000)
#stepperAlt.py

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
coil_A_1_pin = 4 # pink
coil_A_2_pin = 17 # orange
coil_B_1_pin = 27 # blue
coil_B_2_pin = 22 # yellow

# adjust if different
StepCount = 8
Seq    = [0,0,0,0,0,0,0,0] #Initializes vector
Seq[0] = [0,1,0,0]
Seq[1] = [0,1,0,1]
Seq[2] = [0,0,0,1]
Seq[3] = [1,0,0,1]
Seq[4] = [1,0,0,0]
Seq[5] = [1,0,1,0]
Seq[6] = [0,0,1,0]
Seq[7] = [0,1,1,0]
 

GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
 

 
def setStep(w1, w2, w3, w4):
    GPIO.output(coil_A_1_pin, w1)
    GPIO.output(coil_A_2_pin, w2)
    GPIO.output(coil_B_1_pin, w3)
    GPIO.output(coil_B_2_pin, w4)
 
def counterclockwise(delay, steps):
    for i in list(range(steps)):
        for j in list(range(StepCount)):
            setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
            time.sleep(delay/1000)
 
def clockwise(delay, steps):
    for i in list(range(steps)):
        for j in list(reversed(range(StepCount))):
            setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
            time.sleep(delay/1000)