/// <summary>
 /// Update the Wrist with the latest data from the trackedGlove.
 /// Includes conversion from Right- handed coordinate system to the Unity left handed coordinate system.
 /// </summary>
 /// <param name="data"></param>
 private void UpdateWrist(SenseGlove_Data data)
 {
     if (wrist != null && data != null && this.anchor != AnchorPoint.Wrist)
     {
         wrist.transform.rotation = data.absoluteCalibratedWrist;
     }
 }
    /// <summary> (Manually) Update the hand and glove model of the wireframe. </summary>
    /// <param name="data"></param>
    public override void UpdateHand(SenseGlove_Data data)
    {
        if (data.dataLoaded)
        {
            //Update the glove
            {
                Quaternion[][] gloveAngles    = data.gloveRotations;
                Vector3[][]    glovePositions = data.glovePositions;
                for (int f = 0; f < this.gloveJoints.Length; f++)
                {
                    for (int j = 0; j < this.gloveJoints[f].Length; j++)
                    {
                        this.gloveJoints[f][j].localPosition = glovePositions[f][j];
                        this.gloveJoints[f][j].rotation      = this.wristTransfrom.rotation * (gloveAngles[f][j] /* * this.fingerCorrection[f][j]*/);
                    }
                }
            }

            //Update the Hand
            {
                Quaternion[][] handAngles    = data.handRotations;
                Vector3[][]    handPositions = data.handPositions;
                for (int f = 0; f < this.fingerJoints.Count; f++)
                {
                    for (int j = 0; j < this.fingerJoints[f].Count; j++)
                    {
                        this.fingerJoints[f][j].localPosition = handPositions[f][j];
                        this.fingerJoints[f][j].rotation      = this.wristTransfrom.rotation * (handAngles[f][j] * this.fingerCorrection[f][j]);
                    }
                }
            }
        }
    }
    /// <summary> Updates all variables that can change during the simulation.</summary>
    /// <param name="data"></param>
    public void UpdateVariables(SenseGloveCs.GloveData data)
    {
        this.dataLoaded     = data.dataLoaded;
        this.deviceID       = data.deviceID;
        this.gloveValues    = data.gloveValues;
        this.imuValues      = data.imuValues;
        this.imuCalibration = data.imuCalibration;

        this.numberOfSensors = data.numberOfSensors;

        this.packetsPerSecond = data.samplesPerSec;

        this.calibrationStep       = data.currentCalStep;
        this.totalCalibrationSteps = data.totalCalSteps;

        this.absoluteCalibratedWrist = SenseGlove_Util.ToUnityQuaternion(data.wrist.QcalibratedAbs);
        this.absoluteWrist           = SenseGlove_Util.ToUnityQuaternion(data.wrist.QwristAbs);
        this.relativeWrist           = SenseGlove_Util.ToUnityQuaternion(data.wrist.Qrelative);

        SenseGlove_Data.GetChainVariables(ref data.kinematics.gloveLinks, ref this.glovePositions,
                                          ref this.gloveAngles, ref this.gloveRotations, ref this.gloveLengths);

        SenseGlove_Data.GetChainVariables(ref data.kinematics.fingers, ref this.handPositions,
                                          ref this.handAngles, ref this.handRotations, ref this.handLengths);
    }
    //-------------------------------------------------------------------------------------------------------------------
    // 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)
    {
        if (data != null)
        {
            this.dataLoaded = data.dataLoaded;
            this.gloveSide  = SenseGlove_Data.GetSide(data.kinematics.isRight);

            this.deviceID        = data.deviceID;
            this.firmwareVersion = data.firmwareVersion;
            this.gloveVersion    = data.deviceVersion;

            this.gloveValues      = data.gloveValues;
            this.imuValues        = data.imuValues;
            this.imuCalibration   = data.imuCalibration;
            this.packetsPerSecond = data.samplesPerSec;
            this.numberOfSensors  = data.numberOfSensors;

            this.calibrationStep       = data.currentCalStep;
            this.totalCalibrationSteps = data.totalCalSteps;

            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.kinematics.gloveRelPos);
            this.commonOriginRot = SenseGlove_Util.ToUnityQuaternion(data.kinematics.gloveRelRot);

            SenseGlove_Data.GetChainVariables(ref data.kinematics.gloveLinks, ref this.glovePositions,
                                              ref this.gloveAngles, ref this.gloveRotations, ref this.gloveLengths);

            SenseGlove_Data.GetChainVariables(ref data.kinematics.fingers, ref this.handPositions,
                                              ref this.handAngles, ref this.handRotations, ref this.handLengths);
        }
    }
