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