public void AddVIVETracker() { if ((int)selectedDevice > 4) { // Instantiate a new VIVETracker with Player as parent. GameObject playerGO = GameObject.FindGameObjectWithTag("Player"); if (playerGO == null) { throw new Exception("The player GameObject was not found."); } // Load VIVE Tracker prefab. GameObject viveTrackerPrefab = Resources.Load <GameObject>("Trackers/VIVETracker"); if (viveTrackerPrefab == null) { throw new Exception("The requested tracker prefab was not found."); } // Instantiate and with the other SteamVRObjects and set device number GameObject viveTrackerGO = Instantiate(viveTrackerPrefab, viveTrackerPrefab.transform.position, viveTrackerPrefab.transform.rotation, playerGO.transform.GetChild(0).transform); viveTrackerGO.GetComponentInChildren <SteamVR_TrackedObject>().SetDeviceIndex((int)selectedDevice); // Create tracker sensor and add to logger VIVETrackerManager viveTrackerSensor = new VIVETrackerManager(viveTrackerGO.transform); ExperimentSystem.AddSensor(viveTrackerSensor); addExperimentSensorMenu.ReturnToSettingsMenu(); } else { StartCoroutine(DisplayInformationOnLog(3.0f, "Select a valid VIVE Tracker device.")); } }
/// <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 data format taskDataFormat = ablebodiedDataFormat; // Lefty sign /* * if (SaveSystem.ActiveUser.lefty) * leftySign = -1.0f; */ // Audio audio = GetComponent <AudioSource>(); audio.clip = testAudioClip; #region Modify base // 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 // Send the player to the experiment centre position TeleportToStartPosition(); #endregion #region Initialize EMG sensors //Initialse Delsys EMG sensor delsysEMG.Init(); delsysEMG.Connect(); delsysEMG.StartAcquisition(); #endregion #region Initialize world positioning // Set the subject physiological data for grid gridManager.ConfigUserData(); gridManager.ConfigGridPositionFactors(gridCloseDistanceFactor, gridMidDistanceFactor, gridFarDistanceFactor, gridHeightFactor); #endregion #region Initialize motion sensors // // Add arm motion trackers for able-bodied case. // // 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); 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); #endregion }
/// <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 data format taskDataFormat = ablebodiedDataFormat; // Lefty sign /* * if (SaveSystem.ActiveUser.lefty) * leftySign = -1.0f; */ // Audio audio = GetComponent <AudioSource>(); audio.clip = testAudioClip; #region Modify base // 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 // // Create the performance data loggers // performanceDataLogger = new DataStreamLogger("PerformanceData"); ExperimentSystem.AddExperimentLogger(performanceDataLogger); performanceDataLogger.AddNewLogFile(AvatarSystem.AvatarType.ToString(), sessionNumber, performanceDataFormat); // Add file // Send the player to the experiment centre position TeleportToStartPosition(); #endregion #region Initialize EMG sensors //Initialise Delsys EMG sensor delsysEMG.Init(); delsysEMG.Connect(); #endregion #region Initialize motion sensors // // Add arm motion trackers for able-bodied case. // // 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); 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); #endregion // // Target ADL poses // poseListManager.AddPose("Rest", restAudioClip); poseListManager.AddPose("Reach Mug", reachMugAudioClip); poseListManager.AddPose("Mug to Mouth", mug2MouthAudioClip); poseListManager.AddPose("Drink with Mug", drinkAudioClip); poseListManager.AddPose("Reach Key", reachKeyAudioClip); poseListManager.AddPose("Turn Key", turnKeyAudioClip); // Start EMG readings delsysEMG.StartAcquisition(); }
/// <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 configuration // experimentType = ExperimentType.TypeOne; // Able-bodied experiment type if (debug) { ExperimentSystem.SetActiveExperimentID("GridReaching2019"); } // // Iterations configuration // // Make sure flow control is initialised sessionNumber = 1; iterationNumber = 1; // Set iterations variables for flow control. targetNumber = gridRows * gridColumns; iterationsPerSession[sessionNumber] = targetNumber * iterationsPerTarget; maxIterations = iterationsPerSession[sessionNumber] * sessions; // 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(0.0f, gridHeightMultiplier * subjectHeight, gridReachMultiplier * subjectArmLength); // // Create data loggers // motionLogger = new DataStreamLogger("Motion"); ExperimentSystem.AddExperimentLogger(motionLogger); // // Add arm and body motion trackers. // // 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); if (!debug) { // Shoulder acromium head tracker GameObject motionTrackerGO1 = AvatarSystem.AddMotionTracker(); VIVETrackerManager shoulderTracker = new VIVETrackerManager(motionTrackerGO1.transform); ExperimentSystem.AddSensor(shoulderTracker); // C7 tracker GameObject motionTrackerGO2 = AvatarSystem.AddMotionTracker(); VIVETrackerManager c7Tracker = new VIVETrackerManager(motionTrackerGO2.transform); ExperimentSystem.AddSensor(c7Tracker); } // // Hand tracking sensor // GameObject handGO = GameObject.FindGameObjectWithTag("Hand"); VirtualPositionTracker handTracker = new VirtualPositionTracker(handGO.transform); ExperimentSystem.AddSensor(handTracker); }
/// <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; } }