while loop slows down over time

44 views Asked by At

I am calculating azimuth and elevation relative to me with Python, which then sends it to an Arduino via a Serial connection. The python program calculates the position, waits 1 second, calculates the position again and subtracts both values to see how much the position has changed in 1 second. The program does this in a never ending while True: loop:

while True:
    home.date = datetime.utcnow()
    iss.compute(home)
    el = int(iss.alt * degrees_per_radian)    #elevation
    az = int(iss.az * degrees_per_radian)     #azimuth
    print("az: " + str(az), "el: " + str(el))  
    time.sleep(1)

    home.date = datetime.utcnow()
    iss.compute(home)
    az2 = int(iss.az * degrees_per_radian)
    az3 = az2 - az                          #position change in 1 second 
    print(az2, az3)

    str_pos = str(az3) + ";" + str(el) + '\n'
    byte_pos = str_pos.encode()
    port.write(byte_pos)
    print("data transmitted!")
    print("__________________")

Everything works fine for a few minutes, but then the code suddenly slows down and each step takes a few seconds. It also can't determine the difference between az and az2, always returning a zero, even though it's actually 1 or higher.

0

There are 0 answers