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());
    }
Example #2
0
    /// <summary>
    /// Add a new EMG sensor
    /// </summary>
    public void AddSensor()
    {
        // Create and add sensor
        ThalmicMyobandManager emgSensor = new ThalmicMyobandManager();

        AvatarSystem.AddActiveSensor(emgSensor);

        // Get prosthesis and add sensor when tH
        if (AvatarSystem.AvatarType == AvatarType.Transhumeral)
        {
            GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
            ConfigurableElbowManager elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
            elbowManager.AddSensor(emgSensor);
        }

        else if (AvatarSystem.AvatarType == AvatarType.Transradial)
        {
            GameObject      prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
            FakeEMGBoniHand prosthesisManager   = prosthesisManagerGO.GetComponent <FakeEMGBoniHand>();
            prosthesisManager.InitialiseInputSystem(emgSensor);
        }

        // Return to settings menu.
        addSensorMenu.ReturnToSettingsMenu();
    }
Example #3
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));
        }
    }
Example #4
0
    /// <summary>
    /// Initializes the ExperimentSystem and its components.
    /// Verifies that all components needed for the experiment are available.
    /// </summary>
    public override void InitialiseExperimentSystems()
    {
        //
        // Set the experiment type and ID
        //
        experimentType = ExperimentType.TypeOne;
        ExperimentSystem.SetActiveExperimentID("PhotoStage");

        //
        // Create data loggers
        //
        // Restart EMG readings
        foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
        {
            if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
            {
                UDPSensorManager udpSensor = (UDPSensorManager)sensor;
                //Debug.Log(wifiSensor.RunThread);
                udpSensor.StartSensorReading();
                //Debug.Log(wifiSensor.RunThread);
            }
        }
        // Set EMG sensor and reference generator as active.
        // Get prosthesis
        GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
        ConfigurableElbowManager elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();

        // Set active sensor and reference generator to EMG.
        elbowManager.ChangeSensor("VAL_SENSOR_SEMG");
        elbowManager.ChangeReferenceGenerator("VAL_REFGEN_EMGPROP");
    }
Example #5
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);
    }
    /// <summary>
    /// Add a new EMG sensor
    /// </summary>
    public void AddSensor()
    {
        if (ip == null || ip == string.Empty || port == 0 || channelSize <= 0)
        {
            StartCoroutine(DisplayInformationOnLog(3.0f, "The provided sensor info is invalid."));
        }

        try
        {
            // Create and add sensor
            EMGWiFiManager emgSensor = new EMGWiFiManager(ip, port, channelSize, isRaw);
            AvatarSystem.AddActiveSensor(emgSensor);

            // Get prosthesis and add sensor when tH
            if (AvatarSystem.AvatarType == AvatarType.Transhumeral)
            {
                GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
                ConfigurableElbowManager elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                elbowManager.AddSensor(emgSensor);
            }

            else if (AvatarSystem.AvatarType == AvatarType.Transradial)
            {
                GameObject      prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                FakeEMGBoniHand prosthesisManager   = prosthesisManagerGO.GetComponent <FakeEMGBoniHand>();
                prosthesisManager.InitialiseInputSystem(emgSensor);
            }

            // Return to settings menu.
            addSensorMenu.ReturnToSettingsMenu();
        }
        // 10048 address duplicate
        catch (SocketException e) when(e.ErrorCode == 10048)
        {
            StartCoroutine(DisplayInformationOnLog(3.0f, "IP address already in use."));
        }
        // 10045 port duplicate
        catch (SocketException e) when(e.ErrorCode == 10045)
        {
            StartCoroutine(DisplayInformationOnLog(3.0f, "Port already in use."));
        }
        catch (System.Exception e)
        {
            StartCoroutine(DisplayInformationOnLog(3.0f, "An error occured while adding the sensor.\nError message: " + e.Message));
        }
    }
    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();
        }
    }
Example #8
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";
            }
        }
    }