Exemple #5
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Connection Methods

    /// <summary> Link this Sense Glove to one of the SenseGlove_Manager's detected gloves. </summary>
    /// <param name="gloveIndex"></param>
    public bool LinkToGlove(int gloveIndex)
    {
        if (!this.IsLinked)
        {
            this.trackedGloveIndex  = gloveIndex;
            this.actualTrackedIndex = gloveIndex;
            this.linkedGlove        = SenseGlove_DeviceManager.GetSenseGlove(gloveIndex);

            this.linkedGlove.OnFingerCalibrationFinished += LinkedGlove_OnCalibrationFinished;
            //TODO: Subscribe to more events if needed

            //uodating once so glovedata is available, but not through the UpdateHand command, as that one needs the glove to already be connected.
            SenseGloveCs.GloveData rawData = this.linkedGlove.Update(UpdateLevel.HandPositions, this.solver, this.limitFingers, this.updateWrist, new Quat(0, 0, 0, 1), false);
            this.linkedGloveData = new SenseGlove_Data(rawData);

            this.OnGloveLink(); //Fire glove linked event.

            return(true);
        }
        else
        {
            Debug.LogWarning("Could not Link the Sense Glove because it has already been assigned. Unlink it first bu calling the UnlinkGlove() Method.");
        }
        return(false);
    }
Exemple #6
0
        /// <summary> Retrieve a a string containing the instructions to operate this demo. </summary>
        /// <returns></returns>
        private string GetInstructions()
        {
            if (this.senseGlove != null && this.senseGlove.GloveReady())
            {
                string res = this.prevObjKey.ToString() + " / " + this.nextObjKey.ToString() + " to cycle through objects" + "\r\n";

                if (this.senseGlove != null && this.senseGlove.IsCalibrating())
                {
                    SenseGlove_Data data = this.senseGlove.GloveData();
                    res += "Calibrating: Gathered " + data.calibrationStep + " / " + data.totalCalibrationSteps + " points.\r\n";
                    if (this.keyBinds != null)
                    {
                        res += this.keyBinds.cancelCalibrationKey.ToString() + " to cancel.";
                    }
                    return(res);
                }
                else if (this.keyBinds != null)
                {
                    res += this.keyBinds.calibrateHandKey + " to start calibration.\r\n";
                    return(res + this.keyBinds.calibrateWristKey.ToString() + " to calibrate wrist.");
                }
                return(res + "LeftShift / T(humb) to start calibration.");
            }
            return("Waiting to connect to a\r\nSense Glove");
        }
Exemple #7
0
 /// <summary>
 /// Set the positions of the starting finger joints, the CMC or MCP joints.
 /// </summary>
 /// <returns></returns>
 public void SetStartJointPositions(Vector3[] positions)
 {
     if (this.glove != null)
     {
         this.glove.SetJointPositions(SenseGlove_Util.ToPosition(positions));
         SenseGlove_Data newData = new SenseGlove_Data(this.glove.GetData(false));
         this.ReadyCalibration(new GloveCalibrationArgs(this.convertedGloveData, newData), false);
     }
 }
Exemple #8
0
 /// <summary>
 /// Set the positions of the starting finger joints, the CMC or MCP joints.
 /// </summary>
 /// <remarks>Used internally</remarks>
 /// <returns></returns>
 protected void SetStartJointPositions(SenseGloveCs.Kinematics.Vect3D[] positions)
 {
     if (this.glove != null && positions != null)
     {
         this.glove.SetJointPositions(positions);
         SenseGlove_Data newData = new SenseGlove_Data(this.glove.GetData(false));
         this.ReadyCalibration(new GloveCalibrationArgs(this.convertedGloveData, newData), false);
     }
 }
Exemple #9
0
 /// <summary>
 /// Set the finger lengths used by this sense glove as a 5x3 array,
 /// which contains the Proximal-, Medial-, and Distal Phalange lengths for each finger, in that order.
 /// </summary>
 /// <param name="newFingerLengths"></param>
 public void SetFingerLengths(float[][] newFingerLengths)
 {
     if (this.glove != null && newFingerLengths != null)
     {
         this.glove.SetHandLengths(newFingerLengths);
         SenseGlove_Data newData = new SenseGlove_Data(this.glove.GetData(false));
         this.ReadyCalibration(new GloveCalibrationArgs(this.convertedGloveData, newData), false);
     }
 }
