The open source OpenXR runtime
1// Copyright 2020-2021, The Board of Trustees of the University of Illinois.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief ILLIXR plugin
6 * @author RSIM Group <illixr@cs.illinois.edu>
7 * @ingroup drv_illixr
8 */
9
10
11#include "xrt/xrt_device.h"
12
13#include <iostream>
14#include "common/plugin.hpp"
15#include "common/phonebook.hpp"
16#include "common/switchboard.hpp"
17#include "common/data_format.hpp"
18#include "common/pose_prediction.hpp"
19
20using namespace ILLIXR;
21
22/// Simulated plugin class for an instance during phonebook registration
23class illixr_plugin : public plugin
24{
25public:
26 illixr_plugin(std::string name_, phonebook *pb_)
27 : plugin{name_, pb_}, sb{pb->lookup_impl<switchboard>()}, sb_pose{pb->lookup_impl<pose_prediction>()}
28 {}
29
30 const std::shared_ptr<switchboard> sb;
31 const std::shared_ptr<pose_prediction> sb_pose;
32};
33
34static illixr_plugin *illixr_plugin_obj = nullptr;
35
36extern "C" plugin *
37illixr_monado_create_plugin(phonebook *pb)
38{
39 illixr_plugin_obj = new illixr_plugin{"illixr_plugin", pb};
40 illixr_plugin_obj->start();
41 return illixr_plugin_obj;
42}
43
44extern "C" struct xrt_pose
45illixr_read_pose()
46{
47 assert(illixr_plugin_obj && "illixr_plugin_obj must be initialized first.");
48
49 if (!illixr_plugin_obj->sb_pose->fast_pose_reliable()) {
50 std::cerr << "Pose not reliable yet; returning best guess" << std::endl;
51 }
52 struct xrt_pose ret;
53 const fast_pose_type fast_pose = illixr_plugin_obj->sb_pose->get_fast_pose();
54 const pose_type pose = fast_pose.pose;
55
56 ret.orientation.x = pose.orientation.x();
57 ret.orientation.y = pose.orientation.y();
58 ret.orientation.z = pose.orientation.z();
59 ret.orientation.w = pose.orientation.w();
60 ret.position.x = pose.position.x();
61 ret.position.y = pose.position.y();
62 ret.position.z = pose.position.z();
63
64 return ret;
65}