Full control mode communication

Hi Everyone, I implemented the full control mode with a magnetic sensor. It is all working fine. I am after your expert advice…could you please suggest if its all right or need a change?

My Pi device sends a sequence of serial commands to motor controller at once. Sometimes second or third command is sent and executed before the previous movement loop is complete. So, I placed the following While loop there. I will later develop a function to make the value selection dynamic. Could you please suggest if this is the right approach or should there be something simpler?

import serial
from serial import Serial
import time

if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyACM0',115200, timeout=1)
    ser.flush()

    while True:
        ser.write(b"ME1\n")
        time.sleep(1)
        ser.write(b"M150 40 9\n")
        ser.flush()
        while True:
             ser.write(b"MMG6\n")
             response = ser.readline()
             print(response)
             if b"angle: 150" in response:
                 break
             else:
                 time.sleep(5)

        ser.write(b"M0 5 9\n")
        while True:
            ser.write(b"MMG6\n")
            response = ser.readline()
            print(response)
            if b"angle: 0.000" in response:
               break
            else:
               time.sleep(1)

        ser.write(b"ME0\n")
        ser.close()
        break