Пример #1
0
    def data(self, data):
        self.name = data['name']
        self.joints = [Joint.from_data(d) for d in data['joints']]
        self.links = [Link.from_data(d) for d in data['links']]
        self.materials = [Material.from_data(d) for d in data['materials']]
        self.attr = _attr_from_data(data['attr'])
        self._scale_factor = data['_scale_factor']

        self._rebuild_tree()
Пример #2
0
    def _set_data(self, data):
        self.name = data.get('name', '')
        self.joints = [Joint.from_data(d) for d in data.get('joints', [])]
        self.links = [Link.from_data(d) for d in data.get('links', [])]
        self.materials = [Material.from_data(d) for d in data.get('materials', [])]
        self.attr = _attr_from_data(data.get('attr', {}))
        self._scale_factor = data.get('_scale_factor', 1.)

        self._rebuild_tree()
Пример #3
0
 def data(self, data):
     from compas.robots.model.joint import Joint
     self.name = data['name']
     self.type = data['type']
     self.visual = [Visual.from_data(d) for d in data['visual']]
     self.collision = [Collision.from_data(d) for d in data['collision']]
     self.inertial = Inertial.from_data(
         data['inertial']) if data['inertial'] else None
     self.attr = _attr_from_data(data['attr'])
     self.joints = [Joint.from_data(d) for d in data['joints']]
Пример #4
0
    def add_joint(self,
                  name,
                  type,
                  parent_link,
                  child_link,
                  origin=None,
                  axis=None,
                  limit=None,
                  **kwargs):
        """Adds a joint to the robot model.

        Provides an easy way to programmatically add a joint to the robot model.

        Parameters
        ----------
        name : str
            The name of the joint
        type : int
            The joint type, e.g. Joint.REVOLUTE
        parent_link : :class:`Link`
            The joint's parent link.
        child_link : :class:`Link`
            The joint's child link.
        origin : :class:`compas.geometry.Frame`
            The joint's origin frame.
        axis : :class:`compas.geometry.Vector`
            The joint's axis.
        limit : list of 2 float
            The lower and upper limits of the joint (used for joint types Joint.REVOLUTE or Joint.PRISMATIC)

        Returns
        -------
        :class:`Joint`
            The created `Joint`

        Raises
        ------
        ValueError
            If the joint name is already used in the chain.

        Examples
        --------
        >>> robot = RobotModel('robot')
        >>> parent_link = robot.add_link('link0')
        >>> child_link = robot.add_link('link1')
        >>> origin = Frame.worldXY()
        >>> axis = (1, 0, 0)
        >>> j = robot.add_joint("joint1", Joint.CONTINUOUS, parent_link, child_link, origin, axis)
        """

        all_joint_names = [j.name for j in self.joints]
        if name in all_joint_names:
            raise ValueError("Joint name '%s' already used in chain." % name)

        if origin:
            origin = Origin(origin.point, origin.xaxis, origin.yaxis)
        if axis:
            axis = Axis('{} {} {}'.format(*list(axis)))
        if limit:
            lower, upper = limit
            limit = Limit(lower=lower, upper=upper)

        type_str = Joint.SUPPORTED_TYPES[type]

        joint = Joint(name,
                      type_str,
                      parent_link.name,
                      child_link.name,
                      origin=origin,
                      axis=axis,
                      limit=limit,
                      **kwargs)

        self.joints.append(joint)

        # Using only part of self._rebuild_tree()
        parent_link.joints.append(joint)
        child_link.parent_joint = joint

        self._links[parent_link.name] = parent_link
        self._adjacency[parent_link.name] = [
            joint.name for joint in parent_link.joints
        ]
        self._links[child_link.name] = child_link

        if not parent_link.parent_joint:
            self.root = parent_link

        joint.child_link = child_link
        self._joints[joint.name] = joint
        self._adjacency[joint.name] = [child_link.name]

        # Using only part of self._create(link, parent_transformation)
        parent_transformation = Transformation()
        for item in itertools.chain(parent_link.visual, parent_link.collision):
            if not item.init_transformation:
                item.init_transformation = parent_transformation
            else:
                parent_transformation = item.init_transformation

        joint._create(parent_transformation)

        for item in itertools.chain(child_link.visual, child_link.collision):
            item.init_transformation = joint.current_transformation

        return joint
Пример #5
0
    def add_joint(self,
                  name,
                  type,
                  parent_link,
                  child_link,
                  origin=None,
                  axis=None,
                  limit=None,
                  **kwargs):
        """Adds a joint to the robot model.

        Provides an easy way to programmatically add a joint to the robot model.

        Parameters
        ----------
        name : str
            The name of the joint
        type : int
            The joint type, e.g. Joint.REVOLUTE
        parent_link : :class:`Link`
            The joint's parent link.
        child_link : :class:`Link`
            The joint's child link.
        origin : :class:`compas.geometry.Frame`
            The joint's origin frame.
        axis : :class:`compas.geometry.Vector`
            The joint's axis.
        limit : list of 2 float
            The lower and upper limits of the joint (used for joint types Joint.REVOLUTE or Joint.PRISMATIC)
        **kwargs : dict[str, Any], optional
            The keyword arguments (kwargs) collected in a dict.
            These allow using non-standard attributes absent in the URDF specification.

        Returns
        -------
        :class:`Joint`
            The created `Joint`

        Raises
        ------
        ValueError
            If the joint name is already used in the chain.

        Examples
        --------
        >>> from compas.geometry import Frame
        >>> robot = RobotModel('robot')
        >>> parent_link = robot.add_link('link0')
        >>> child_link = robot.add_link('link1')
        >>> origin = Frame.worldXY()
        >>> axis = (1, 0, 0)
        >>> j = robot.add_joint("joint1", Joint.CONTINUOUS, parent_link, child_link, origin, axis)

        """
        all_joint_names = [j.name for j in self.joints]
        if name in all_joint_names:
            raise ValueError("Joint name '%s' already used in chain." % name)

        if origin:
            origin = Frame(origin.point, origin.xaxis, origin.yaxis)
        if axis:
            axis = Axis('{} {} {}'.format(*list(axis)))
        if limit:
            lower, upper = limit
            limit = Limit(lower=lower, upper=upper)

        type_str = Joint.SUPPORTED_TYPES[type]

        joint = Joint(name,
                      type_str,
                      parent_link.name,
                      child_link.name,
                      origin=origin,
                      axis=axis,
                      limit=limit,
                      **kwargs)

        self.joints.append(joint)

        # Using only part of self._rebuild_tree()
        parent_link.joints.append(joint)
        child_link.parent_joint = joint

        self._links[parent_link.name] = parent_link
        self._adjacency[parent_link.name] = [
            joint.name for joint in parent_link.joints
        ]
        self._links[child_link.name] = child_link

        if not parent_link.parent_joint:
            self.root = parent_link

        joint.child_link = child_link
        self._joints[joint.name] = joint
        self._adjacency[joint.name] = [child_link.name]

        self._create(self.root, Transformation())

        return joint