Exemple #10
0
    //------------------------------------------------------------------------------------------------------------------------------------
    // Manual Calibration methods

    #region Calibration

    /// <summary> Reset all finger lengths to their original sizes and positions to their original positions. </summary>
    public void ResetHand()
    {
        this.SetFingerLengths(this.originalLengths);
        this.SetStartJointPositions(this.originalJoints);

        SenseGlove_Data newData = new SenseGlove_Data(this.glove.GetData(false));   //oldData is currently contained within this class' property.

        this.ReadyCalibration(new GloveCalibrationArgs(this.convertedGloveData, newData), false);
    }
Exemple #11
0
 /// <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);
     }
 }
Exemple #12
0
    /// <summary> Reset the internal handmodel back to the default finger lengths and -positions </summary>
    public void ResetKinematics()
    {
        if (this.linkedGlove != null)
        {
            this.linkedGlove.RestoreHand();
        }
        SenseGlove_Data newData = new SenseGlove_Data(this.linkedGlove.GetData(false));

        this.ReadyCalibration(new GloveCalibrationArgs(this.linkedGloveData, newData), false);
    }
Exemple #13
0
 /// <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 Methods

    #region Update

    /// <summary>
    /// Update the (absolute) finger orientations, which move realtive to the (absolute) wrist transform.
    /// Note: This method is called after UpdateWrist() is called.
    /// </summary>
    /// <param name="data"></param>
    public virtual void UpdateHand(SenseGlove_Data data)
    {
        if (data.dataLoaded)
        {
            Quaternion[][] angles = data.handRotations;
            for (int f = 0; f < this.fingerJoints.Count; f++)
            {
                for (int j = 0; j < this.fingerJoints[f].Count; j++)
                {
                    this.fingerJoints[f][j].rotation = this.wristTransfrom.rotation * (angles[f][j] * this.fingerCorrection[f][j]);
                }
            }
        }
    }
 /// <summary>
 /// Update the (absolute) wrist orientation, which moves realtive to the (absolute) lower arm transform.
 /// Note: This method is called before UpdateFingers() is called.
 /// </summary>
 /// <param name="data"></param>
 protected virtual void UpdateWrist(SenseGlove_Data data)
 {
     if (this.updateWrist && data.dataLoaded)
     {
         if (data.dataLoaded)
         {
             this.wristTransfrom.rotation = this.foreArmTransfrom.rotation * this.wristCorrection * data.relativeWrist;
         }
     }
     else
     {
         this.wristTransfrom.rotation = this.wristCorrection * this.foreArmTransfrom.rotation;
     }
 }
    /// <summary>
    /// Fill a number of arrays with data from a single kinematic chain.
    /// </summary>
    /// <param name="chains"></param>
    /// <param name="positions"></param>
    /// <param name="angles"></param>
    /// <param name="rotations"></param>
    /// <param name="lengths"></param>
    protected static void GetChainVariables(ref SenseGloveCs.Kinematics.JointChain[] chains, ref Vector3[][] positions, ref Vector3[][] angles, ref Quaternion[][] rotations, ref Vector3[][] lengths)
    {
        int N = chains.Length;

        angles    = new Vector3[N][];
        lengths   = new Vector3[N][];
        positions = new Vector3[N][];
        rotations = new Quaternion[N][];

        for (int f = 0; f < N; f++)
        {
            SenseGlove_Data.GetLinkVariables(ref chains[f], ref positions[f], ref angles[f], ref rotations[f], ref lengths[f]);
        }
    }
    /// <summary> Check whether or not the user is intending to pick up any of the Interactables. </summary>
    public bool[] CheckGestures()
    {
        bool[] res = new bool[5] {
            true, true, true, true, true
        };
        if (this.checkIntention != CheckIntention.Off)
        {
            if (this.senseGlove != null && this.senseGlove.GloveReady())
            {
                bool[] D = new bool[5] {
                    true, true, true, true, true
                };

                //collect the relative flexion angles of the fingers.
                SenseGlove_Data data           = this.senseGlove.GloveData();
                float[]         relDipFlexions = new float[5];
                for (int f = 0; f < 5; f++)
                {
                    relDipFlexions[f] = data.handAngles[f][2].z;
                }
                dipAngles = relDipFlexions;

                if (this.checkIntention >= CheckIntention.Static)
                {
                    //in Unity, the HandAngles are positive (extension) and negative (flexion), both in degrees.
                    //thumb
                    res[0] = relDipFlexions[0] >= -70 && relDipFlexions[0] <= -17.5f;
                    for (int f = 1; f < 4; f++)
                    {
                        res[f] = relDipFlexions[f] >= maxDIPFlexion && relDipFlexions[f] <= maxDIPExtension;
                    }
                    res[4] = relDipFlexions[4] >= maxDIPFlexion && relDipFlexions[4] <= maxDIPExtension - 5;
                }
                //also perform a dynamic analysis
                //if (this.checkIntention >= CheckIntention.Dynamic)
                //{

                //}
            }
            else
            {
                res = new bool[5] {
                    false, false, false, false, false
                };
            }
        }
        return(res);
    }
