Ejemplo n.º 1
0
def test_lock_events(start_processes: None, ars: ARServer, scene: cmn.Scene, project: cmn.Project) -> None:

    assert ars.call_rpc(rpc.p.OpenProject.Request(get_id(), IdArgs(project.id)), rpc.p.OpenProject.Response).result
    prj_evt = event(ars, events.p.OpenProject)

    event(ars, events.s.SceneState)

    prj = prj_evt.data.project

    # get default project objects
    ap = next(ap for ap in prj.action_points if ap.name == "ap")
    ap_ap = next(ap for ap in prj.action_points if ap.name == "ap_ap")
    ap_ap_ap = next(ap for ap in prj.action_points if ap.name == "ap_ap_ap")
    ori = ap_ap_ap.orientations[0]

    lock_object(ars, ap.id, True)

    # lock object and expect event about it on newly logged UI
    ars2 = ARServer(ars_connection_str(), timeout=30, event_mapping=event_mapping)
    event(ars2, events.p.OpenProject)
    event(ars2, events.s.SceneState)
    second_ui = "ars2"
    assert ars2.call_rpc(
        rpc.u.RegisterUser.Request(get_id(), rpc.u.RegisterUser.Request.Args(second_ui)),
        rpc.u.RegisterUser.Response,
    ).result
    locked_evt = event(ars2, events.lk.ObjectsLocked)
    assert locked_evt.data.owner == "testUser"
    for obj_id in (ap.id, ap_ap.id, ap_ap_ap.id, ori.id):
        assert obj_id in locked_evt.data.object_ids

    # attempt to lock/unlock objects locked by someone else
    for obj_id in (ap.id, ap_ap.id, ap_ap_ap.id, ori.id):
        # lock
        assert not ars2.call_rpc(
            rpc.lock.WriteLock.Request(get_id(), rpc.lock.WriteLock.Request.Args(obj_id)), rpc.lock.WriteLock.Response
        ).result
        # lock tree
        assert not ars2.call_rpc(
            rpc.lock.WriteLock.Request(get_id(), rpc.lock.WriteLock.Request.Args(obj_id, True)),
            rpc.lock.WriteLock.Response,
        ).result
        # unlock
        assert not ars2.call_rpc(
            rpc.lock.WriteUnlock.Request(get_id(), rpc.lock.WriteUnlock.Request.Args(obj_id)),
            rpc.lock.WriteUnlock.Response,
        ).result

    unlock_object(ars, ap.id)
    event(ars2, events.lk.ObjectsUnlocked)

    # test lock will stay locked after logout for a while
    lock_object(ars2, ori.id)
    event(ars, events.lk.ObjectsLocked)

    ars2.close()

    # wait for some time
    sleep(2)  # TODO fill this sleep with another actions

    # register again and check if objects still locked
    ars2 = ARServer(ars_connection_str(), timeout=30, event_mapping=event_mapping)
    event(ars2, events.p.OpenProject)
    event(ars2, events.s.SceneState)
    assert ars2.call_rpc(
        rpc.u.RegisterUser.Request(get_id(), rpc.u.RegisterUser.Request.Args("ars2")),
        rpc.u.RegisterUser.Response,
    ).result
    locked_evt = event(ars2, events.lk.ObjectsLocked)
    assert locked_evt.data.owner == second_ui
    assert len(locked_evt.data.object_ids) == 1
    assert ori.id in locked_evt.data.object_ids
    ars2.close()
