// ===================== Update is called once per frame ===================== void Update() { float move = Input.GetAxis("Vertical"); anim.SetFloat(makeTransition, move); // Set model colour //ModelColour setColour = new ModelColour(); //setColour.setModelColour(trans_snow); // Start of timer secondsNow = secondsNow + Time.deltaTime; switch (routineStage) { // Case 0 case (0): { instruction1 = "Welcome to Piego"; if (secondsNow >= 1) //4 { routineStage = routineStage + 1; } break; } // Case 1 case (1): { instruction1 = "I'm your Instructor, Milo"; // Tilt head towards the camera if (head_rot.y < 80) { head_rot = new Vector3(0, head_rot.y + 2, 0); } if (secondsNow >= 1.5) //6 { routineStage = routineStage + 1; } break; } // Case 2 case (2): { instruction1 = "Let's begin your neuro assessment!"; if (secondsNow >= 2) //( { routineStage = routineStage + 1; } break; } // Case 3 - Extend arm case (3): { instruction1 = "First, let your arms drop to the sides"; // Update Linear Progress Bar if (ProgressBarLinear.current < 2) { ProgressBarLinear.current = ProgressBarLinear.current + 0.02f; } // Tilt head down to the hand if (head_rot.x > -20) { head_rot = new Vector3(head_rot.x - 5f, head_rot.y - 2, 0); } // Arm to the sides // Define transition steps for next animation int steps_trans = 15; if (rightElbow_rot_routine.x > 0) { rightShoulder_rot = new Vector3(rightShoulder_rot.x - (15 / steps_trans), 0, 0); rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x - (15 / steps_trans), rightElbow_rot_routine.y - (40 / steps_trans), rightElbow_rot_routine.z - (45 / steps_trans)); } leftShoulder_rot = new Vector3(70, 0, 0); leftElbow_rot = new Vector3(15, 0, 0); //Next step if (secondsNow >= 3) //12 { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 5 - Supinate Wrist case (4): { instruction1 = "Rotate your palm to face forward and close your fist"; // Supinate if (rightElbow_rot_routine.y > -90) { rightElbow_rot_routine = new Vector3(0, rightElbow_rot_routine.y - 10, 0); } if ((secondsNow - secondsChange) >= 1.5f) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 5 - Close fist case (5): { //instruction1 = "Now, close your fist"; // Close fist for (int i = 1; i < 5; i++) { if (RProxFingers[i].x < 90) { RProxFingers[i] = new Vector3(RProxFingers[i].x + 5, 0, 0); RIntFingers[i] = new Vector3(RProxFingers[i].x + 5, 0, 0); RDistFingers[i] = new Vector3(RProxFingers[i].x + 5, 0, 0); } } //RProxFingers[0] = new Vector3(0, 0, 20); // Different values for thumb //RIntFingers[0] = new Vector3(0, 30, 0); //RDistFingers[0] = new Vector3(0, 50, 0); if ((secondsNow - secondsChange) >= 3) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 6 case (6): { instruction1 = "In the first 2 rounds, we will practice together"; // Turn observe icon ON ObserveTurnIcon.showIconImage = true; if ((secondsNow - secondsChange) >= 4) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 7 case (7): { instruction1 = "In the third round, you should perform the task as accurately as possible"; // Turn your-turn icon ON and observe icon OFF YourTurnIcon.showIconImage = true; ObserveTurnIcon.showIconImage = false; // Update Linear Progress Bar if (ProgressBarLinear.current < 3) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } if ((secondsNow - secondsChange) >= 7) { instruction1 = "The task is to bend your elbow to catch the pear"; ProgressBarRadial.showBar = true; RadialProgressMarker.showMarker = true; RadialRoutineMarker.showMarker = true; YourTurnIcon.showIconImage = false; if ((secondsNow - secondsChange) >= 10) { secondsChange = secondsNow; routineStage = routineStage + 1; } } break; } // Case 8 case (8): { instruction1 = "A countdown will tell you when to start"; YourTurnIcon.showCountImage = true; if ((secondsNow - secondsChange) >= 3) { instruction1 = "Now, practice with me by following my motion"; secondsChange = secondsNow; routineStage = routineStage + 1; // Remove all the EMG data recorded during the tutorial SaveRoutine_Plotless save = new SaveRoutine_Plotless(); save.resetEMGholders(); } break; } // Case 9 - Countdown case (9): { // Move instructor avatar rightElbow_rot_routine = new Vector3(0, -90, 0); // Return to original elbow position if ((secondsNow - secondsChange) >= 3) { ObserveTurnIcon.showCountImage = true; ObserveTurnIcon.countNumber = 3; if ((secondsNow - secondsChange) >= 4) { ObserveTurnIcon.countNumber = 2; if ((secondsNow - secondsChange) >= 5) { ObserveTurnIcon.countNumber = 1; if ((secondsNow - secondsChange) >= 6) { ObserveTurnIcon.showCountImage = false; ObserveTurnIcon.countNumber = 4; // Hide all countdown images secondsChange = secondsNow; routineStage = routineStage + 1; } } } } break; } // Case 10 - Practice Elbow Bend case (10): { if (rightElbow_rot_routine.x < elbowMotion) { rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x + elbowSpeed, rightElbow_rot_routine.y, 0); } // Move radial diagram clientElbow_error = rightElbow_rot_routine.x - (RadialProgressMarker.clientElbow_rot - 270); ProgressBarRadial.maximum = 360; // x2 as we only want for the circle to reach 0-180º, not 360º ProgressBarRadial.minimum = 0; ProgressBarRadial.current = (180 - rightElbow_rot_routine.x); RadialRoutineMarker.clientElbow_rot_routine = rightElbow_rot_routine.x - 90; // Set rotation of pair equal to fill amount // End case when elbow joint reaches target if (rightElbow_rot_routine.x >= elbowMotion) { if (practiceRoundsCounter == 0) { practiceRoundsCounter = 1; instruction1 = "Let's practice this again"; secondsChange = secondsNow; routineStage = 9; } else if (practiceRoundsCounter == 1) { practiceRoundsCounter = 0; secondsChange = secondsNow; routineStage = routineStage + 1; } } break; } // Case 11 - Test Run case (11): { instruction1 = "Now's let's do the test run. Get ready"; // Update Linear Progress Bar if (elbowSpeedCounter == 0) { if (ProgressBarLinear.current < 4) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } } else if (elbowSpeedCounter == 1) { if (ProgressBarLinear.current < 7) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } } else if (elbowSpeedCounter == 2) { if (ProgressBarLinear.current < 10) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } } // Prepare other assets rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x, 0, 0); // Return to original elbow position YourTurnIcon.showCountImage = true; ObserveTurnIcon.showIconImage = false; if ((secondsNow - secondsChange) >= 3) { YourTurnIcon.countNumber = 3; if ((secondsNow - secondsChange) >= 5) { YourTurnIcon.countNumber = 2; if ((secondsNow - secondsChange) >= 6) { YourTurnIcon.countNumber = 1; if ((secondsNow - secondsChange) >= 7) { YourTurnIcon.showCountImage = false; YourTurnIcon.countNumber = 4; secondsChange = secondsNow; routineStage = routineStage + 1; } } } } break; } // Wait case (12): { instruction1 = "Bend your elbow to catch the pear"; if ((secondsNow - secondsChange) > 1) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Test Run case (13): { if (rightElbow_rot_routine.x < elbowMotion) { // Move radial diagram clientElbow_error = rightElbow_rot_routine.x - (RadialProgressMarker.clientElbow_rot - 270); ProgressBarRadial.maximum = 360; // x2 as we only want for the circle to reach 0-180º, not 360º ProgressBarRadial.minimum = 0; ProgressBarRadial.current = 180 - rightElbow_rot_routine.x; RadialRoutineMarker.clientElbow_rot_routine = rightElbow_rot_routine.x - 90; // Set rotation of pair equal to fill amount // UnityEngine.Debug.Log("Elbow Error: " + clientElbow_error); rightElbow_rot_routine.x = rightElbow_rot_routine.x + elbowSpeed; } if (rightElbow_rot_routine.x >= elbowMotion) { secondsChange = secondsNow; // Define csv name for next step if (elbowSpeedCounter == 0) { SaveRoutine_Plotless.filename = "RawEMG_Task01.csv"; if (ProgressBarLinear.current < 5) // Update Pogress Bar { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } else { routineStage = routineStage + 1; // Next Step rightElbow_phantom = 0; // Back to original position } } else if (elbowSpeedCounter == 1) { SaveRoutine_Plotless.filename = "RawEMG_Task02.csv"; if (ProgressBarLinear.current < 8) // Update Pogress Bar { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } else { routineStage = routineStage + 1; // Next Step rightElbow_phantom = 0; // Back to original position } } else if (elbowSpeedCounter == 2) { SaveRoutine_Plotless.filename = "RawEMG_Task03.csv"; if (ProgressBarLinear.current < 11) // Update Pogress Bar { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } else { routineStage = routineStage + 1; // Next Step rightElbow_phantom = 0; // Back to original position } } } break; } // What next? case (14): { // Save to CSV if (elbowSpeedCounter == 0) { instruction1 = "Great job! Now wait while I save your progress. This can take a while."; if (SaveRoutine_Plotless.saveSwitch == 0) { SaveRoutine_Plotless.saveSwitch = 1; } // Saving Routine /* * SaveRoutine_Plotless save = new SaveRoutine_Plotless(); * save.emgCSVsave("RawEMG_Task01.csv"); // Call function to save both the raw and processed EMG CSVs * save.resetEMGholders(); // Empty all the list variables that hold/store the EMG data to be saved * saveSwitch = true; */ // If saving is complete, move to next step if (SaveRoutine_Plotless.saveSwitch == 3) { // Update Linear Progress Bar if (ProgressBarLinear.current < 6) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } // Move to next step else { elbowSpeed = 3.0f; elbowSpeedCounter = 1; secondsChange = secondsNow; instruction1 = "Done! Let's practice moving your elbow faster"; SaveRoutine_Plotless.saveSwitch = 0; routineStage = 9; } } } else if (elbowSpeedCounter == 1) { instruction1 = "Fantastic! Now wait while I save your progress. This can take a while."; if (SaveRoutine_Plotless.saveSwitch == 9) { SaveRoutine_Plotless.saveSwitch = 1; } // If saving is complete, move to next step if (SaveRoutine_Plotless.saveSwitch == 3) { // Update Linear Progress Bar if (ProgressBarLinear.current < 9) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } // Move to next step else { elbowSpeed = 5.0f; elbowSpeedCounter = 2; secondsChange = secondsNow; instruction1 = "Done! Let's practice moving your elbow even faster"; SaveRoutine_Plotless.saveSwitch = 0; routineStage = 9; } } } else if (elbowSpeedCounter == 2) { instruction1 = "Awesome! Wait while I'm saving your patient data... This can take a while."; if (SaveRoutine_Plotless.saveSwitch == 0) { SaveRoutine_Plotless.saveSwitch = 1; } // If saving is complete, move to next step if (SaveRoutine_Plotless.saveSwitch == 3) { // Update Linear Progress Bar if (ProgressBarLinear.current < 12) { ProgressBarLinear.current = ProgressBarLinear.current + 0.01f; } // Move to next step else { secondsChange = secondsNow; SaveRoutine_Plotless.saveSwitch = 0; routineStage = routineStage + 1; } } } break; } // Save the processed EMG data in a CSV file at the end of the routine case (15): { instruction1 = "Assessment complete. Well Done!"; break; } } }
// ===================== Update is called once per frame ===================== void Update() { float move = Input.GetAxis("Vertical"); anim.SetFloat(makeTransition, move); // Set model colour //ModelColour setColour = new ModelColour(); //setColour.setModelColour(trans_snow); // Start of timer secondsNow = secondsNow + Time.deltaTime; switch (routineStage) { // Case 0 case (0): { instruction1 = "Welcome to Piego"; if (secondsNow >= 5) { routineStage = routineStage + 1; } break; } // Case 1 case (1): { instruction1 = "I'm your Instructor, Milo"; // Tilt head towards the camera if (head_rot.x > -40) { head_rot = new Vector3(head_rot.x - 5f, 0, 0); } if (secondsNow >= 8) { routineStage = routineStage + 1; } break; } // Case 2 case (2): { instruction1 = "Let's begin your neuro assessment!"; if (secondsNow >= 12) { routineStage = routineStage + 1; } break; } // Case 3 - Extend arm case (3): { instruction1 = "First, extend your right arm parallel to the floor"; if (head_rot.y < 10) { head_rot = new Vector3(head_rot.x, head_rot.y + 2, 0); // Look down slightly to hand } //setColour.setModelColour(trans_fuchsia); if (rightShoulder_rot.y < 90) { rightShoulder_rot = new Vector3(0, rightShoulder_rot.y + 5, 0); } if (secondsNow >= 16) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } case (4): { instruction1 = "Now, close your fist"; // Close fist for (int i = 1; i < 5; i++) { if (RProxFingers[i].y > -90) { RProxFingers[i] = new Vector3(0, RProxFingers[i].y - 10, 0); RIntFingers[i] = new Vector3(0, RIntFingers[i].y - 10, 0); RDistFingers[i] = new Vector3(0, RDistFingers[i].y - 10, 0); } } RProxFingers[0] = new Vector3(0, 0, -20); // Different values for thumb RIntFingers[0] = new Vector3(0, -30, 0); RDistFingers[0] = new Vector3(0, -50, 0); if ((secondsNow - secondsChange) >= 3) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 5 - Supinate Wrist case (5): { instruction1 = "Supinate your wrist"; if (rightShoulder_rot.x < 65) { rightShoulder_rot = new Vector3(rightShoulder_rot.x + 5, rightShoulder_rot.y, rightShoulder_rot.z); } if (rightElbow_rot_routine.x < 100) { rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x + 10, 0, 0); } if ((secondsNow - secondsChange) >= 3) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 6 case (6): { instruction1 = "In the first 2 rounds, we will practice together"; // Turn observe icon ON ObserveTurnIcon.showIconImage = true; if ((secondsNow - secondsChange) >= 4) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 7 case (7): { instruction1 = "In the third round, you should perform the task as accurately as possible"; // Turn your-turn icon ON and observe icon OFF YourTurnIcon.showIconImage = true; ObserveTurnIcon.showIconImage = false; if ((secondsNow - secondsChange) >= 7) { instruction1 = "The task is to bend your elbow to catch the pear"; ProgressBarRadial.showBar = true; RadialProgressMarker.showMarker = true; RadialRoutineMarker.showMarker = true; YourTurnIcon.showIconImage = false; if ((secondsNow - secondsChange) >= 10) { secondsChange = secondsNow; routineStage = routineStage + 1; } } break; } // Case 8 case (8): { instruction1 = "A countdown will tell you when to start"; ObserveTurnIcon.showCountImage = true; if ((secondsNow - secondsChange) >= 3) { instruction1 = "Practice with me by following my motion"; secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 9 - Countdown case (9): { // Move instructor avatar rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x, 0, 0); // Return to original elbow position if ((secondsNow - secondsChange) >= 3) { ObserveTurnIcon.showCountImage = true; if ((secondsNow - secondsChange) >= 4) { ObserveTurnIcon.countNumber = 3; if ((secondsNow - secondsChange) >= 5) { ObserveTurnIcon.countNumber = 2; if ((secondsNow - secondsChange) >= 6) { ObserveTurnIcon.countNumber = 1; if ((secondsNow - secondsChange) >= 7) { ObserveTurnIcon.showCountImage = false; ObserveTurnIcon.countNumber = 4; // Hide all countdown images secondsChange = secondsNow; routineStage = routineStage + 1; } } } } } break; } // Case 10 - Practice Elbow Bend case (10): { if (rightElbow_rot_routine.y < elbowMotion) { rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x, rightElbow_rot_routine.y + elbowSpeed, 0); } // Move radial diagram clientElbow_error = rightElbow_rot_routine.y - (RadialProgressMarker.clientElbow_rot - 270); ProgressBarRadial.maximum = 360; // x2 as we only want for the circle to reach 0-180º, not 360º ProgressBarRadial.minimum = 0; ProgressBarRadial.current = 180 - rightElbow_rot_routine.y; RadialRoutineMarker.clientElbow_rot_routine = rightElbow_rot_routine.y - 90; // Set rotation of pair equal to fill amount // End case when elbow joint reaches target if (rightElbow_rot_routine.y >= elbowMotion) { if (practiceRoundsCounter == 0) { practiceRoundsCounter = 1; instruction1 = "Let's practice this again"; secondsChange = secondsNow; routineStage = 9; } else if (practiceRoundsCounter == 1) { practiceRoundsCounter = 0; secondsChange = secondsNow; routineStage = routineStage + 1; } } break; } // Case 11 - Test Run case (11): { instruction1 = "Now's let's do the test run. Get ready"; rightElbow_rot_routine = new Vector3(rightElbow_rot_routine.x, 0, 0); // Return to original elbow position YourTurnIcon.showCountImage = true; ObserveTurnIcon.showIconImage = false; if ((secondsNow - secondsChange) >= 3) { YourTurnIcon.countNumber = 3; if ((secondsNow - secondsChange) >= 5) { YourTurnIcon.countNumber = 2; if ((secondsNow - secondsChange) >= 6) { YourTurnIcon.countNumber = 1; if ((secondsNow - secondsChange) >= 7) { YourTurnIcon.showCountImage = false; YourTurnIcon.countNumber = 4; secondsChange = secondsNow; routineStage = routineStage + 1; } } } } break; } // Case 10 - Wait case (12): { instruction1 = "Bend your elbow to catch the pear"; if ((secondsNow - secondsChange) > 0) { secondsChange = secondsNow; routineStage = routineStage + 1; } break; } // Case 11 - Your turn case (13): { // Move radial diagram clientElbow_error = rightElbow_phantom - (RadialProgressMarker.clientElbow_rot - 270); ProgressBarRadial.maximum = 360; // x2 as we only want for the circle to reach 0-180º, not 360º ProgressBarRadial.minimum = 0; ProgressBarRadial.current = 180 - rightElbow_phantom; RadialRoutineMarker.clientElbow_rot_routine = rightElbow_phantom - 90; // Set rotation of pair equal to fill amount // UnityEngine.Debug.Log("Elbow Error: " + clientElbow_error); if (rightElbow_phantom < elbowMotion) { rightElbow_phantom = rightElbow_phantom + elbowSpeed; } if (rightElbow_phantom >= elbowMotion) { rightElbow_phantom = 0; secondsChange = secondsNow; if (elbowSpeedCounter == 0) { elbowSpeed = 3.0f; elbowSpeedCounter = 1; instruction1 = "Great job! Now let's practice moving your elbow faster"; routineStage = 9; } else if (elbowSpeedCounter == 1) { elbowSpeed = 5.0f; elbowSpeedCounter = 2; instruction1 = "Fantastic! Let's practice moving your elbow even faster"; routineStage = 9; } else if (elbowSpeedCounter == 2) { routineStage = routineStage + 1; } } break; } case (14): { instruction1 = "Saving patient data, please wait..."; if ((secondsNow - secondsChange) > 4) { routineStage = routineStage + 1; } break; } case (15): { SaveRoutine_Plotless save = new SaveRoutine_Plotless(); save.emgCSVsave("EMG_data.csv"); // Call function to save the raw and processed EMG CSVs routineStage = routineStage; break; } // Save the processed EMG data in a CSV file at the end of the routine case (16): { instruction1 = "Assessment complete. Well Done!"; break; } } }