Monado OpenXR Runtime
rs_ddev.c File Reference

RealSense helper driver for in-device SLAM 6DOF tracking. More...

#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "math/m_api.h"
#include "math/m_space.h"
#include "math/m_predict.h"
#include "math/m_relation_history.h"
#include "os/os_time.h"
#include "os/os_threading.h"
#include "util/u_time.h"
#include "util/u_device.h"
#include "util/u_logging.h"
#include "util/u_json.h"
#include "util/u_config_json.h"
#include "rs_driver.h"
#include <librealsense2/rs.h>
#include <librealsense2/h/rs_pipeline.h>
#include <librealsense2/h/rs_option.h>
#include <librealsense2/h/rs_frame.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <inttypes.h>
Include dependency graph for rs_ddev.c:

Data Structures

struct  rs_ddev
 Device-SLAM tracked RealSense device (T26X series). More...
 

Macros

#define print_pose(msg, pose)
 Convenience macro to print out a pose, only used for debugging. More...
 
#define CHECK_RS2()
 

Functions

static struct rs_ddevrs_ddev (struct xrt_device *xdev)
 Helper to convert a xdev to a rs_ddev. More...
 
static int check_error (struct rs_ddev *rs, rs2_error *e)
 Simple helper to check and print error messages. More...
 
static void close_ddev (struct rs_ddev *rs)
 Frees all RealSense resources. More...
 
static int create_ddev (struct rs_ddev *rs, int device_idx)
 Create all RealSense resources needed for 6DOF tracking. More...
 
static void process_frame (struct rs_ddev *rs, rs2_frame *frame)
 Process a frame as 6DOF data, does not assume ownership of the frame. More...
 
static int update (struct rs_ddev *rs)
 
static void * rs_run_thread (void *ptr)
 
static bool load_config (struct rs_ddev *rs)
 
static void rs_ddev_get_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
static void rs_ddev_get_view_poses (struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, uint64_t at_timestamp_ns, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
 
static void rs_ddev_destroy (struct xrt_device *xdev)
 
struct xrt_devicers_ddev_create (int device_idx)
 Create a RealSense device tracked with device-SLAM (T26x). More...
 

Detailed Description

Macro Definition Documentation

◆ CHECK_RS2

#define CHECK_RS2 ( )
Value:
do { \
if (check_error(rs, e) != 0) { \
close_ddev(rs); \
return 1; \
} \
} while (0)
static int check_error(struct rs_ddev *rs, rs2_error *e)
Simple helper to check and print error messages.
Definition: rs_ddev.c:86

◆ print_pose

#define print_pose (   msg,
  pose 
)
Value:
U_LOG_E(msg " %f %f %f %f %f %f %f", pose.position.x, pose.position.y, pose.position.z, pose.orientation.x, \
pose.orientation.y, pose.orientation.z, pose.orientation.w)
#define U_LOG_E(...)
Log a message at U_LOGGING_ERROR level, conditional on the global log level.
Definition: u_logging.h:301

Convenience macro to print out a pose, only used for debugging.

Function Documentation

◆ check_error()

static int check_error ( struct rs_ddev rs,
rs2_error *  e 
)
static

Simple helper to check and print error messages.

References U_LOG_E.

Referenced by process_frame().

◆ close_ddev()

static void close_ddev ( struct rs_ddev rs)
static

Frees all RealSense resources.

References rs_container::pipeline, rs_container_cleanup(), and rs_ddev::rsc.

◆ create_ddev()

static int create_ddev ( struct rs_ddev rs,
int  device_idx 
)
static

Create all RealSense resources needed for 6DOF tracking.

Todo:
0 index hardcoded, check device with RS2_EXTENSION_POSE_SENSOR or similar instead

References rs_container::context, and rs_ddev::rsc.

◆ process_frame()

static void process_frame ( struct rs_ddev rs,
rs2_frame *  frame 
)
static

Process a frame as 6DOF data, does not assume ownership of the frame.

References check_error(), os_monotonic_get_ns(), and os_realtime_get_ns().

◆ rs_ddev()

static struct rs_ddev* rs_ddev ( struct xrt_device xdev)
inlinestatic

Helper to convert a xdev to a rs_ddev.