Ejemplo n.º 2
0
def test_object_parameters(start_processes: None, ars: ARServer, scene: Scene) -> None:

    assert ars.call_rpc(rpc.s.OpenScene.Request(uid(), IdArgs(scene.id)), rpc.s.OpenScene.Response).result

    event(ars, events.s.OpenScene)
    event(ars, events.s.SceneState)

    req_params = [  # TODO create settings_to_params and use it
        Parameter("str_param", "string", json.dumps("str_param")),
        Parameter("float_param", "double", json.dumps(1.0)),
        Parameter("int_param", "integer", json.dumps(1)),
        Parameter("bool_param", "boolean", json.dumps(True)),
    ]

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(
            uid(), rpc.s.AddObjectToScene.Request.Args("ows", ObjectWithSettings.__name__, parameters=req_params)
        ),
        rpc.s.AddObjectToScene.Response,
    ).result

    soc = event(ars, events.s.SceneObjectChanged)
    assert soc.change_type
    assert soc.change_type == soc.change_type.ADD
    assert soc.data.type == ObjectWithSettings.__name__
    assert soc.data.parameters == req_params
    obj_id = soc.data.id

    req_params2 = [  # TODO create settings_to_params and use it
        Parameter("str_param", "string", json.dumps("str_param2")),
        Parameter("float_param", "double", json.dumps(2.0)),
        Parameter("int_param", "integer", json.dumps(2)),
        Parameter("bool_param", "boolean", json.dumps(True)),
    ]

    lock_object(ars, soc.data.id)

    assert ars.call_rpc(
        rpc.s.UpdateObjectParameters.Request(
            uid(), rpc.s.UpdateObjectParameters.Request.Args(soc.data.id, parameters=req_params2)
        ),
        rpc.s.AddObjectToScene.Response,
    ).result

    soc2 = event(ars, events.s.SceneObjectChanged)
    assert soc2.change_type == soc.change_type.UPDATE
    assert soc2.data.type == ObjectWithSettings.__name__
    assert soc2.data.parameters == req_params2

    unlock_object(ars, soc.data.id)

    # let's continue with testing overrides
    assert ars.call_rpc(
        rpc.p.NewProject.Request(uid(), rpc.p.NewProject.Request.Args(scene.id, "Project name")),
        rpc.p.NewProject.Response,
    ).result

    event(ars, events.p.OpenProject)
    event(ars, events.s.SceneState)

    assert not ars.call_rpc(
        rpc.o.DeleteOverride.Request(
            uid(), rpc.o.DeleteOverride.Request.Args(obj_id, Parameter("bool_param", "boolean", json.dumps(True)))
        ),
        rpc.o.DeleteOverride.Response,
    ).result

    assert not ars.call_rpc(
        rpc.o.UpdateOverride.Request(
            uid(), rpc.o.UpdateOverride.Request.Args(obj_id, Parameter("bool_param", "boolean", json.dumps(True)))
        ),
        rpc.o.UpdateOverride.Response,
    ).result

    # int_param has to be set to special value, so without override, StartScene should fail now
    assert ars.call_rpc(
        rpc.s.StartScene.Request(uid()),
        rpc.s.StartScene.Response,
    ).result

    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Starting
    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Stopping
    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Stopped

    lock_object(ars, obj_id)

    override = Parameter("int_param", "integer", json.dumps(ObjectWithSettings.INT_PARAM_SPECIAL_VALUE))

    assert ars.call_rpc(
        rpc.o.AddOverride.Request(uid(), rpc.o.AddOverride.Request.Args(obj_id, override)),
        rpc.o.AddOverride.Response,
    ).result

    override_evt = event(ars, events.o.OverrideUpdated)
    assert override_evt.data == override
    assert override_evt.change_type
    assert override_evt.change_type == override_evt.change_type.ADD
    assert override_evt.parent_id == obj_id

    override2 = Parameter("str_param", "string", json.dumps("test"))

    assert ars.call_rpc(
        rpc.o.AddOverride.Request(uid(), rpc.o.AddOverride.Request.Args(obj_id, override2)),
        rpc.o.AddOverride.Response,
    ).result

    event(ars, events.o.OverrideUpdated)

    unlock_object(ars, obj_id)

    save_project(ars)

    # now it should be possible to start the scene
    assert ars.call_rpc(
        rpc.s.StartScene.Request(uid()),
        rpc.s.StartScene.Response,
    ).result

    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Starting
    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Started
