Пример #1
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project, action_id: str, parameter_id: str) -> Any:

        param = project.action(action_id).parameter(parameter_id)
        try:
            return json.loads(param.value)
        except json.decoder.JSONDecodeError as e:
            raise ParameterPluginException(f"Value of {action_id}/{parameter_id} is not a valid JSON.", e)
Пример #2
0
    def uses_robot_joints(cls, project: Project, action_id: str,
                          parameter_id: str, robot_joints_id: str) -> bool:

        param = project.action(action_id).parameter(parameter_id)
        value_id = cls.param_value(param)

        return value_id == robot_joints_id
Пример #3
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project,
              action_id: str, parameter_id: str) -> Pose:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        ori_id: str = cls.param_value(param)

        ap, ori = project.ap_and_orientation(ori_id)
        return Pose(ap.position, ori.orientation)
Пример #4
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project, action_id: str, parameter_id: str) ->\
            RelativePose:

        param = project.action(action_id).parameter(parameter_id)

        try:
            return RelativePose.from_json(param.value)
        except ValidationError as e:
            raise ParameterPluginException(e)
Пример #5
0
    def uses_orientation(cls, project: Project, action_id: str,
                         parameter_id: str, orientation_id: str) -> bool:

        action = project.action(action_id)
        param = action.parameter(parameter_id)

        for ori_id in cls.param_value_list(param):
            if ori_id == orientation_id:
                return True
        return False
Пример #6
0
    def execution_value(cls, type_defs: TypesDict, scene: Scene,
                        project: Project, action_id: str,
                        parameter_id: str) -> Pose:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        ori_id: str = cls.param_value(param)

        ap, _ = project.ap_and_orientation(ori_id)

        copy_of_ap = copy.deepcopy(ap)
        tr.make_relative_ap_global(scene, project, copy_of_ap)

        return Pose(copy_of_ap.position, ap.orientation(ori_id).orientation)
Пример #7
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project,
              action_id: str, parameter_id: str) -> Enum:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        obj_id, action_type = action.parse_type()
        obj_type = type_defs[scene.object_or_service(obj_id).type]

        method = getattr(obj_type, action_type)
        ttype = get_type_hints(method)[param.id]

        if not issubclass(ttype, cls.type()):
            raise ParameterPluginException(
                f"Type {ttype.__name__} is not subclass of {cls.type().__name__}."
            )

        try:
            return ttype(json.loads(param.value))
        except ValueError:
            raise ParameterPluginException(
                f"Parameter {parameter_id} of action {action.name} has invalid value."
            )
Пример #8
0
    def uses_orientation(cls, project: Project, action_id: str,
                         parameter_id: str, orientation_id: str) -> bool:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        return orientation_id == cls.param_value(param)