Exemple #18
0
    // Update is called once per frame
    void Update()
    {
        if (this.senseGlove != null && this.senseGlove.GloveReady)
        {
            if (Input.GetKeyDown(this.nextSolverKey))
            {
                this.currentSolver++;
                if (this.currentSolver >= this.possibleSolvers.Length)
                {
                    this.currentSolver = 0;
                }
                this.SetSolver(this.possibleSolvers[this.currentSolver]);
            }
            else if (Input.GetKeyDown(this.prevSolverKey))
            {
                this.currentSolver--;
                if (this.currentSolver < 0)
                {
                    this.currentSolver = this.possibleSolvers.Length - 1;
                }
                this.SetSolver(this.possibleSolvers[this.currentSolver]);
            }


            if (Input.GetKeyDown(this.startCalibrationKey))
            {
                if (this.CanCalibrate())
                {
                    this.senseGlove.StartCalibration(this.variableToCalibrate, CollectionMethod.SemiAutomatic);
                }
                else
                {
                    Debug.Log("Cannot start calibration with the " + this.senseGlove.solver.ToString() + " solver.");
                }
            }
            else if (Input.GetKeyDown(this.cancelCalibrationKey))
            {
                this.StepText = "";
                this.senseGlove.CancelCalibration();
            }

            if (this.senseGlove.IsCalibrating)
            {
                SenseGlove_Data data = this.senseGlove.GloveData;
                this.StepText = "" + data.calibrationStep + " out of " + data.totalCalibrationSteps + " points collected.";
            }
        }
    }
 /// <summary>
 /// Update the (absolute) wrist orientation, which moves realtive to the (absolute) lower arm transform.
 /// Note: This method is called before UpdateFingers() is called.
 /// </summary>
 /// <param name="data"></param>
 public virtual void UpdateWrist(SenseGlove_Data data)
 {
     if (this.updateWrist && data.dataLoaded)
     {
         if (data.dataLoaded)
         {
             this.wristTransfrom.rotation = /*this.foreArmTransfrom.rotation */ this.wristCorrection * (this.wristCalibration * data.absoluteWrist);
             this.wristAngles             = Quaternion.Inverse(this.foreArmTransfrom.rotation) * this.wristTransfrom.rotation;
         }
     }
     else
     {
         this.wristTransfrom.rotation = this.wristCorrection * this.foreArmTransfrom.rotation;
         this.wristAngles             = Quaternion.identity; //ignore wrist angle(s).
     }
 }
    //------------------------------------------------------------------------------------------------------------------------------------
    // Transform methods


    /// <summary> Update all glove positions based on the latest data taken from the trackedGlove, but only if the gloveGroup is active in the heirarchy. </summary>
    /// <param name="data"></param>
    private void UpdateGlove(SenseGlove_Data data)
    {
        if (glovePositions != null && gloveGroup.activeInHierarchy && data.dataLoaded)
        {
            Vector3[][]    pos = data.glovePositions;
            Quaternion[][] rot = data.gloveRotations;
            for (int f = 0; f < glovePositions.Length && f < data.glovePositions.Length; f++)
            {
                for (int i = 0; i < glovePositions[f].Length && i < pos[f].Length; i++)
                {
                    glovePositions[f][i].transform.localPosition = pos[f][i];
                    glovePositions[f][i].transform.localRotation = rot[f][i];
                }
            }
        }
    }
    /// <summary> Check whether or not the user is intending to pick up any of the Interactables. </summary>
    protected bool[] CheckGestures()
    {
        bool[] res = new bool[5] {
            true, true, true, true, true
        };
        if (this.checkIntention != CheckIntention.Off)
        {
            if (this.senseGlove != null && this.senseGlove.GloveReady)
            {
                //bool[] D = new bool[5] { true, true, true, true, true };

                Vector3[] sumAngles = this.senseGlove.GloveData.TotalGloveAngles();

                //collect the relative flexion angles of the fingers.
                SenseGlove_Data data = this.senseGlove.GloveData;
                this.dipAngles = new float[5];
                for (int f = 0; f < 5; f++)
                {
                    this.dipAngles[f] = sumAngles[f].z;
                }

                if (this.checkIntention >= CheckIntention.Static)
                {
                    //in Unity, the HandAngles are positive (extension) and negative (flexion), both in degrees.
                    //thumb
                    res[0] = dipAngles[0] >= -70 && dipAngles[0] <= -17.5f;
                    for (int f = 1; f < 4; f++)
                    {
                        res[f] = dipAngles[f] >= maxDIPFlexion && dipAngles[f] <= maxDIPExtension;
                    }
                    res[4] = dipAngles[4] >= (maxDIPFlexion + 10) && dipAngles[4] <= (maxDIPExtension - 15); //the pinky
                }
                //and/or perform a dynamic analysis
                //if (this.checkIntention >= CheckIntention.Dynamic)
                //{

                //}
            }
            else
            {
                res = new bool[5] {
                    false, false, false, false, false
                };
            }
        }
        return(res);
    }
    protected override void SetupDevice()
    {
        this.linkedGlove = (SenseGlove)this.linkedDevice;
        //this.linkedGlove.OnFingerCalibrationFinished += LinkedGlove_OnCalibrationFinished;
        //uodating once so glovedata is available, but not through the UpdateHand command, as that one needs the glove to already be connected.
        SenseGloveCs.GloveData rawData = this.linkedGlove.GetData(false);
        this.linkedGloveData = new SenseGlove_Data(rawData);

        //Device has been linked, now retrieve calibration.
        string serialized;

        if (SG.Calibration.SG_CalibrationStorage.LoadInterpolation(SenseGloveCs.DeviceType.SenseGlove, linkedGloveData.gloveSide, out serialized))
        {
            //Debug.Log("Loaded Calibration for the " + (linkedGloveData.gloveSide == GloveSide.LeftHand ? "Left Hand" : "Right Hand"));
            linkedGlove.SetInterpolationValues(serialized); //sets internal values
        }
    }
