//------------------------------------------------------------------------------------------------------------------- // Constructor /// <summary> Extract right-handed coordinate system data from the SenseGlove DLL and convert it into Unity values. </summary> /// <param name="data"></param> /// <param name="packets"></param> /// <param name="totalCSteps"></param> /// <param name="currCStep"></param> public SenseGlove_Data(SenseGloveCs.GloveData data, int packets, int totalCSteps, int currCStep) { if (data != null) { this.dataLoaded = data.dataLoaded; this.isRight = data.isRight; this.deviceID = data.deviceID; this.firmwareVersion = data.firmwareVersion; this.gloveVersion = data.gloveVersion; this.gloveValues = data.gloveValues; this.imuValues = data.imuValues; this.packetsPerSecond = packets; this.numberOfSensors = data.numberOfSensors; this.calibrationStep = currCStep; this.totalCalibrationSteps = totalCSteps; this.absoluteCalibratedWrist = SenseGlove_Util.ToUnityQuaternion(data.wrist.QcalibratedAbs); this.absoluteWrist = SenseGlove_Util.ToUnityQuaternion(data.wrist.QwristAbs); this.relativeWrist = SenseGlove_Util.ToUnityQuaternion(data.wrist.Qrelative); this.commonOriginPos = SenseGlove_Util.ToUnityPosition(data.handModel.gloveRelPos); this.commonOriginRot = SenseGlove_Util.ToUnityQuaternion(data.handModel.gloveRelOrient); this.gloveAngles = SenseGlove_Data.ToEuler(data.handModel.gloveAngles); this.gloveLengths = SenseGlove_Data.ToVector3(data.handModel.gloveLengths); this.gloveRotations = SenseGlove_Data.ToQuaternion(data.handModel.gloveRotations); this.glovePositions = SenseGlove_Data.ToVector3(data.handModel.glovePositions); this.handAngles = SenseGlove_Data.ToEuler(data.handModel.handAngles); this.handLengths = SenseGlove_Data.ToVector3(data.handModel.handLengths); this.handRotations = SenseGlove_Data.ToQuaternion(data.handModel.handRotations); this.handPositions = SenseGlove_Data.ToVector3(data.handModel.handPositions); } }
/// <summary> Apply hand parameters to the Sense Glove internal model. </summary> /// <param name="jointPositions"></param> /// <param name="handLengths"></param> public void SetHandParameters(Vector3[] jointPositions, Vector3[][] handLengths) { if (this.linkedGlove != null && this.linkedGlove.IsReady() && jointPositions.Length > 4 && handLengths.Length > 4) { this.StartJointPositions = jointPositions; for (int f = 0; f < handLengths.Length; f++) { if (handLengths[f].Length > 2) { //Set Hand Lengths for (int i = 0; i < handLengths[f].Length; i++) { this.linkedGlove.gloveData.kinematics.fingers[f].lengths[i] = SenseGlove_Util.ToPosition(handLengths[f][i]); } } } Debug.Log(this.name + " Applied hand Lengths to Sense Glove Internal Model"); } }
// Update is called once per frame void Update() { if (Tracker != null) { Vector3 pos = Tracker.transform.position; if (Input.GetKey(KeyCode.W)) { pos = new Vector3(pos.x + (spd * Time.deltaTime), pos.y, pos.z); } else if (Input.GetKey(KeyCode.S)) { pos = new Vector3(pos.x - (spd * Time.deltaTime), pos.y, pos.z); } if (Input.GetKey(KeyCode.A)) { pos = new Vector3(pos.x, pos.y, pos.z + (spd * Time.deltaTime)); } else if (Input.GetKey(KeyCode.D)) { pos = new Vector3(pos.x, pos.y, pos.z - (spd * Time.deltaTime)); } if (Input.GetKey(KeyCode.Q)) { pos = new Vector3(pos.x, pos.y + (spd * Time.deltaTime), pos.z); } else if (Input.GetKey(KeyCode.E)) { pos = new Vector3(pos.x, pos.y - (spd * Time.deltaTime), pos.z); } if (Input.GetKey(KeyCode.A)) { pos = new Vector3(pos.x, pos.y, pos.z + (spd * Time.deltaTime)); } else if (Input.GetKey(KeyCode.D)) { pos = new Vector3(pos.x, pos.y, pos.z - (spd * Time.deltaTime)); } Tracker.transform.position = pos; } if (wireframe != null) { if (UnityEngine.Input.GetKeyDown(KeyCode.G)) { gloveActive = !gloveActive; wireframe.SetGlove(gloveActive); } if (Input.GetKeyDown(KeyCode.H)) { handActive = !handActive; wireframe.SetHand(handActive); } //if (Input.GetKeyDown(KeyCode.Space)) //{ // //SenseGlove_Debugger.Log("Calibrate Glove."); // wireframe.CalibrateWrist(); //} } if (debugText != null && glove.GloveData() != null) { //debugText.text = ""; //debugText.text = "Samples / Second = " + glove.GetSenseGlove().communicator.samplesPerSecond; debugText.text = "Angles: " + SenseGlove_Util.ToString(glove.GloveData().handAngles[1][0]); //debugText.text = SenseGlove_Util.ToString(SenseGloveCs.Values.Degrees(glove.GetGloveData().handModel.handAngles[1][2])); //debugText.text = SenseGlove_Util.ToString(glove.GetData().absoluteRelativeWrist.eulerAngles); //Vector3 X = new Vector3(1, 0, 0); //Vector3 Y = new Vector3(0, 1, 0); //Vector3 Z = new Vector3(0, 0, 1); //float xAngle = Vector3.Angle(glove.GetData().relativeWrist * X, glove.foreArm.transform.rotation * X); //float yAngle = Vector3.Angle(glove.GetData().relativeWrist * Y, glove.foreArm.transform.rotation * Y); //float zAngle = Vector3.Angle(glove.GetData().relativeWrist * Z, glove.foreArm.transform.rotation * Z); // debugText.text = "X:" + xAngle.ToString() + ". Y:" + yAngle.ToString() + ". Z:" + zAngle.ToString(); //float[] DLLwristEuler = SenseGloveCs.Values.Degrees(SenseGloveCs.Quaternions.ToEuler(glove.GetGloveData().wrist.Qrelative )); //float[] DLLforeArmEuler = SenseGloveCs.Values.Degrees(SenseGloveCs.Quaternions.ToEuler(glove.GetGloveData().wrist.QforeArm )); //debugText.text = SenseGlove_Util.ToString(DLLwristEuler) + "\r\n" + SenseGlove_Util.ToString(DLLforeArmEuler); } if (debugText != null && grabScript != null) { //debugText.text = SenseGlove_Util.ToString(grabScript.GetVelocity()); } if (this.glove != null && this.glove.GloveReady()) { if (Input.GetKeyDown(KeyCode.V)) { float[][] handLengths = new float[5][] { new float[3] { 43, 33, 33 }, //thumb new float[3] { 40, 22, 22 }, //index new float[3] { 45, 28, 22 }, //middle new float[3] { 47, 24, 23 }, //ring new float[3] { 33, 18, 21 }, //pinky }; this.glove.CalculateJointPositions(handLengths); } if (Input.GetKeyDown(KeyCode.Backspace)) { // this.glove.TestCalibration(); } } }
/// <summary> Get the lastest (converted and unconverted) glove data from the SenseGlove. </summary> private void UpdateGloveData() { if (this.glove != null && !this.standBy && this.gloveReady) { //Update to the latest GloveData. Quaternion lowerArm = this.foreArm != null ? this.foreArm.transform.rotation : Quaternion.identity; this.gloveData = this.glove.Update(this.updateTo, this.solver, this.limitFingers, this.updateWrist, SenseGlove_Util.ToQuaternion(lowerArm), this.limitWrist, this.checkGestures); this.convertedGloveData = new SenseGlove_Data(this.gloveData, this.glove.communicator.samplesPerSecond, this.glove.TotalCalibrationSteps(), this.glove.CurrentCalibrationStep()); } }
// Update is called once per frame void Update() { if (!standBy) { if (this.elapsedTime < SenseGlove_Object.setupTime) { this.elapsedTime += Time.deltaTime; } else if (this.glove == null) //No connection yet... { if (this.connectionMethod == ConnectionMethod.HardCoded) { //no glove was ever assigned... this.RetryConnection(); //keep trying! } else { SenseGlove myGlove = ExtractSenseGlove(SenseGloveCs.DeviceScanner.GetDevices()); if (myGlove != null) //The glove matches our parameters! { this.glove = myGlove; SenseGlove_Manager.SetUsed(this.glove.GetData(false).deviceID, true); this.glove.OnFingerCalibrationFinished += Glove_OnFingerCalibrationFinished; } else { if (this.canReport) { string message = this.gameObject.name + " looking for SenseGlove..."; if (this.connectionMethod == ConnectionMethod.FindNextLeftHand) { message = this.gameObject.name + " looking for left-handed SenseGlove..."; } else if (this.connectionMethod == ConnectionMethod.FindNextRightHand) { message = this.gameObject.name + " looking for right-handed SenseGlove..."; } SenseGlove_Debugger.Log(message); this.canReport = false; } this.elapsedTime = 0; } } } else if (this.connectionMethod == ConnectionMethod.HardCoded && !this.glove.IsConnected()) { //lost connection :( this.canReport = true; this.RetryConnection(); //keep trying! } else if (!gloveReady) { if (this.glove.GetData(false).dataLoaded) { bool runSetup = this.gloveData == null; //used to raise event only once! float[][] oldFingerLengths = null; float[][] oldStartPositions = null; if (this.gloveData != null) { oldFingerLengths = this.GetFingerLengths(); oldStartPositions = SenseGlove_Util.ToPosition(this.GetStartJointPositions()); } this.gloveData = this.glove.GetData(false); //get the latest data without calculating anything. this.rightHand = this.gloveData.isRight; //so that users can use this variable during setup. if (oldFingerLengths != null) { this.SetFingerLengths(oldFingerLengths); } //re-apply old fingerlengths, if possible. if (oldStartPositions != null) { this.SetStartJointPositions(oldStartPositions); } //re=apply joint positions, if possible. this.convertedGloveData = new SenseGlove_Data(this.gloveData, this.glove.communicator.samplesPerSecond, this.glove.TotalCalibrationSteps(), this.glove.TotalCalibrationSteps()); this.SetupWrist(); this.calibratedWrist = false; this.gloveReady = true; if (runSetup) { this.originalLengths = this.gloveData.handModel.GetFingerLengths(); this.originalJoints = this.gloveData.handModel.GetJointPositions(); SenseGlove_Debugger.Log("Sense Glove " + this.convertedGloveData.deviceID + " is ready!"); this.GloveLoaded(); //raise the event! } } } else //glove != null && gloveReady! { this.CheckCalibration(); //Update to the latest GloveData. this.UpdateGloveData(); //Calibrate once more after reconnecting to the glove. if (!calibratedWrist) { this.CalibrateWrist(); this.calibratedWrist = true; } //Update the public values automatically. if (connectionMethod != ConnectionMethod.HardCoded) { this.address = glove.communicator.Address(); } this.rightHand = glove.IsRight(); } } }
public static int ListIndex(MonoBehaviour obj, List <MonoBehaviour> objects) //List<> needs standardization { return(SenseGlove_Util.ListIndex(obj.gameObject, objects)); }
/// <summary> Get the lastest (converted and unconverted) glove data from the SenseGlove. </summary> private void UpdateGloveData() { if (this.glove != null && !this.standBy && this.gloveReady) { //Update to the latest GloveData. Quaternion lowerArm = this.foreArm != null ? this.foreArm.transform.rotation : Quaternion.identity; this.gloveData = this.glove.Update(this.updateTo, this.solver, this.limitFingers, this.updateWrist, SenseGlove_Util.ToQuaternion(lowerArm), this.limitWrist, this.checkGestures); this.convertedGloveData = new SenseGlove_Data(this.gloveData); } }