Adjuvo / SenseGlove-API

Sense Glove API for native C++ development
https://senseglove.gitlab.io/SenseGloveDocs/native/core-api-intro.html
MIT License
15 stars 11 forks source link

Acquire raw encoder readings from within the Unity plugin? #14

Closed revanj closed 2 years ago

revanj commented 2 years ago

Hi there, thanks for the awesome library!

We were doing something that requires the encoder values from the sense gloves, to animate the SenseGlove itself. Is it possible to acquire the raw encoder readings using the Unity plugin or the C++ API?

MaxLammers commented 2 years ago

Hi Revanj,

The SenseGlove DK1 exoskeleton and SenseGlove Nova differ in their number and configuration of sensors. To do so, you will need to have a reference to a specific SenseGlove or NovaGlove class (as opposed to using the more generic HapticGlove class).

For now, I'll assume you're asking about the SenseGlove DK1. For this glove, you can access SG_SensorData through the SenseGlove class, which will contain everything received from the hardware itself. The device does not send raw encoder values, but the 4 sensor angles between the linkages. You'll need to know which parts of the glove are animated by each angle.

If you instead use the SG_GlovePose class, you'll not only get access to all positions and rotations relative to the glove's origin, but also the angles between the linkages placed in their proper xyz notation.

SGCore::SG::SenseGlove testGlove;
if (SGCore::SG::SenseGlove::GetSenseGlove(testGlove)) //retrieves the first Sense Glove it can find. Returns true if one can be found
{
    //Retrieving Sensor Data (raw). The lowest level data available
    SGCore::SG::SG_SensorData sensorData;
    if (testGlove.GetSensorData(sensorData)) //if GetSensorData is true, we have sucesfully recieved data
    {
        std::cout << std::endl;
        std::cout << sensorData.ToString() << std::endl;
    }

    //Retrieving Glove Pose: The position / rotation of the glove, as well as its sensor angles placed in the right direction.
    SGCore::SG::SG_GlovePose glovePose;
    if (testGlove.GetGlovePose(glovePose))
    {
        std::cout << std::endl;
        std::cout << glovePose.ToString() << std::endl;
    }
}
MaxLammers commented 2 years ago

Accessing this pose in the Unity Engine works similar, though you'd be using the C# API.

SGCore.SG.SenseGlove testGlove;
if (SGCore.SG.SenseGlove.GetSenseGlove(testGlove)) //retrieves the first Sense Glove it can find. Returns true if one can be found
{
    //Retrieving Sensor Data (raw). The lowest level data available
    SGCore.SG.SG_SensorData sensorData;
    if (testGlove.GetSensorData(sensorData)) //if GetSensorData is true, we have sucesfully recieved data
    {
        Debug.Log( sensorData.ToString() );
    }

    //Retrieving Glove Pose: The position / rotation of the glove, as well as its sensor angles placed in the right direction.
    SGCore.SG.SG_GlovePose glovePose;
    if (testGlove.GetGlovePose(glovePose))
    {
        Debug.Log( glovePose.ToString() );
    }
}

There's no .h files to link to in C#, but it has the exact same variable names and content as the C++ API.

revanj commented 2 years ago

That works, thank you so much!