Example #1
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");
    }
    public void OnEnable()
    {
        //Debug.Log(Application.persistentDataPath);
        if (createdUser)
        {
            logManager.DisplayInformationOnLog(3.0f, "Created new user with ID " + SaveSystem.ActiveUser.id);
            createdUser = false;
        }

        if (loadedUser)
        {
            logManager.DisplayInformationOnLog(3.0f, "Loaded user with ID " + SaveSystem.ActiveUser.id);
            createdUser = false;
        }

        // Display active user name.
        if (SaveSystem.IsUserAvailable)
        {
            activeUserTMP.text = "Active User: \n" + SaveSystem.ActiveUser.name + " " + SaveSystem.ActiveUser.familyName;
        }

        // Display available user sensors name.
        if (AvatarSystem.GetActiveSensors().Count > 0)
        {
            sensorTMP.text = "Sensors: \n";
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                sensorTMP.text = sensorTMP.text + sensor.GetSensorType().ToString() + "\n";
            }
        }

        // Display available experiment sensors name.
        if (ExperimentSystem.GetActiveSensors().Count > 0)
        {
            experimentSensorsTMP.text = "Experiment Sensors: \n";
            foreach (ISensor sensor in ExperimentSystem.GetActiveSensors())
            {
                experimentSensorsTMP.text = experimentSensorsTMP.text + sensor.GetSensorType().ToString() + "\n";
            }
        }

        // Conditional menus
        // Show avatar menu when there is an available user.
        if (SaveSystem.IsUserAvailable)
        {
            avatarOptionsButton.SetActive(true);
        }

        // Show sensors menu when there is an available avatar.
        if (AvatarSystem.IsPlayerAvailable && AvatarSystem.IsAvatarAvaiable)
        {
            sensorOptionsButton.SetActive(true);
            modeSelectionButton.SetActive(true);
        }
    }
 public void OnDestroy()
 {
     foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
     {
         // Stop all UDP sensors
         if (sensor.GetSensorType() == SensorType.EMGWiFi)
         {
             UDPSensorManager udpSensor = (UDPSensorManager)sensor;
             udpSensor.StopSensorReading();
         }
     }
 }
 private void OnApplicationQuit()
 {
     // Check if WiFi sensors are available
     foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
     {
         if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
         {
             UDPSensorManager udpSensor = (UDPSensorManager)sensor;
             udpSensor.StopSensorReading();
         }
     }
     //
     // Save and close all logs
     //
     ExperimentSystem.CloseAllExperimentLoggers();
 }
    public void OnEnable()
    {
        // Clear list
        sensorList.Clear();
        // Add an empty one as default to force selection.
        sensorList.Add(string.Empty);

        // Display available sensors name.
        foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
        {
            sensorList.Add(sensor.GetSensorType().ToString());
        }
        // Add the options to the dropdown
        sensorDropdown.AddOptions(sensorList);
        // And select the last choice.
        UpdatedSelectedSensor(selectedSensor);
    }
    //private ISensor sensorDebug;

    public void OnEnable()
    {
        // Display available user sensors name.
        if (AvatarSystem.GetActiveSensors().Count > 0)
        {
            userSensorsTMP.text = "User Sensors: \n";
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                userSensorsTMP.text = userSensorsTMP.text + sensor.GetSensorType().ToString() + "\n";
            }
        }

        // Display available experiment sensors name.
        if (ExperimentSystem.GetActiveSensors().Count > 0)
        {
            experimentSensorsTMP.text = "Experiment Sensors: \n";
            foreach (ISensor sensor in ExperimentSystem.GetActiveSensors())
            {
                experimentSensorsTMP.text = experimentSensorsTMP.text + sensor.GetSensorType().ToString() + "\n";
            }
        }
    }
    /// <summary>
    /// Handles when the sensor selection has been updated.
    /// </summary>
    /// <param name="selectedSensor"></param>
    public void UpdatedSelectedSensor(int selectedSensor)
    {
        this.selectedSensor = selectedSensor;
        ISensor sensor;

        // If selected a sensor extract it.
        if (selectedSensor > 0)
        {
            sensor = AvatarSystem.GetActiveSensors()[selectedSensor - 1];
        }
        else
        {
            // Deactivate all
            EMGWiFiConfig.SetActive(false);
            return;
        }

        // Select the sensor config menu.
        if (sensor.GetSensorType() == SensorType.EMGWiFi)
        {
            EMGWiFiConfig.SetActive(true);
            EMGWiFiConfig.GetComponent <ConfigEMGWiFi>().SetSensorToConfigure((EMGWiFiManager)sensor);
        }
    }
