43 #include <boost/program_options.hpp>
44 #include <boost/thread/thread.hpp>
45 #include <boost/date_time/posix_time/posix_time.hpp>
46 #include <boost/variant/get.hpp>
47 #include <boost/optional.hpp>
48 #include <json/value.h>
49 #include <json/reader.h>
70 boost::optional<osvr::common::elements::AliasElement>
75 }
catch (std::exception &e) {
76 cerr <<
"Could not get node at path '" << path
77 <<
"' - exception: " << e.what() << endl;
80 auto elt = boost::get<osvr::common::elements::AliasElement>(&node->value());
87 auto SETTLE_TIME = boost::posix_time::seconds(2);
90 static const char FLAG_KEY[] =
"resetYaw";
92 int main(
int argc,
char *argv[]) {
93 namespace po = boost::program_options;
95 po::options_description desc(
"Options");
97 (
"help",
"produce help message")
98 (
"path", po::value<std::string>()->default_value(
"/me/head"),
"path to reset-yaw on")
99 (
"no-wait",
"headless mode - immediately resets yaw without waiting")
103 po::variables_map vm;
104 po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
107 const bool noWait = vm.count(
"no-wait");
113 if (vm.count(
"help")) {
114 cout <<
"Usage: osvr_reset_yaw [options]" << endl;
115 cout << desc <<
"\n";
120 std::string
const path = vm[
"path"].as<std::string>();
128 cout <<
"Running client mainloop briefly to start up..." << endl;
129 client.loopForDuration(boost::chrono::seconds(2));
130 cout <<
"Removing any previous yaw-reset transforms..." << endl;
133 auto elt = getAliasElement(ctx, path);
136 cerr <<
"Couldn't get the alias at " << path << endl;
147 if (!origAlias.isValid()) {
148 cerr <<
"Couldn't parse the alias!" << endl;
151 cout <<
"Original transform: "
152 << origAlias.getAliasValue().toStyledString() <<
"\n" << endl;
155 return current.isMember(FLAG_KEY) && current[FLAG_KEY].isBool() &&
156 current[FLAG_KEY].asBool();
158 cout <<
"Cleaned transform: "
159 << xforms.get(origAlias.getLeaf()).toStyledString() <<
"\n"
165 cout <<
"Sent cleaned transform, starting again and waiting a few "
166 "seconds for startup..."
169 boost::this_thread::sleep(SETTLE_TIME);
172 cout <<
"\n\nPlease place your device for " << path
173 <<
" in its 'zero' orientation and press enter." << endl;
183 ClientMainloopThread::lock_type lock(client.getMutex());
186 cerr <<
"Sorry, no orientation state available for this path - "
187 "are you sure you have a device plugged in and your "
195 auto q = osvr::util::eigen_interop::map(state);
197 cout <<
"Correction: " << -yaw <<
" radians about Y" << endl;
199 Json::Value newLayer(Json::objectValue);
200 newLayer[
"postrotate"][
"radians"] = -yaw;
201 newLayer[
"postrotate"][
"axis"] =
"y";
202 newLayer[FLAG_KEY] =
true;
203 xforms.wrap(newLayer);
204 cout <<
"New source: "
205 << xforms.get(origAlias.getLeaf()).toStyledString() << endl;
208 xforms.get(origAlias.getLeaf())));
210 boost::this_thread::sleep(SETTLE_TIME / 2);
213 boost::this_thread::sleep(SETTLE_TIME);
216 cout <<
"Press enter to exit.";
The element type corresponding to a path alias, with a priority level for sorting out whether automat...
Header containing wrappers for some common jsoncpp operations.
Interface handle object. Typically acquired from a ClientContext.
Client context object: Create and keep one in your application. Handles lifetime management and provi...
::osvr::util::TreeNode< PathElement > PathNode
The specific tree node type that contains a path element.
void sendRoute(std::string const &route)
Sends a JSON route/transform object to the server.
AliasPriority & priority()
Get/set whether this alias was automatically set (and thus subject to being override by explicit rout...
std::string & getSource()
Get the source of data for this alias.
auto extractYaw(T const &quat) -> decltype(std::atan(quat.w()))
Header to bring unique_ptr into the osvr namespace.
A structure defining a quaternion, often a unit quaternion representing 3D rotation.
int main(int argc, char *argv[])
Interface getInterface(const std::string &path)
Get the interface associated with the given path.
PathNode & getNodeByPath(std::string const &path)
Returns the node indicated by the path, which must be absolute (begin with a /). Any non-existent nod...
Json::Value applyPriorityToAlias(Json::Value const &alias, AliasPriority priority)
Given a JSON object describing one or more aliases, set the priority of the alias(es).
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
osvr::common::PathTree const & getPathTree() const
Accessor for the path tree.
OSVR_ClientContext get()
Gets the bare OSVR_ClientContext.
std::string jsonToCompactString(Json::Value const &val)
Turns the JSON value into a compact string representation.
void setSource(std::string const &source)
Sets the source of this alias.
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN's quatlib.
Json::Value createJSONAlias(std::string const &path, Json::Value const &destination)
Given a path and a destination, combine them into a JSON alias description.
OSVR_ReturnCode osvrGetOrientationState(OSVR_ClientInterface iface, struct OSVR_TimeValue *timestamp, OSVR_OrientationState *state)
Get Orientation state from an interface, returning failure if none \ * exists.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Json::Value jsonParse(std::string const &str)
Parses a string as JSON, returning a null value if parsing fails.
void remove_if(GeneralizedTransform &transform, UnaryPredicate pred)
Remove levels from a generalized transform as dictated by an arbitrary predicate. ...