Ejemplo n.º 3
0
def test_update_object_pose(start_processes: None, ars: ARServer) -> None:

    upload_def(Box, BoxModel("Box", 0.1, 0.1, 0.1))
    upload_def(DummyMultiArmRobot)

    test = "test"

    event(ars, events.c.ShowMainScreen)

    assert ars.call_rpc(
        rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args(test)),
        rpc.s.NewScene.Response).result

    assert len(event(ars, events.o.ChangedObjectTypes).data) == 2

    event(ars, events.s.OpenScene)
    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(
            get_id(),
            rpc.s.AddObjectToScene.Request.Args("obj", Box.__name__, Pose())),
        rpc.s.AddObjectToScene.Response,
    ).result

    scene_obj = event(ars, events.s.SceneObjectChanged).data

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(
            get_id(),
            rpc.s.AddObjectToScene.Request.Args("robot",
                                                DummyMultiArmRobot.__name__,
                                                Pose())),
        rpc.s.AddObjectToScene.Response,
    ).result

    scene_robot = event(ars, events.s.SceneObjectChanged).data

    new_pose = Pose(Position(1))

    lock_object(ars, scene_obj.id)

    assert ars.call_rpc(
        rpc.s.UpdateObjectPose.Request(
            get_id(),
            rpc.s.UpdateObjectPose.Request.Args(scene_obj.id, new_pose)),
        rpc.s.UpdateObjectPose.Response,
    ).result

    assert event(ars, events.s.SceneObjectChanged).data.pose == new_pose
    unlock_object(ars, scene_obj.id)

    lock_object(ars, scene_robot.id)

    assert ars.call_rpc(
        rpc.s.UpdateObjectPose.Request(
            get_id(),
            rpc.s.UpdateObjectPose.Request.Args(scene_robot.id, new_pose)),
        rpc.s.UpdateObjectPose.Response,
    ).result

    assert event(ars, events.s.SceneObjectChanged).data.pose == new_pose
    unlock_object(ars, scene_robot.id)

    assert ars.call_rpc(
        rpc.s.StartScene.Request(get_id()),
        rpc.s.StartScene.Response,
    ).result

    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Starting
    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Started

    lock_object(ars, scene_obj.id)

    # with started scene, it should still be possible to manipulate the object
    assert ars.call_rpc(
        rpc.s.UpdateObjectPose.Request(
            get_id(),
            rpc.s.UpdateObjectPose.Request.Args(scene_obj.id, Pose())),
        rpc.s.UpdateObjectPose.Response,
    ).result

    assert event(ars, events.s.SceneObjectChanged).data.pose == Pose()
    unlock_object(ars, scene_obj.id)

    lock_object(ars, scene_robot.id)

    # ...but it should not be possible to manipulate the robot
    assert not ars.call_rpc(
        rpc.s.UpdateObjectPose.Request(
            get_id(),
            rpc.s.UpdateObjectPose.Request.Args(scene_robot.id, Pose())),
        rpc.s.UpdateObjectPose.Response,
    ).result

    unlock_object(ars, scene_robot.id)
