コード例 #1
0
def loadParameters(RDK=None):
    if RDK is None:
        RDK = Robolink()

    global BOX_SIZE_XYZ
    global USE_METRIC
    global PARENT
    global CONV_PARENT

    size_x = RDK.getParam(PARAM_BOX_X, True)
    if size_x is not None and size_x != '':
        BOX_SIZE_XYZ[0] = float(size_x)

    size_y = RDK.getParam(PARAM_BOX_Y, True)
    if size_y is not None and size_y != '':
        BOX_SIZE_XYZ[1] = float(size_y)

    size_z = RDK.getParam(PARAM_BOX_Z, True)
    if size_z is not None and size_z != '':
        BOX_SIZE_XYZ[2] = float(size_z)

    metric = RDK.getParam(PARAM_UNITS, True)
    if metric is not None and metric != '':
        USE_METRIC = bool(metric == 'True')

    parent_name = RDK.getParam(PARAM_PARENT_NAME, True)
    if parent_name is not None and parent_name != '':
        item = RDK.Item(parent_name)
        if item.Valid() and item.Name() == parent_name:
            PARENT = item
    if PARENT is None:
        PARENT = RDK.ActiveStation()

    conv_parent_name = RDK.getParam(PARAM_CONV_PARENT_NAME, True)
    if conv_parent_name is not None and conv_parent_name != '':
        item = RDK.Item(conv_parent_name)
        if item.Valid() and item.Name() == conv_parent_name:
            CONV_PARENT = item
コード例 #2
0
def loadParameters(RDK=None):
    if RDK is None:
        RDK = Robolink()

    global RADIUS
    global PARENT

    radius = RDK.getParam(PARAM_RADIUS, True)
    if radius is not None and radius != '':
        RADIUS = float(radius)

    parent_name = RDK.getParam(PARAM_PARENT_NAME, True)
    if parent_name is not None and parent_name != '':
        item = RDK.Item(parent_name)
        if item.Valid() and item.Name() == parent_name:
            PARENT = item
    if PARENT is None:
        PARENT = RDK.ActiveStation()
コード例 #3
0
class robodk_api(driver):
    '''
    This driver uses the RoboDK API to connect to a robot controller. It is based on the Robodk API (https://robodk.com/offline-programming).
    
    The driver will always provide access to the robot axis through the variable called "Axis" (float[6]).
    Optional variable definitions are used to access Station Parameters in RobotDK to be read or written by the driver.

    controller: str
        Robot name in RoboDK. Default = '', will take the first that founds.
    '''

    def __init__(self, name: str, pipe: Optional[Pipe] = None):
        """
        :param name: (optional) Name for the driver
        :param pipe: (optional) Pipe used to communicate with the driver thread. See gateway.py
        """
        # Inherit
        driver.__init__(self, name, pipe)

        # Parameters
        self.controller = ''


    def connect(self) -> bool:
        """ Connect driver.
        
        : returns: True if connection stablished False if not
        """
        try:
            #assert ROBODK_API_FOUND, "RoboDK API is not available."
            self._connection = Robolink()
            if self._connection:
                self.robot = self._connection.Item(self.controller)
                if self.robot:
                    if self.robot.Valid() and self.robot.Type() == ITEM_TYPE_ROBOT:
                        self.sendDebugInfo(f'Driver RoboDK Connected to {self.controller}...')
                        return True
                    else:
                        self.sendDebugInfo(f'Item {self.controller} not found!')
                else:
                    self.sendDebugInfo(f'Controler not found!')
            else:
                self.sendDebugInfo(f'Connection with Robolink not possible.')

        except Exception as e:
            self.sendDebugInfo('Exception '+str(e))
        
        return False

    def disconnect(self):
        """ Disconnect driver.
        """
        pass


    def addVariables(self, variables: dict):
        """ Add variables to the driver. Correctly added variables will be added to internal dictionary 'variables'.
        Any error adding a variable should be communicated to the server using sendDebugInfo() method.

        : param variables: Variables to add in a dict following the setup format. (See documentation) 
        
        """
        for var_id, var_data in variables.items():
            try:
                if var_id == 'Axis':
                    var_data['value'] = [None for i in range(var_data['size'])]
                    self.variables[var_id] = var_data
                    continue
                else:
                    value = self._connection.getParam(var_id)
                    if value is not None:
                        var_data['value'] = None # Force first update
                        self.variables[var_id] = var_data
                        self.sendDebugVarInfo((f'SETUP: Variable found {var_id}', var_id))
                        continue
            except:
                pass
            
            self.sendDebugVarInfo((f'SETUP: Variable not found {var_id}', var_id))


    def readVariables(self, variables: list) -> list:
        """ Read given variable values. In case that the read is not possible or generates an error BAD quality should be returned.
        : param variables: List of variable ids to be read. 

        : returns: list of tupples including (var_id, var_value, VariableQuality)
        """
        res = []
        for var_id in variables:
            try:
                if var_id == 'Axis':
                    new_value = self.robot.Joints().tr().rows[0] # robot joint rotations [Rax_1, Rax_2, Rax_3, Rax_4, Rax_5, Rax_6]
                    new_value = [round(x,3) for x in new_value]
                    res.append((var_id, new_value, VariableQuality.GOOD))
                    continue
                else:
                    new_value = self._connection.getParam(var_id)
                    if new_value is not None:
                        new_value = self.getValueFromString(self.variables[var_id]['datatype'], new_value)
                        res.append((var_id, new_value, VariableQuality.GOOD))
                        continue
            except:
                res.append((var_id, self.variables[var_id]['value'], VariableQuality.BAD))
            
        return res


    def writeVariables(self, variables: list) -> list:
        """ Write given variable values. In case that the write is not possible or generates an error BAD quality should be returned.
        : param variables: List of tupples with variable ids and the values to be written (var_id, var_value). 

        : returns: list of tupples including (var_id, var_value, VariableQuality)
        """
        res = []
        # TODO: Possible improvement can be to send multiple at once
        for (var_id, new_value) in variables:
            try:
                self._connection.setParam(var_id, new_value)
                res.append((var_id, new_value, VariableQuality.GOOD))
            except:
                res.append((var_id, new_value, VariableQuality.BAD))
                     
        return res