203 lines
6.3 KiB
C++
203 lines
6.3 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
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "Containers/Array.h"
|
|
#include "Math/Vector.h"
|
|
#include "Templates/UniquePtr.h"
|
|
#include "UObject/Object.h"
|
|
#include "UObject/ObjectMacros.h"
|
|
|
|
#include "SGCore/SGSensorRange.h"
|
|
#include "SGTypes/SGCoreTypes.h"
|
|
|
|
#include "SGHapticGloveCalibrationCheck.generated.h"
|
|
|
|
class FSGHapticGloveCalibrationCheckImpl;
|
|
|
|
/**
|
|
* An algorithm that checks whether or not our current user is running in the same calibration range as last time.
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class SENSEGLOVECORE_API USGHapticGloveCalibrationCheck final : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
static USGHapticGloveCalibrationCheck* NewHapticGloveCalibrationCheck(
|
|
UObject* Outer, const FSGHapticGloveCalibrationCheckImpl& HapticGloveCalibrationCheckImpl);
|
|
|
|
public:
|
|
/**
|
|
* The last calibration range can be null, at which point you definitely need calibration.
|
|
*/
|
|
static USGHapticGloveCalibrationCheck* NewHapticGloveCalibrationCheck(UObject* Outer);
|
|
|
|
/**
|
|
* The last calibration range can be null, at which point you definitely need calibration.
|
|
*/
|
|
static USGHapticGloveCalibrationCheck* NewHapticGloveCalibrationCheck(
|
|
UObject* Outer, const USGSensorRange* LastCalibrationRange);
|
|
|
|
public:
|
|
/**
|
|
* SenseGlove: How far from the threshold one can be where we would still call it 'the same as before'.
|
|
*/
|
|
static float GetSenseGloveThreshold();
|
|
|
|
/**
|
|
* Nova: How far from the threshold one can be where we would still call it 'the same as before'.
|
|
*/
|
|
static float GetNovaGloveThreshold();
|
|
|
|
/**
|
|
* SenseGlove: The minimum amount of sensor flexion movement before we start testing for a smaller hand.
|
|
*/
|
|
static float GetSenseGloveMinFlexion();
|
|
|
|
/**
|
|
* Nova: The minimum amount of sensor flexion movement before we start testing for a smaller hand.
|
|
*/
|
|
static float GetNovaGloveMinFlexion();
|
|
|
|
/**
|
|
* SenseGlove: The minimum amount of sensor movement on the thumb abduction before we start testing for a smaller hand.
|
|
*/
|
|
static float GetSenseGloveMinAbduction();
|
|
|
|
/**
|
|
* Nova: The minimum amount of sensor movement on the thumb abduction before we start testing for a smaller hand.
|
|
*/
|
|
static float GetNovaGloveMinAbduction();
|
|
|
|
public:
|
|
/**
|
|
* Returns true if this DeviceType requires a calibration check.
|
|
*/
|
|
static bool NeedsCheck(ESGDeviceType DeviceType);
|
|
|
|
/**
|
|
* Checks if current values are operating out of the previous range. Returns -1 if all is fine. 0...4 to indicate which finger is out of bounds.
|
|
*/
|
|
static int32 OutOfBounds(const USGSensorRange* PreviousRange, const TArray<FVector>& CurrentValues,
|
|
ESGDeviceType DeviceType);
|
|
|
|
/**
|
|
* Returns true if the user has moved enough in both flexion and thumb abduction movement to be considered 'active'
|
|
*/
|
|
static bool MovedMinimum(const TArray<FVector>& CurrentRange, ESGDeviceType DeviceType);
|
|
|
|
/**
|
|
* Returns true if the current sensor values have moved roughly as much as last time.
|
|
*/
|
|
static bool MatchesLast(const TArray<FVector>& CurrentRange, const TArray<FVector>& LastRange,
|
|
ESGDeviceType DeviceType);
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
public:
|
|
/**
|
|
* The last calibration range can be null, at which point you definitely need calibration.
|
|
*/
|
|
USGHapticGloveCalibrationCheck();
|
|
|
|
/**
|
|
* The last calibration range can be null, at which point you definitely need calibration.
|
|
*/
|
|
explicit USGHapticGloveCalibrationCheck(const USGSensorRange* LastCalibrationRange);
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit USGHapticGloveCalibrationCheck(const FSGHapticGloveCalibrationCheckImpl& HapticGloveCalibrationCheckImpl);
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~USGHapticGloveCalibrationCheck() override;
|
|
|
|
protected:
|
|
/**
|
|
* Allows to set the underlying object after construction.
|
|
*/
|
|
void SetHapticGloveCalibrationCheckImpl(const FSGHapticGloveCalibrationCheckImpl& HapticGloveCalibrationCheckImpl);
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
const FSGHapticGloveCalibrationCheckImpl& ToHapticGloveCalibrationCheckImpl() const;
|
|
|
|
public:
|
|
/**
|
|
*
|
|
*/
|
|
USGSensorRange* GetLastSensorRange(UObject* Outer) const;
|
|
|
|
public:
|
|
/**
|
|
*
|
|
*/
|
|
ESGCalibrationStage GetCalibrationStage() const;
|
|
|
|
/**
|
|
* Whether this algorithm has determined if calibration is required, or not.
|
|
*/
|
|
bool ReachedConclusion() const;
|
|
|
|
public:
|
|
/**
|
|
* Reset the calibration check. so it may be used again. This does not reset the last range.
|
|
*/
|
|
void Reset();
|
|
|
|
/**
|
|
* Using the currently received Sensor Values, check if calibration is required. This function will have to be called until a conclusion can be reached.
|
|
*/
|
|
void CheckRange(const TArray<FVector>& CurrentValues, float DeltaSeconds, ESGDeviceType DeviceType);
|
|
};
|