ovr_sdk
diff LibOVR/Src/Tracking/Tracking_SensorState.h @ 0:1b39a1b46319
initial 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 06:51:16 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Tracking/Tracking_SensorState.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,212 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : Tracking_SensorState.h 1.7 +Content : Sensor state information shared by tracking system with games 1.8 +Created : May 13, 2014 1.9 +Authors : Dov Katz, Chris Taylor 1.10 + 1.11 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.12 + 1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.15 +which is provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +You may obtain a copy of the License at 1.19 + 1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.21 + 1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.23 +distributed under the License is distributed on an "AS IS" BASIS, 1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.25 +See the License for the specific language governing permissions and 1.26 +limitations under the License. 1.27 + 1.28 +*************************************************************************************/ 1.29 + 1.30 +#ifndef Tracking_SensorState_h 1.31 +#define Tracking_SensorState_h 1.32 + 1.33 +#include "Tracking_PoseState.h" 1.34 +#include "../Kernel/OVR_SharedMemory.h" 1.35 +#include "../Kernel/OVR_Lockless.h" 1.36 +#include "../Kernel/OVR_String.h" 1.37 +#include "../Util/Util_LatencyTest2State.h" 1.38 +#include "../Sensors/OVR_DeviceConstants.h" 1.39 + 1.40 +// CAPI forward declarations. 1.41 +struct ovrTrackingState_; 1.42 +typedef struct ovrTrackingState_ ovrTrackingState; 1.43 +struct ovrPoseStatef_; 1.44 +typedef struct ovrPoseStatef_ ovrPoseStatef; 1.45 + 1.46 +namespace OVR { namespace Tracking { 1.47 + 1.48 + 1.49 +//------------------------------------------------------------------------------------- 1.50 +// ***** Sensor State 1.51 +// These values are reported as compatible with C API. 1.52 + 1.53 +// Bit flags describing the current status of sensor tracking. 1.54 +enum StatusBits 1.55 +{ 1.56 + // Tracked bits: Toggled by SensorFusion 1.57 + Status_OrientationTracked = 0x0001, // Orientation is currently tracked (connected and in use) 1.58 + Status_PositionTracked = 0x0002, // Position is currently tracked (false if out of range) 1.59 + Status_CameraPoseTracked = 0x0004, // Camera pose is currently tracked 1.60 + 1.61 + // Connected bits: Toggled by TrackingManager 1.62 + Status_PositionConnected = 0x0020, // Position tracking HW is connected 1.63 + Status_HMDConnected = 0x0080, // HMD is available & connected 1.64 + 1.65 + // Masks 1.66 + Status_AllMask = 0xffff, 1.67 + Status_TrackingMask = Status_PositionTracked | Status_OrientationTracked | Status_CameraPoseTracked, 1.68 + Status_ConnectedMask = Status_PositionConnected | Status_HMDConnected, 1.69 +}; 1.70 + 1.71 + 1.72 +// Full state of of the sensor reported by GetSensorState() at a given absolute time. 1.73 +class TrackingState 1.74 +{ 1.75 +public: 1.76 + TrackingState() : HeadPose(), CameraPose(), LeveledCameraPose(), RawSensorData(), StatusFlags(0), LastVisionProcessingTime(0.0) { } 1.77 + 1.78 + // C-interop support 1.79 + TrackingState(const ovrTrackingState& s); 1.80 + operator ovrTrackingState () const; 1.81 + 1.82 + // HMD pose information for the requested time. 1.83 + PoseStatef HeadPose; 1.84 + 1.85 + // Orientation and position of the external camera, if present. 1.86 + Posef CameraPose; 1.87 + // Orientation and position of the camera after alignment with gravity 1.88 + Posef LeveledCameraPose; 1.89 + 1.90 + // Most recent sensor data received from the HMD 1.91 + SensorDataType RawSensorData; 1.92 + 1.93 + // Sensor status described by ovrStatusBits. 1.94 + uint32_t StatusFlags; 1.95 + 1.96 + //// 0.4.1 1.97 + 1.98 + // Measures the time from receiving the camera frame until vision CPU processing completes. 1.99 + double LastVisionProcessingTime; 1.100 + 1.101 + //// 0.4.3 1.102 + 1.103 + // Measures the time from exposure until the pose is available for the frame, including processing time. 1.104 + double LastVisionFrameLatency; 1.105 + 1.106 + // Tag the vision processing results to a certain frame counter number. 1.107 + uint32_t LastCameraFrameCounter; 1.108 +}; 1.109 + 1.110 + 1.111 +// ----------------------------------------------- 1.112 + 1.113 +#pragma pack(push, 8) 1.114 + 1.115 +struct LocklessSensorStatePadding; 1.116 + 1.117 +// State version stored in lockless updater "queue" and used for 1.118 +// prediction by GetPoseAtTime/GetSensorStateAtTime 1.119 +struct LocklessSensorState 1.120 +{ 1.121 + PoseState<double> WorldFromImu; 1.122 + SensorDataType RawSensorData; 1.123 + Pose<double> WorldFromCamera; 1.124 + uint32_t StatusFlags; 1.125 + uint32_t _PAD_0_; 1.126 + 1.127 + // ImuFromCpf for HMD pose tracking 1.128 + Posed ImuFromCpf; 1.129 + 1.130 + // Performance logging 1.131 + double LastVisionProcessingTime; 1.132 + double LastVisionFrameLatency; 1.133 + uint32_t LastCameraFrameCounter; 1.134 + uint32_t _PAD_1_; 1.135 + 1.136 + // Initialized to invalid state 1.137 + LocklessSensorState() : 1.138 + WorldFromImu() 1.139 + , RawSensorData() 1.140 + , WorldFromCamera() 1.141 + , StatusFlags(0) 1.142 + , _PAD_0_(0) // This assignment should be irrelevant, but it quells static/runtime analysis complaints. 1.143 + , ImuFromCpf() 1.144 + , LastVisionProcessingTime(0.0) 1.145 + , LastVisionFrameLatency(0.0) 1.146 + , LastCameraFrameCounter(0) 1.147 + , _PAD_1_(0) // " 1.148 + { 1.149 + } 1.150 + 1.151 + LocklessSensorState& operator = (const LocklessSensorStatePadding& rhs); 1.152 +}; 1.153 + 1.154 +static_assert((sizeof(LocklessSensorState) == sizeof(PoseState<double>) + sizeof(SensorDataType) + sizeof(Pose<double>) + 2*sizeof(uint32_t) + sizeof(Posed) + sizeof(double)*2 + sizeof(uint32_t)*2), "sizeof(LocklessSensorState) failure"); 1.155 + 1.156 +// Padded out version stored in the updater slots 1.157 +// Designed to be a larger fixed size to allow the data to grow in the future 1.158 +// without breaking older compiled code. 1.159 +struct LocklessSensorStatePadding 1.160 +{ 1.161 + uint64_t words[64]; 1.162 + 1.163 + static const int DataWords = (sizeof(LocklessSensorState) + sizeof(uint64_t) - 1) / sizeof(uint64_t); 1.164 + 1.165 + // Just copy the low data words 1.166 + inline LocklessSensorStatePadding& operator=(const LocklessSensorState& rhs) 1.167 + { 1.168 + const uint64_t* src = (const uint64_t*)&rhs; 1.169 + 1.170 + // if this fires off, then increase words' array size 1.171 + OVR_ASSERT(sizeof(words) > sizeof(LocklessSensorState)); 1.172 + 1.173 + for (int i = 0; i < DataWords; ++i) 1.174 + { 1.175 + words[i] = src[i]; 1.176 + } 1.177 + 1.178 + return *this; 1.179 + } 1.180 +}; 1.181 + 1.182 +// Just copy the low data words 1.183 +inline LocklessSensorState& LocklessSensorState::operator = (const LocklessSensorStatePadding& rhs) 1.184 +{ 1.185 + uint64_t* dest = (uint64_t*)this; 1.186 + 1.187 + for (int i = 0; i < LocklessSensorStatePadding::DataWords; ++i) 1.188 + { 1.189 + dest[i] = rhs.words[i]; 1.190 + } 1.191 + 1.192 + return *this; 1.193 +} 1.194 + 1.195 +#pragma pack(pop) 1.196 + 1.197 +// A lockless updater for sensor state 1.198 +typedef LocklessUpdater<LocklessSensorState, LocklessSensorStatePadding> SensorStateUpdater; 1.199 + 1.200 + 1.201 +//// Combined state 1.202 + 1.203 +struct CombinedSharedStateUpdater 1.204 +{ 1.205 + SensorStateUpdater SharedSensorState; 1.206 + Util::LockessRecordUpdater SharedLatencyTestState; 1.207 +}; 1.208 + 1.209 +typedef SharedObjectWriter< CombinedSharedStateUpdater > CombinedSharedStateWriter; 1.210 +typedef SharedObjectReader< CombinedSharedStateUpdater > CombinedSharedStateReader; 1.211 + 1.212 + 1.213 +}} // namespace OVR::Tracking 1.214 + 1.215 +#endif