Ejemplo n.º 4
0
def test_project_const(start_processes: None, ars: ARServer) -> None:

    event(ars, events.c.ShowMainScreen)

    assert ars.call_rpc(
        rpc.s.NewScene.Request(uid(),
                               rpc.s.NewScene.Request.Args("Test scene")),
        rpc.s.NewScene.Response).result

    scene_data = event(ars, events.s.OpenScene).data
    assert scene_data
    scene = scene_data.scene

    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(
            uid(),
            rpc.s.AddObjectToScene.Request.Args("random_actions",
                                                RandomActions.__name__)),
        rpc.s.AddObjectToScene.Response,
    ).result

    obj = event(ars, events.s.SceneObjectChanged).data
    assert obj

    # ------------------------------------------------------------------------------------------------------------------

    assert ars.call_rpc(
        rpc.p.NewProject.Request(
            uid(), rpc.p.NewProject.Request.Args(scene.id, "Project name")),
        rpc.p.NewProject.Response,
    ).result

    proj = event(ars, events.p.OpenProject).data
    assert proj

    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.p.AddConstant.Request(
            uid(),
            rpc.p.AddConstant.Request.Args("min_time", "double",
                                           json.dumps(0.45))),
        rpc.p.AddConstant.Response,
    ).result

    c1 = event(ars, events.p.ProjectConstantChanged).data
    assert c1

    assert not ars.call_rpc(
        rpc.p.AddConstant.Request(
            uid(),
            rpc.p.AddConstant.Request.Args("min_time", "double",
                                           json.dumps(0.62))),
        rpc.p.AddConstant.Response,
    ).result

    assert not ars.call_rpc(  # attempt to update without lock
        rpc.p.UpdateConstant.Request(
            uid(),
            rpc.p.UpdateConstant.Request.Args(c1.id, name="min_time_updated")),
        rpc.p.UpdateConstant.Response,
    ).result

    # ------------------------------------------------------------------------------------------------------------------
    # the user opens a menu and then closes it without actually changing anything

    lock_object(ars, c1.id)

    assert ars.call_rpc(
        rpc.p.UpdateConstant.Request(uid(),
                                     rpc.p.UpdateConstant.Request.Args(
                                         c1.id, name="min_time_1"),
                                     dry_run=True),
        rpc.p.UpdateConstant.Response,
    ).result

    assert ars.call_rpc(
        rpc.p.UpdateConstant.Request(uid(),
                                     rpc.p.UpdateConstant.Request.Args(
                                         c1.id, name="min_time_2"),
                                     dry_run=True),
        rpc.p.UpdateConstant.Response,
    ).result

    unlock_object(ars, c1.id)

    # ------------------------------------------------------------------------------------------------------------------

    lock_object(ars, c1.id)

    assert ars.call_rpc(
        rpc.p.UpdateConstant.Request(
            uid(),
            rpc.p.UpdateConstant.Request.Args(c1.id, name="min_time_updated")),
        rpc.p.UpdateConstant.Response,
    ).result

    c1u = event(ars, events.p.ProjectConstantChanged).data
    assert c1u

    event(ars, events.lk.ObjectsUnlocked)

    assert c1u.id == c1.id
    assert c1.name != c1u.name
    assert c1.type == c1u.type

    # ------------------------------------------------------------------------------------------------------------------
    # try to add and remove

    assert ars.call_rpc(
        rpc.p.AddConstant.Request(
            uid(),
            rpc.p.AddConstant.Request.Args("min_time_2", "double",
                                           json.dumps(0.62))),
        rpc.p.AddConstant.Response,
    ).result

    c2 = event(ars, events.p.ProjectConstantChanged).data
    assert c2

    assert ars.call_rpc(
        rpc.p.RemoveConstant.Request(uid(),
                                     rpc.p.RemoveConstant.Request.Args(c2.id)),
        rpc.p.RemoveConstant.Response,
    ).result

    c2e = event(ars, events.p.ProjectConstantChanged)
    assert c2e.data
    assert c2e.data.id == c2.id
    assert c2e.change_type == c2e.Type.REMOVE

    # ------------------------------------------------------------------------------------------------------------------
    # attempt to add a constant with duplicate name

    assert not ars.call_rpc(
        rpc.p.AddConstant.Request(
            uid(),
            rpc.p.AddConstant.Request.Args(c1u.name, "double",
                                           json.dumps(0.62))),
        rpc.p.AddConstant.Response,
    ).result

    # ------------------------------------------------------------------------------------------------------------------

    assert ars.call_rpc(
        rpc.p.AddActionPoint.Request(
            uid(), rpc.p.AddActionPoint.Request.Args("ap1",
                                                     common.Position())),
        rpc.p.AddActionPoint.Response,
    ).result

    ap = event(ars, events.p.ActionPointChanged).data
    assert ap is not None

    assert ars.call_rpc(
        rpc.p.AddAction.Request(
            uid(),
            rpc.p.AddAction.Request.Args(
                ap.id,
                "test_action",
                f"{obj.id}/{RandomActions.random_double.__name__}",
                [
                    common.ActionParameter(
                        "range_min", common.ActionParameter.TypeEnum.CONSTANT,
                        json.dumps(c1.id)),
                    common.ActionParameter("range_max", "double", "0.55"),
                ],
                [common.Flow(outputs=["random_value"])],
            ),
        ),
        rpc.p.AddAction.Response,
    ).result

    action = event(ars, events.p.ActionChanged).data
    assert action

    assert not ars.call_rpc(
        rpc.p.RemoveConstant.Request(uid(),
                                     rpc.p.RemoveConstant.Request.Args(c1.id)),
        rpc.p.RemoveConstant.Response).result

    # ------------------------------------------------------------------------------------------------------------------
    # try to execute action using constant parameter

    assert ars.call_rpc((rpc.s.StartScene.Request(uid())),
                        rpc.s.StartScene.Response).result

    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Starting
    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Started

    assert ars.call_rpc(
        rpc.p.ExecuteAction.Request(
            uid(), rpc.p.ExecuteAction.Request.Args(action.id)),
        rpc.p.ExecuteAction.Response)

    event(ars, events.a.ActionExecution)
    res = event(ars, events.a.ActionResult)

    assert res.data
    assert res.data.action_id == action.id
    assert not res.data.error

    assert ars.call_rpc((rpc.s.StopScene.Request(uid())),
                        rpc.s.StopScene.Response).result
    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Stopping
    assert event(ars, events.s.SceneState
                 ).data.state == events.s.SceneState.Data.StateEnum.Stopped

    assert ars.call_rpc(
        rpc.p.RemoveAction.Request(uid(), rpc.p.IdArgs(action.id)),
        rpc.p.RemoveAction.Response).result
    assert event(ars, events.p.ActionChanged).data

    assert ars.call_rpc(
        rpc.p.RemoveConstant.Request(uid(),
                                     rpc.p.RemoveConstant.Request.Args(c1.id)),
        rpc.p.RemoveConstant.Response).result
    event(ars, events.p.ProjectConstantChanged)
