-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TrackerSpin virtual plugin #519
Open
gfrolov
wants to merge
5
commits into
master
Choose a base branch
from
trackerSpin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e5dc8ed
add TrackerSpin virtual plugin
498000e
add TrackeSpin README, add logic to only detect one device, update os…
cf2061f
remove TrackerSpin from default plugins and move it to example plugins
ea312e2
add position in device descriptor because the plugin reports full pos…
2e9dc46
Merge branch 'master' into trackerSpin
rpavlik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/** @file | ||
@brief Implementation | ||
|
||
@date 2016 | ||
|
||
@author | ||
Sensics, Inc. | ||
<http://sensics.com/osvr> | ||
*/ | ||
|
||
// 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 <osvr/PluginKit/PluginKit.h> | ||
#include <osvr/PluginKit/TrackerInterfaceC.h> | ||
#include <quat/quat.h> | ||
|
||
// Generated JSON header file | ||
#include "com_osvr_example_TrackerSpin_json.h" | ||
|
||
// Library/third-party includes | ||
#include <json/reader.h> | ||
#include <json/value.h> | ||
|
||
// Standard includes | ||
#include <iostream> | ||
#include <memory> | ||
#include <vector> | ||
|
||
// 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_osvr_example_TrackerSpin_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() : 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 spin!" | ||
<< 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; | ||
} | ||
|
||
private: | ||
bool m_found; | ||
}; | ||
} // namespace | ||
|
||
OSVR_PLUGIN(com_osvr_example_TrackerSpin) { | ||
osvr::pluginkit::PluginContext context(ctx); | ||
|
||
/// Register a detection callback function object. | ||
context.registerDriverInstantiationCallback(DRIVER_NAME, | ||
TrackerSpinCreate()); | ||
|
||
return OSVR_RETURN_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"deviceVendor": "OSVR", | ||
"deviceName": "Tracker Spin", | ||
"author": "Georgiy Frolov <[email protected]>", | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
examples/plugin/osvr_server_config.TrackerSpin.sample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) */ | ||
} | ||
}] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually get this installed, since it's useful for testing? I don't think we need manual_load here either, since it has a constructor argument.