def moveangleinc(self, x, y, z, r=0, q=1):
        if q == 1:
            lastIndex = dType.SetPTPCmd(self.api,
                                        dType.PTPMode.PTPMOVJANGLEINCMode,
                                        x,
                                        y,
                                        z,
                                        r,
                                        isQueued=1)[0]
            dType.SetQueuedCmdStartExec(self.api)

            while lastIndex > dType.GetQueuedCmdCurrentIndex(self.api)[0]:
                # print(f"{dType.GetQueuedCmdCurrentIndex(self.api)} :current index")
                # print(dType.GetQueuedCmdCurrentIndex(self.api))
                dType.dSleep(500)
                # Stop to Execute Command Queued
            dType.SetQueuedCmdStopExec(self.api)
            dType.SetQueuedCmdClear(self.api)
        else:
            dType.SetPTPCmd(self.api,
                            dType.PTPMode.PTPMOVJANGLEINCMode,
                            x,
                            y,
                            z,
                            r,
                            isQueued=0)
    def __init__(self, port="ttyUSB0"):
        self.DEFINED_HOME = (206, 0, 135, 0)
        # self.DEFINED_HOME = (190,58,146,17)
        CON_STR = {
            dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
            dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
            dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"
        }

        self.api = dType.load()
        print("Loaded API")
        state = dType.ConnectDobot(self.api, port, 115200)[0]
        print("Connect status:", CON_STR[state])

        if (state == dType.DobotConnect.DobotConnect_Occupied):
            print("Error - Dobot Can't Connect")
            print("Possible Problems - ")
            print("1) Wrong Port. Pls check /dev and use the correct port.")
            print(
                "2) User doesn't have required priveleges for the port. Pls add user to dialout group or use chmod on the port."
            )
            print(
                "3) Robot wasn't disconnected properly. Pls restart the robot and replug the USB and try again."
            )
            exit()
        if (state == dType.DobotConnect.DobotConnect_NoError):
            print("Connected.")
            # Clean Command Queued
            dType.SetQueuedCmdClear(self.api)

            # Async Motion Params Setting
            dType.SetHOMEParams(self.api, 206, 0, 135, 0,
                                isQueued=1)  # set home co-ordinates  [x,y,z,r]
            # dType.SetPTPJointParams(self.api, 100, 100, 100, 100, 100, 100, 100, 100,
            #                         isQueued=1)  # joint velocities(4) and joint acceleration(4)
            print(1)
            dType.SetPTPCommonParams(
                self.api, 90, 90,
                isQueued=1)  # velocity ratio, acceleration ratio
            print(2)
            dType.SetPTPJumpParams(self.api, 30, 135,
                                   isQueued=1)  # jump height , zLimit
            print(3)
            dType.SetPTPJointParams(self.api,
                                    50,
                                    50,
                                    50,
                                    50,
                                    50,
                                    50,
                                    50,
                                    50,
                                    isQueued=1)
            print(4)
            # dType.SetJOGJointParams(self.api, 10, 10, 10, 10, 10, 10, 10, 10, isQueued=1)
            # dType.SetJOGCoordinateParams(self.api, 100, 100, 100, 100, 100, 100, 100,100, isQueued=1)

            # lastIndex = dType.SetPTPCmd(self.api, dType.PTPMode.PTPMOVJXYZMode, 212, -83, 20, 100, isQueued=1)[0]
            #   # mode, x,y,z,r
            print("start moving")
            lastIndex = dType.SetPTPCmd(self.api,
                                        dType.PTPMode.PTPMOVJXYZMode,
                                        *self.DEFINED_HOME,
                                        isQueued=1)[0]
            print("got initial command")
            dType.SetQueuedCmdStartExec(self.api)
            print("step1")
            while lastIndex > dType.GetQueuedCmdCurrentIndex(self.api)[0]:
                print("step2")
                dType.dSleep(500)
                # print(dType.GetQueuedCmdCurrentIndex(self.api))
            # print(lastIndex)
            # print(lastIndex)
            dType.SetQueuedCmdStopExec(self.api)
            dType.SetQueuedCmdClear(self.api)
            print("Done moving to home")