public void LoadTHAvatar()
    {
        // Fade
        SteamVR_Fade.Start(Color.black, 0.0f);
        // Load
        avatarType = AvatarType.Transhumeral;

        AvatarSystem.LoadPlayer(UserType.Ablebodied, AvatarType.Transhumeral);
        AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);
        // Fade
        SteamVR_Fade.Start(Color.black, 0.0f);

        // Initialize prosthesis
        GameObject prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");

        elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
        elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + SaveSystem.ActiveUser.handLength / 2.0f), 1.5f);
        // Set the reference generator to jacobian-based.
        elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");

        StartCoroutine(EnableColliders());
        // Initialize UI.
        InitializeUI();

        // Teleport to the start position
        StartCoroutine(TeleportCoroutine());
    }
示例#2
0
    public void LoadTranshumeralAvatar()
    {
        try
        {
            AvatarSystem.LoadPlayer(SaveSystem.ActiveUser.type, AvatarType.Transhumeral);
            AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);

            //mainCamera.fieldOfView = 60;
            KeepPlayerGameObjects();

            StartCoroutine(ResetCamera());
            StartCoroutine(DisplayInformationAndReturn(2.0f, "Successfully loaded transhumeral avatar."));

            // Initialize prosthesis
            GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
            ConfigurableElbowManager elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
            elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + (SaveSystem.ActiveUser.handLength / 2.0f)));
            // Set the reference generator to jacobian-based.
            elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");
        }
        catch (System.Exception e)
        {
            StartCoroutine(DisplayInformationAndReturn(10.0f, e.Message));
        }
    }
示例#3
0
    public void LoadTHAvatar()
    {
        SaveSystem.LoadUserData("MD1942");
        AvatarSystem.LoadPlayer(UserType.Ablebodied, AvatarType.Transhumeral);
        AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);

        // Initialize prosthesis
        GameObject prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");

        elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
        elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + SaveSystem.ActiveUser.handLength / 2.0f), 1.5f);
        // Set the reference generator to jacobian-based.
        elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");
        //elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");

        // Initialize UI.
        //InitializeUI();
        // Configure the grasp manager
        GameObject graspManagerGO = GameObject.FindGameObjectWithTag("GraspManager");

        if (graspManagerGO == null)
        {
            throw new System.Exception("Grasp Manager not found.");
        }
        GraspManager graspManager = graspManagerGO.GetComponent <GraspManager>();

        graspManager.managerType = GraspManager.GraspManagerType.Assisted;
        graspManager.managerMode = GraspManager.GraspManagerMode.Restriced;

        // set syn
        elbowManager.SetSynergy(theta);
    }
    private void LoadDebugAvatar()
    {
        // Load avatar
        if (avatarType == AvatarType.Transhumeral)
        {
            AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);

            // Find the residual limb and change the follower
            GameObject   residualLimbGO = GameObject.FindGameObjectWithTag("ResidualLimbAvatar");
            LimbFollower limbFollower   = residualLimbGO.GetComponent <LimbFollower>();
            Destroy(limbFollower);
            AngleFollower angleFollower = residualLimbGO.AddComponent <AngleFollower>();
            angleFollower.fixedTransform = fixedProsthesisPosition;


            // Initialize prosthesis
            GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
            ConfigurableElbowManager elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
            elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + SaveSystem.ActiveUser.handLength / 2.0f));
            // Set the reference generator to jacobian-based.
            elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");
            instructionsText = synergyInstructions;

            // Enable & configure EMG
            if (emgEnable)
            {
                // Create and add sensor
                //EMGWiFiManager emgSensor = new EMGWiFiManager(ip, port, channelSize);
                ThalmicMyobandManager emgSensor = new ThalmicMyobandManager();
                //emgSensor.ConfigureLimits(0, 1023, 0);
                //emgSensor.ConfigureLimits(1, 1023, 0);
                AvatarSystem.AddActiveSensor(emgSensor);
                elbowManager.AddSensor(emgSensor);
                //emgSensor.StartSensorReading();

                // Set active sensor and reference generator to EMG.
                elbowManager.ChangeSensor("VAL_SENSOR_SEMG");
                elbowManager.ChangeReferenceGenerator("VAL_REFGEN_EMGPROP");
                instructionsText = emgInstructions;
            }
        }
        else
        {
            throw new System.NotImplementedException();
        }
    }
