Motor degree movement function
if diff &lt; 0:
        target_qc = is_qc + deg2qc(abs(diff))
    else:
        target_qc = is_qc + deg2qc(-diff)



If diff &lt; 0, then abs(diff) == -diff, just the same as the else case. The

    target_qc = is_qc + deg2qc(-diff)


(no if's and else's) should suffice. The else case (that is, abs(diff) &gt; 180.0) also can be rewritten as

    if diff &lt; 0:
        target_qc = is_qc + deg2qc(-diff - 360)
    else:
        target_qc = is_qc + deg2qc(-diff + 360)


where the cases only differ in signs of 360, which suggests that you are looking for the remainder -diff % 360; notice that python supports the remainder of floats.

To get rid of ugly leading -, you may want to calculate diff as

    diff = target_deg - is_deg