예제 #1
0
    /// <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);
    }
예제 #2
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);
    }
    //-------------------------------------------------------------------------------------------------------------------
    // 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);
        }
    }
예제 #4
0
    //--------------------------------------------------------------------------------------------------------------------------
    // Class Methods

    /// <summary> Updates this glove's data. </summary>
    protected void UpdateGlove()
    {
        if (this.wasConnected && this.linkedGlove != null && this.IsConnected) //if we are connected then linkedGlove is assumed not null.
        {
            //lower arm rotation is set to identity (n/a) since we will calibrate at _HandModel Level
            SenseGloveCs.GloveData rawData = this.linkedGlove.Update(UpdateLevel.HandPositions, this.solver, this.limitFingers, this.updateWrist,
                                                                     new Quat(0, 0, 0, 1), false);
            this.linkedGloveData.UpdateVariables(rawData);
        }
    }
예제 #5
0
 public void ThreadProc()
 {
     while (UpdateThread.linkedGlove == null)
     {
         Thread.Sleep(10);
     }
     while (UpdateThread.linkedGlove != null)
     {
         rawData = linkedGlove.Update(UpdateLevel.HandPositions, this.solver, this.limitFingers, this.updateWrist, new Quat(0, 0, 0, 1), false);
         Thread.Sleep(10);
     }
 }
    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
        }
    }
예제 #7
0
    /// <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);
        }
    }
예제 #8
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);
        }
    }