Example #8
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");
    }
    private void FixedUpdate()
    {
        //
        // Tasks performed determinalistically throughout the experiment
        // E.g. data gathering.
        //
        switch (experimentState)
        {
        case ExperimentState.PerformingTask:
            //
            // Gather data while experiment is in progress
            //
            string displayData = "Training time elapsed: " + taskTime.ToString() + " seconds.";
            // Read from all user sensors
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                if (sensor.GetSensorType().Equals(SensorType.EMGWiFi))
                {
                    displayData += "\n" + sensor.GetSensorType().ToString() + " Command:";
                    float[] sensorData = sensor.GetAllProcessedData();
                    foreach (float element in sensorData)
                    {
                        displayData += "\n" + element.ToString();
                    }
                }
                else if (sensor.GetSensorType().Equals(SensorType.VirtualEncoder))
                {
                    displayData += "\n" + sensor.GetSensorType().ToString() + " Command:";
                    float[] sensorData = sensor.GetAllProcessedData();
                    foreach (float element in sensorData)
                    {
                        displayData += "\n" + element.ToString();
                    }
                }
            }


            InstructionManager.DisplayText(displayData);
            //hudManager.DisplayText(logData);

            //
            // Append data to lists
            //
            taskTime += Time.fixedDeltaTime;

            //
            // Raycast debug
            //
            // Vector3 shoulderToElbow = elbowGO.transform.position - residualLimbGO.transform.position;
            // Vector3 shoulderToHand = handGO.transform.position - (residualLimbGO.transform.position - 0.25f * shoulderToElbow);
            // Debug.DrawRay(residualLimbGO.transform.position - 0.2f * shoulderToElbow, shoulderToHand, Color.magenta);

            //
            // Save log and reset flags when successfully compeleted task
            //
            if (IsTaskDone())
            {
                //
                // Perform data management, such as appending data to lists for analysis
                //

                //
                // Save logger for current experiment and change to data analysis
                //
                //ExperimentSystem.GetActiveLogger(1).CloseLog();

                //
                // Clear data management buffers
                //
                experimentState = ExperimentState.AnalizingResults;
                break;
            }

            // Check if requested to end training
            UpdateEnd();

            break;

        default:
            break;
        }
    }
Example #11
0
    private void FixedUpdate()
    {
        //
        // Tasks performed determinalistically throughout the experiment
        // E.g. data gathering.
        //
        switch (experimentState)
        {
        case ExperimentState.PerformingTask:
            //
            // Gather data while experiment is in progress
            //
            string logData = taskTime.ToString();
            // Read from all user sensors
            foreach (ISensor sensor in AvatarSystem.GetActiveSensors())
            {
                float[] sensorData = sensor.GetAllProcessedData();
                foreach (float element in sensorData)
                {
                    logData += "," + element.ToString();
                }
            }
            // Read from all experiment sensors
            foreach (ISensor sensor in ExperimentSystem.GetActiveSensors())
            {
                float[] sensorData = sensor.GetAllProcessedData();
                foreach (float element in sensorData)
                {
                    logData += "," + element.ToString();
                }
            }

            //
            // Append data to lists
            //
            taskTime += Time.fixedDeltaTime;

            //
            // Log current data
            //
            //motionLogger.AppendData(logData);

            //
            // Save log and reset flags when successfully compeleted task
            //
            if (IsTaskDone())
            {
                //
                // Perform data management, such as appending data to lists for analysis
                //

                //
                // Save logger for current experiment and change to data analysis
                //
                //motionLogger.CloseLog();

                //
                // Clear data management buffers
                //
                experimentState = ExperimentState.AnalizingResults;
                break;
            }

            break;

        default:
            break;
        }
    }
    /// <summary>
    /// Initializes the ExperimentSystem and its components.
    /// Verifies that all components needed for the experiment are available.
    /// </summary>
    public override void InitialiseExperimentSystems()
    {
        // Check the experiment parameters
        if (startAngleList.Count <= 0 || endAngleList.Count <= 0 || movementTimeList.Count <= 0)
        {
            throw new System.Exception("An experiment configuration list is empty.");
        }

        if (startAngleList.Count != endAngleList.Count)
        {
            throw new System.Exception("The angle lists do not match in size.");
        }

        //
        // Set the experiment type and ID
        //
        if (AvatarSystem.AvatarType == AvatarType.AbleBodied)
        {
            // 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;
                    //Debug.Log(wifiSensor.RunThread);
                    udpSensor.StartSensorReading();
                    //Debug.Log(wifiSensor.RunThread);
                }
            }
            // Set whether emg or synergy based
            if (EMGAvailable)
            {
                experimentType = ExperimentType.TypeTwo;
                ExperimentSystem.SetActiveExperimentID("EMG_Data");
            }
            else
            {
                if (debug)
                {
                    // DEBUG ONLY
                    experimentType = ExperimentType.TypeTwo;
                    ExperimentSystem.SetActiveExperimentID("EMG_Data");
                    // DEBUG ONLY
                }
                else
                {
                    throw new System.Exception("An EMG measurement device is required.");
                }
            }
        }
        else
        {
            throw new System.NotImplementedException();
        }

        //
        // Create data loggers
        //
        motionLogger = new DataStreamLogger("Motion");
        ExperimentSystem.AddExperimentLogger(motionLogger);

        //
        // Check and add experiment sensors
        //
        //
        // Add VIVE Trackers.
        //
        if (!debug)
        {
            GameObject         motionTrackerGO = AvatarSystem.AddMotionTracker();
            VIVETrackerManager upperArmTracker = new VIVETrackerManager(motionTrackerGO.transform);
            ExperimentSystem.AddSensor(upperArmTracker);
            // Shoulder acromium head tracker
            GameObject         motionTrackerGO1 = AvatarSystem.AddMotionTracker();
            VIVETrackerManager shoulderTracker  = new VIVETrackerManager(motionTrackerGO1.transform);
            ExperimentSystem.AddSensor(shoulderTracker);

            // Set arm guide position tracking
            guideManager.shoulderLocationTransform = motionTrackerGO1.transform;
        }
    }
Example #13
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;
        }
    }