ovr_sdk

annotate 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
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 Filename : Tracking_SensorState.h
nuclear@0 4 Content : Sensor state information shared by tracking system with games
nuclear@0 5 Created : May 13, 2014
nuclear@0 6 Authors : Dov Katz, Chris Taylor
nuclear@0 7
nuclear@0 8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 9
nuclear@0 10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 11 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 12 which is provided at the time of installation or download, or which
nuclear@0 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 14
nuclear@0 15 You may obtain a copy of the License at
nuclear@0 16
nuclear@0 17 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 18
nuclear@0 19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 20 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 22 See the License for the specific language governing permissions and
nuclear@0 23 limitations under the License.
nuclear@0 24
nuclear@0 25 *************************************************************************************/
nuclear@0 26
nuclear@0 27 #ifndef Tracking_SensorState_h
nuclear@0 28 #define Tracking_SensorState_h
nuclear@0 29
nuclear@0 30 #include "Tracking_PoseState.h"
nuclear@0 31 #include "../Kernel/OVR_SharedMemory.h"
nuclear@0 32 #include "../Kernel/OVR_Lockless.h"
nuclear@0 33 #include "../Kernel/OVR_String.h"
nuclear@0 34 #include "../Util/Util_LatencyTest2State.h"
nuclear@0 35 #include "../Sensors/OVR_DeviceConstants.h"
nuclear@0 36
nuclear@0 37 // CAPI forward declarations.
nuclear@0 38 struct ovrTrackingState_;
nuclear@0 39 typedef struct ovrTrackingState_ ovrTrackingState;
nuclear@0 40 struct ovrPoseStatef_;
nuclear@0 41 typedef struct ovrPoseStatef_ ovrPoseStatef;
nuclear@0 42
nuclear@0 43 namespace OVR { namespace Tracking {
nuclear@0 44
nuclear@0 45
nuclear@0 46 //-------------------------------------------------------------------------------------
nuclear@0 47 // ***** Sensor State
nuclear@0 48 // These values are reported as compatible with C API.
nuclear@0 49
nuclear@0 50 // Bit flags describing the current status of sensor tracking.
nuclear@0 51 enum StatusBits
nuclear@0 52 {
nuclear@0 53 // Tracked bits: Toggled by SensorFusion
nuclear@0 54 Status_OrientationTracked = 0x0001, // Orientation is currently tracked (connected and in use)
nuclear@0 55 Status_PositionTracked = 0x0002, // Position is currently tracked (false if out of range)
nuclear@0 56 Status_CameraPoseTracked = 0x0004, // Camera pose is currently tracked
nuclear@0 57
nuclear@0 58 // Connected bits: Toggled by TrackingManager
nuclear@0 59 Status_PositionConnected = 0x0020, // Position tracking HW is connected
nuclear@0 60 Status_HMDConnected = 0x0080, // HMD is available & connected
nuclear@0 61
nuclear@0 62 // Masks
nuclear@0 63 Status_AllMask = 0xffff,
nuclear@0 64 Status_TrackingMask = Status_PositionTracked | Status_OrientationTracked | Status_CameraPoseTracked,
nuclear@0 65 Status_ConnectedMask = Status_PositionConnected | Status_HMDConnected,
nuclear@0 66 };
nuclear@0 67
nuclear@0 68
nuclear@0 69 // Full state of of the sensor reported by GetSensorState() at a given absolute time.
nuclear@0 70 class TrackingState
nuclear@0 71 {
nuclear@0 72 public:
nuclear@0 73 TrackingState() : HeadPose(), CameraPose(), LeveledCameraPose(), RawSensorData(), StatusFlags(0), LastVisionProcessingTime(0.0) { }
nuclear@0 74
nuclear@0 75 // C-interop support
nuclear@0 76 TrackingState(const ovrTrackingState& s);
nuclear@0 77 operator ovrTrackingState () const;
nuclear@0 78
nuclear@0 79 // HMD pose information for the requested time.
nuclear@0 80 PoseStatef HeadPose;
nuclear@0 81
nuclear@0 82 // Orientation and position of the external camera, if present.
nuclear@0 83 Posef CameraPose;
nuclear@0 84 // Orientation and position of the camera after alignment with gravity
nuclear@0 85 Posef LeveledCameraPose;
nuclear@0 86
nuclear@0 87 // Most recent sensor data received from the HMD
nuclear@0 88 SensorDataType RawSensorData;
nuclear@0 89
nuclear@0 90 // Sensor status described by ovrStatusBits.
nuclear@0 91 uint32_t StatusFlags;
nuclear@0 92
nuclear@0 93 //// 0.4.1
nuclear@0 94
nuclear@0 95 // Measures the time from receiving the camera frame until vision CPU processing completes.
nuclear@0 96 double LastVisionProcessingTime;
nuclear@0 97
nuclear@0 98 //// 0.4.3
nuclear@0 99
nuclear@0 100 // Measures the time from exposure until the pose is available for the frame, including processing time.
nuclear@0 101 double LastVisionFrameLatency;
nuclear@0 102
nuclear@0 103 // Tag the vision processing results to a certain frame counter number.
nuclear@0 104 uint32_t LastCameraFrameCounter;
nuclear@0 105 };
nuclear@0 106
nuclear@0 107
nuclear@0 108 // -----------------------------------------------
nuclear@0 109
nuclear@0 110 #pragma pack(push, 8)
nuclear@0 111
nuclear@0 112 struct LocklessSensorStatePadding;
nuclear@0 113
nuclear@0 114 // State version stored in lockless updater "queue" and used for
nuclear@0 115 // prediction by GetPoseAtTime/GetSensorStateAtTime
nuclear@0 116 struct LocklessSensorState
nuclear@0 117 {
nuclear@0 118 PoseState<double> WorldFromImu;
nuclear@0 119 SensorDataType RawSensorData;
nuclear@0 120 Pose<double> WorldFromCamera;
nuclear@0 121 uint32_t StatusFlags;
nuclear@0 122 uint32_t _PAD_0_;
nuclear@0 123
nuclear@0 124 // ImuFromCpf for HMD pose tracking
nuclear@0 125 Posed ImuFromCpf;
nuclear@0 126
nuclear@0 127 // Performance logging
nuclear@0 128 double LastVisionProcessingTime;
nuclear@0 129 double LastVisionFrameLatency;
nuclear@0 130 uint32_t LastCameraFrameCounter;
nuclear@0 131 uint32_t _PAD_1_;
nuclear@0 132
nuclear@0 133 // Initialized to invalid state
nuclear@0 134 LocklessSensorState() :
nuclear@0 135 WorldFromImu()
nuclear@0 136 , RawSensorData()
nuclear@0 137 , WorldFromCamera()
nuclear@0 138 , StatusFlags(0)
nuclear@0 139 , _PAD_0_(0) // This assignment should be irrelevant, but it quells static/runtime analysis complaints.
nuclear@0 140 , ImuFromCpf()
nuclear@0 141 , LastVisionProcessingTime(0.0)
nuclear@0 142 , LastVisionFrameLatency(0.0)
nuclear@0 143 , LastCameraFrameCounter(0)
nuclear@0 144 , _PAD_1_(0) // "
nuclear@0 145 {
nuclear@0 146 }
nuclear@0 147
nuclear@0 148 LocklessSensorState& operator = (const LocklessSensorStatePadding& rhs);
nuclear@0 149 };
nuclear@0 150
nuclear@0 151 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");
nuclear@0 152
nuclear@0 153 // Padded out version stored in the updater slots
nuclear@0 154 // Designed to be a larger fixed size to allow the data to grow in the future
nuclear@0 155 // without breaking older compiled code.
nuclear@0 156 struct LocklessSensorStatePadding
nuclear@0 157 {
nuclear@0 158 uint64_t words[64];
nuclear@0 159
nuclear@0 160 static const int DataWords = (sizeof(LocklessSensorState) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
nuclear@0 161
nuclear@0 162 // Just copy the low data words
nuclear@0 163 inline LocklessSensorStatePadding& operator=(const LocklessSensorState& rhs)
nuclear@0 164 {
nuclear@0 165 const uint64_t* src = (const uint64_t*)&rhs;
nuclear@0 166
nuclear@0 167 // if this fires off, then increase words' array size
nuclear@0 168 OVR_ASSERT(sizeof(words) > sizeof(LocklessSensorState));
nuclear@0 169
nuclear@0 170 for (int i = 0; i < DataWords; ++i)
nuclear@0 171 {
nuclear@0 172 words[i] = src[i];
nuclear@0 173 }
nuclear@0 174
nuclear@0 175 return *this;
nuclear@0 176 }
nuclear@0 177 };
nuclear@0 178
nuclear@0 179 // Just copy the low data words
nuclear@0 180 inline LocklessSensorState& LocklessSensorState::operator = (const LocklessSensorStatePadding& rhs)
nuclear@0 181 {
nuclear@0 182 uint64_t* dest = (uint64_t*)this;
nuclear@0 183
nuclear@0 184 for (int i = 0; i < LocklessSensorStatePadding::DataWords; ++i)
nuclear@0 185 {
nuclear@0 186 dest[i] = rhs.words[i];
nuclear@0 187 }
nuclear@0 188
nuclear@0 189 return *this;
nuclear@0 190 }
nuclear@0 191
nuclear@0 192 #pragma pack(pop)
nuclear@0 193
nuclear@0 194 // A lockless updater for sensor state
nuclear@0 195 typedef LocklessUpdater<LocklessSensorState, LocklessSensorStatePadding> SensorStateUpdater;
nuclear@0 196
nuclear@0 197
nuclear@0 198 //// Combined state
nuclear@0 199
nuclear@0 200 struct CombinedSharedStateUpdater
nuclear@0 201 {
nuclear@0 202 SensorStateUpdater SharedSensorState;
nuclear@0 203 Util::LockessRecordUpdater SharedLatencyTestState;
nuclear@0 204 };
nuclear@0 205
nuclear@0 206 typedef SharedObjectWriter< CombinedSharedStateUpdater > CombinedSharedStateWriter;
nuclear@0 207 typedef SharedObjectReader< CombinedSharedStateUpdater > CombinedSharedStateReader;
nuclear@0 208
nuclear@0 209
nuclear@0 210 }} // namespace OVR::Tracking
nuclear@0 211
nuclear@0 212 #endif