Skip to content

Commit

Permalink
v0.4.1
Browse files Browse the repository at this point in the history
v0.4.1
  • Loading branch information
lucas-vrtech committed Aug 23, 2021
2 parents a572644 + 8b858f0 commit 31caa8d
Show file tree
Hide file tree
Showing 38 changed files with 1,052 additions and 876 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libraries/openvr"]
path = libraries/openvr
url = https://github.com/ValveSoftware/openvr.git
url = https://github.com/ValveSoftware/openvr.git
[submodule "libraries/tinygltf"]
path = libraries/tinygltf
url = https://github.com/syoyo/tinygltf.git
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Deps
set(OPENVR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/openvr/headers")
set(TINYGLTF_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/tinygltf")

set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})

Expand Down Expand Up @@ -35,7 +36,7 @@ file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

add_library("${OPENGLOVE_PROJECT}" SHARED "${HEADERS}" "${SOURCES}")

target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_INCLUDE_DIR}")
target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_INCLUDE_DIR}" "${TINYGLTF_INCLUDE_DIR}")

target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/")
target_link_libraries("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_LIB}" setupapi wsock32 ws2_32 bthprops)
Expand Down
125 changes: 77 additions & 48 deletions include/Bones.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,83 @@
#pragma once
#include <openvr_driver.h>

const int NUM_BONES = 31;
extern vr::VRBoneTransform_t rightOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t rightFistPose[NUM_BONES];
#include <array>
#include <memory>

#include "openvr_driver.h"

enum class HandSkeletonBone : vr::BoneIndex_t {
eBone_Root = 0,
eBone_Wrist,
eBone_Thumb0,
eBone_Thumb1,
eBone_Thumb2,
eBone_Thumb3,
eBone_IndexFinger0,
eBone_IndexFinger1,
eBone_IndexFinger2,
eBone_IndexFinger3,
eBone_IndexFinger4,
eBone_MiddleFinger0,
eBone_MiddleFinger1,
eBone_MiddleFinger2,
eBone_MiddleFinger3,
eBone_MiddleFinger4,
eBone_RingFinger0,
eBone_RingFinger1,
eBone_RingFinger2,
eBone_RingFinger3,
eBone_RingFinger4,
eBone_PinkyFinger0,
eBone_PinkyFinger1,
eBone_PinkyFinger2,
eBone_PinkyFinger3,
eBone_PinkyFinger4,
eBone_Aux_Thumb,
eBone_Aux_IndexFinger,
eBone_Aux_MiddleFinger,
eBone_Aux_RingFinger,
eBone_Aux_PinkyFinger,
eBone_Count
};

const short NUM_BONES = (short)HandSkeletonBone::eBone_Count;

extern vr::VRBoneTransform_t rightOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t leftOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t leftFistPose[NUM_BONES];

