Пример #1
0
def upsert_collision(model: Models,
                     pose: Pose,
                     mesh_parameters: Optional[MeshParameters] = None) -> None:
    """Adds arbitrary collision model to the collision scene.

    :param model: Box, Sphere, Cylinder, Mesh
    :param pose: Pose of the collision object.
    :param mesh_parameters: Some additional parameters might be specified for mesh collision model.
    :return:

    Example usage:

    >>> from arcor2.data.object_type import Box
    >>> from arcor2.data.common import Pose, Position, Orientation
    >>> box = Box("UniqueBoxId", 0.1, 0.1, 0.1)
    >>> scene_service.upsert_collision(box, Pose(Position(1, 0, 0), Orientation(0, 0, 0, 1)))
    """

    model_id = model.id
    params = model.to_dict()
    del params["id"]
    params[model.__class__.__name__.lower() + "Id"] = model_id

    if model.type() == Model3dType.MESH and mesh_parameters:
        params.update(mesh_parameters.to_dict())

    rest.call(rest.Method.PUT,
              f"{URL}/collisions/{model.type().value.lower()}",
              body=pose,
              params=params)
Пример #2
0
    def delete_notifications(self, *, an: Optional[str] = None) -> None:
        """Clears all notifications.

        :return:
        """

        rest.call(rest.Method.DELETE, f"{self.settings.url}/notifications")
Пример #3
0
    def set_distance(
        self,
        velocity: float = 0.5,
        distance: float = 0.55,
        direction: Direction = Direction.FORWARD,
        *,
        an: Optional[str] = None,
    ) -> None:
        """Belt will move by given distance.

        :param velocity:
        :param distance:
        :param direction:
        :param an:
        :return:
        """

        assert 0.0 <= velocity <= 1.0
        assert 0.0 <= distance <= 9999.0

        rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/conveyor/distance",
            params={
                "velocity": velocity * 100,
                "distance": distance,
                "direction": direction
            },
        )
Пример #4
0
def upload_file(file_id: str, file_content: bytes) -> None:
    """Uploads a file."""

    rest.call(rest.Method.PUT,
              f"{URL}/files/{file_id}",
              files={"file": file_content})
    assert file_id in files_ids()
Пример #5
0
    def set_joints(
        self,
        joints: ProjectRobotJoints,
        move_type: MoveTypeEnum,
        speed: float = 0.5,
        acceleration: float = 0.5,
        safe: bool = True,
        *,
        an: Optional[str] = None,
    ) -> None:

        assert 0.0 <= speed <= 1.0
        assert 0.0 <= acceleration <= 1.0

        url = f"{self.settings.url}/joints"
        params = {
            "moveType": move_type.value,
            "speed": speed,
            "acceleration": acceleration,
            "safe": safe
        }

        with self._move_lock:
            rest.call(rest.Method.PUT,
                      url,
                      body=joints.joints,
                      params=params,
                      timeout=self.move_timeout)
Пример #6
0
    def move(
        self,
        pose: Pose,
        move_type: MoveType,
        velocity: float = 50.0,
        acceleration: float = 50.0,
        *,
        an: Optional[str] = None,
    ) -> None:
        """Moves the robot's end-effector to a specific pose.

        :param pose: Target pose.
        :move_type: Move type.
        :param velocity: Speed of move (percent).
        :param acceleration: Acceleration of move (percent).
        :return:
        """

        assert 0.0 <= velocity <= 100.0
        assert 0.0 <= acceleration <= 100.0

        with self._move_lock:
            rest.call(
                rest.Method.PUT,
                f"{self.settings.url}/eef/pose",
                body=pose,
                params={
                    "move_type": move_type,
                    "velocity": velocity,
                    "acceleration": acceleration
                },
            )
Пример #7
0
    def delete_group(self, group_id: str, *, an: Optional[str] = None) -> None:
        """Deletes all tracked values stored in given group.

        :param group_id:
        :return:
        """

        rest.call(rest.Method.DELETE, f"{self.settings.url}/values/{group_id}")
Пример #8
0
def upsert_transform(transform_id: str, parent: str, pose: Pose) -> None:
    """Add or updates transform."""

    rest.call(rest.Method.PUT,
              f"{URL}/transforms",
              body=pose,
              params={
                  "transformId": transform_id,
                  "parent": parent
              })
Пример #9
0
    def resolve_dialog(self, option: str, *, an: Optional[str] = None) -> None:
        """Resolves current dialog using one of the options.

        :param option:
        :return:
        """

        rest.call(rest.Method.PUT,
                  f"{self.settings.url}/dialog/resolve",
                  params={"option": option})