示例#5
0
    // Here are all the methods you need to write for your experiment.
    #region GameMaster Inherited Methods

    // Place debug stuff here, for when you want to test the experiment directly from the world without
    // having to load it from the menus.
    private void Awake()
    {
        if (debug)
        {
            //// Save some test config data
            //string configFilePath = Application.dataPath + "/Resources/Experiments/GridReaching2020.json";
            //Debug.Log(configFilePath);
            //configurator = new GridReachingConfigurator();
            //string configuratorAsJson = JsonUtility.ToJson(configurator);
            //File.WriteAllText(configFilePath, configuratorAsJson);

            //
            // Debug able
            //
            SaveSystem.LoadUserData("TB1995175"); // Load the test/demo user (Mr Demo)
            //
            // Debug using able-bodied configuration
            //

            /*
             * AvatarSystem.LoadPlayer(SaveSystem.ActiveUser.type, AvatarType.AbleBodied);
             * AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.AbleBodied);
             */

            //
            // Debug prosthetic
            //

            AvatarSystem.LoadPlayer(UserType.Ablebodied, AvatarType.Transhumeral);
            AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);
            // Initialize prosthesis
            GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
            ConfigurableElbowManager elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
            elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + SaveSystem.ActiveUser.handLength / 2.0f));
            // Set the reference generator to jacobian-based.
            //elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");
            // Set the reference generator to linear synergy.
            elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");
        }
    }
    // Update is called once per frame
    void Update()
    {
        switch (experimentState)
        {
        /*
         *************************************************
         *  HelloWorld
         *************************************************
         */
        // Welcome subject to the virtual world.
        case ExperimentState.Welcome:
            // Load avatar
            if (avatarType == AvatarType.AbleBodied)
            {
                //AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.AbleBodied);
            }
            else if (avatarType == AvatarType.Transhumeral)
            {
                AvatarSystem.LoadAvatar(SaveSystem.ActiveUser, AvatarType.Transhumeral);

                // Initialize prosthesis
                GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
                ConfigurableElbowManager elbowManager = prosthesisManagerGO.AddComponent <ConfigurableElbowManager>();
                elbowManager.InitializeProsthesis(SaveSystem.ActiveUser.upperArmLength, (SaveSystem.ActiveUser.forearmLength + SaveSystem.ActiveUser.handLength / 2.0f));
                // Set the reference generator to jacobian-based.
                elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");
            }

            // Teleport to the start position
            TeleportToStartPosition();

            experimentState = ExperimentState.Initialising;
            break;

        /*
         *************************************************
         *  InitializingApplication
         *************************************************
         */
        // Perform initialization functions before starting experiment.
        case ExperimentState.Initialising:
            //
            // Perform experiment initialization procedures
            //

            //
            // Initialize data logs
            //

            //
            // Go to training
            //
            experimentState = ExperimentState.Training;
            break;

        /*
         *************************************************
         *  Practice
         *************************************************
         */
        // Perform initialization functions before starting experiment.
        case ExperimentState.Training:
            //
            // Guide subject through training
            //

            //
            // Go to instructions
            //
            experimentState = ExperimentState.Instructions;
            break;

        /*
         *************************************************
         *  GivingInstructions
         *************************************************
         */
        case ExperimentState.Instructions:
            // Skip instructions when repeating sessions
            if (SkipInstructions)
            {
                HudManager.DisplayText("Welcome...", 2.0f);
                // Turn targets clear
                experimentState = ExperimentState.WaitingForStart;
                break;
            }

            //
            // Give instructions
            //

            //
            // Go to waiting for start
            //
            HudManager.DisplayText("Welcome...", 2.0f);
            // Turn targets clear
            experimentState = ExperimentState.WaitingForStart;

            break;

        /*
         *************************************************
         *  WaitingForStart
         *************************************************
         */
        case ExperimentState.WaitingForStart:

            // Check if pause requested
            UpdatePause();
            switch (waitState)
            {
            // Waiting for subject to get to start position.
            case WaitState.Waiting:
                SetWaitFlag(3.0f);
                waitState = WaitState.Countdown;
                break;

            case WaitState.Countdown:
                if (WaitFlag)
                {
                    experimentState = ExperimentState.PerformingTask;
                }
                break;

            default:
                break;
            }
            break;

        /*
         *************************************************
         *  PerformingTask
         *************************************************
         */
        case ExperimentState.PerformingTask:
            // Task performance is handled deterministically in FixedUpdate.
            if (avatarType == AvatarType.AbleBodied)
            {
                HudManager.colour = HUDManager.HUDColour.Green;
            }
            else
            {
                if (elbowManager.IsEnabled)
                {
                    HudManager.colour = HUDManager.HUDColour.Blue;
                }
                else
                {
                    HudManager.colour = HUDManager.HUDColour.Red;
                }
            }
            break;

        /*
         *************************************************
         *  AnalizingResults
         *************************************************
         */
        case ExperimentState.AnalizingResults:
            // Allow 3 seconds after task end to do calculations
            SetWaitFlag(3.0f);

            //
            // Data analysis and calculations
            //

            //
            // System update
            //

            //
            // Data logging
            //

            //
            // Flow managment
            //
            // Rest for some time when required
            if (IsRestTime())
            {
                SetWaitFlag(RestTime);
                experimentState = ExperimentState.Resting;
            }
            // Check whether the new session condition is met
            else if (IsEndOfSession())
            {
                experimentState = ExperimentState.InitializingNext;
            }
            // Check whether the experiment end condition is met
            else if (IsEndOfExperiment())
            {
                experimentState = ExperimentState.End;
            }
            else
            {
                experimentState = ExperimentState.UpdatingApplication;
            }
            break;

        /*
         *************************************************
         *  UpdatingApplication
         *************************************************
         */
        case ExperimentState.UpdatingApplication:
            if (WaitFlag)
            {
                //
                // Update iterations and flow control
                //

                //
                // Update log requirements
                //

                //
                //
                // Go to start of next iteration
                experimentState = ExperimentState.WaitingForStart;
            }
            break;

        /*
         *************************************************
         *  InitializingNext
         *************************************************
         */
        case ExperimentState.InitializingNext:
            //
            // Perform session closure procedures
            //

            //
            // Initialize new session variables and flow control
            //
            iterationNumber = 1;
            sessionNumber++;
            skipInstructions = true;

            //
            // Initialize data logging
            //
            //ExperimentSystem.GetActiveLogger(1).AddNewLogFile(sessionNumber, iterationNumber, "Data format");

            experimentState = ExperimentState.Initialising;     // Initialize next session
            break;

        /*
         *************************************************
         *  Resting
         *************************************************
         */
        case ExperimentState.Resting:
            //
            // Check for session change or end request from experimenter
            //
            if (UpdateNext())
            {
                ConfigureNextSession();
                break;
            }
            else if (UpdateEnd())
            {
                EndExperiment();
                break;
            }
            //
            // Restart after flag is set by wait coroutine
            //
            if (WaitFlag)
            {
                HudManager.DisplayText("Get ready to restart!", 3.0f);
                SetWaitFlag(5.0f);
                experimentState = ExperimentState.UpdatingApplication;
                break;
            }
            break;

        /*
         *************************************************
         *  Paused
         *************************************************
         */
        case ExperimentState.Paused:
            //
            // Check for session change or end request from experimenter
            //
            UpdatePause();
            if (UpdateNext())
            {
                ConfigureNextSession();
                break;
            }
            else if (UpdateEnd())
            {
                EndExperiment();
                break;
            }
            break;

        /*
         *************************************************
         *  End
         *************************************************
         */
        case ExperimentState.End:
        //
        // Update log data and close logs.
        //

        //
        // Return to main menu
        //
        default:
            break;
        }

        //
        // Update information displayed on monitor
        //

        //
        // Update information displayed for debugging purposes
        //
        if (debug)
        {
            debugText.text = experimentState.ToString() + "\n";
            if (experimentState == ExperimentState.WaitingForStart)
            {
                debugText.text += waitState.ToString() + "\n";
            }
        }
    }