Exemple #23
0
    /// <summary> (Manually) Update the hand and glove model of the wireframe. </summary>
    /// <param name="data"></param>
    public override void UpdateHand(SenseGlove_Data data)
    {
        if (data.dataLoaded)
        {
            //Update the glove
            {
                Quaternion[][] gloveAngles    = data.gloveRotations;
                Vector3[][]    glovePositions = data.glovePositions;
                for (int f = 0; f < this.gloveJoints.Length; f++)
                {
                    for (int j = 0; j < this.gloveJoints[f].Length; j++)
                    {
                        this.gloveJoints[f][j].localPosition = glovePositions[f][j];
                        this.gloveJoints[f][j].rotation      = this.wristTransfrom.rotation * (gloveAngles[f][j] /* * this.fingerCorrection[f][j]*/);
                    }
                }
            }

            //Update the Hand
            {
                Quaternion[][] handAngles    = data.handRotations;
                Vector3[][]    handPositions = data.handPositions;
                for (int f = 0; f < this.fingerJoints.Length; f++)
                {
                    for (int j = 0; j < this.fingerJoints[f].Length; j++)
                    {
                        this.fingerJoints[f][j].localPosition = handPositions[f][j];
                        this.fingerJoints[f][j].rotation      = this.wristTransfrom.rotation * (handAngles[f][j] * this.fingerCorrection[f][j]);
                    }
                }
            }
        }


        if (Input.GetKeyDown(this.toggleGloveKey))
        {
            //Debug.Log("Toggling G");
            this.SetGlove(this.gloveBase != null && !this.gloveBase.activeInHierarchy);
        }
        if (Input.GetKeyDown(this.toggleHandKey))
        {
            //Debug.Log("Toggling H");
            this.SetHand(this.handBase != null && !this.handBase.activeInHierarchy);
        }
    }
    /// <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)
    {
        if (data != null)
        {
            this.gloveSide = SenseGlove_Data.GetSide(data.kinematics.isRight);

            this.deviceID        = data.deviceID;
            this.firmwareVersion = data.firmwareVersion;
            this.gloveVersion    = data.deviceVersion;

            this.packetsPerSecond = data.samplesPerSec;

            this.commonOriginPos = SenseGlove_Util.ToUnityPosition(data.kinematics.gloveRelPos);
            this.commonOriginRot = SenseGlove_Util.ToUnityQuaternion(data.kinematics.gloveRelRot);

            this.UpdateVariables(data);
        }
    }
