Files
Plugin/Source/SenseGloveCoreKismet/Public/SGCoreKismet/SGNovaGloveKismetLibrary.h
T

514 lines
22 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2026 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
* An interface for the "Nova" - a soft glove.
* Contains methods for Kinematics, Haptics and Serialization.
*/
#pragma once
#include "SGKismet/SGBlueprintFunctionLibrary.h"
#include "SGTypes/SGCoreTypes.h"
#include "SGTypes/SGVectorArray.h"
#include "SGNovaGloveKismetLibrary.generated.h"
class USGBasicHandModel;
class USGDevice;
class USGHandPose;
class USGHandProfile;
class USGNovaGlove;
class USGNovaGloveHandProfile;
class USGNovaGloveSensorData;
/**
* A soft glove with Force- and Vibrotactile Feedback and limited tracking.
*/
UCLASS(meta=(ScriptName = "SenseGloveNovaGloveKismetLibrary"))
class SENSEGLOVECOREKISMET_API USGNovaGloveKismetLibrary final : public USGBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Deserializes a Nova from its ConstantsString. Returns a nullptr if unsuccessful.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static USGDevice* Parse(UObject* WorldContextObject, const FString& ConstantsString);
/**
* Retrieve all Nova's.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static TArray<USGNovaGlove*> GetNovaGloves(UObject* WorldContextObject);
/**
* Retrieve the first connected Nova there is.
*/
UFUNCTION(BlueprintCallable, DisplayName="Get Nova Glove", Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static bool GetNovaGlove_OutG(UObject* WorldContextObject, USGNovaGlove*& OutGlove);
/**
* Retrieve the first (connected) right or left handed Nova.
*/
UFUNCTION(BlueprintCallable, DisplayName="Get Nova Glove", Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static bool GetNovaGlove_bRH_OutG(UObject* WorldContextObject,
bool bRightHanded, USGNovaGlove*& OutGlove);
/**
* Retrieve the location of the glove origin, based on a reference location without requiring an object reference.
*/
UFUNCTION(BlueprintCallable, DisplayName="Calculate Glove Location",
Category="SenseGlove | Core | Nova | Nova Glove")
static void CalculateGloveLocation_RP_FQuat_RR_TH_bRH_OutGP_OutGR(
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutGlovePosition, FQuat& OutGloveRotation);
/**
* Retrieve the location of the glove origin, based on a reference location without requiring an object reference.
*/
UFUNCTION(BlueprintCallable, DisplayName="Calculate Glove Location",
Category="SenseGlove | Core | Nova | Nova Glove")
static void CalculateGloveLocation_RP_FRotator_RR_TH_bRH_OutGP_OutGR(
const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutGlovePosition, FRotator& OutGloveRotation);
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets, without
* needing an object reference.
*
* @remarks The simplest interface, using default offsets.
*/
UFUNCTION(BlueprintCallable, DisplayName="Calculate Wrist Location",
Category="SenseGlove | Core | Nova | Nova Glove")
static void CalculateWristLocation_RP_FQuat_RR_TH_bRH_OutWP_OutWR(
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutWristPosition, FQuat& OutWristRotation);
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets, without
* needing an object reference.
*
* @remarks The simplest interface, using default offsets.
*/
UFUNCTION(BlueprintCallable, DisplayName="Calculate Wrist Location",
Category="SenseGlove | Core | Nova | Nova Glove")
static void CalculateWristLocation_RP_FRotator_RR_TH_bRH_OutWP_OutWR(
const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutWristPosition, FRotator& OutWristRotation);
/**
* Byte indicating a new Nova haptic command.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static FString GetHapticsByte();
/**
* Byte indicating a new Nova thresholds command.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static FString GetThresholdsByte();
/**
* Byte to ignore Thresholds.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static FString GetIgnoreThresholdsByte();
/**
* Ranges before a Nova 1.0 Sensor is allowed to move.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static TArray<float> GetNovaSensorRanges();
/**
* Converts Nova Sensor Data into floating point inputs for normalization.
*/
UFUNCTION(BlueprintCallable, DisplayName="To Normalized Values", Category="SenseGlove | Core | Nova | Nova Glove")
static TArray<float> ToNormalizedValues_SD(const USGNovaGloveSensorData* SensorData);
/**
* Convert Sensor Data into a series of normalized values.
*/
UFUNCTION(BlueprintCallable, DisplayName="To Normalized Values", Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static TArray<float> ToNormalizedValues_SD_OutSN(
UObject* WorldContextObject,
const USGNovaGloveSensorData* SensorData, USGSensorNormalization*& OutSensorNormalizer);
/**
* Calculate Hand Angles for a Nova Glove, based on normalized input.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static TArray<FSGVectorArray> CalculateHandAngles(
const TArray<float>& NormalizedValues, const USGHandInterpolator* Interpolator);
/**
* Converts a Threshold command into a Nova Glove command.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static FString ToNovaCommandAsFlexion(const USGThresholdCommand* Thresholds);
/**
* Converts a Threshold command into a Nova Glove command.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static FString ToNovaCommandAsRaw(
const USGThresholdCommand* Thresholds, const USGSensorNormalization* Interpolator);
/**
* Return the DeviceType of this Nova.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static ESGDeviceType GetDeviceType(const USGNovaGlove* NovaGlove);
/**
* Returns this device's unique identifier.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static FString GetDeviceId(const USGNovaGlove* NovaGlove);
/**
* Access this device's hardware designation.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static FString GetHardwareVersion(const USGNovaGlove* NovaGlove);
/**
* Access this device's main firmware version. (ex: v3.2 -> 3).
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static int32 GetFirmwareVersion(const USGNovaGlove* NovaGlove);
/**
* Access this device's sub-firmware version. (ex: v3.2 -> 2).
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static int32 GetSubFirmwareVersion(const USGNovaGlove* NovaGlove);
/**
* Change this device's index within the SenseCom. Warning: Can cause errors.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void SetDeviceIndex(UPARAM(ref) USGNovaGlove* NovaGlove, int32 NewIndex);
/**
* Returns true if this device operates on a battery.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool HasBattery(const USGNovaGlove* NovaGlove);
/**
* Returns true if this device is currently charging.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool IsCharging(UPARAM(ref) USGNovaGlove* NovaGlove);
/**
* Returns the device's battery level, as a value between 0 (empty) and 1 (full).
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool GetBatteryLevel(UPARAM(ref) USGNovaGlove* NovaGlove, float& OutBatteryLevel);
/**
* Returns true if this glove is meant for right hands.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool IsRight(const USGNovaGlove* NovaGlove);
/**
* Retrieve Nova rotation.
*/
UFUNCTION(BlueprintCallable, DisplayName="Get Imu Rotation", Category="SenseGlove | Core | Nova | Nova Glove")
static bool GetImuRotation_FQuat_OutI(UPARAM(ref) USGNovaGlove* NovaGlove, FQuat& OutImu);
/**
* Retrieve Nova rotation.
*/
UFUNCTION(BlueprintCallable, DisplayName="Get Imu Rotation", Category="SenseGlove | Core | Nova | Nova Glove")
static bool GetImuRotation_FRotator_OutI(UPARAM(ref) USGNovaGlove* NovaGlove, FRotator& OutImu);
/**
* Retrieve a new hand pose using this glove, based on (calibrated) user data.
*/
UFUNCTION(BlueprintCallable, DisplayName="Get Hand Pose", Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static bool GetHandPose(UObject* WorldContextObject,
UPARAM(ref) USGNovaGlove* NovaGlove,
const USGBasicHandModel* HandModel,
USGHandPose*& OutHandPose);
/**
* Returns the Hand Angles calculated by this Nova Glove. Used for input for HandPoses, but can be used in and of
* itself.
*
* @param OutHandAngles
*/
UFUNCTION(BlueprintPure, DisplayName="Get Hand Angles", Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static bool GetHandAngles(const USGNovaGlove* NovaGlove, TArray<FSGVectorArray>& OutHandAngles);
/*
* Retrieve the calibration status of this Nova Glove.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static ESGHapticGloveCalibrationState GetCalibrationState(const USGNovaGlove* NovaGlove);
/*
* Completes sensor Normalization on the Nova's end.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void EndCalibration(UPARAM(ref) USGNovaGlove* NovaGlove);
/*
* Completes sensor Normalization on the Nova's end.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void ResetCalibration(UPARAM(ref) USGNovaGlove* NovaGlove);
public:
/*
* Stop all haptic feedback effects playing on this device.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void StopHaptics(UPARAM(ref) USGNovaGlove* NovaGlove);
/**
* Stop only all vibrotactile feedback.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void StopVibrations(UPARAM(ref) USGNovaGlove* NovaGlove);
/**
* Take all active commands in the device queue, compile them into one and send them to the device.
*
* @returns Returns true if the message was successfully sent to SenseCom. Returns false if no changes to commands
* were detected.
*
* @remarks Generic function across any Haptic Interface in SGCore.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SendHaptics(UPARAM(ref) USGNovaGlove* NovaGlove);
/**
* Returns true if this Glove supports the chosen haptic location.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SupportsCustomWaveform(const USGNovaGlove* NovaGlove, ESGHapticLocation AtLocation);
/**
* Send a custom waveform to the Nova.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SendCustomWaveform(UPARAM(ref) USGNovaGlove* NovaGlove,
USGCustomWaveform* OutWaveform, ESGHapticLocation Location);
/**
* Queue a list of force-feedback levels, between 0.0 and 1.0. Your list should be sorted from thumb to pinky.
*
* @remarks Devices that 'only' have on/off FFB will treat any value > 0.0 as 1.0.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueForceFeedbackLevels(UPARAM(ref) USGNovaGlove* NovaGlove, const TArray<float>& Levels01);
/**
* Set the Force-Feedback value of a particular finger to a specific level.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueForceFeedbackLevel(UPARAM(ref) USGNovaGlove* NovaGlove, int32 Finger, float Level01);
/**
* Queue a vibrotactile level for each finger.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueVibroLevels(UPARAM(ref) USGNovaGlove* NovaGlove, const TArray<float>& Amplitudes);
/**
* Queue a command to set the (continuous) vibration level at a specific location to a set amplitude.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueVibroLevel_L_L(UPARAM(ref) USGNovaGlove* NovaGlove, ESGHapticLocation Location, float Level01);
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
UFUNCTION(BlueprintPure, DisplayName="Get Glove Location", Category="SenseGlove | Core | Nova | Nova Glove")
static void GetGloveLocation_RP_FQuat_RR_TH_OutGP_FQuat_OutGR(
const USGNovaGlove* NovaGlove,
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FQuat& OutGloveRotation);
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
UFUNCTION(BlueprintPure, DisplayName="Get Glove Location", Category="SenseGlove | Core | Nova | Nova Glove")
static void GetGloveLocation_RP_FRotator_RR_TH_OutGP_FRotator_OutGR(
const USGNovaGlove* NovaGlove,
const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FRotator& OutGloveRotation);
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
UFUNCTION(BlueprintPure, DisplayName="Get Wrist Location", Category="SenseGlove | Core | Nova | Nova Glove")
static void GetWristLocation_RP_FQuat_RR_TH_OutWP_FQuat_OutWR(
const USGNovaGlove* NovaGlove,
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FQuat& OutWristRotation);
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
UFUNCTION(BlueprintPure, DisplayName="Get Wrist Location", Category="SenseGlove | Core | Nova | Nova Glove")
static void GetWristLocation_RP_FRotator_RR_TH_OutWP_FRotator_OutWR(
const USGNovaGlove* NovaGlove,
const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FRotator& OutWristRotation);
/**
* Access all sorts of device info specific to this Nova.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove", meta=(WorldContext="WorldContextObject"))
static USGNovaGloveInfo* GetGloveInfo(UObject* WorldContextObject, const USGNovaGlove* NovaGlove);
/**
* If true, this Nova Glove supports sending special firmware commands to lock brakes at specific sensor values.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SupportsThresholds(const USGNovaGlove* NovaGlove);
/**
* If true, this Nova Glove supports sending custom 'fire-and-forget' waveforms.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SupportsCustomWaveforms(const USGNovaGlove* NovaGlove);
/**
* If true, this glove's sensor calibration runs on board the device.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SupportsOnBoardNormalization(const USGNovaGlove* NovaGlove);
/**
* Get the latest Sensor Data from this Glove.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove",
meta=(WorldContext="WorldContextObject"))
static bool GetSensorData(UObject* WorldContextObject,
UPARAM(ref) USGNovaGlove* NovaGlove, USGNovaGloveSensorData*& OutSensorData);
/**
* Converts a set of commands into a series of bytes (string) this glove can understand.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static FString ToNovaCommand(
const USGNovaGlove* NovaGlove,
const TArray<float>& ForceFeedbackLevels, const TArray<float>& BuzzLevels, float WristLevel);
/**
* Queue a vibrotactle level for a specific finger.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueVibroLevel_F_A(UPARAM(ref) USGNovaGlove* NovaGlove, int32 Finger, float Amplitude);
/**
* Queue a command to the vibration amplitude of a general wrist actuator to a set level.
*
* @returns Returns true if the wrist command has been successfully queued. If false, the device might not support
* direct wrist control or have the appropriate firmware.
*
* @remarks This one isn't contained in an interface as it's not used outside of the NovaGlove class.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueWristLevel(UPARAM(ref) USGNovaGlove* NovaGlove, float Amplitude);
/**
* Convert a HapticLocation into a Nova Motor location.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static ESGNovaVibroMotor ToNovaMotor(const USGNovaGlove* NovaGlove, ESGHapticLocation Location);
/**
* Returns the channel index for a particular motor. Can make this as complex as I want for the Nova GLove(s).
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static int32 ChannelIndex(const USGNovaGlove* NovaGlove, ESGNovaVibroMotor Motor);
/**
* Ensures the waveform that is to be sent to this Nova Glove has the appropriate parameters.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static void ValidateWaveform(const USGNovaGlove* NovaGlove,
USGCustomWaveform* OutWaveform, ESGNovaVibroMotor Motor);
/**
* Directly sends a custom waveform to the Nova Glove motors, as opposed to specifying a Haptic Location.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool SendCustomWaveform_Nova(
UPARAM(ref) USGNovaGlove* NovaGlove,
USGCustomWaveform* OutWaveform, ESGNovaVibroMotor Motor, bool bValidateWaveform = true);
/**
* Stops the glove when flexing pas this point.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueThresholdCommand_Flexion(UPARAM(ref) USGNovaGlove* NovaGlove,
int32 Finger, float FlexionThreshold);
/**
* Queue a command to clear the threshold for a specific finger.
*
* @returns Returns true if the command was queued. If false, the device does not have the required firmware for
* these commands.
*/
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Nova | Nova Glove")
static bool QueueClearThreshold(UPARAM(ref) USGNovaGlove* NovaGlove, int32 Finger);
/**
* Create a string representation of this device for reporting purposes.
*/
UFUNCTION(BlueprintPure, Category="SenseGlove | Core | Nova | Nova Glove")
static FString ToString(const USGNovaGlove* NovaGlove);
};