Example #1
0
    def connect(self):
        state = dType.ConnectDobot(self.DobotAPI, "", 115200)

        if state[0] != dType.DobotConnect.DobotConnect_NoError:
            raise ValueError("Failed to connect dobot. ", CON_STR[state[0]])

        dType.SetQueuedCmdClear(self.DobotAPI)
        dType.SetHOMEParams(self.DobotAPI,
                            self.home_x,
                            self.home_y,
                            self.home_z,
                            0,
                            isQueued=1)
Example #2
0
    def __init__(self, width, height, start_x, start_y):

        # initialize state
        self.state = None

        # scale factor
        self.scale_x = 1.0
        self.scale_y = 1.0

        # x-y coordinate of start position
        self.start_x = start_x
        self.start_y = start_y

        # load dll
        self.api = dType.load()

        self.CON_STR = {
            dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
            dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
            dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"
        }

        # dimensions of actual engraving area
        self.width = width
        self.height = height
Example #3
0
    def getPose(self):
        if self.production:
            pose = dType.GetPose(self.DobotAPI)
            pose[1] = pose[1] / Y_OFFSET
        else:
            pose = [200, 0, 0]

        return pose[:3]
Example #4
0
    def __init__(self, home_x=200, home_y=0, home_z=50, production=False):
        self.production = production

        if production:
            self.DobotAPI = dType.load()

        self.home_x = home_x
        self.home_y = home_y
        self.home_z = home_z

        if production:
            self.connect()
Example #5
0
    def moveXYZ(self, x, y, z, r=0, mode="movl", sleep_sec=0.4):
        if self.production:
            ptp_mode = dType.PTPMode.PTPMOVLXYZMode
            if mode == 'jump':
                ptp_mode = dType.PTPMode.PTPJUMPXYZMode

            idx = dType.SetPTPCmd(self.DobotAPI,
                                  ptp_mode,
                                  x,
                                  y * Y_OFFSET,
                                  z,
                                  r,
                                  isQueued=1)[0]
            self.sleep(sleep_sec)
        else:
            print("try to move ({x}, {y}, {z})".format(x=x, y=y, z=z))
            idx = -1
        return idx
Example #6
0
 def sleep(self, s):
     if self.production:
         dType.dSleep(s)
Example #7
0
 def getCurrentIndex(self):
     return dType.GetQueuedCmdCurrentIndex(self.DobotAPI)
Example #8
0
 def stopQueue(self):
     dType.SetQueuedCmdStopExec(self.DobotAPI)
     dType.SetQueuedCmdClear(self.DobotAPI)
     dType.SetQueuedCmdStartExec(self.DobotAPI)
Example #9
0
 def startQueue(self):
     dType.SetQueuedCmdStartExec(self.DobotAPI)
Example #10
0
 def setHOME(self):
     dType.SetHOMECmd(self.DobotAPI, temp=0, isQueued=1)
Example #11
0
 def setHOMEParam(self, x, y, z):
     dType.SetHOMEParams(self.DobotAPI, x, y, z, 0, isQueued=1)
Example #12
0
 def disconnect(self):
     dType.DisconnectDobot(self.DobotAPI)
Example #13
0
    def move_sequence(self, command_list):
        """command list contains 4-tuples in the form of (G.., x, y, on/off)"""
        self.command_list = command_list

        lastIndex = 0

        # calculate scaling
        self.get_scale(command_list)

        if self.state == dType.DobotConnect.DobotConnect_NoError:

            # Clean Command Queue
            dType.SetQueuedCmdClear(self.api)

            # Async Motion Params Setting
            dType.SetHOMEParams(self.api, 250, 0, 50, 0, isQueued=1)
            dType.SetPTPJointParams(self.api,
                                    300,
                                    300,
                                    300,
                                    300,
                                    300,
                                    300,
                                    300,
                                    300,
                                    isQueued=1)
            dType.SetPTPCommonParams(self.api, 100, 100, isQueued=1)

            # home the robot
            dType.SetHOMECmd(self.api, temp=0, isQueued=1)

            # start filling up command queue; first move robot to starting point
            lastIndex = dType.SetPTPCmd(self.api,
                                        dType.PTPMode.PTPMOVLXYZMode,
                                        self.start_x,
                                        self.start_y,
                                        50,
                                        0,
                                        isQueued=1)[0]

            # loop through list of gcode commands and create command queue
            for point in self.command_list:
                if point[3] == 'OFF':
                    lastIndex = dType.SetEndEffectorLaser(self.api,
                                                          1,
                                                          0,
                                                          isQueued=1)[0]
                elif point[3] == 'ON':
                    lastIndex = dType.SetEndEffectorLaser(self.api,
                                                          1,
                                                          1,
                                                          isQueued=1)[0]
                elif point[3] == '0':
                    x_offset = self.scale_x * point[2]
                    y_offset = self.scale_y * point[1]
                    # print(x_offset, y_offset)
                    # point coordinates from the start position
                    lastIndex = dType.SetPTPCmd(self.api,
                                                dType.PTPMode.PTPMOVLXYZMode,
                                                self.start_x + x_offset,
                                                self.start_y - y_offset,
                                                50,
                                                0,
                                                isQueued=1)[0]

            # end the command queue by turning off the laser and moving back to start position
            lastIndex = dType.SetEndEffectorLaser(self.api, 1, 0,
                                                  isQueued=1)[0]
            lastIndex = dType.SetPTPCmd(self.api,
                                        dType.PTPMode.PTPMOVLXYZMode,
                                        self.start_x,
                                        self.start_y,
                                        50,
                                        0,
                                        isQueued=1)[0]

            # start the queue of commands
            dType.SetQueuedCmdStartExec(self.api)

            # Wait until last command (index) has been executed successfully
            while lastIndex > dType.GetQueuedCmdCurrentIndex(self.api)[0]:
                # must be 100 or more, if not steps will be skipped
                dType.dSleep(100)

            # Stop executing commands in command queue
            dType.SetQueuedCmdStopExec(self.api)

            # clean queued commands
            dType.SetQueuedCmdClear(self.api)
            time.sleep(1)
Example #14
0
 def connect(self, port):
     # Connect Dobot
     self.port = port
     self.state = dType.ConnectDobot(self.api, self.port, 115200)[0]
     print("Connect status:", self.CON_STR[self.state])
Example #15
0
 def disconnect(self):
     # Disconnect Dobot
     dType.DisconnectDobot(self.api)