public ExerciseConfiguration(LimbConfiguration limbConfig, HandleResults resultsHandler = null, LimbConfiguration ghostLimbConfiguration = null) { limbConfiguration = limbConfig; OnExecutionStepEvaluated += resultsHandler; isRealTimeSampling = ghostLimbConfiguration != null; this.ghostLimbConfiguration = ghostLimbConfiguration; }
void Update() { if (Input.GetKeyDown(keyIdeal)) { // settings // define tollerance (in this case is used the same tollerance for all variables and articulations float tolleranceRadius = 0.2f; ArticolationTollerance tollerance = new ArticolationTollerance(); tollerance.positionSpeedTolleranceRadius = tolleranceRadius; tollerance.positionTolleranceRadius = tolleranceRadius; tollerance.rotationSpeedTolleranceRadius = tolleranceRadius; tollerance.rotationTolleranceRadius = tolleranceRadius; // Configure limb, one per exercise per limb (if you want an exercise that involves to limbs, use two limbs configurations) // example made for the arm // instance sensors Sensor shoulderSensor = new Sensor(shoulder, tollerance, "spalla"); Sensor elbowSensor = new Sensor(elbow, tollerance, "gomito"); Sensor handSensor = new Sensor(hand, tollerance, "mano"); // with the sensors instances create a limb configuration LimbConfiguration config = new LimbConfiguration(shoulderSensor, elbowSensor, handSensor); // configure exercise ExerciseConfiguration exerciseConfiguration = new ExerciseConfiguration( config, (EvaluationResults results) => { AIProxy aiProxy = new AIProxy(); // should be taken from context //ArticolationError elbowError = aiProxy.UnwrapFromResults("gomito", results); } ); // to add more events handler: exerciseConfiguration.OnExecutionStepEvaluated += (EvaluationResults results) => { }; // exercise configuration should be taken from somewhere // configure the virtual physioteraphyst VirtualPhysioterphyst eval = VirtualPhysioterphyst.Instance; // define a timing for the sampling float timing = 0.5f, totalDuration = 2f; eval.timingBetweenSamples = timing; // setup the exercise with the built configuration eval.ExerciseSetup(exerciseConfiguration); // start recording eval.StartSetup(); // Start playing a new exercise (guided by the real physioteraphyst) Sequence sequence = DOTween.Sequence(); sequence.Append(hand.transform.DOMove(hand.transform.position * 2, totalDuration)); // once finished the exercise, stop setup sequence.OnComplete(() => { eval.EndSetup(); // stop registering // ... evaluating if the movement has to be saved or discarded eval.SaveSetup(); // save registration // eval.DiscardSetup(); // discard registration }); } if (Input.GetKeyDown(keyReal)) { // turn back to initial position hand.transform.position = initialPositionHand; elbow.transform.position = initialPositionElbow; shoulder.transform.position = initialPositionShoulder; // start evaluation of the exercise VirtualPhysioterphyst.Instance.StartEvaluation(); // play the exercise Sequence sequence = DOTween.Sequence(); sequence.Append(hand.transform.DOMove(hand.transform.position * 2, timing / 2)); // on finish stop evaluating sequence.OnComplete(() => VirtualPhysioterphyst.Instance.StopEvaluation()); } }
private void CreateAI() { Sensor shoulderSensor = new Sensor(shoulder, shoulderTollerance, "spalla"); Sensor elbowSensor = new Sensor(elbow, elbowTollerance, "gomito"); Sensor handSensor = new Sensor(hand, handTollerance, "mano"); LimbConfiguration config = new LimbConfiguration(shoulderSensor, elbowSensor, handSensor); // check that there is the ghost if (sampleRecorder.trackersPreview.Count != 3) { throw new System.Exception("Ghost non correttamente configurato"); } LimbConfiguration ghostConfig = new LimbConfiguration(new Sensor(sampleRecorder.trackersPreview[0]), new Sensor(sampleRecorder.trackersPreview[1]), new Sensor(sampleRecorder.trackersPreview[2])); exerciseConfiguration = new ExerciseConfiguration( config, (EvaluationResults results) => { AIProxy aiProxy = new AIProxy(); // should be taken from context List <string> articolationNames = new List <string>() { "spalla", "gomito", "mano" }; foreach (string articolationName in articolationNames) { ArticolationError error = aiProxy.UnwrapFromResults(articolationName, results, articolationNames); bool isPositionCorrect = error.Position.IsSpeedCorrect && error.Position.IsMagnitudeCorrect, isRotationCorrect = error.Angle.IsSpeedCorrect && error.Angle.IsMagnitudeCorrect; Debug.Log(articolationName + ": POSITION IS CORRECT - " + isPositionCorrect.ToString() + " # ROTATION IS CORRECT - " + isRotationCorrect.ToString()); GameObject trackerOb; string nameID = ""; switch (articolationName) { case "spalla": nameID = "Shoulder"; trackerOb = shoulder; break; case "gomito": nameID = "Elbow"; trackerOb = elbow; break; case "mano": nameID = "Wrist"; trackerOb = hand; break; default: trackerOb = hand; break; } //Genera evento con risultati AI -> contesto SendResult(nameID, isPositionCorrect); if (isPositionCorrect) { trackerOb.GetComponent <MeshRenderer>().material.color = Color.green; } else { trackerOb.GetComponent <MeshRenderer>().material.color = Color.red; } } }, ghostConfig ); VirtualPhysioterphyst.Instance.ExerciseSetup(exerciseConfiguration); }