enum HandSkeletonBone : vr::BoneIndex_t {
eBone_Root = 0,
eBone_Wrist,
eBone_Thumb0,
eBone_Thumb1,
eBone_Thumb2,
eBone_Thumb3,
eBone_IndexFinger0,
eBone_IndexFinger1,
eBone_IndexFinger2,
eBone_IndexFinger3,
eBone_IndexFinger4,
eBone_MiddleFinger0,
eBone_MiddleFinger1,
eBone_MiddleFinger2,
eBone_MiddleFinger3,
eBone_MiddleFinger4,
eBone_RingFinger0,
eBone_RingFinger1,
eBone_RingFinger2,
eBone_RingFinger3,
eBone_RingFinger4,
eBone_PinkyFinger0,
eBone_PinkyFinger1,
eBone_PinkyFinger2,
eBone_PinkyFinger3,
eBone_PinkyFinger4,
eBone_Aux_Thumb,
eBone_Aux_IndexFinger,
eBone_Aux_MiddleFinger,
eBone_Aux_RingFinger,
eBone_Aux_PinkyFinger,
eBone_Count

struct Transform_t {
Transform_t();
std::array<float, 4> rotation;
std::array<float, 3> translation;
};

void ComputeBoneFlexion(vr::VRBoneTransform_t* bone_transform, float transform, int index, const bool isRightHand);
void ComputeBoneSplay(vr::VRBoneTransform_t* bone_transform, const float transform, int index, const bool isRightHand);
vr::HmdQuaternionf_t CalculateOrientation(const float transform, const int boneIndex, const vr::VRBoneTransform_t* openPose, const vr::VRBoneTransform_t* fistPose);
vr::HmdVector4_t CalculatePosition(const float transform, const int boneIndex, const vr::VRBoneTransform_t* openPose, const vr::VRBoneTransform_t* fistPose);
int FingerFromBone(vr::BoneIndex_t bone);
/**
*Linear interpolation between a and b.
**/
float Lerp(const float a, const float b, const float f);
struct AnimationData_t {
AnimationData_t();
Transform_t startTransform;
float startTime;
Transform_t endTransform;
float endTime;
};

class IModelManager {
public:
virtual bool Load() = 0;

virtual AnimationData_t GetAnimationDataByBoneIndex(const HandSkeletonBone& boneIndex, float f) const = 0;
virtual Transform_t GetTransformByBoneIndex(const HandSkeletonBone& boneIndex) const = 0;
};

class BoneAnimator {
public:
BoneAnimator(const std::string& fileName);
void ComputeSkeletonTransforms(vr::VRBoneTransform_t* skeleton, const std::array<float, 5>& flexion, const bool rightHand);
void TransformLeftBone(vr::VRBoneTransform_t& bone, const HandSkeletonBone& boneIndex);

private:
vr::VRBoneTransform_t GetTransformForBone(const HandSkeletonBone& boneIndex, const float f, const bool rightHand);

std::string m_fileName;
std::unique_ptr<IModelManager> m_modelManager;
bool m_loaded;
std::vector<float> m_keyframes;
};
4 changes: 2 additions & 2 deletions include/Calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Calibration {

void StartCalibration(vr::DriverPose_t maintainPose);

VRPoseConfiguration_t FinishCalibration(vr::TrackedDevicePose_t controllerPose, VRPoseConfiguration_t poseConfiguration, bool isRightHand);
VRPoseConfiguration_t CompleteCalibration(vr::TrackedDevicePose_t controllerPose, VRPoseConfiguration_t poseConfiguration, bool isRightHand);

void CancelCalibration();

Expand All @@ -19,5 +19,5 @@ class Calibration {

private:
vr::DriverPose_t m_maintainPose;
bool m_isCalibrating = false;
bool m_isCalibrating;
};
30 changes: 16 additions & 14 deletions include/Communication/BTSerialCommunicationManager.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#pragma once
#include <Winsock2.h>
#include <Ws2bth.h>
#include <bluetoothapis.h>
#include <windows.h>

#include <atomic>
#include <chrono>
#include <memory>
#include <mutex>
#include <sstream>
#include <thread>
#include <vector>
#include <mutex>

#include "CommunicationManager.h"
#include "DeviceConfiguration.h"
#include "DriverLog.h"

#include <windows.h>
#include <bluetoothapis.h>
#include <Ws2bth.h>


#define ARDUINO_WAIT_TIME 1000
class BTSerialCommunicationManager : public ICommunicationManager {
public:
BTSerialCommunicationManager(const VRBTSerialConfiguration_t& configuration, std::unique_ptr<IEncodingManager> encodingManager);
// connect to the device using serial
void Connect();

// start a thread that listens for updates from the device and calls the callback with data
void BeginListener(const std::function<void(VRCommData_t)>& callback);
// returns if connected or not
Expand All @@ -34,13 +30,19 @@ class BTSerialCommunicationManager : public ICommunicationManager {
void QueueSend(const VRFFBData_t& data);

private:
bool Connect();
void ListenerThread(const std::function<void(VRCommData_t)>& callback);
bool ReceiveNextPacket(std::string& buff);
bool getPairedDeviceBtAddress();
bool startupWindowsSocket();
bool connectToDevice();
bool sendMessageToDevice();
bool m_isConnected;
bool GetPairedDeviceBtAddress();
bool StartupWindowsSocket();
bool ConnectToDevice();
bool SendMessageToDevice();
void WaitAttemptConnection();
bool DisconnectFromDevice();
void LogError(const char* message);
void LogMessage(const char* message);

std::atomic<bool> m_isConnected;
std::atomic<bool> m_threadActive;
std::thread m_serialThread;

Expand Down
1 change: 0 additions & 1 deletion include/Communication/CommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class ICommunicationManager {
public:
virtual void Connect() = 0;
virtual void BeginListener(const std::function<void(VRCommData_t)>& callback) = 0;
virtual bool IsConnected() = 0;
virtual void Disconnect() = 0;
Expand Down
14 changes: 7 additions & 7 deletions include/Communication/SerialCommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "CommunicationManager.h"
#include "DeviceConfiguration.h"

#define ARDUINO_WAIT_TIME 1000

class SerialCommunicationManager : public ICommunicationManager {
public:
SerialCommunicationManager(const VRSerialConfiguration_t& configuration, std::unique_ptr<IEncodingManager> encodingManager)
Expand All @@ -27,22 +25,24 @@ class SerialCommunicationManager : public ICommunicationManager {

m_writeString = m_encodingManager->Encode(data);
};
// connect to the device using serial
void Connect();
// start a thread that listens for updates from the device and calls the callback with data

void BeginListener(const std::function<void(VRCommData_t)>& callback);
// returns if connected or not
bool IsConnected();
// close the serial port
void Disconnect();

void QueueSend(const VRFFBData_t& data);

private:
bool Connect();
void ListenerThread(const std::function<void(VRCommData_t)>& callback);
bool ReceiveNextPacket(std::string& buff);
bool PurgeBuffer();
bool Write();
void WaitAttemptConnection();
bool DisconnectFromDevice();

void LogMessage(const char* message);
void LogError(const char* message);

bool m_isConnected;
// Serial comm handler
Expand Down
7 changes: 4 additions & 3 deletions include/ControllerPose.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once
#include <openvr_driver.h>
#include <memory>

#include "DeviceConfiguration.h"
#include "ControllerDiscovery.h"
#include "Calibration.h"
#include "Util/NamedPipe.h"

class ControllerPose {
public:
Expand All @@ -14,7 +16,7 @@ class ControllerPose {

void StartCalibration();

void FinishCalibration();
void CompleteCalibration();

void CancelCalibration();

Expand All @@ -31,10 +33,9 @@ class ControllerPose {

vr::TrackedDevicePose_t GetControllerPose();

bool IsOtherRole(int32_t test);

bool isRightHand();

std::unique_ptr<ControllerDiscovery> m_controllerDiscoverer;
std::unique_ptr<NamedPipeUtil> m_calibrationPipe;
std::unique_ptr<Calibration> m_calibration;
};
20 changes: 13 additions & 7 deletions include/DeviceConfiguration.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
#pragma once

#include "openvr_driver.h"

#include "Communication/CommunicationManager.h"
#include "DeviceDriver/DeviceDriver.h"
#include "Encode/EncodingManager.h"
#include "openvr_driver.h"

static const char *c_driverSettingsSection = "driver_openglove";
static const char *c_poseSettingsSection = "pose_settings";
extern const char* c_poseSettingsSection;
extern const char* c_driverSettingsSection;
extern const char* c_serialCommunicationSettingsSection;
extern const char* c_btserialCommunicationSettingsSection;
extern const char* c_knuckleDeviceSettingsSection;
extern const char* c_lucidGloveDeviceSettingsSection;

enum VRCommunicationProtocol {
enum class VRCommunicationProtocol {
SERIAL = 0,
BTSERIAL = 1,
};

enum VREncodingProtocol {
enum class VREncodingProtocol {
LEGACY = 0,
ALPHA = 1,
};

enum VRDeviceDriver {
enum class VRDeviceDriver {
LUCIDGLOVES = 0,
EMULATED_KNUCKLES = 1,
};

struct VRSerialConfiguration_t {
std::string port;
int baudRate;

VRSerialConfiguration_t(std::string port) : port(port) {};
VRSerialConfiguration_t(std::string port, int baudRate) : port(port), baudRate(baudRate) {};
};

struct VRBTSerialConfiguration_t {
Expand Down
7 changes: 4 additions & 3 deletions include/DeviceDriver/KnuckleDriver.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#pragma once
#include <openvr_driver.h>

#include "openvr_driver.h"

#include <functional>
#include <memory>
Expand All @@ -15,7 +15,7 @@

class KnuckleDeviceDriver : public IDeviceDriver {
public:
KnuckleDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber);
KnuckleDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber, std::shared_ptr<BoneAnimator> boneAnimator);

vr::EVRInitError Activate(uint32_t unObjectId);
void Deactivate();
Expand Down Expand Up @@ -49,4 +49,5 @@ class KnuckleDeviceDriver : public IDeviceDriver {

std::unique_ptr<ControllerPose> m_controllerPose;
std::unique_ptr<FFBListener> m_ffbProvider;
std::shared_ptr<BoneAnimator> m_boneAnimator;
};
Loading

0 comments on commit 31caa8d

Please sign in to comment.