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

351 lines
11 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 any of our gloves that can track hand motion and/or send
* force / vibrotactile feedback.
*/
#pragma once
#include "Containers/Array.h"
#include "HAL/Platform.h"
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "SGCore/SGBasicHandModel.h"
#include "SGCore/SGDevice.h"
#include "SGCore/SGHandPose.h"
#include "SGCore/SGHandProfile.h"
#include "SGCore/SGThumperCommand.h"
#include "SGTypes/SGCoreTypes.h"
#include "SGHapticGlove.generated.h"
class FSGHapticGloveImpl;
class FSGNovaGloveImpl;
class FSGSenseGloveImpl;
class USGBuzzCommand;
class USGForceFeedbackCommand;
/**
* A glove developed by SenseGlove, that has hand tracking and/or haptic feedback functionality.
*/
UCLASS(BlueprintType)
class SENSEGLOVECORE_API USGHapticGlove : public USGDevice
{
GENERATED_BODY()
private:
friend class USGHapticGloveCalibrationSequence;
protected:
static USGHapticGlove* NewHapticGlove(UObject* Outer, const FSGHapticGloveImpl& HapticGloveImpl);
static USGHapticGlove* NewHapticGlove(UObject* Outer, TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
protected:
/**
*
*/
static USGHapticGlove* NewHapticGlove(UObject* Outer);
public:
/**
* Get all Haptic Gloves detected on this system.
*/
static TArray<USGHapticGlove*> GetHapticGloves(UObject* Outer);
/**
* Get the first Haptic Glove detected on this system.
*/
static bool GetGlove(UObject* Outer, USGHapticGlove*& OutGlove);
/**
* Get the first left/right Haptic Glove detected on this system.
*/
static bool GetGlove(UObject* Outer, bool bRightHanded, USGHapticGlove*& OutGlove);
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
protected:
/**
* The basic constructor.
*/
USGHapticGlove();
public:
/**
* The cast from underlying parent type constructor.
*/
explicit USGHapticGlove(const FSGDeviceImpl& SGDeviceImpl);
/**
* The cast from underlying type constructor.
*/
explicit USGHapticGlove(const FSGHapticGloveImpl& HapticGloveImpl);
/**
* The cast from underlying child type constructor.
*/
explicit USGHapticGlove(const FSGNovaGloveImpl& NovaGloveImpl);
/**
* The cast from underlying child type constructor.
*/
explicit USGHapticGlove(const FSGSenseGloveImpl& SenseGloveImpl);
protected:
/**
* The cast from underlying parent pointer type constructor.
*/
explicit USGHapticGlove(TSharedRef<FSGDeviceImpl> SGDeviceImpl);
/**
* The cast from underlying pointer type constructor.
*/
explicit USGHapticGlove(TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
/**
* The cast from underlying child pointer type constructor.
*/
explicit USGHapticGlove(TSharedRef<FSGNovaGloveImpl> NovaGloveImpl);
/**
* The cast from underlying child pointer type constructor.
*/
explicit USGHapticGlove(TSharedRef<FSGSenseGloveImpl> SenseGloveImpl);
public:
/**
* The destructor.
*/
virtual ~USGHapticGlove() override;
public:
/**
* The cast to underlying type method.
*/
TSharedRef<FSGHapticGloveImpl> ToHapticGloveImpl() 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:
/**
* Get the DeviceType enumerator of this device; used to check if its a SenseGlove/Nova/etc.
*/
virtual ESGDeviceType GetDeviceType() const override;
/**
* Retrieve this glove's unique identifier.
*/
virtual FString GetDeviceId() const override;
/**
* Retrieve this glove's hardware (sub) version. "DK1", "DK2", etc.
*/
virtual FString GetHardwareVersion() const override;
/**
* Retrieve this device's main firmware version. v4.12 returns 4.
*/
virtual int32 GetFirmwareVersion() const override;
/**
* Retrieve this device's sub firmware version. v4.12 returns 12.
*/
virtual int32 GetSubFirmwareVersion() const override;
/**
* Returns true if this glove is made for a right hand. If false, it's a left hand.
*/
virtual bool IsRight() const;
/**
* Retrieve this glove's IMU rotation, if if has any.
*/
virtual bool GetImuRotation(FQuat& OutImu);
/**
* Retrieve this glove's IMU rotation, if if has any.
*/
virtual bool GetImuRotation(FRotator& OutImu);
/**
* 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);
/**
* 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);
/**
* Retrieve a HandPose based on the latest profile, but with a specific hand geometry.
*/
virtual bool GetHandPose(UObject* Outer, const USGBasicHandModel* HandGeometry, USGHandPose*& OutHandPose);
/**
* Retrieve a HandPose based on the latest profile and default hand Geometry.
*/
virtual bool GetHandPose(UObject* Outer, USGHandPose*& OutHandPose);
public:
/**
* Stops all Haptic effects if any are currently playing. Useful at the end of simulations or when resetting.
*/
virtual void StopHaptics();
/**
* Send Haptic Commands to this Glove.
*/
virtual void StopVibrations();
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand);
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGBuzzCommand* BuzzCommand);
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGThumperCommand* ThumperCommand);
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand,
const USGBuzzCommand* BuzzCommand);
/**
* Send Haptic Commands to this Glove.
*/
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand,
const USGBuzzCommand* BuzzCommand,
const USGThumperCommand* ThumperCommand);
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);
/**
* Reset Calibration range for this Device.
*/
virtual void ResetCalibrationRange();
/**
* Updates calibration values only.
*/
virtual void UpdateCalibrationRange();
/**
* Updates calibration values only.
*/
virtual void UpdateCalibrationRange(const TArray<FVector>& CalibrationValues);
/**
* Access the minimum- and maximum sensor values measured by this Haptic Glove, in this session.
*/
virtual void GetCalibrationRange(TArray<FVector>& OutMinValues,
TArray<FVector>& OutMaxValues);
/**
* Updates Calibration values and applies it to the Profile.
*/
virtual void UpdateCalibration(UObject* Outer, USGHandProfile*& OutProfile);
/**
* Apply this glove's calibration range to a handProfile.
*/
virtual void ApplyCalibration(UObject* Outer, USGHandProfile*& OutProfile) const;
public:
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*
* @remarks The simplest interface, using default offsets.
*/
virtual void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FQuat& OutWristRotation) const;
/**
* Retrieve the location of the wrist, based on a reference location and default glove-hand offsets.
*
* @remarks The simplest interface, using default offsets.
*/
virtual void GetWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FRotator& OutWristRotation) const;
/**
* 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;
/**
* 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;
};