Ejemplo n.º 5
0
def test_object_aiming(start_processes: None, ars: ARServer) -> None:

    mesh = Mesh(Box.__name__, "mesh.dae", [Pose(), Pose(), Pose()])
    assert mesh.focus_points
    Box.mesh_filename = mesh.data_id

    with tempfile.NamedTemporaryFile("wb") as file:
        upload_def(Box, model=mesh, file_to_upload=file.name)

    upload_def(DummyMultiArmRobot)

    test = "test"

    event(ars, events.c.ShowMainScreen)

    assert ars.call_rpc(
        rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args(test)), rpc.s.NewScene.Response
    ).result

    assert len(event(ars, events.o.ChangedObjectTypes).data) == 2

    event(ars, events.s.OpenScene)
    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(get_id(), rpc.s.AddObjectToScene.Request.Args("obj", Box.__name__, Pose())),
        rpc.s.AddObjectToScene.Response,
    ).result

    scene_obj = event(ars, events.s.SceneObjectChanged).data

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(
            get_id(), rpc.s.AddObjectToScene.Request.Args("robot", DummyMultiArmRobot.__name__, Pose())
        ),
        rpc.s.AddObjectToScene.Response,
    ).result

    scene_robot = event(ars, events.s.SceneObjectChanged).data

    assert ars.call_rpc(
        rpc.s.StartScene.Request(get_id()),
        rpc.s.StartScene.Response,
    ).result

    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Starting
    assert event(ars, events.s.SceneState).data.state == events.s.SceneState.Data.StateEnum.Started

    arm = DummyMultiArmRobot.Arms.left
    robot_arg = RobotArg(scene_robot.id, list(DummyMultiArmRobot.EEF[arm])[0], arm)

    # ------------------------------------------------------------------------------------------------------------------

    lock_object(ars, scene_obj.id)
    lock_object(ars, scene_robot.id)

    assert ars.call_rpc(
        rpc.o.ObjectAimingStart.Request(get_id(), rpc.o.ObjectAimingStart.Request.Args(scene_obj.id, robot_arg)),
        rpc.o.ObjectAimingStart.Response,
    ).result

    assert not ars.call_rpc(
        rpc.o.ObjectAimingStart.Request(get_id(), rpc.o.ObjectAimingStart.Request.Args(scene_obj.id, robot_arg)),
        rpc.o.ObjectAimingStart.Response,
    ).result

    assert ars.call_rpc(
        rpc.o.ObjectAimingAddPoint.Request(get_id(), rpc.o.ObjectAimingAddPoint.Request.Args(0)),
        rpc.o.ObjectAimingAddPoint.Response,
    ).result

    assert ars.call_rpc(
        rpc.o.ObjectAimingCancel.Request(get_id()),
        rpc.o.ObjectAimingCancel.Response,
    ).result

    unlock_object(ars, scene_obj.id)
    unlock_object(ars, scene_robot.id)

    # ------------------------------------------------------------------------------------------------------------------

    lock_object(ars, scene_obj.id)
    lock_object(ars, scene_robot.id)

    assert ars.call_rpc(
        rpc.o.ObjectAimingStart.Request(get_id(), rpc.o.ObjectAimingStart.Request.Args(scene_obj.id, robot_arg)),
        rpc.o.ObjectAimingStart.Response,
    ).result

    assert not ars.call_rpc(
        rpc.o.ObjectAimingAddPoint.Request(get_id(), rpc.o.ObjectAimingAddPoint.Request.Args(-1)),
        rpc.o.ObjectAimingAddPoint.Response,
    ).result

    assert not ars.call_rpc(
        rpc.o.ObjectAimingAddPoint.Request(get_id(), rpc.o.ObjectAimingAddPoint.Request.Args(len(mesh.focus_points))),
        rpc.o.ObjectAimingAddPoint.Response,
    ).result

    assert not ars.call_rpc(
        rpc.o.ObjectAimingDone.Request(get_id()),
        rpc.o.ObjectAimingDone.Response,
    ).result

    for idx in range(len(mesh.focus_points)):

        assert ars.call_rpc(
            rpc.o.ObjectAimingAddPoint.Request(get_id(), rpc.o.ObjectAimingAddPoint.Request.Args(idx)),
            rpc.o.ObjectAimingAddPoint.Response,
        ).result

    assert ars.call_rpc(
        rpc.o.ObjectAimingDone.Request(get_id()),
        rpc.o.ObjectAimingDone.Response,
    ).result

    assert event(ars, events.s.SceneObjectChanged).data.id == scene_obj.id

    unlock_object(ars, scene_obj.id)
    unlock_object(ars, scene_robot.id)