Пример #10
0
    def set_output(self,
                   output_id: str,
                   value: float,
                   *,
                   an: Optional[str] = None) -> None:

        assert 0.0 <= value <= 1.0
        rest.call(rest.Method.PUT,
                  f"{self.settings.url}/outputs/{output_id}",
                  params={"value": value})
Пример #11
0
    def unlink(self, end_effector_id: str) -> None:
        """Unlinks collision object from end effector.

        :param end_effector_id: Unique end-effector id.
        :return:
        """

        rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/endEffectors/{end_effector_id}/unlink")
Пример #12
0
    def _start(self, model: str) -> None:

        if self._started():
            self._stop()

        rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/state/start",
            params={"model": model, "port": self.settings.port},
            body=self.pose,
        )
Пример #13
0
    def link(self, end_effector_id: str, collision_id: str) -> None:
        """Links collision object to end effector.

        :param end_effector_id: Unique end-effector id.
        :param collision_id: Unique id of collision
        :return:
        """

        rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/endEffectors/{end_effector_id}/link",
            params={"collisionId": collision_id},
        )
Пример #14
0
    def set_search_parameters(self,
                              parameters: SearchEngineParameters,
                              *,
                              an: Optional[str] = None) -> None:
        """Sets the search parameters.

        :param parameters:
        :return:
        """

        rest.call(rest.Method.PUT,
                  f"{self.settings.url}/search",
                  body=parameters)
Пример #15
0
    def __init__(self, obj_id: str, name: str, pose: Pose,
                 settings: Settings) -> None:
        super(AbstractRobot, self).__init__(obj_id, name, pose, settings)
        rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/system/set",
            body=pose,
            params={
                "configId": self.settings.configuration_id,
                "id": self.id
            },
        )

        self.move_timeout = rest.Timeout(read=5 * 60)
Пример #16
0
 def __init__(
     self,
     obj_id: str,
     name: str,
     pose: Pose,
     collision_model: Optional[Models] = None,
     settings: Optional[Settings] = None,
 ) -> None:
     super(AbstractWithPose, self).__init__(obj_id, name, pose, collision_model, settings)
     rest.call(
         rest.Method.PUT,
         f"{self.settings.url}/system/set",
         body=pose,
         params={"configId": self.settings.configuration_id, "id": self.id},
     )
Пример #17
0
 def is_item_attached(self,
                      suction_id: str,
                      *,
                      an: Optional[str] = None) -> bool:
     return rest.call(rest.Method.GET,
                      f"{self.settings.url}/suctions/{suction_id}/attached",
                      return_type=bool)
Пример #18
0
    def inverse_kinematics(
        self,
        end_effector_id: str,
        pose: Pose,
        start_joints: Optional[List[Joint]] = None,
        avoid_collisions: bool = True,
    ) -> List[Joint]:
        """Computes inverse kinematics.

        :param end_effector_id: IK target pose end-effector
        :param pose: IK target pose
        :param start_joints: IK start joints (if not provided, current joint values will be used)
        :param avoid_collisions: Return non-collision IK result if true
        :return: Inverse kinematics
        """

        if start_joints is None:
            start_joints = self.robot_joints()

        body = IKPoseJointsParameters(pose, start_joints)

        return rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/endEffectors/{end_effector_id}/inverseKinematics",
            params={"avoidCollisions": avoid_collisions},
            body=body,
            list_return_type=Joint,
        )
Пример #19
0
 def is_item_gripped(self,
                     gripper_id: str,
                     *,
                     an: Optional[str] = None) -> bool:
     return rest.call(rest.Method.GET,
                      f"{self.settings.url}/grippers/{gripper_id}/gripped",
                      return_type=bool)
Пример #20
0
def estimate_camera_pose(camera: CameraParameters,
                         image: Image,
                         inverse: bool = False) -> EstimatedPose:
    """Returns camera pose with respect to the origin.

    :param camera: Camera parameters.
    :param image: Image.
    :param inverse: When set, the method returns pose of the origin wrt. the camera.
    :return:
    """

    with BytesIO() as buff:

        image.save(buff, format="PNG")

        params = camera.to_dict()
        params["inverse"] = inverse

        try:
            return rest.call(
                rest.Method.PUT,
                f"{CALIBRATION_URL}/calibrate/camera",
                params=params,
                return_type=EstimatedPose,
                files={"image": buff.getvalue()},
            )
        except rest.RestException as e:
            if isinstance(e, rest.RestHttpException) and e.error_code == 404:
                raise MarkerNotFound(str(e)) from e

            raise CalibrationException(str(e)) from e
