330 lines
15 KiBLFS
C++
330 lines
15 KiBLFS
C++
/**
|
|
* @file
|
|
*
|
|
* @author Max Lammers <max@senseglove.com>
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* Copyright (c) 2020 - 2022 SenseGlove
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
* An interface for the "Nova" - a soft glove.
|
|
* Contains methods for Kinematics, Haptics and Serialization.
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "HapticGlove.hpp"
|
|
#include "Platform.hpp"
|
|
|
|
namespace SGCore
|
|
{
|
|
namespace Kinematics
|
|
{
|
|
class Quat;
|
|
|
|
class Vect3D;
|
|
};// namespace Kinematics
|
|
|
|
namespace Nova
|
|
{
|
|
class NovaGloveInfo;
|
|
|
|
class NovaGloveHandProfile;
|
|
|
|
class NovaGloveSensorData;
|
|
|
|
class SGCORE_API NovaGlove;
|
|
}// namespace Nova
|
|
}// namespace SGCore
|
|
|
|
/// <summary> A soft glove with Force- and Vibrotactile Feedback and limited tracking. </summary>
|
|
class SGCORE_API SGCore::Nova::NovaGlove : public HapticGlove
|
|
{
|
|
public:
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
// Static Properties
|
|
|
|
/// <summary> Byte indicating a new Nova haptic command. </summary>
|
|
static char GetHapticsByte();
|
|
|
|
/// <summary> Minimum calibration value distance until we apply the range. </summary>
|
|
static const Kinematics::Vect3D& GetMinCalibrationRange();
|
|
|
|
public:
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
// Device Data
|
|
|
|
/// <summary> Calculate a Hand Pose based on a HandMode; sensor data from a Nova, and a UserProfile. </summary>
|
|
/// <param name="handModel"></param>
|
|
/// <param name="NovaData"></param>
|
|
/// <param name="profile"></param>
|
|
/// <returns></returns>
|
|
static HandPose CalculateHandPose(const Kinematics::BasicHandModel& handModel,
|
|
const NovaGloveSensorData& novaData, const NovaGloveHandProfile& profile);
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// DeviceList Integration
|
|
|
|
///<summary> Deserializes a Nova from its ConstantsString. Returns a nullptr if unsuccessful. </summary>
|
|
/// <param name="constantsString"></param>
|
|
/// <returns></returns>
|
|
static std::shared_ptr<SGDevice> Parse(const std::string& constantsString);
|
|
|
|
/// <summary> Retrieve all Nova's. </summary>
|
|
static std::vector<NovaGlove> GetNovaGloves();
|
|
|
|
/// <summary> Retrieve the first connected Nova there is. </summary>
|
|
static bool GetNovaGlove(NovaGlove& out_glove);
|
|
|
|
/// <summary> Retrieve the first (connected) right- or left handed Nova. </summary>
|
|
static bool GetNovaGlove(bool bRightHanded, NovaGlove& out_glove);
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// Calibration Methods
|
|
|
|
/// <summary> Convert a SenseGlove GlovePose into calibrationValues. </summary>
|
|
/// <param name="sensorData"></param>
|
|
/// <returns></returns>
|
|
static std::vector<Kinematics::Vect3D> GetCalibrationValues(const NovaGloveSensorData& sensorData);
|
|
|
|
static void CalibrateInterpolation(const std::vector<Kinematics::Vect3D>& minValues,
|
|
const std::vector<Kinematics::Vect3D>& maxValues,
|
|
NovaGloveHandProfile& out_profile);
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// 6DoF Position Tracking
|
|
|
|
/// <summary> Retrieve the location of the glove origin, based on a reference location without requiring an object reference.. </summary>
|
|
/// <param name="refPosition">Position of the tracked object, in mm, relative to your origin</param>
|
|
/// <param name="refRotation">Rotation of the tracked object relative to your origin</param>
|
|
/// <param name="trackingHardware">The hardware mounted on the SenseGlove.</param>
|
|
/// <param name="bRightHanded">Whether this is a left or right-handed glove.</param>
|
|
/// <param name="out_glovePosition">The 3D Position of the glove, in mm, relative to your origin</param>
|
|
/// <param name="out_gloveRotation">The 3D Rotation of the glove, relative to your origin</param>
|
|
static void CalculateGloveLocation(const Kinematics::Vect3D& refPosition, const Kinematics::Quat& refRotation,
|
|
EPositionalTrackingHardware trackingHardware, bool bRightHanded,
|
|
Kinematics::Vect3D& out_glovePosition, Kinematics::Quat& out_gloveRotation);
|
|
|
|
/// <summary> Retrieve the location of the wrist, based on a reference location and default glove-hand offsets, without needing an object reference. </summary>
|
|
/// <remarks> The simplest interface, using default offsets </remarks>
|
|
/// <param name="refPosition">Position of the tracked object, in mm, relative to your origin</param>
|
|
/// <param name="refRotation">Rotation of the tracked object relative to your origin</param>
|
|
/// <param name="trackingHardware">The hardware mounted on the SenseGlove.</param>
|
|
/// <param name="bRightHanded">Whether this is right or left hand</param>
|
|
/// <param name="out_wristPosition">The 3D Position of the wrist, in mm, relative to your origin</param>
|
|
/// <param name="out_wristRotation">The 3D Rotation of the wrist, relative to your origin</param>
|
|
static void CalculateWristLocation(const Kinematics::Vect3D& refPosition, const Kinematics::Quat& refRotation,
|
|
EPositionalTrackingHardware trackingHardware, bool bRightHanded,
|
|
Kinematics::Vect3D& out_wristPosition, Kinematics::Quat& out_wristRotation);
|
|
|
|
public:
|
|
/// <summary> Converts a thumper command into bytes that the Nova can understand. </summary>
|
|
static std::string ToBytes(const Haptics::ThumperCommand& thumperCommand);
|
|
|
|
/// <summary> Converts a force-feedback command into bytes that the Nova can understand. </summary>
|
|
static std::string ToBytes(const Haptics::ForceFeedbackCommand& forceFeedbackCommand);
|
|
|
|
/// <summary> Converts a buzz-motor command into bytes that the Nova can understand. </summary>
|
|
static std::string ToBytes(const Haptics::BuzzCommand& buzzCommand);
|
|
|
|
private:
|
|
struct Impl;
|
|
std::unique_ptr<Impl> Pimpl;
|
|
|
|
public:
|
|
/// <summary> Default Constructor </summary>
|
|
/// <returns></returns>
|
|
NovaGlove();
|
|
|
|
/// <summary> Creates a new instance of a Nova Glove. </summary>
|
|
/// <param name="deviceInfo"></param>
|
|
/// <returns></returns>
|
|
explicit NovaGlove(const NovaGloveInfo& deviceInfo);
|
|
|
|
/**
|
|
* The copy constructor.
|
|
*/
|
|
NovaGlove(const NovaGlove& rhs);
|
|
|
|
/**
|
|
* The move constructor.
|
|
*/
|
|
NovaGlove(NovaGlove&& rhs) noexcept;
|
|
|
|
virtual ~NovaGlove() override;
|
|
|
|
public:
|
|
/**
|
|
* The copy assignment operator.
|
|
*/
|
|
NovaGlove& operator=(const NovaGlove& rhs);
|
|
|
|
/**
|
|
* The move assignment operator.
|
|
*/
|
|
NovaGlove& operator=(NovaGlove&& rhs) noexcept;
|
|
|
|
protected:
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
// Properties
|
|
|
|
/// <summary> Access all sorts of device info specific to this Nova. </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] const NovaGloveInfo& GetGloveInfo() const;
|
|
|
|
/// <summary> Returns true if this glove is meant for right hands. </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual bool IsRight() const override;
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// SGDevice Methods
|
|
|
|
/// <summary> Return the DeviceType of this Nova. </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual EDeviceType GetDeviceType() const override;
|
|
|
|
/// <summary> Returns this device's unique identifier. </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual std::string GetDeviceId() const override;
|
|
|
|
/// <summary> Access this device's hardware designation. </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual std::string GetHardwareVersion() const override;
|
|
|
|
/// <summary> Access this device's main firmware version. (ex: v3.2 -> 3) </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual int32_t GetFirmwareVersion() const override;
|
|
|
|
/// <summary> Access this device's sub-firmware version. (ex: v3.2 -> 2) </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual int32_t GetSubFirmwareVersion() const override;
|
|
|
|
public:
|
|
/// <summary> Returns true if this device operates on a battery </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual bool HasBattery() const override;
|
|
|
|
/// <summary> Returns true if this device is currently charging </summary>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual bool IsCharging() override;
|
|
|
|
/// <summary> Returns the device's battery level, as a value between 0 (empty) and 1 (full). </summary>
|
|
/// <param name="batteryLevel"></param>
|
|
/// <returns></returns>
|
|
[[nodiscard]] virtual bool GetBatteryLevel(float& out_batteryLevel) override;
|
|
|
|
public:
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
// Device Data
|
|
|
|
/// <summary> Get the latest Sensor Data from this Sense Glove. </summary>
|
|
/// <returns></returns>
|
|
bool GetSensorData(NovaGloveSensorData& out_sensorData);
|
|
|
|
/// <summary> Retrieve Nova rotation </summary>
|
|
/// <param name="IMU"></param>
|
|
/// <returns></returns>
|
|
virtual bool GetImuRotation(Kinematics::Quat& out_imu) override;
|
|
|
|
/// <summary> Retrieve a new hand pose using this glove, based on (calibrated) user data. </summary>
|
|
/// <param name="profile"></param>
|
|
/// <param name="solver"></param>
|
|
/// <param name="out_handPose"></param>
|
|
/// <returns></returns>
|
|
bool GetHandPose(const Kinematics::BasicHandModel& handModel, const NovaGloveHandProfile& profile,
|
|
HandPose& out_handPose);
|
|
|
|
/// <summary> Retrieve a new hand pose using this glove, based on (calibrated) user data. </summary>
|
|
/// <param name="handGeometry"></param>
|
|
/// <param name="handProfile"></param>
|
|
/// <param name="out_handPose"></param>
|
|
/// <returns></returns>
|
|
virtual bool GetHandPose(const Kinematics::BasicHandModel& handGeometry, const HandProfile& handProfile,
|
|
HandPose& out_handPose) override;
|
|
|
|
/// <summary> Calculate the HandPose of this Device, taking into account user values, but not hand geometry. </summary>
|
|
virtual bool GetHandPose(const HandProfile& handProfile, HandPose& out_handPose) override;
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// Haptics
|
|
|
|
/// <summary> Send all available haptics to a Nova. </summary>
|
|
/// <param name="forceFeedbackCommand"></param>
|
|
/// <param name="buzzCommand"></param>
|
|
/// <param name="thumperCommand"></param>
|
|
virtual void SendHaptics(const Haptics::ForceFeedbackCommand& forceFeedbackCommand,
|
|
const Haptics::BuzzCommand& buzzCommand,
|
|
const Haptics::ThumperCommand& thumperCommand) override;
|
|
|
|
/// <summary> Send Haptic Commands to this Glove. </summary>
|
|
virtual void SendHaptics(const Haptics::ForceFeedbackCommand& forceFeedbackCommand) override;
|
|
|
|
/// <summary> Send Haptic Commands to this Glove. </summary>
|
|
virtual void SendHaptics(const Haptics::BuzzCommand& buzzCommand) override;
|
|
|
|
/// <summary> Send Haptic Commands to this Glove. </summary>
|
|
virtual void SendHaptics(const Haptics::ThumperCommand& thumperCommand) override;
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// Calibration Methods
|
|
|
|
/// <summary> Retrieve calibration values of this glove, as an array of size 5, containing x (roll), y (flexion), z (abduction) values. </summary>
|
|
/// <param name="values"></param>
|
|
/// <returns></returns>
|
|
virtual bool GetCalibrationValues(std::vector<Kinematics::Vect3D>& out_values) override;
|
|
|
|
/// <summary> Applies the calibration range of this Nova a HandProfile </summary>
|
|
/// <param name="profile"></param>
|
|
virtual void ApplyCalibration(HandProfile& out_profile) const override;
|
|
|
|
/// <summary> Applies the calibration range of this SenseGlove to a NovaGloveHandProfile </summary>
|
|
/// <param name="profile"></param>
|
|
void ApplyCalibration(NovaGloveHandProfile& out_profile) const;
|
|
|
|
public:
|
|
//--------------------------------------------------------------------------------------
|
|
// 6DoF Position Tracking
|
|
|
|
/// <summary> Retrieve the location of the glove origin, based on a reference location. </summary>
|
|
/// <param name="referencePosition">Position of the tracked object, in mm, relative to your origin</param>
|
|
/// <param name="referenceRotation">Rotation of the tracked object relative to your origin</param>
|
|
/// <param name="trackingHardware">The hardware mounted on the Nova.</param>
|
|
/// <param name="out_glovePosition">The 3D Position of the glove, in mm, relative to your origin</param>
|
|
/// <param name="out_gloveRotation">The 3D Rotation of the glove, relative to your origin</param>
|
|
virtual void GetGloveLocation(const Kinematics::Vect3D& refPosition, const Kinematics::Quat& refRotation,
|
|
EPositionalTrackingHardware trackingHardware,
|
|
Kinematics::Vect3D& out_glovePosition,
|
|
Kinematics::Quat& out_gloveRotation) const override;
|
|
|
|
/// <summary> Retrieve the location of the wrist, based on a reference location and default glove-hand offsets. </summary>
|
|
/// <remarks> The simplest interface, using default offsets </remarks>
|
|
/// <param name="referencePosition">Position of the tracked object, in mm, relative to your origin</param>
|
|
/// <param name="referenceRotation">Rotation of the tracked object relative to your origin</param>
|
|
/// <param name="trackingHardware">The hardware mounted on the SenseGlove.</param>
|
|
/// <param name="out_wristPosition">The 3D Position of the wrist, in mm, relative to your origin</param>
|
|
/// <param name="out_wristRotation">The 3D Rotation of the wrist, relative to your origin</param>
|
|
virtual void GetWristLocation(const Kinematics::Vect3D& referencePosition,
|
|
const Kinematics::Quat& referenceRotation,
|
|
EPositionalTrackingHardware trackingHardware,
|
|
Kinematics::Vect3D& out_wristPosition,
|
|
Kinematics::Quat& out_wristRotation) const override;
|
|
|
|
public:
|
|
/// <summary> Create a string representation of this device for reporting purposes. </summary>
|
|
[[nodiscard]] virtual std::string ToString() const override;
|
|
}; |