Ejemplo n.º 6
0
def test_update_object_model(start_processes: None, ars: ARServer) -> None:

    upload_def(BoxType, Box(BoxType.__name__, 0.1, 0.1, 0.1))
    upload_def(DummyMultiArmRobot)

    event(ars, events.c.ShowMainScreen)

    assert ars.call_rpc(
        rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args("TestScene")), rpc.s.NewScene.Response
    ).result

    assert len(event(ars, events.o.ChangedObjectTypes).data) == 2

    event(ars, events.s.OpenScene)
    event(ars, events.s.SceneState)

    lock_object(ars, BoxType.__name__)

    om = ObjectModel(Model3dType.SPHERE, sphere=Sphere(BoxType.__name__, 0.1))

    assert ars.call_rpc(
        rpc.o.UpdateObjectModel.Request(get_id(), rpc.o.UpdateObjectModel.Request.Args(BoxType.__name__, om)),
        rpc.o.UpdateObjectModel.Response,
    ).result

    ot_evt = event(ars, events.o.ChangedObjectTypes)
    assert ot_evt.change_type == ot_evt.Type.UPDATE
    assert len(ot_evt.data) == 1
    assert ot_evt.data[0].object_model == om
    assert ot_evt.data[0].type == BoxType.__name__
    assert ot_evt.data[0].has_pose
    assert not ot_evt.data[0].disabled

    assert BoxType.__name__ in {obj.id for obj in project_service.get_object_type_ids()}
    assert BoxType.__name__ in {mod.id for mod in project_service.get_models()}

    unlock_object(ars, BoxType.__name__)

    lock_object(ars, DummyMultiArmRobot.__name__)

    assert not ars.call_rpc(
        rpc.o.UpdateObjectModel.Request(
            get_id(),
            rpc.o.UpdateObjectModel.Request.Args(
                DummyMultiArmRobot.__name__,
                ObjectModel(Model3dType.SPHERE, sphere=Sphere(DummyMultiArmRobot.__name__, 0.1)),
            ),
        ),
        rpc.o.UpdateObjectModel.Response,
    ).result

    unlock_object(ars, DummyMultiArmRobot.__name__)

    delete_res_1 = ars.call_rpc(
        rpc.o.DeleteObjectTypes.Request(get_id(), {BoxType.__name__}, dry_run=True),
        rpc.o.DeleteObjectTypes.Response,
    )

    assert delete_res_1.result
    assert delete_res_1.data is None

    delete_res_2 = ars.call_rpc(
        rpc.o.DeleteObjectTypes.Request(get_id(), {BoxType.__name__}),
        rpc.o.DeleteObjectTypes.Response,
    )

    assert delete_res_2.result
    assert delete_res_2.data is None

    ot_evt2 = event(ars, events.o.ChangedObjectTypes)
    assert ot_evt2.change_type == ot_evt.Type.REMOVE
    assert len(ot_evt2.data) == 1
    assert ot_evt2.data[0].object_model == om
    assert ot_evt2.data[0].type == BoxType.__name__

    assert BoxType.__name__ not in {obj.id for obj in project_service.get_object_type_ids()}
    assert BoxType.__name__ not in {mod.id for mod in project_service.get_models()}