Example #10
0
    /// <summary>
    /// Initializes the ExperimentSystem and its components.
    /// Verifies that all components needed for the experiment are available.
    /// This must be done in Start.
    /// Extend this method by doing your own implementation, with base.InitExperimentSystem() being called at the start.
    /// </summary>
    public override void InitialiseExperimentSystems()
    {
        //
        // Set the experiment type configuration
        //
        // Type one if able-bodied subject
        if (AvatarSystem.AvatarType == AvatarType.AbleBodied)
        {
            experimentType        = ExperimentType.TypeOne; // Able-bodied experiment type
            taskDataFormat        = ablebodiedDataFormat;
            performanceDataFormat = ablebodiedPerformanceDataFormat;
        }
        // Type two if prosthetic (Adaptive Synergy)
        else if (AvatarSystem.AvatarType == AvatarType.Transhumeral)
        {
            experimentType        = ExperimentType.TypeTwo; // Able-bodied experiment type
            taskDataFormat        = prostheticDataFormat;
            performanceDataFormat = prostheticPerformanceDataFormat;
        }
        // Then run the base initialisation which is needed, with a small modification
        //
        // Set the experiment name only when debugging. Take  the name from the gameobject + Debug
        //
        if (debug)
        {
            ExperimentSystem.SetActiveExperimentID(this.gameObject.name + "_Debug");
        }

        // Make sure flow control is initialised
        sessionNumber   = 1;
        iterationNumber = 1;

        //
        // Create the default data loggers
        //
        taskDataLogger = new DataStreamLogger("TaskData/" + AvatarSystem.AvatarType.ToString());
        ExperimentSystem.AddExperimentLogger(taskDataLogger);
        taskDataLogger.AddNewLogFile(sessionNumber, iterationNumber, taskDataFormat); // Add file

        // Restart UDP threads
        foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
        {
            if (sensor is UDPSensorManager udpSensor)
            {
                //Debug.Log(wifiSensor.RunThread);
                udpSensor.StartSensorReading();
                //Debug.Log(wifiSensor.RunThread);
            }
        }

        // Send the player to the experiment centre position
        TeleportToStartPosition();

        startPosPhoto.SetActive(false);

        //
        // Create the performance data loggers
        //
        performanceDataLogger = new DataStreamLogger("PerformanceData");
        ExperimentSystem.AddExperimentLogger(performanceDataLogger);
        performanceDataLogger.AddNewLogFile(AvatarSystem.AvatarType.ToString(), sessionNumber, performanceDataFormat); // Add file

        if (SaveSystem.ActiveUser.lefty)
        {
            leftySign = -1.0f;
        }

        //
        // Iterations configuration
        //
        // Set iterations variables for flow control.
        targetNumber = gridRows * gridColumns;
        for (int i = 0; i < iterationsPerSession.Count; i++)
        {
            iterationsPerSession[i] = targetNumber * iterationsPerTarget;
        }

        // Create the list of target indexes and shuffle it.
        for (int i = 0; i < targetNumber; i++)
        {
            for (int j = 0; j < iterationsPerTarget; j++)
            {
                targetOrder.Add(i);
            }
        }
        targetOrder.Shuffle();

        //
        // Initialize world positioning
        //
        // Get user physiological data.
        float subjectHeight    = SaveSystem.ActiveUser.height;
        float subjectArmLength = SaveSystem.ActiveUser.upperArmLength + SaveSystem.ActiveUser.forearmLength + (SaveSystem.ActiveUser.handLength / 2);

        // Set the grid distance from subject
        gridManager.transform.position = new Vector3((-gridReachMultiplier * subjectArmLength) - 0.1f, gridHeightMultiplier * subjectHeight, 0.0f);

        //
        // Add arm motion trackers for able-bodied case.
        //
        if (experimentType == ExperimentType.TypeOne)
        {
            // Lower limb motion tracker
            GameObject llMotionTrackerGO = GameObject.FindGameObjectWithTag("ForearmTracker");
            lowerArmTracker = new VIVETrackerManager(llMotionTrackerGO.transform);
            ExperimentSystem.AddSensor(lowerArmTracker);

            // Upper limb motion tracker
            GameObject ulMotionTrackerGO = AvatarSystem.AddMotionTracker();
            upperArmTracker = new VIVETrackerManager(ulMotionTrackerGO.transform);
            ExperimentSystem.AddSensor(upperArmTracker);
        }
        else if (experimentType == ExperimentType.TypeTwo)
        {
            // Get active sensors from avatar system and get the vive tracker being used for the UA
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                if (sensor is VIVETrackerManager)
                {
                    upperArmTracker = (VIVETrackerManager)sensor;
                }
            }
            if (upperArmTracker == null)
            {
                throw new System.NullReferenceException("The residual limb tracker was not found.");
            }

            // Set VIVE tracker and Linear synergy as active.
            // Get prosthesis
            prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
            elbowManager        = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
            // Set the reference generator to linear synergy.
            elbowManager.ChangeSensor("VAL_SENSOR_VIVETRACKER");
            elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");

            // Create the personalisation algorithm object
            elbowManager.SetSynergy(theta);
            float[]   ditherFrequency = { Mathf.PI / 4, 2 * Mathf.PI / 4 };
            float[]   observerGain    = { 0.3840f, 0.6067f, -0.2273f, -0.8977f, -1.0302f };
            float[][] A = new float[2][];
            A[0] = new float[2] {
                1.3130f, -0.8546f
            };
            A[1] = new float[2] {
                1.0f, 0.0f
            };
            float[] B = { 1.0f, 0.0f };
            float[] C = { 0.0131f, -0.0131f };
            float   D = 0.0f;
            personaliser = new TransCyberHPIPersonalisation(ditherAmplitude, 0, ditherFrequency, observerGain, 1, optimiserGain, 0.1f, A, B, C, D, theta, 0.1f, 3.0f);
        }

        if (evaluatorType == EvaluatorType.Compensation)
        {
            // Performance evaluation objects
            evaluator    = new UpperBodyCompensationMotionPM(0.5f, 0.5f);
            shDataBuffer = new List <Vector3>();
            c7DataBuffer = new List <Vector3>();
        }
        else if (evaluatorType == EvaluatorType.KinematicEnergy)
        {
            throw new System.NotImplementedException("KE method not yet implemented");
        }

        // Debug?
        if (!debug)
        {
            // Shoulder acromium head tracker
            GameObject motionTrackerGO1 = AvatarSystem.AddMotionTracker();
            shoulderTracker = new VIVETrackerManager(motionTrackerGO1.transform);
            ExperimentSystem.AddSensor(shoulderTracker);
            // C7 tracker
            GameObject motionTrackerGO2 = AvatarSystem.AddMotionTracker();
            c7Tracker = new VIVETrackerManager(motionTrackerGO2.transform);
            ExperimentSystem.AddSensor(c7Tracker);
        }

        //
        // Hand tracking sensor
        //
        GameObject handGO = GameObject.FindGameObjectWithTag("Hand");

        handTracker = new VirtualPositionTracker(handGO.transform);
        ExperimentSystem.AddSensor(handTracker);

        // Spawn grid
        gridManager.SpawnGrid(gridRows, gridColumns, gridSpacing);
    }
    /// <summary>
    /// Initializes the ExperimentSystem and its components.
    /// Verifies that all components needed for the experiment are available.
    /// </summary>
    public override void InitialiseExperimentSystems()
    {
        //
        // Set the experiment type and ID
        //
        if (AvatarSystem.AvatarType == AvatarType.AbleBodied)
        {
            experimentType = ExperimentType.TypeOne;
            MonitorManager.DisplayText("Wrong avatar used. Please use a Transhumeral avatar.");
            throw new System.Exception("Able-bodied avatar not suitable for prosthesis training.");
        }
        else if (AvatarSystem.AvatarType == AvatarType.Transhumeral)
        {
            // Check if EMG is available
            bool EMGAvailable = false;
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
                {
                    EMGAvailable = true;
                    UDPSensorManager udpSensor = (UDPSensorManager)sensor;
                    udpSensor.StartSensorReading();
                }
                else if (sensor.GetSensorType().Equals(SensorType.ThalmicMyo))
                {
                    EMGAvailable = true;
                }
            }
            // Set whether emg or synergy based
            if (EMGAvailable)
            {
                experimentType   = ExperimentType.TypeTwo;
                instructionsText = emgInstructions;
                // Set EMG sensor and reference generator as active.
                // Get prosthesis
                GameObject prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                // Set active sensor and reference generator to EMG.
                //elbowManager.ChangeSensor("VAL_SENSOR_SEMG");
                elbowManager.ChangeSensor("VAL_SENSOR_THALMYO");
                elbowManager.ChangeReferenceGenerator("VAL_REFGEN_EMGPROP");
            }
            else
            {
                experimentType   = ExperimentType.TypeThree;
                instructionsText = synergyInstructions;
                // Set VIVE tracker and Jacobian synergy as active.
                // Get prosthesis
                GameObject prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                if (elbowManager.GetInterfaceType() == ReferenceGeneratorType.JacobianSynergy)
                {
                    // Set the reference generator to jacobian-based.
                    elbowManager.ChangeSensor("VAL_SENSOR_VIVETRACKER");
                    elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");
                }
                else if (elbowManager.GetInterfaceType() == ReferenceGeneratorType.LinearKinematicSynergy)
                {
                    // Set the reference generator to linear synergy.
                    elbowManager.ChangeSensor("VAL_SENSOR_VIVETRACKER");
                    elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");
                }
                else
                {
                    throw new System.Exception("The prosthesis interface available is not supported.");
                }
            }

            if (!debug)
            {
                // Find the residual limb and change the follower
                residualLimbGO               = GameObject.FindGameObjectWithTag("ResidualLimbAvatar");
                limbFollower                 = residualLimbGO.GetComponent <LimbFollower>();
                limbFollower.enabled         = false;
                angleFollower                = residualLimbGO.AddComponent <AngleFollower>();
                angleFollower.fixedTransform = fixedProsthesisPosition;
            }
        }
        else
        {
            throw new System.NotImplementedException();
        }

        // Get Raycast Debug info
        // handGO = GameObject.FindGameObjectWithTag("Hand");
        // elbowGO = GameObject.FindGameObjectWithTag("Elbow_Upper");
        // residualLimbGO = GameObject.FindGameObjectWithTag("ResidualLimbAvatar");
    }
