Files
Plugin/Source/SenseGloveCore/Public/SGCore/SGSenseGlove.h
T

480 lines
17 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 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 Sense Glove exoskeleton glove.
* Contains methods for Kinematics, Haptics and Serialization.
*/
#pragma once
#include "SGHapticGlove.h"
#include "Containers/Array.h"
#include "HAL/Platform.h"
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "SGCore/SGBasicHandModel.h"
#include "SGCore/SGHandPose.h"
#include "SGCore/SGHandProfile.h"
#include "SGCore/SGHapticGlove.h"
#include "SGCore/SGSenseGlovePose.h"
#include "SGCore/SGSenseGloveSensorData.h"
#include "SGCore/SGThumperCommand.h"
#include "SGTypes/SGCoreTypes.h"
#include "SGSenseGlove.generated.h"
class FSGSenseGloveImpl;
class USGBuzzCommand;
class USGForceFeedbackCommand;
/**
* Interface for the Sense Glove; and exoskeleton Force-Feedback glove.
*/
UCLASS(BlueprintType)
class SENSEGLOVECORE_API USGSenseGlove final : public USGHapticGlove
{
GENERATED_BODY()
public:
static USGSenseGlove* NewSenseGlove(UObject* Outer, const FSGSenseGloveImpl& SenseGloveImpl);
static USGSenseGlove* NewSenseGlove(UObject* Outer, TSharedRef<FSGSenseGloveImpl> SenseGloveImpl);
public:
/**
*
*/
static USGSenseGlove* NewSenseGlove(UObject* Outer);
/**
* Create a new instance of a Sense Glove.
*/
static USGSenseGlove* NewSenseGlove(UObject* Outer, const USGSenseGloveInfo& Model);
public:
/**
* Byte indicating a new Sense Glove haptic command.
*/
static ANSICHAR GetHapticsByte();
/**
* Byte indicating a new Thumper command.
*/
static ANSICHAR GetThumperByte();
public:
/**
* Calculates a GlovePose based on sensor angles and a glove model.
*
* @remarks Use this when you already have gloveAngles collected.
*/
static USGSenseGlovePose* CalculateGlovePose(UObject* Outer,
const USGSenseGloveSensorData* SensorData,
const USGSenseGloveInfo* GloveModel);
/**
* Calculates a GlovePose based on gloveAngles and a glove model.
*
* @remarks Use this when you already have gloveAngles collected.
*/
static USGSenseGlovePose* CalculateGlovePose(UObject* Outer,
const TArray<TArray<FVector>>& GloveAngles,
const USGSenseGloveInfo* GloveModel);
/**
* @remarks Use this when you already have a GlovePose.
*/
static USGHandPose* CalculateHandPose(UObject* Outer,
const USGSenseGlovePose* GlovePose,
const USGBasicHandModel* HandModel,
const USGSenseGloveHandProfile* Profile);
public:
/**
* Deserializes a Sense Glove from its ConstantsString. Returns a nullptr if unsuccessful.
*/
static USGDevice* Parse(UObject* Outer, const FString& ConstantsString);
/**
* Retrieve all Sense Gloves connected to this system.
*/
static TArray<USGSenseGlove*> GetSenseGloves(UObject* Outer);
/**
* Retrieve the first connected Sense Glove there is.
*/
static bool GetSenseGlove(UObject* Outer, USGSenseGlove*& OutGlove);
/**
* Retrieve the first (connected) right or left handed sense glove.
*/
static bool GetSenseGlove(UObject* Outer, bool bRightHanded, USGSenseGlove*& OutGlove);
public:
/**
* Convert a SenseGlove GlovePose into calibrationValues.
*/
static TArray<FVector> GetCalibrationValues(const USGSenseGlovePose* GlovePose);
/**
* Apply interpolation values to the correct fields in the SenseGlove Profile, based on min/max sensor values.
*/
static void CalibrateInterpolation(UObject* Outer,
const TArray<FVector>& MinValues, const TArray<FVector>& MaxValues,
bool bRightHanded, USGSenseGloveHandProfile*& OutProfile);
public:
/**
* Retrieve the location of the glove origin, based on a reference location without requiring an object reference.
*/
static void CalculateGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
FVector& OutGlovePosition, FQuat& OutGloveRotation);
/**
* Retrieve the location of the glove origin, based on a reference location without requiring an object reference.
*/
static void CalculateGloveLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
FVector& OutGlovePosition, FRotator& OutGloveRotation);
/**
* Calculates the full wrist location.
*/
static void CalculateWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
const FVector& GloveWristPositionOffset,
const FQuat& GloveWristRotationOffset,
FVector& OutWristPosition, FQuat& OutWristRotation);
/**
* Calculates the full wrist location.
*/
static void CalculateWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
const FVector& GloveWristPositionOffset,
const FRotator& GloveWristRotationOffset,
FVector& OutWristPosition, FRotator& OutWristRotation);
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
protected:
/**
*
*/
USGSenseGlove();
/**
* Create a new instance of a Sense Glove.
*/
explicit USGSenseGlove(const USGSenseGloveInfo& Model);
public:
/**
* The cast from underlying parent type constructor.
*/
explicit USGSenseGlove(const FSGDeviceImpl& SGDeviceImpl);
/**
* The cast from underlying parent type constructor.
*/
explicit USGSenseGlove(const FSGHapticGloveImpl& HapticGloveImpl);
/**
* The cast from underlying type constructor.
*/
explicit USGSenseGlove(const FSGSenseGloveImpl& SenseGloveImpl);
protected:
/**
* The cast from underlying parent pointer type constructor.
*/
explicit USGSenseGlove(TSharedRef<FSGDeviceImpl> SGDeviceImpl);
/**
* The cast from underlying parent pointer type constructor.
*/
explicit USGSenseGlove(TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
/**
* The cast from underlying pointer type constructor.
*/
explicit USGSenseGlove(TSharedRef<FSGSenseGloveImpl> SenseGloveImpl);
public:
/**
* The destructor.
*/
virtual ~USGSenseGlove() override;
public:
/**
* The cast to underlying type method.
*/
TSharedRef<FSGSenseGloveImpl> ToSenseGloveImpl() const;
protected:
/**
* Allows the child classes to synchronize the parent's underlying object at any time.
*/
virtual void SyncImplObject() const override;
/**
* Allows the child classes to synchronize the parent's uproperties at any time.
*/
virtual void SyncUProperties() override;
public:
/**
* Retrieve this glove's hardware model, which contains its hardware data.
*/
USGSenseGloveInfo* GetGloveModel(UObject* Outer) const;
/**
* Check if this Sense Glove is right handed.
*
* @remarks While the variable is stored in SG_GloveModel, added direct access here since its frequently used.
*/
virtual bool IsRight() const override;
public:
/**
* Get the DeviceType enumerator of this SenseGlove, used in DeviceList enumeration.
*/
virtual ESGDeviceType GetDeviceType() const override;
/**
* Retrieve this Sense Glove's unique identifier.
*/
virtual FString GetDeviceId() const override;
/**
* Retrieve this glove's hardware (sub) version.
*/
virtual FString GetHardwareVersion() const override;
/**
* Retrieve this device's firmware version.
*/
virtual int32 GetFirmwareVersion() const override;
/**
* Retrieve this device's sub-firmware version.
*/
virtual int32 GetSubFirmwareVersion() const override;
public:
/**
* Get the latest Sensor Data from this Sense Glove.
*/
bool GetSensorData(UObject* Outer, USGSenseGloveSensorData*& OutSensorData) const;
/**
*
*/
virtual bool GetImuRotation(FQuat& OutImu) override;
/**
*
*/
virtual bool GetImuRotation(FRotator& OutImu) override;
/**
* Get the pose of this Sense Glove's hardware, based on its latest Sensor Data.
*/
bool GetGlovePose(UObject* Outer, USGSenseGlovePose*& OutGlovePose);
/**
* Get the pose of this Sense Glove's hardware based on a set of Sensor Data.
*/
bool GetGlovePose(UObject* Outer, const USGSenseGloveSensorData* SensorData, USGSenseGlovePose*& OutGlovePose);
/// HACK
/// 'FSGSenseGloveImpl::GetHandPose' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
/// tell the compiler we want both the GetHandPose from USGHapticGlove and USGSenseGlove
using USGHapticGlove::GetHandPose;
/**
* Retrieve a new hand pose using this glove's data, based on (calibrated) user data.
*/
bool GetHandPose(UObject* Outer, const USGBasicHandModel* HandModel, const USGSenseGloveHandProfile* Profile,
USGHandPose*& OutHandPose);
/**
* Calculate the Hand Pose of this device, provided it has Hand Tracking available.
*/
virtual bool GetHandPose(UObject* Outer, const USGBasicHandModel* HandGeometry, const USGHandProfile* HandProfile,
USGHandPose*& OutHandPose) override;
/**
* Calculate the HandPose of this Device, taking into account user values, but not hand geometry.
*/
virtual bool GetHandPose(UObject* Outer, const USGHandProfile* HandProfile, USGHandPose*& OutHandPose) override;
public:
/// HACK
/// 'USGSenseGlove::SendHaptics' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
/// tell the compiler we want both the SendHaptics from USGHapticGlove and USGSenseGlove
using USGHapticGlove::SendHaptics;
/**
* Set the level(s) of Force and Vibrotactile feedback, with an optional thumper command.
*/
bool SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand,
const USGBuzzCommand* BuzzCommand,
ESGSenseGloveThumperCommand ThumperCommand = ESGSenseGloveThumperCommand::None);
/**
* Send a thumper command.
*/
bool SendHaptics(ESGSenseGloveThumperCommand ThumperCommand);
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand) override;
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGBuzzCommand* BuzzCommand) override;
/**
* Retrieve this device's firmware version.
*/
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand,
const USGBuzzCommand* BuzzCommand,
const USGThumperCommand* ThumperCommand) override;
public:
/**
* Retrieve calibration values of this glove, as an array of size 5, containing x (roll), y (flexion), z (abduction) values.
*/
virtual bool GetCalibrationValues(TArray<FVector>& OutValues) override;
/**
* Reset the glove's calibration range.
*/
virtual void ResetCalibrationRange() override;
/**
* Apply this glove's calibration range to a handProfile.
*/
virtual void ApplyCalibration(UObject* Outer, USGHandProfile*& OutProfile) const override;
/**
* Apply this glove's calibration range to a SenseGloveHandProfile.
*/
void ApplyCalibration(UObject* Outer, USGSenseGloveHandProfile*& OutProfile) const;
public:
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
virtual void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FQuat& OutGloveRotation) const override;
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
virtual void GetGloveLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FRotator& OutGloveRotation) const override;
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, ESGFinger MountedOn,
FVector& OutGlovePosition, FQuat& OutGloveRotation) const;
/**
* Retrieve the location of the glove origin, based on a reference location.
*/
void GetGloveLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, ESGFinger MountedOn,
FVector& OutGlovePosition, FRotator& OutGloveRotation) const;
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
virtual void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FQuat& OutWristRotation) const override;
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
virtual void GetWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FRotator& OutWristRotation) const override;
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
const FVector& GloveWristPositionOffset,
const FQuat& GloveWristRotationOffset,
FVector& OutWristPosition, FQuat& OutWristRotation) const;
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*/
void GetWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
const FVector& GloveWristPositionOffset,
const FRotator& GloveWristRotationOffset,
FVector& OutWristPosition, FRotator& OutWristRotation) const;
public:
/**
* Create a string representation of this device for reporting purposes.
*/
virtual FString ToString() const override;
};