Ejemplo n.º 7
0
def test_project_ap_rpcs(start_processes: None, ars: ARServer) -> None:

    upload_def(Box, BoxModel(Box.__name__, 1, 2, 3))

    event(ars, events.c.ShowMainScreen)

    assert ars.call_rpc(
        rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args("Test scene")), rpc.s.NewScene.Response
    ).result

    assert len(event(ars, events.o.ChangedObjectTypes).data) == 1

    scene_data = event(ars, events.s.OpenScene).data
    assert scene_data
    scene = scene_data.scene

    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.s.AddObjectToScene.Request(get_id(), rpc.s.AddObjectToScene.Request.Args("box", Box.__name__, Pose())),
        rpc.s.AddObjectToScene.Response,
    ).result

    obj = event(ars, events.s.SceneObjectChanged).data
    assert obj

    # ------------------------------------------------------------------------------------------------------------------

    assert ars.call_rpc(
        rpc.p.NewProject.Request(get_id(), rpc.p.NewProject.Request.Args(scene.id, "Project name")),
        rpc.p.NewProject.Response,
    ).result

    event(ars, events.s.SceneSaved)
    event(ars, events.p.OpenProject)
    event(ars, events.s.SceneState)

    assert ars.call_rpc(
        rpc.p.AddActionPoint.Request(get_id(), rpc.p.AddActionPoint.Request.Args("parent_ap", Position())),
        rpc.p.AddActionPoint.Response,
    ).result

    parent_ap_evt = event(ars, events.p.ActionPointChanged)

    assert ars.call_rpc(
        rpc.p.AddActionPoint.Request(
            get_id(), rpc.p.AddActionPoint.Request.Args("child_ap", Position(-1), parent_ap_evt.data.id)
        ),
        rpc.p.AddActionPoint.Response,
    ).result

    child_ap_evt = event(ars, events.p.ActionPointChanged)
    assert child_ap_evt.data.parent == parent_ap_evt.data.id

    lock_object(ars, child_ap_evt.data.id)

    assert ars.call_rpc(
        rpc.p.AddActionPointOrientation.Request(
            get_id(), rpc.p.AddActionPointOrientation.Request.Args(child_ap_evt.data.id, Orientation())
        ),
        rpc.p.AddActionPointOrientation.Response,
    ).result

    ori = event(ars, events.p.OrientationChanged)

    assert ars.call_rpc(
        rpc.p.AddAction.Request(
            get_id(),
            rpc.p.AddAction.Request.Args(
                child_ap_evt.data.id,
                "act_name",
                f"{obj.id}/{Box.update_pose.__name__}",
                [ActionParameter("new_pose", PosePlugin.type_name(), json.dumps(ori.data.id))],
                [Flow()],
            ),
        ),
        rpc.p.AddAction.Response,
    ).result

    event(ars, events.p.ActionChanged)

    unlock_object(ars, child_ap_evt.data.id)

    ars.event_mapping[ActionChanged.__name__] = ActionChanged

    assert ars.call_rpc(
        rpc.p.CopyActionPoint.Request(get_id(), rpc.p.CopyActionPoint.Request.Args(parent_ap_evt.data.id)),
        rpc.p.CopyActionPoint.Response,
    ).result

    new_parent_ap = event(ars, events.p.ActionPointChanged)
    assert not new_parent_ap.data.parent

    new_child_ap = event(ars, events.p.ActionPointChanged)
    assert new_child_ap.data.parent == new_parent_ap.data.id

    new_ori = event(ars, events.p.OrientationChanged)
    assert new_ori.parent_id == new_child_ap.data.id

    # with events.p.ActionChanged it would return only BareAction (without parameters)
    new_action = event(ars, ActionChanged)
    ars.event_mapping[ActionChanged.__name__] = events.p.ActionChanged
    assert new_action.parent_id == new_child_ap.data.id

    # Pose parameter (orientation id) should be updated now
    assert len(new_action.data.parameters) == 1
    assert json.loads(new_action.data.parameters[0].value) == new_ori.data.id