Example #12
0
    /// <summary>
    /// Checks that all the required components have been loaded and starts experiment.
    /// </summary>
    public void InitialiseExperiment()
    {
        bool EMGAvailable = false;

        switch (experimentNumber)
        {
        case NONE:
            // Check that a valid experiment has been selected
            logManager.DisplayInformationOnLog(3.0f, "Please select a valid experiment.");
            break;

        //
        // Jacobian synergy experiment
        //
        case JACOBIAN_SYNERGY:
            // Able-bodied case
            if (optionNumber == 1 && AvatarSystem.AvatarType == AvatarType.AbleBodied)
            {
                KeepOnLoad();
                // Load experiment.
                SteamVR_LoadLevel.Begin("JacobianSynergyExperiment");
            }
            // EMG case
            else if (optionNumber == 2 && AvatarSystem.AvatarType == AvatarType.Transhumeral)
            {
                // Check that an EMG sensor is available
                EMGAvailable = false;
                foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
                {
                    if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
                    {
                        EMGAvailable = true;
                    }
                    else if (sensor.GetSensorType().Equals(SensorType.ThalmicMyo))
                    {
                        EMGAvailable = true;
                    }
                }
                // Load when EMG is available.
                if (EMGAvailable)
                {
                    KeepOnLoad();

                    // Load experiment.
                    //SteamVR_LoadLevel.Begin("JacobianSynergyExperiment");

                    // Load training
                    SteamVR_LoadLevel.Begin("ProsthesisTraining");
                }
                else
                {
                    logManager.DisplayInformationOnLog(3.0f, "Please add and configure an EMG sensor.");
                }
            }
            // Synergy case
            else if ((optionNumber == 3 || optionNumber == 4) && AvatarSystem.AvatarType == AvatarType.Transhumeral)
            {
                KeepOnLoad();

                // Load experiment.
                // SteamVR_LoadLevel.Begin("JacobianSynergyExperiment");

                GameObject prosthesisManagerGO        = GameObject.FindGameObjectWithTag("ProsthesisManager");
                ConfigurableElbowManager elbowManager = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                if (optionNumber == 3)
                {
                    // Set VIVE tracker and Jacobian synergy as active.
                    // Get prosthesis
                    prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                    elbowManager        = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                    // Set the reference generator to jacobian-based.
                    elbowManager.ChangeSensor("VAL_SENSOR_VIVETRACKER");
                    elbowManager.ChangeReferenceGenerator("VAL_REFGEN_JACOBIANSYN");
                }
                else if (optionNumber == 4)
                {
                    // Set VIVE tracker and Linear synergy as active.
                    // Get prosthesis
                    prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                    elbowManager        = prosthesisManagerGO.GetComponent <ConfigurableElbowManager>();
                    // Set the reference generator to linear synergy.
                    elbowManager.ChangeSensor("VAL_SENSOR_VIVETRACKER");
                    elbowManager.ChangeReferenceGenerator("VAL_REFGEN_LINKINSYN");
                }

                // Load training
                SteamVR_LoadLevel.Begin("ProsthesisTraining");
                // Load experiment.
                //SteamVR_LoadLevel.Begin("JacobianSynergyExperiment");
            }
            else
            {
                logManager.DisplayInformationOnLog(3.0f, "Please configure the " + optionList[optionNumber] + " avatar.");
            }
            break;

        case FEEDBACK2019:
            // Check that a transradial prosthesis has been set.
            if (AvatarSystem.AvatarType != AvatarType.Transradial)
            {
                logManager.DisplayInformationOnLog(3.0f, "Please configure the Transradial avatar.");
            }
            else
            {
                //  Initialise the prosthesis
                try
                {
                    GameObject      prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");
                    FakeEMGBoniHand prosthesisManager   = prosthesisManagerGO.GetComponent <FakeEMGBoniHand>();
                    prosthesisManager.InitializeProsthesis();

                    // Set the name from the selected dropdown!
                    ExperimentSystem.SetActiveExperimentID("Feedback2019");
                }
                catch (Exception e)
                {
                    logManager.DisplayInformationOnLog(10.0f, "Error encountered: " + e.Message);
                }
            }
            break;

        //
        //
        //
        case EMG_DATA:
            // Check that an EMG sensor is available
            EMGAvailable = false;
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
                {
                    EMGAvailable = true;
                }
            }
            // Load when EMG is available.
            if (EMGAvailable)
            {
                KeepOnLoad();
                // Load experiment.
                SteamVR_LoadLevel.Begin("EMGShoulderData");
            }
            else
            {
                logManager.DisplayInformationOnLog(3.0f, "Please add and configure an EMG sensor.");
            }
            break;
        }
    }