Skip to content

Commit

Permalink
Merge pull request #37 from OSVR/openvr110
Browse files Browse the repository at this point in the history
Update to OpenVR 1.0.11, Support Multiple Vive Trackers
  • Loading branch information
mars979 authored Dec 10, 2017
2 parents e0ebcdb + 13dcfa3 commit f70a570
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ osvr_add_plugin(com_osvr_Vive
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_Vive_json.h"
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_ViveSync_json.h")

target_link_libraries(com_osvr_Vive ViveLoaderLib)
target_link_libraries(com_osvr_Vive ViveLoaderLib JsonCpp::JsonCpp)
target_include_directories(com_osvr_Vive
PRIVATE
${EIGEN3_INCLUDE_DIR})
Expand Down
90 changes: 76 additions & 14 deletions OSVRViveTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "com_osvr_Vive_json.h"

// Library/third-party includes
#include "json/reader.h"
#include <boost/assert.hpp>
#include <osvr/Util/EigenCoreGeometry.h>
#include <osvr/Util/EigenInterop.h>
Expand All @@ -49,8 +50,9 @@ namespace vive {
/// sensor numbers in SteamVR and for tracking
static const auto HMD_SENSOR = 0;
static const auto CONTROLLER_SENSORS = {1, 2};
static const auto PUCK_SENSOR = 3;
static const auto MAX_CONTROLLER_ID = 2;
static const auto BASE_STATIONS_SENSORS = {3, 4};
static const auto PUCK_SENSOR = 5;

static const auto NUM_ANALOGS = 7;
static const auto NUM_BUTTONS = 14;
Expand Down Expand Up @@ -80,6 +82,11 @@ namespace vive {
static const auto TRACKPAD_Y_ANALOG_OFFSET = 1;
static const auto TRIGGER_ANALOG_OFFSET = 2;

/// Device descriptor values
static const auto TRACKER_VALUE = "tracker";
static const auto PUCK_KEY = "pucks";
static const auto SEMANTIC_KEY = "semantic";

/// Add a util::time::TimeValue and a std::chrono::duration, returning a
/// TimeValue again.
///
Expand Down Expand Up @@ -117,7 +124,8 @@ namespace vive {
ViveDriverHost::ViveDriverHost()
: m_universeXform(Eigen::Isometry3d::Identity()),
m_universeRotation(Eigen::Quaterniond::Identity()),
m_logger(osvr::util::log::make_logger(PREFIX)) {}
m_logger(osvr::util::log::make_logger(PREFIX)),
m_puckIdx(PUCK_SENSOR), m_devDescriptor(com_osvr_Vive_json) {}

ViveDriverHost::StartResult
ViveDriverHost::start(OSVR_PluginRegContext ctx,
Expand All @@ -139,7 +147,7 @@ namespace vive {
m_logger->info("null input device");
return false;
}
auto ret = activateDevice(dev, eDeviceClass);
auto ret = activateDevice(serialNum, dev, eDeviceClass);
if (!ret) {
m_logger->error("Device with serial number ")
<< serialNum << " couldn't be added to the devices vector.";
Expand Down Expand Up @@ -215,7 +223,7 @@ namespace vive {
m_dev.initSync(ctx, "Vive", opts);

/// Send JSON descriptor
m_dev.sendJsonDescriptor(com_osvr_Vive_json);
m_dev.sendJsonDescriptor(m_devDescriptor);

/// Register update callback
m_dev.registerUpdateCallback(this);
Expand Down Expand Up @@ -292,9 +300,10 @@ namespace vive {
}

ViveDriverHost::DevIdReturnValue
ViveDriverHost::activateDevice(vr::ITrackedDeviceServerDriver *dev,
ViveDriverHost::activateDevice(const char *serialNumber,
vr::ITrackedDeviceServerDriver *dev,
vr::ETrackedDeviceClass trackedDeviceClass) {
auto ret = activateDeviceImpl(dev, trackedDeviceClass);
auto ret = activateDeviceImpl(serialNumber, dev, trackedDeviceClass);
vr::TrackedDeviceIndex_t idx = ret.value;
auto mfrProp = getProperty<Props::ManufacturerName>(idx);
auto modelProp = getProperty<Props::ModelNumber>(idx);
Expand All @@ -311,7 +320,7 @@ namespace vive {
}

ViveDriverHost::DevIdReturnValue ViveDriverHost::activateDeviceImpl(
vr::ITrackedDeviceServerDriver *dev,
const char *serialNumber, vr::ITrackedDeviceServerDriver *dev,
vr::ETrackedDeviceClass trackedDeviceClass) {
auto &devs = m_vive->devices();
if (getComponent<vr::IVRDisplayComponent>(dev)) {
Expand All @@ -325,8 +334,17 @@ namespace vive {
/// This is a controller.... or a puck!
if (trackedDeviceClass ==
vr::ETrackedDeviceClass::TrackedDeviceClass_GenericTracker) {
// puck
return devs.addAndActivateDeviceAt(dev, PUCK_SENSOR);
/// find the next available device id because number of pucks
/// is dynamic
while (devs.hasDeviceAt(m_puckIdx)) {
m_puckIdx++;
}
auto ret = devs.addAndActivateDeviceAt(dev, m_puckIdx);
// need to update device descriptor
AddDeviceToDevDescriptor(serialNumber, m_puckIdx);
DeviceDescriptorUpdated();
m_puckIdx++;
return ret;
}
// controllers
for (auto ctrlIdx : CONTROLLER_SENSORS) {
Expand All @@ -336,6 +354,16 @@ namespace vive {
}
}

/// this is a base station
if (trackedDeviceClass ==
vr::ETrackedDeviceClass::TrackedDeviceClass_TrackingReference) {
for (auto ctrlIdx : BASE_STATIONS_SENSORS) {
if (!devs.hasDeviceAt(ctrlIdx)) {
return devs.addAndActivateDeviceAt(dev, ctrlIdx);
}
}
}

/// This still may be a controller, if somehow there are more than
/// 2...
return devs.addAndActivateDevice(dev);
Expand Down Expand Up @@ -787,13 +815,47 @@ namespace vive {
state, eventTimeOffset);
}
}
#if 0
void
ViveDriverHost::DeviceDescriptorUpdated(std::string const &json) {

m_dev.sendJsonDescriptor(json);
void ViveDriverHost::DeviceDescriptorUpdated() {
try {
m_dev.sendJsonDescriptor(m_devDescriptor);
} catch (std::logic_error &e) {
/// dev token hasn't been activated yet
/// we already update device descriptor so it will be sent once
/// token is activated
m_logger->info(e.what());
}
}

void ViveDriverHost::AddDeviceToDevDescriptor(const char *serialNumber,
uint32_t deviceIndex) {

m_logger->debug("AddDeviceToDevDescriptor, serialNumber: ")
<< std::string(serialNumber);

Json::Value root;
Json::Reader reader;
if (!reader.parse(m_devDescriptor, root)) {
m_logger->error("Could not parse device descriptor");
} else {
std::ostringstream trackerVal;
trackerVal << TRACKER_VALUE << "/" << deviceIndex;
std::string puckAlias = serialNumber;
/// in case serial number is not available
if (puckAlias.empty()) {
m_logger->info("Serial number not available. Using device "
"index to enumerate Vive Tracker (Puck) in "
"device descriptor");
uint32_t puckIdx = deviceIndex - PUCK_SENSOR;
puckAlias = std::to_string(puckIdx);
}
root[SEMANTIC_KEY][PUCK_KEY][puckAlias] = trackerVal.str();
m_logger->info("Added Vive Tracker (Puck) : "
"/com_osvr_Vive/Vive/semantic/pucks/")
<< puckAlias << " -> /com_osvr_Vive/Vive/" << trackerVal.str();
m_devDescriptor = root.toStyledString();
}
}
#endif

} // namespace vive
} // namespace osvr
20 changes: 14 additions & 6 deletions OSVRViveTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ namespace vive {
/// to activate. Delegates the real work - this just displays
/// information.
DevIdReturnValue
activateDevice(vr::ITrackedDeviceServerDriver *dev,
activateDevice(const char *serialNumber,
vr::ITrackedDeviceServerDriver *dev,
vr::ETrackedDeviceClass trackedDeviceClass);

/// @name ServerDriverHost overrides - called from a tracker thread (not
Expand Down Expand Up @@ -140,11 +141,15 @@ namespace vive {
const VRControllerAxis_t &axisState) override;

IVRSettings *GetSettings(const char *) { return nullptr; }
/// @}
/// @}

/// Add new Vive Tracker aka Puck to the device descriptor
/// Called when more than 1 puck is connected
/// todo Can be expanded to add controllers
void AddDeviceToDevDescriptor(const char *serialNumber,
uint32_t deviceIndex);

#if 0
void DeviceDescriptorUpdated(std::string const &json);
#endif
void DeviceDescriptorUpdated();

private:
std::ostream &msg() const;
Expand Down Expand Up @@ -175,7 +180,8 @@ namespace vive {

/// Does the real work of adding a new device.
DevIdReturnValue
activateDeviceImpl(vr::ITrackedDeviceServerDriver *dev,
activateDeviceImpl(const char *serialNumber,
vr::ITrackedDeviceServerDriver *dev,
vr::ETrackedDeviceClass trackedDeviceClass);

osvr::pluginkit::DeviceToken m_dev;
Expand Down Expand Up @@ -238,6 +244,8 @@ namespace vive {
Eigen::Quaterniond m_universeRotation;
std::vector<vr::ETrackingResult> m_trackingResults;

std::uint32_t m_puckIdx;
std::string m_devDescriptor;
/// @}
};
using DriverHostPtr = std::unique_ptr<ViveDriverHost>;
Expand Down
53 changes: 53 additions & 0 deletions PropertyTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace vive {
ViveSystemButtonFixRequired = vr::Prop_ViveSystemButtonFixRequired_Bool,
ParentDriver = vr::Prop_ParentDriver_Uint64,
ResourceRoot = vr::Prop_ResourceRoot_String,
RegisteredDeviceType = vr::Prop_RegisteredDeviceType_String,
InputProfileName = vr::Prop_InputProfileName_String,
ReportsTimeSinceVSync = vr::Prop_ReportsTimeSinceVSync_Bool,
SecondsFromVsyncToPhotons = vr::Prop_SecondsFromVsyncToPhotons_Float,
DisplayFrequency = vr::Prop_DisplayFrequency_Float,
Expand Down Expand Up @@ -145,6 +147,18 @@ namespace vive {
vr::Prop_DriverDirectModeSendsVsyncEvents_Bool,
DisplayDebugMode = vr::Prop_DisplayDebugMode_Bool,
GraphicsAdapterLuid = vr::Prop_GraphicsAdapterLuid_Uint64,
DriverProvidedChaperonePath =
vr::Prop_DriverProvidedChaperonePath_String,
ExpectedTrackingReferenceCount =
vr::Prop_ExpectedTrackingReferenceCount_Int32,
ExpectedControllerCount = vr::Prop_ExpectedControllerCount_Int32,
NamedIconPathControllerLeftDeviceOff =
vr::Prop_NamedIconPathControllerLeftDeviceOff_String,
NamedIconPathControllerRightDeviceOff =
vr::Prop_NamedIconPathControllerRightDeviceOff_String,
NamedIconPathTrackingReferenceDeviceOff =
vr::Prop_NamedIconPathTrackingReferenceDeviceOff_String,
DoNotApplyPrediction = vr::Prop_DoNotApplyPrediction_Bool,
AttachedDeviceId = vr::Prop_AttachedDeviceId_String,
SupportedButtons = vr::Prop_SupportedButtons_Uint64,
Axis0Type = vr::Prop_Axis0Type_Int32,
Expand Down Expand Up @@ -314,6 +328,13 @@ namespace vive {
using type = std::string;
};
template <>
struct PropertyTypeTrait<vr::Prop_RegisteredDeviceType_String> {
using type = std::string;
};
template <> struct PropertyTypeTrait<vr::Prop_InputProfileName_String> {
using type = std::string;
};
template <>
struct PropertyTypeTrait<vr::Prop_ReportsTimeSinceVSync_Bool> {
using type = bool;
};
Expand Down Expand Up @@ -481,6 +502,38 @@ namespace vive {
struct PropertyTypeTrait<vr::Prop_GraphicsAdapterLuid_Uint64> {
using type = uint64_t;
};
template <>
struct PropertyTypeTrait<vr::Prop_DriverProvidedChaperonePath_String> {
using type = std::string;
};
template <>
struct PropertyTypeTrait<
vr::Prop_ExpectedTrackingReferenceCount_Int32> {
using type = int32_t;
};
template <>
struct PropertyTypeTrait<vr::Prop_ExpectedControllerCount_Int32> {
using type = int32_t;
};
template <>
struct PropertyTypeTrait<
vr::Prop_NamedIconPathControllerLeftDeviceOff_String> {
using type = std::string;
};
template <>
struct PropertyTypeTrait<
vr::Prop_NamedIconPathControllerRightDeviceOff_String> {
using type = std::string;
};
template <>
struct PropertyTypeTrait<
vr::Prop_NamedIconPathTrackingReferenceDeviceOff_String> {
using type = std::string;
};
template <>
struct PropertyTypeTrait<vr::Prop_DoNotApplyPrediction_Bool> {
using type = bool;
};
template <> struct PropertyTypeTrait<vr::Prop_AttachedDeviceId_String> {
using type = std::string;
};
Expand Down
7 changes: 7 additions & 0 deletions ServerDriverHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ void ServerDriverHost::GetRawTrackedDevicePoses(
logger_->debug("GetRawTrackedDevicePoses(")
<< fPredictedSecondsFromNow << ", " << unTrackedDevicePoseArrayCount
<< ")";
}

void ServerDriverHost::TrackedDeviceDisplayTransformUpdated(
uint32_t unWhichDevice, HmdMatrix34_t eyeToHeadLeft,
HmdMatrix34_t eyeToHeadRight) {
logger_->debug("TrackedDeviceDisplayTransformUpdated(")
<< unWhichDevice << ", eyeToHeadLeft, eyeToHeadRight)";
}
5 changes: 5 additions & 0 deletions ServerDriverHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ServerDriverHost : public vr::IVRServerDriverHost {
TrackedDevicePose_t *pTrackedDevicePoseArray,
uint32_t unTrackedDevicePoseArrayCount);

virtual void
TrackedDeviceDisplayTransformUpdated(uint32_t unWhichDevice,
HmdMatrix34_t eyeToHeadLeft,
HmdMatrix34_t eyeToHeadRight);

IVRSettings *vrSettings = nullptr;

private:
Expand Down
15 changes: 8 additions & 7 deletions com_osvr_Vive.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
}
},
"semantic": {
"hmd": {
"hmd": {
"$target": "tracker/0",
"button": "button/0",
"button": "button/0",
"proximity": "button/1"
},
"puck": {
"$target": "tracker/3"
},
},
"baseStations": {
"0": "tracker/3",
"1": "tracker/4"
},
"pucks": {},
"ipd": "analog/0",
"controller": {
"left": {
Expand Down Expand Up @@ -65,7 +67,6 @@
},
"automaticAliases": {
"/me/head": "semantic/hmd",
"/me/puck": "semantic/puck",
"/me/ipd": "semantic/ipd",
"/controller": "semantic/controller/*",
"/me/hands/left": "semantic/controller/left",
Expand Down
2 changes: 1 addition & 1 deletion vendor/openvr
Submodule openvr updated 42 files
+ bin/linux32/libopenvr_api.so
+ bin/linux32/libopenvr_api.so.dbg
+ bin/linux64/libopenvr_api.so
+ bin/linux64/libopenvr_api.so.dbg
+ bin/osx32/libopenvr_api.dylib
+ bin/osx32/libopenvr_api.dylib.dSYM/Contents/Resources/DWARF/libopenvr_api.dylib
+124 −68 bin/osx64/OpenVR.framework/Versions/A/Headers/openvr.h
+60 −5 bin/osx64/OpenVR.framework/Versions/A/Headers/openvr_api.cs
+39 −3 bin/osx64/OpenVR.framework/Versions/A/Headers/openvr_api.json
+27 −3 bin/osx64/OpenVR.framework/Versions/A/Headers/openvr_capi.h
+77 −59 bin/osx64/OpenVR.framework/Versions/A/Headers/openvr_driver.h
+ bin/osx64/OpenVR.framework/Versions/A/OpenVR
+ bin/win32/openvr_api.dll
+ bin/win32/openvr_api.pdb
+ bin/win64/openvr_api.dll
+ bin/win64/openvr_api.pdb
+213 −78 headers/openvr.h
+148 −7 headers/openvr_api.cs
+130 −6 headers/openvr_api.json
+100 −5 headers/openvr_capi.h
+159 −69 headers/openvr_driver.h
+ lib/linux32/libopenvr_api.so
+ lib/linux64/libopenvr_api.so
+ lib/win32/openvr_api.lib
+ lib/win64/openvr_api.lib
+ samples/bin/linux64/libopenvr_api.so
+ samples/bin/osx32/libopenvr_api.dylib
+ samples/bin/win32/openvr_api.dll
+ samples/bin/win64/openvr_api.dll
+2 −2 samples/driver_sample/driver_sample.cpp
+5 −2 samples/hellovr_opengl/hellovr_opengl_main.cpp
+27 −9 samples/hellovr_vulkan/hellovr_vulkan_main.cpp
+5 −4 samples/shared/pathtools.cpp
+2 −2 src/ivrclientcore.h
+36 −22 src/openvr_api_public.cpp
+1 −1 src/vrcommon/envvartools_public.cpp
+74 −70 src/vrcommon/hmderrors_public.cpp
+10 −8 src/vrcommon/pathtools_public.cpp
+2 −2 src/vrcommon/sharedlibtools_public.cpp
+18 −0 src/vrcommon/strtools_public.cpp
+3 −0 src/vrcommon/strtools_public.h
+5 −3 src/vrcommon/vrpathregistry_public.cpp

0 comments on commit f70a570

Please sign in to comment.