From e5dc8ed504ff9d9c93800ebecefaf91f77546451 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 10 Jan 2017 11:30:35 -0500 Subject: [PATCH 1/4] add TrackerSpin virtual plugin --- plugins/CMakeLists.txt | 1 + plugins/trackerspin/CMakeLists.txt | 25 +++ .../trackerspin/com_Sensics_Tracker_Spin.cpp | 175 ++++++++++++++++++ .../trackerspin/com_Sensics_Tracker_Spin.json | 22 +++ ...osvr_server_config.TrackerSpin.sample.json | 13 ++ 5 files changed, 236 insertions(+) create mode 100644 plugins/trackerspin/CMakeLists.txt create mode 100644 plugins/trackerspin/com_Sensics_Tracker_Spin.cpp create mode 100644 plugins/trackerspin/com_Sensics_Tracker_Spin.json create mode 100644 plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 618531424..ff6925c89 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(multiserver) +add_subdirectory(trackerspin) if(BUILD_OPENCV_CAMERA_PLUGIN) add_subdirectory(opencv) endif() diff --git a/plugins/trackerspin/CMakeLists.txt b/plugins/trackerspin/CMakeLists.txt new file mode 100644 index 000000000..ab4823f04 --- /dev/null +++ b/plugins/trackerspin/CMakeLists.txt @@ -0,0 +1,25 @@ +osvr_convert_json(com_Sensics_Tracker_Spin_json + com_Sensics_Tracker_Spin.json + "${CMAKE_CURRENT_BINARY_DIR}/com_Sensics_Tracker_Spin_json.h") + +# Be able to find our generated header file. +include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +# Build and install the plugin +osvr_add_plugin(com_Sensics_Tracker_Spin + SOURCES + com_Sensics_Tracker_Spin.cpp + "${CMAKE_CURRENT_BINARY_DIR}/com_Sensics_Tracker_Spin_json.h") + +target_link_libraries(com_Sensics_Tracker_Spin + osvrPluginKitCpp + osvrUtilCpp + JsonCpp::JsonCpp + vendored-vrpn) + +target_compile_options(com_Sensics_Tracker_Spin + PRIVATE + ${OSVR_CXX11_FLAGS}) + +set_target_properties(com_Sensics_Tracker_Spin PROPERTIES + FOLDER "OSVR Plugins") \ No newline at end of file diff --git a/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp b/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp new file mode 100644 index 000000000..30061df31 --- /dev/null +++ b/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp @@ -0,0 +1,175 @@ +/** @file + @brief Implementation + + @date 2016 + + @author + Sensics, Inc. + +*/ + +// Copyright 2016 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include +#include +#include +#include + +// Generated JSON header file +#include "com_Sensics_Tracker_Spin_json.h" + +// Library/third-party includes +#include +#include + +// Standard includes +#include +#include +#include + +// Anonymous namespace to avoid symbol collision +namespace { + +static const auto DRIVER_NAME = "TrackerSpin"; +static double inline getDefaultReportRate() { return 200.0; } +static double inline getDefaultXSpin() { return 0.0; } +static double inline getDefaultYSpin() { return 1.0; } +static double inline getDefaultZSpin() { return 0.0; } +static double inline getDefaultRotationRate() { return 0.1; } + +class TrackerSpinDevice { + public: + TrackerSpinDevice(OSVR_PluginRegContext ctx, std::string const &name, + double &axisX, double &axisY, double &axisZ, + double &updateRate, double &rotationRate) + : x(axisX), y(axisY), z(axisZ), reportRate(updateRate), + spinRate(rotationRate) { + + if (spinRate < 0.) { + x *= -1.; + y *= -1.; + z *= -1.; + } + + double dt; + if (spinRate == 0.) { + dt = 1.0; + } else { + dt = 0.9 * (0.5 / spinRate); + } + q_from_axis_angle(vel_quat, x, y, z, dt * spinRate * Q_PI); + vel_quat_dt = dt; + osvrTimeValueGetNow(×tamp); + osvrTimeValueGetNow(&start); + + /// Create the initialization options + OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); + + osvrDeviceTrackerConfigure(opts, &m_tracker); + + /// Create the device token with the options + m_dev.initAsync(ctx, name, opts); + + /// Send JSON descriptor + m_dev.sendJsonDescriptor(com_Sensics_Tracker_Spin_json); + + /// Register update callback + m_dev.registerUpdateCallback(this); + } + + OSVR_ReturnCode update() { + + osvrTimeValueGetNow(¤tTime); + /// time to report + if (osvrTimeValueDurationSeconds(¤tTime, ×tamp) >= + 1.0 / reportRate) { + timestamp.seconds = currentTime.seconds; + timestamp.microseconds = currentTime.microseconds; + double duration = + osvrTimeValueDurationSeconds(¤tTime, &start); + q_from_axis_angle(d_quat, x, y, z, duration * spinRate * 2 * Q_PI); + OSVR_OrientationState state; + osvrQuatSetW(&state, d_quat[3]); + osvrQuatSetX(&state, d_quat[0]); + osvrQuatSetY(&state, d_quat[1]); + osvrQuatSetZ(&state, d_quat[2]); + osvrDeviceTrackerSendOrientationTimestamped(m_dev, m_tracker, + &state, 0, ×tamp); + } + + OSVR_OrientationState orientState; + + return OSVR_RETURN_SUCCESS; + } + + private: + OSVR_TrackerDeviceInterface m_tracker; + osvr::pluginkit::DeviceToken m_dev; + double x, y, z, spinRate, reportRate, vel_quat_dt; + q_type vel_quat, d_quat; + OSVR_TimeValue timestamp, currentTime, start; +}; + +class TrackerSpinCreate { + public: + TrackerSpinCreate() {} + OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx, const char *params) { + Json::Value root; + { + Json::Reader reader; + if (!reader.parse(params, root)) { + std::cerr << "Couldn't parse JSON for tracker blendor!" + << std::endl; + return OSVR_RETURN_FAILURE; + } + } + + auto updateRate = + root.get("report_rate", getDefaultReportRate()).asDouble(); + auto xAxisSpin = + root.get("x_of_axis_to_spin_around", getDefaultXSpin()).asDouble(); + auto yAxisSpin = + root.get("y_of_axis_to_spin_around", getDefaultYSpin()).asDouble(); + auto zAxisSpin = + root.get("z_of_axis_to_spin_around", getDefaultZSpin()).asDouble(); + auto spinRate = root.get("rotation_rate_around_axis_in_Hz", + getDefaultRotationRate()) + .asDouble(); + // optional + auto deviceName = root.get("name", DRIVER_NAME).asString(); + + osvr::pluginkit::PluginContext context(ctx); + + /// @todo make the token own this instead once there is API for that. + context.registerObjectForDeletion( + new TrackerSpinDevice(ctx, deviceName, xAxisSpin, yAxisSpin, + zAxisSpin, updateRate, spinRate)); + return OSVR_RETURN_SUCCESS; + } +}; +} // namespace + +OSVR_PLUGIN(com_Sensics_Tracker_Spin) { + osvr::pluginkit::PluginContext context(ctx); + + /// Register a detection callback function object. + context.registerDriverInstantiationCallback(DRIVER_NAME, + TrackerSpinCreate()); + + return OSVR_RETURN_SUCCESS; +} diff --git a/plugins/trackerspin/com_Sensics_Tracker_Spin.json b/plugins/trackerspin/com_Sensics_Tracker_Spin.json new file mode 100644 index 000000000..65ab7e2a2 --- /dev/null +++ b/plugins/trackerspin/com_Sensics_Tracker_Spin.json @@ -0,0 +1,22 @@ +{ + "deviceVendor": "OSVR", + "deviceName": "Tracker Spin", + "author": "Georgiy Frolov ", + "version": 1, + "lastModified": "2017-01-09T21:13:07.585Z", + "interfaces": { + "tracker": { + "position": false, + "orientation": true, + "cout": 1 + } + }, + "semantic": { + "head": { + "$target": "tracker/0" + } + }, + "automaticAliases": { + "/me/head": "semantic/head" + } +} \ No newline at end of file diff --git a/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json b/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json new file mode 100644 index 000000000..06fefb38e --- /dev/null +++ b/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json @@ -0,0 +1,13 @@ +{ + "drivers": [{ + "plugin": "com_Sensics_Tracker_Spin", + "driver": "TrackerSpin", + "params": { + "report_rate": 400.0, + "x_of_axis_to_spin_around": 0.0, + "y_of_axis_to_spin_around": 1.0, + "z_of_axis_to_spin_around": 0.0, + "rotation_rate_around_axis_in_Hz": 0.1 + } + }] +} \ No newline at end of file From 498000e52d247d23ba676fbb9001aaff34c380c7 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 10 Jan 2017 12:50:22 -0500 Subject: [PATCH 2/4] add TrackeSpin README, add logic to only detect one device, update osvr_server_config --- plugins/trackerspin/README.md | 13 +++++++++++++ plugins/trackerspin/com_Sensics_Tracker_Spin.cpp | 14 ++++++++++++-- .../osvr_server_config.TrackerSpin.sample.json | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 plugins/trackerspin/README.md diff --git a/plugins/trackerspin/README.md b/plugins/trackerspin/README.md new file mode 100644 index 000000000..4b90f18d8 --- /dev/null +++ b/plugins/trackerspin/README.md @@ -0,0 +1,13 @@ +# OSVR-Tracker-Spin Plugin + +This plugin is adapter from VRPN Tracker Spin, which is a virtual plugin for a tracker that stays around the origin and spin around the specified axis at the specified rate of rotation, reporting orientation at specified rate. +It can be used to test the smoothness of rendering for VR system. + +You will need to provide parameters in osvr_server config file: + +1. `report_rate` (default 200.0) - Rate at which reports will be sent, +2. `x_of_axis_to_spin_around` (default 0.0) - How much to spin around X axis +3. `y_of_axis_to_spin_around`: (default 1.0) - How much to spin around Y axis +3. `z_of_axis_to_spin_around`: (default 0.0) - How much to spin around Z axis +4. `rotation_rate_around_axis_in_Hz`: (default 0.1) - How fast to spin the tracker +5. `name`: `TrackerSpin` (optional) \ No newline at end of file diff --git a/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp b/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp index 30061df31..44dd79250 100644 --- a/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp +++ b/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp @@ -127,13 +127,20 @@ class TrackerSpinDevice { class TrackerSpinCreate { public: - TrackerSpinCreate() {} + TrackerSpinCreate() : m_found(false) {} OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx, const char *params) { + + if (m_found) { + return OSVR_RETURN_SUCCESS; + } + + m_found = true; + Json::Value root; { Json::Reader reader; if (!reader.parse(params, root)) { - std::cerr << "Couldn't parse JSON for tracker blendor!" + std::cerr << "Couldn't parse JSON for tracker spin!" << std::endl; return OSVR_RETURN_FAILURE; } @@ -161,6 +168,9 @@ class TrackerSpinCreate { zAxisSpin, updateRate, spinRate)); return OSVR_RETURN_SUCCESS; } + + private: + bool m_found; }; } // namespace diff --git a/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json b/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json index 06fefb38e..9254201ae 100644 --- a/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json +++ b/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json @@ -7,7 +7,8 @@ "x_of_axis_to_spin_around": 0.0, "y_of_axis_to_spin_around": 1.0, "z_of_axis_to_spin_around": 0.0, - "rotation_rate_around_axis_in_Hz": 0.1 + "rotation_rate_around_axis_in_Hz": 0.1, + "name": "TrackerSpin" } }] } \ No newline at end of file From cf2061f5598784699cecc99aff3162cf297135ae Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 18 Jan 2017 14:34:53 -0500 Subject: [PATCH 3/4] remove TrackerSpin from default plugins and move it to example plugins --- examples/plugin/CMakeLists.txt | 17 +++++++++++++ .../plugin/com_osvr_example_TrackerSpin.cpp | 9 +++---- .../plugin/com_osvr_example_TrackerSpin.json | 0 ...osvr_server_config.TrackerSpin.sample.json | 15 +++++++++++ plugins/CMakeLists.txt | 1 - plugins/trackerspin/CMakeLists.txt | 25 ------------------- plugins/trackerspin/README.md | 13 ---------- ...osvr_server_config.TrackerSpin.sample.json | 14 ----------- 8 files changed, 35 insertions(+), 59 deletions(-) rename plugins/trackerspin/com_Sensics_Tracker_Spin.cpp => examples/plugin/com_osvr_example_TrackerSpin.cpp (95%) rename plugins/trackerspin/com_Sensics_Tracker_Spin.json => examples/plugin/com_osvr_example_TrackerSpin.json (100%) create mode 100644 examples/plugin/osvr_server_config.TrackerSpin.sample.json delete mode 100644 plugins/trackerspin/CMakeLists.txt delete mode 100644 plugins/trackerspin/README.md delete mode 100644 plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json diff --git a/examples/plugin/CMakeLists.txt b/examples/plugin/CMakeLists.txt index 00604e724..ec2acf07c 100644 --- a/examples/plugin/CMakeLists.txt +++ b/examples/plugin/CMakeLists.txt @@ -12,6 +12,7 @@ set(OSVR_EXAMPLE_DEVICE_PLUGINS_SIMPLE set(OSVR_EXAMPLE_DEVICE_PLUGINS com_osvr_example_selfcontained org_osvr_example_SampleCPlugin + com_osvr_example_TrackerSpin ${OSVR_EXAMPLE_DEVICE_PLUGINS_SIMPLE} CACHE INTERNAL "" FORCE) @@ -72,6 +73,22 @@ osvr_add_plugin(NAME org_osvr_example_SampleCPlugin set_target_properties(org_osvr_example_SampleCPlugin PROPERTIES FOLDER "OSVR Example Plugins") +## Build the TrackerSpin example +osvr_convert_json(com_osvr_example_TrackerSpin_json + com_osvr_example_TrackerSpin.json + "${CMAKE_CURRENT_BINARY_DIR}/com_osvr_example_TrackerSpin_json.h") +osvr_add_plugin(com_osvr_example_TrackerSpin + NO_INSTALL MANUAL_LOAD CPP + SOURCES + com_osvr_example_TrackerSpin.cpp + "${CMAKE_CURRENT_BINARY_DIR}/com_osvr_example_TrackerSpin_json.h") +target_link_libraries(com_osvr_example_TrackerSpin + JsonCpp::JsonCpp + vendored-vrpn + osvr_cxx11_flags) +set_target_properties(com_osvr_example_TrackerSpin PROPERTIES + FOLDER "OSVR Example Plugins") + # Put all the example plugins in a suitable solution folder. foreach(pluginname ${OSVR_EXAMPLE_DEVICE_PLUGINS}) diff --git a/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp b/examples/plugin/com_osvr_example_TrackerSpin.cpp similarity index 95% rename from plugins/trackerspin/com_Sensics_Tracker_Spin.cpp rename to examples/plugin/com_osvr_example_TrackerSpin.cpp index 44dd79250..9a0a7e8e7 100644 --- a/plugins/trackerspin/com_Sensics_Tracker_Spin.cpp +++ b/examples/plugin/com_osvr_example_TrackerSpin.cpp @@ -25,13 +25,10 @@ // Internal Includes #include #include -#include -#include -#include #include // Generated JSON header file -#include "com_Sensics_Tracker_Spin_json.h" +#include "com_osvr_example_TrackerSpin_json.h" // Library/third-party includes #include @@ -86,7 +83,7 @@ class TrackerSpinDevice { m_dev.initAsync(ctx, name, opts); /// Send JSON descriptor - m_dev.sendJsonDescriptor(com_Sensics_Tracker_Spin_json); + m_dev.sendJsonDescriptor(com_osvr_example_TrackerSpin_json); /// Register update callback m_dev.registerUpdateCallback(this); @@ -174,7 +171,7 @@ class TrackerSpinCreate { }; } // namespace -OSVR_PLUGIN(com_Sensics_Tracker_Spin) { +OSVR_PLUGIN(com_osvr_example_TrackerSpin) { osvr::pluginkit::PluginContext context(ctx); /// Register a detection callback function object. diff --git a/plugins/trackerspin/com_Sensics_Tracker_Spin.json b/examples/plugin/com_osvr_example_TrackerSpin.json similarity index 100% rename from plugins/trackerspin/com_Sensics_Tracker_Spin.json rename to examples/plugin/com_osvr_example_TrackerSpin.json diff --git a/examples/plugin/osvr_server_config.TrackerSpin.sample.json b/examples/plugin/osvr_server_config.TrackerSpin.sample.json new file mode 100644 index 000000000..4c23e45af --- /dev/null +++ b/examples/plugin/osvr_server_config.TrackerSpin.sample.json @@ -0,0 +1,15 @@ +{ + "desciprtion" : "This plugin is adapter from VRPN Tracker Spin, which is a virtual plugin for a tracker that stays around the origin and spin around the specified axis at the specified rate of rotation, reporting orientation at specified rate. It can be used to test the smoothness of rendering for VR system." + "drivers": [{ + "plugin": "com_osvr_example_TrackerSpin", + "driver": "TrackerSpin", + "params": { + "report_rate": 400.0, /* (default 200.0) - Rate at which reports will be sent */ + "x_of_axis_to_spin_around": 0.0, /* (default 0.0) - How much to spin around X axis */ + "y_of_axis_to_spin_around": 1.0, /* (default 1.0) - How much to spin around Y axis */ + "z_of_axis_to_spin_around": 0.0, /* (default 0.0) - How much to spin around Z axis */ + "rotation_rate_around_axis_in_Hz": 0.1, /* (default 0.1) - How fast to spin the tracker */ + "name": "TrackerSpin" /* (optional) */ + } + }] +} \ No newline at end of file diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ff6925c89..618531424 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(multiserver) -add_subdirectory(trackerspin) if(BUILD_OPENCV_CAMERA_PLUGIN) add_subdirectory(opencv) endif() diff --git a/plugins/trackerspin/CMakeLists.txt b/plugins/trackerspin/CMakeLists.txt deleted file mode 100644 index ab4823f04..000000000 --- a/plugins/trackerspin/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -osvr_convert_json(com_Sensics_Tracker_Spin_json - com_Sensics_Tracker_Spin.json - "${CMAKE_CURRENT_BINARY_DIR}/com_Sensics_Tracker_Spin_json.h") - -# Be able to find our generated header file. -include_directories("${CMAKE_CURRENT_BINARY_DIR}") - -# Build and install the plugin -osvr_add_plugin(com_Sensics_Tracker_Spin - SOURCES - com_Sensics_Tracker_Spin.cpp - "${CMAKE_CURRENT_BINARY_DIR}/com_Sensics_Tracker_Spin_json.h") - -target_link_libraries(com_Sensics_Tracker_Spin - osvrPluginKitCpp - osvrUtilCpp - JsonCpp::JsonCpp - vendored-vrpn) - -target_compile_options(com_Sensics_Tracker_Spin - PRIVATE - ${OSVR_CXX11_FLAGS}) - -set_target_properties(com_Sensics_Tracker_Spin PROPERTIES - FOLDER "OSVR Plugins") \ No newline at end of file diff --git a/plugins/trackerspin/README.md b/plugins/trackerspin/README.md deleted file mode 100644 index 4b90f18d8..000000000 --- a/plugins/trackerspin/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# OSVR-Tracker-Spin Plugin - -This plugin is adapter from VRPN Tracker Spin, which is a virtual plugin for a tracker that stays around the origin and spin around the specified axis at the specified rate of rotation, reporting orientation at specified rate. -It can be used to test the smoothness of rendering for VR system. - -You will need to provide parameters in osvr_server config file: - -1. `report_rate` (default 200.0) - Rate at which reports will be sent, -2. `x_of_axis_to_spin_around` (default 0.0) - How much to spin around X axis -3. `y_of_axis_to_spin_around`: (default 1.0) - How much to spin around Y axis -3. `z_of_axis_to_spin_around`: (default 0.0) - How much to spin around Z axis -4. `rotation_rate_around_axis_in_Hz`: (default 0.1) - How fast to spin the tracker -5. `name`: `TrackerSpin` (optional) \ No newline at end of file diff --git a/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json b/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json deleted file mode 100644 index 9254201ae..000000000 --- a/plugins/trackerspin/osvr_server_config.TrackerSpin.sample.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "drivers": [{ - "plugin": "com_Sensics_Tracker_Spin", - "driver": "TrackerSpin", - "params": { - "report_rate": 400.0, - "x_of_axis_to_spin_around": 0.0, - "y_of_axis_to_spin_around": 1.0, - "z_of_axis_to_spin_around": 0.0, - "rotation_rate_around_axis_in_Hz": 0.1, - "name": "TrackerSpin" - } - }] -} \ No newline at end of file From ea312e24470e54df4e78a0405339e3e61b55c4b9 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 18 Jan 2017 14:42:48 -0500 Subject: [PATCH 4/4] add position in device descriptor because the plugin reports full pose (position and orientation) --- examples/plugin/org_osvr_example_Tracker.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plugin/org_osvr_example_Tracker.json b/examples/plugin/org_osvr_example_Tracker.json index 281ff9e13..739431099 100644 --- a/examples/plugin/org_osvr_example_Tracker.json +++ b/examples/plugin/org_osvr_example_Tracker.json @@ -8,7 +8,7 @@ "tracker": { "count": 1, "bounded": true, - "position": false, + "position": true, "orientation": true } },