Commit 65d5f720 authored by DeriZSY's avatar DeriZSY
Browse files

minor reconstruction

1. Converter is shifted to communicate module. Since there's still problems with converter, the current version of code might be unusable.
2. A time limiter is added to avoid over emission of coordinate which might destroy the microcomputer
parent 66fb36c6
Loading
Loading
Loading
Loading
+4 −22
Original line number Diff line number Diff line
@@ -445,25 +445,6 @@ if SRC == PIC:

if SRC == CAM:
    cap = cv2.VideoCapture(1)
    pitch = 5000
    def converter(x, y):
        global pitch
        huge_step = 40
        big_step = 20
        small_step = 5
        if 250 < y and pitch <= 5500:
            pitch += huge_step
        if 210 < y <= 250 and pitch <= 5500:
            pitch += big_step
        elif 190 < y <= 210 and pitch <= 5500:
            pitch += small_step
        elif 150 <= y < 180 and pitch >= 4000:
            pitch -= small_step
        elif 110 <= y < 150 and pitch >= 4000:
            pitch -= big_step
        elif y < 110 and pitch >= 4000:
            pitch -= huge_step

    if cap.isOpened():
        success, frame = cap.read()
        frame = cv2.resize(frame,(480,360))
@@ -474,8 +455,9 @@ if SRC == CAM:
        mat = cv2.resize(mat, (480, 360))
        mat = func_undistort(mat)
        target = main(mat)
        angles = converter(target[0],target[1])
        # wrt.write(angles[0],angles[1])
        angles = cmc.converter(target[0],target[1])
        time.sleep(0.015) # limit transmission time for protection
        wrt.write(angles[0],angles[1])
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
+20 −1
Original line number Diff line number Diff line
@@ -23,3 +23,22 @@ class SerialWriter:
    # writer.write(5000, 5000)
    # cap = cv2.VideoCapture(0)


def converter(x, y):
    pitch = 5000;
    global pitch
    huge_step = 40
    big_step = 20
    small_step = 5
    if 250 < y and pitch <= 5500:
        pitch += huge_step
    if 210 < y <= 250 and pitch <= 5500:
        pitch += big_step
    elif 190 < y <= 210 and pitch <= 5500:
        pitch += small_step
    elif 150 <= y < 180 and pitch >= 4000:
        pitch -= small_step
    elif 110 <= y < 150 and pitch >= 4000:
        pitch -= big_step
    elif y < 110 and pitch >= 4000:
        pitch -= huge_step