Example #1
0
def test_global_aps_cls() -> None:

    proj = Project("test", "scene_id")

    pos = Position(1, 2, 3)
    ap1 = ActionPoint("ap1", pos)
    ap1_o1 = NamedOrientation("o1", Orientation(0.707, 0, 0, 0.707))
    ap1.orientations.append(ap1_o1)
    ap1_j1 = ProjectRobotJoints("j1", "robot", [Joint("whatever", 1234)])
    ap1.robot_joints.append(ap1_j1)
    proj.action_points.append(ap1)

    os.environ["ARCOR2_PROJECT_PATH"] = "/tmp"
    import arcor2.resources  # noqa

    my_name = "my_module"
    my_spec = importlib.util.spec_from_loader(my_name, loader=None)
    my_module = importlib.util.module_from_spec(my_spec)

    cproj = CachedProject(proj)

    src = global_action_points_class(cproj)
    exec(src, my_module.__dict__)
    sys.modules["my_module"] = my_module

    aps = my_module.ActionPoints(SimResources(cproj))  # type: ignore

    assert aps.ap1.position == pos
    assert aps.ap1.position is not pos

    assert aps.ap1.poses.o1 == Pose(ap1.position, ap1_o1.orientation)
    assert aps.ap1.poses.o1.orientation is not ap1_o1.orientation

    assert aps.ap1.joints.j1 == ap1_j1
    assert aps.ap1.joints.j1 is not ap1_j1
Example #2
0
 def move_to_joints(self,
                    target_joints: List[Joint],
                    speed: float,
                    safe: bool = True) -> None:
     self.set_joints(ProjectRobotJoints("", "", target_joints),
                     MoveTypeEnum.SIMPLE,
                     speed,
                     safe=safe)
def main() -> None:

    # robots
    aubo = Aubo(uid("rbt"), "Whatever", Pose(), RobotSettings("http://127.0.0.1:13000", "aubo"))
    simatic = Aubo(uid("rbt"), "Whatever", Pose(), RobotSettings("http://127.0.0.1:13001", "simatic"))

    # objects with pose, with 'System' and 'Configurations' controllers
    barcode = Barcode(uid("srv"), "Whatever", Pose(), settings=Settings("http://127.0.0.1:14000", "simulator"))
    search = Search(uid("srv"), "Whatever", Pose(), settings=Settings("http://127.0.0.1:12000", "simulator"))
    ict = Ict(uid("srv"), "Whatever", Pose(), settings=Settings("http://127.0.0.1:19000", "simulator"))

    # objects without pose, without 'System' and 'Configurations' controllers
    interaction = Interaction(uid("srv"), "Whatever", SimpleSettings("http://127.0.0.1:17000"))
    statistic = Statistic(uid("srv"), "Whatever", SimpleSettings("http://127.0.0.1:16000"))

    # Add @action decorator to all actions of each object using patch_object_actions.
    # It has to be called exactly once for each type!
    # Certain functions of Execution unit (as e.g. pausing script execution) would not work without this step.
    # Note: in a generated script, this is done within the Resources context manager.
    # Side effect: a lot of JSON data will be printed out to the console when running the script manually.
    patch_object_actions(Aubo)
    patch_object_actions(Barcode)
    patch_object_actions(Search)
    patch_object_actions(Ict)
    patch_object_actions(Interaction)
    patch_object_actions(Statistic)

    scene_service.delete_all_collisions()
    scene_service.upsert_collision(Box("box_id", 0.1, 0.1, 0.1), Pose())
    scene_service.start()  # this is normally done by auto-generated Resources class

    aubo.move("suction", Pose(), MoveTypeEnum.SIMPLE, safe=False)
    simatic.set_joints(ProjectRobotJoints("", "", [Joint("x", 0), Joint("y", 0)]), MoveTypeEnum.SIMPLE)
    barcode.scan()
    search.set_search_parameters(SearchEngineParameters(search_log_level=SearchLogLevel(LogLevel.DEBUG)))
    search.grab_image()
    interaction.add_notification("Test", NotificationLevelEnum.INFO)

    try:
        statistic.get_groups()
    except rest.RestHttpException as e:
        # service returned error code
        print(f"The error code is {e.error_code}.")
    except rest.RestException as e:
        # request totally failed (timeout, connection error, etc)
        print(str(e))

    if ict.ready():
        test = ict.test("OK")
        print(test)

    scene_service.stop()  # this is normally done by auto-generated Resources class
Example #4
0
def test_get_value() -> None:

    scene = Scene("s1", "s1")
    obj = SceneObject("test_name", TestObject.__name__)
    prj = ProjectRobotJoints("name", obj.id, [Joint("name", 0.333)])
    scene.objects.append(obj)
    project = Project("p1", "s1")
    ap1 = ActionPoint("ap1", Position(1, 0, 0))
    ap1.robot_joints.append(prj)
    project.action_points.append(ap1)

    invalid_param_name = "invalid_param"

    act = Action(
        "ac1",
        f"{obj.id}/{TestObject.action.__name__}",
        parameters=[
            ActionParameter(param_name, JointsPlugin.type_name(),
                            json.dumps(prj.id)),
            ActionParameter(invalid_param_name, JointsPlugin.type_name(),
                            json.dumps("non_sense")),
        ],
    )

    ap1.actions.append(act)

    cscene = CachedScene(scene)
    cproject = CachedProject(project)

    with pytest.raises(Arcor2Exception):
        JointsPlugin.parameter_value(type_defs, cscene, cproject, act.id,
                                     "non_sense")

    with pytest.raises(Arcor2Exception):
        JointsPlugin.parameter_value(type_defs, cscene, cproject, "non_sense",
                                     param_name)

    with pytest.raises(ParameterPluginException):
        JointsPlugin.parameter_value(type_defs, cscene, cproject, act.id,
                                     invalid_param_name)

    value = JointsPlugin.parameter_value(type_defs, cscene, cproject, act.id,
                                         param_name)
    exe_value = JointsPlugin.parameter_execution_value(type_defs, cscene,
                                                       cproject, act.id,
                                                       param_name)

    assert value == value
    assert value == exe_value
Example #5
0
 def value_to_json(cls, value: ProjectRobotJoints) -> str:
     return value.to_json()
Example #6
0
def test_value_to_json() -> None:

    prj = ProjectRobotJoints("name", "robot_id", [Joint("name", 0.333)])
    assert JointsPlugin.value_to_json(prj) == prj.to_json()
Example #7
0
def test_plugin_from_instance() -> None:

    assert plugin_from_instance(ProjectRobotJoints("name", "robot_id", [Joint("name", 0.333)])) is JointsPlugin