Exemple #25
0
    /// <summary> Override the OnGloveLoaded event so we may create the glove model. </summary>
    /// <param name="source"></param>
    /// <param name="args"></param>
    protected override void SenseGlove_OnGloveLoaded(object source, EventArgs args)
    {
        //setup the glove model.
        if (this.previewGroup != null)
        {
            Destroy(this.previewGroup);
        }

        SenseGlove_Data data = this.senseGlove.GloveData;

        this.SetupFingers(data);
        this.SetupGlove(data);
        this.SetupHandPalm(data.gloveSide == GloveSide.RightHand);

        this.setupComplete = true;
        this.resizeFingers = true;
        base.SenseGlove_OnGloveLoaded(source, args);
    }
    /// <summary> Update all hand positions based on the latest data taken from the trackedGlove, but only if the handGroup is active in the heirarchy </summary>
    /// <param name="data"></param>
    private void UpdateHand(SenseGlove_Data data)
    {
        if (handPositions != null && handGroup.activeInHierarchy && data.dataLoaded)
        {
            Vector3[][]    pos = data.handPositions;
            Quaternion[][] rot = data.handRotations;
            for (int f = 0; f < handPositions.Length && f < data.handPositions.Length; f++)
            {
                for (int i = 0; i < handPositions[f].Length && i < pos[f].Length; i++)
                {
                    handPositions[f][i].transform.localPosition = pos[f][i];
                    handPositions[f][i].transform.localRotation = rot[f][i];
                }
            }

            Debug.DrawLine(handPositions[0][1].transform.position, handPositions[1][0].transform.position);
            UpdateConnector(data.handPositions[0][1], data.handPositions[1][0]);
        }
    }
Exemple #27
0
 /// <summary>
 /// Update the (absolute) wrist orientation, which moves realtive to the (absolute) lower arm transform.
 /// Note: This method is called before UpdateFingers() is called.
 /// </summary>
 /// <param name="data"></param>
 public virtual void UpdateWrist(SenseGlove_Data data)
 {
     if (this.updateWrist && data.dataLoaded)
     {
         if (data.dataLoaded)
         {
             Vector3 euler = (this.wristCalibration * data.absoluteWrist).eulerAngles;
             euler.x = -euler.x;
             euler.y = -euler.y;
             this.wristTransfrom.localEulerAngles = euler;
             //this.wristAngles = this.wristTransfrom.localRotation;
             //this.wristTransfrom.rotation = /*this.foreArmTransfrom.rotation */ this.wristCorrection * (this.wristCalibration * data.absoluteWrist);
             //this.wristAngles = Quaternion.Inverse(this.foreArmTransfrom.rotation) * this.wristTransfrom.rotation;
         }
     }
     else
     {
         //this.wristTransfrom.localRotation = this.wristCorrection * this.foreArmTransfrom.rotation;
         this.wristTransfrom.rotation = this.wristCorrection * this.foreArmTransfrom.rotation;
         this.wristAngles             = Quaternion.identity; //ignore wrist angle(s).
     }
 }
Exemple #28
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 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);
        }
    }
Exemple #29
0
    public override void UpdateHand(SenseGlove_Data data)
    {
        if (data.dataLoaded)
        {
            for (int f = 0; f < this.thimbles.Length && f < 5; f++)
            {
                int L = data.gloveRotations[f].Length - 1;
                this.thimbles[f].localRotation = data.gloveRotations[f][L];
                this.thimbles[f].localPosition = data.glovePositions[f][L];

                Transform baseT = this.wristTransfrom.GetChild(0);

                //Debug: Draw the glove's parts(?)
                Vector3[] poses = new Vector3[data.glovePositions[f].Length]; //-1 because we already have the last position

                poses[0] = baseT.TransformPoint(data.glovePositions[f][0]);
                for (int i = 1; i < poses.Length; i++)
                {
                    poses[i] = baseT.TransformPoint(data.glovePositions[f][i]);
                    Debug.DrawLine(poses[i - 1], poses[i], Color.white);
                }
            }
        }
    }
Exemple #30
0
 /// <summary> Creates a new instance of the unity-friendly calibration args. </summary>
 /// <param name="args"></param>
 public GloveCalibrationArgs(SenseGlove_Data oldD, SenseGlove_Data newD)
 {
     this.oldData = oldD;
     this.newData = newD;
 }