Пример #21
0
def estimate_camera_pose(camera: CameraParameters,
                         image: Image,
                         inverse: bool = False) -> Pose:
    """Returns camera pose with respect to the origin.

    :param camera: Camera parameters.
    :param image: Image.
    :param inverse: When set, the method returns pose of the origin wrt. the camera.
    :return:
    """

    with BytesIO() as buff:

        image.save(buff, format="PNG")

        params = camera.to_dict()
        params["inverse"] = inverse

        return rest.call(
            rest.Method.PUT,
            f"{CALIBRATION_URL}/calibrate/camera",
            params=params,
            return_type=Pose,
            files={"image": buff.getvalue()},
        )
Пример #22
0
def update_project_parameters(project_id: str,
                              parameters: List[ProjectParameter]) -> datetime:
    return datetime.fromisoformat(
        rest.call(rest.Method.GET,
                  f"{URL}/projects/{project_id}/parameters",
                  body=parameters,
                  return_type=str))
Пример #23
0
    def add_dialog(self,
                   title: str,
                   content: str,
                   options: List[str],
                   *,
                   an: Optional[str] = None) -> str:
        """Creates dialog, block until operator selects one of the options.

        :param title: Dialog title
        :param content: Dialog content
        :param options: Dialog options.
        :return:
        """

        return rest.call(
            rest.Method.PUT,
            f"{self.settings.url}/dialogs",
            return_type=str,
            params={
                "title": title,
                "content": content
            },
            body=options,
            timeout=rest.Timeout(read=8 * 60 * 60),
        )
Пример #24
0
    def get_gripper_opening(self,
                            gripper_id: str,
                            *,
                            an: Optional[str] = None) -> float:

        return rest.call(rest.Method.GET,
                         f"{self.settings.url}/grippers/{gripper_id}/opening",
                         return_type=float)
Пример #25
0
def update_project(project: Project) -> datetime:

    assert project.id
    return datetime.fromisoformat(
        rest.call(rest.Method.PUT,
                  f"{URL}/project",
                  return_type=str,
                  body=project))
Пример #26
0
def update_object_type(object_type: ObjectType) -> datetime:

    assert object_type.id
    return datetime.fromisoformat(
        rest.call(rest.Method.PUT,
                  f"{URL}/object_type",
                  body=object_type,
                  return_type=str))
Пример #27
0
    def ready(self, *, an: Optional[str] = None) -> bool:
        """Determines whether the ICT Tester is open and ready to start
        testing.

        :return: True if ICT tester is ready; otherwise, false.
        """

        return rest.call(rest.Method.GET, f"{self.settings.url}/tester/ready", return_type=bool)
Пример #28
0
    def get_pose(self, *, an: Optional[str] = None) -> Pose:
        """Gets capture device pose in actual initialized spatial system space.

        :return:
        """
        return rest.call(rest.Method.GET,
                         f"{self.settings.url}/capture/pose",
                         return_type=Pose)
Пример #29
0
def files_ids() -> set[str]:
    """Gets IDs of stored files."""

    ret_list = rest.call(rest.Method.GET, f"{URL}/files", list_return_type=str)
    ret_set = set(ret_list)
    assert len(ret_list) == len(
        ret_set), f"There is a duplicate file ID in {ret_list}."
    return ret_set
Пример #30
0
    def move_relative_joints(
        self,
        end_effector_id: str,
        joints: ProjectRobotJoints,
        rel_pose: RelativePose,
        move_type: MoveTypeEnum,
        speed: float = 0.5,
        acceleration: float = 0.5,
        safe: bool = True,
        *,
        an: Optional[str] = None,
    ) -> None:
        """Moves the robot's end-effector relatively to specific joint values.

        :param robot_id: Unique robot id.
        :param end_effector_id: Unique end-effector id.
        :param joints: Target joints.
        :param rel_pose: Relative pose.
        :param move_type: Type of move.
        :param speed: Speed of move.
        :param acceleration: Acceleration of move.
        :param safe: When true, robot will consider its environment and avoid collisions.
        :return:
        """

        assert 0.0 <= speed <= 1.0
        assert 0.0 <= acceleration <= 1.0

        url = f"{self.settings.url}/endEffectors/{end_effector_id}/moveJointsRelative"

        body = MoveRelativeJointsParameters(joints.joints, rel_pose.position,
                                            rel_pose.orientation)
        params = {
            "moveType": move_type.value,
            "speed": speed,
            "acceleration": acceleration,
            "safe": safe
        }

        with self._move_lock:
            rest.call(rest.Method.PUT,
                      url,
                      body=body,
                      params=params,
                      timeout=self.move_timeout)