NDEVR
API Documentation
RealSensePositionSensor.h
1#pragma once
2#include <NDEVR/PositionSensor.h>
3#include "Design/Headers/DesignObjectLookup.h"
4#include "Design/Headers/StationModel.h"
5#include "Base/Headers/QueueBuffer.hpp"
6#include <librealsense2/rs.hpp>
7namespace NDEVR
8{
15 {
19
38
43 {
44 fltp08 dt_s = (t - time) / 1000.0;;
45 return position + dt_s * ((dt_s / 2 * acceleration) + velocity);
46 }
47
51 {
52 return cast<fltp08>(tracker_confidence) / (2 * acceleration.magnitudeSquared() + velocity.magnitudeSquared() + 0.1);
53 }
55 Ray<3, fltp08> velocity;
56 Ray<3, fltp08> acceleration;
60 };
61
67 {
68 public:
76 RealSensePositionSensor(DesignObjectLookup* lookup, const Model& model, ProgressInfo* log, QObject* parent = nullptr)
77 : PositionSensor(model, log, parent)
79 , m_transform(1.0)
80 , m_lookup(lookup)
81 {}
82
86 void setLocation(rs2::pose_frame frame)
87 {
88 auto pose_data = frame.get_pose_data();
89 Vertex<3, fltp08> offset(-pose_data.translation.z, -pose_data.translation.x, pose_data.translation.y);
90
91 Ray<3, fltp08> acceleration(-pose_data.acceleration.z, -pose_data.acceleration.x, pose_data.acceleration.y);
92
93 Ray<3, fltp08> velocity(-pose_data.velocity.z, -pose_data.velocity.x, pose_data.velocity.y);
94
95 offset = m_transform * offset;
96 acceleration = m_transform * acceleration;
97 velocity = m_transform * velocity;
98
99 PositionReading reading(offset, velocity, acceleration,
100 pose_data.tracker_confidence,
101 pose_data.mapper_confidence, frame.get_timestamp());
102 setPosition(reading.position);
104 if (m_historic_positions.size() > 100)
106 m_historic_positions.push(reading);
107 }
108
113 {
114 Vertex<3, fltp08> offset = m_transform * Vertex<3, fltp08>(slam.decomposeOffset());
115 Vector<3, fltp08> velocity(0.0);
116 Vector<3, fltp08> acceleration(0.0);
117 if (m_historic_positions.size() > 0)
118 {
119 auto& reading = m_historic_positions[m_historic_positions.size() - 1];
120 if (time > reading.time)
121 {
122 velocity = (offset - reading.position) / (time - reading.time);
123 acceleration = (velocity - reading.velocity) / (time - reading.time);
124 }
125 }
126 PositionReading reading(offset, velocity, acceleration, 1.0, 1.0, time);
127 setPosition(reading.position);
128 /*if (m_historic_positions.size() > 100)
129 m_historic_positions.pop();
130 m_historic_positions.push(reading);*/
131 }
132
136 {
137 WLock wlock(&m_station_model);
138 lib_assert(m_station_model.isValid(), "No station for segment");
139 if (m_station_model.isValid())
140 {
141 WLock lock = m_lookup->writeLock();
142 if (!m_deployment.isValid())
143 {
144 m_deployment = Deployment(m_station_model.createChild());
145 m_deployment.set<NDPO::deletion_allowed>(true);
146 m_deployment.setUseTube(Geometry::ThicknessMode::e_pixel, 1.0);
147 m_lookup->addModel(m_deployment);
148 emit deploymentChangedSignal(m_deployment.get<NDPO::guid>());
149 }
150 else
151 {
152 }
153 setPosition(m_deployment.currentLocation());
155 m_lookup->modified_time.set(Time::SystemTime());
156 m_lookup->requestAutoSave();
157 }
158 }
159
164 {
165 PositionReading reading;
166 {
168
170 if (size == 0)
171 {
172 Vertex<3, fltp08> location = lastPosition();
173 if (IsInvalid(location))
174 location = 0.0;
175 return location;
176 }
177 reading = m_historic_positions[size - 1];
178 for (uint04 i = size - 2; !IsInvalid(i); i--)
179 {
180 if (m_historic_positions[i].time < time)
181 {
182 reading = m_historic_positions[i];
183 break;
184 }
185 }
186 }
187 if (reading.time > time || (time - reading.time) > 200.0)
188 {
189 return Constant<Vertex<3, fltp08>>::Invalid;
190 }
191 if (reading.time < time)
192 {
193 return reading.positionAt(time);
194 }
195 return reading.position;
196 }
197
200 void requestReset(bool reset_requested)
201 {
202 m_request_reset = reset_requested;
203 }
204
207 bool resetRequested() const
208 {
209 return m_request_reset;
210 }
211 protected:
212 PositionReadingBuffer m_historic_positions;
214 bool m_request_reset = false;
216 };
217}
A core class where all Design Objects including models, materials, and geometries are stored.
@ e_pixel
Thickness in screen pixels.
Definition Geometry.h:197
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
Vector< 3, fltp08 > size() const
Returns the size (extents) of the model's bounding box.
void deploymentSegmentAddedSignal()
Emitted when a deployment segment has been added.
void deploymentChangedSignal(UUID deployment)
Emitted when the deployment configuration has changed.
void setPosition(const Vertex< 3, fltp08 > &location)
Sets the current position of this sensor.
PositionSensor(const Model &name, LogPtr log, QObject *parent=nullptr)
Constructs a PositionSensor with the given model, log, and optional parent.
virtual Vertex< 3, fltp08 > lastPosition() const
Returns the last known 3D position of this sensor.
Used with InfoPipe to signal that the system will be using progress.
Stores objects in a first-in, first out queue based Buffer with push and pop functions.
Used to lock a particular variable for reading.
Definition RWLock.h:157
bool resetRequested() const
Returns whether a reset has been requested.
void setLocation(rs2::pose_frame frame)
Updates the position from a RealSense T265 pose frame.
Vertex< 3, fltp08 > locationAt(fltp08 time)
Returns the interpolated position at a given time.
PositionReadingBuffer m_historic_positions
Circular buffer of historic position readings.
Matrix< fltp08 > m_transform
Coordinate transformation matrix.
DesignObjectLookup * m_lookup
The design object lookup.
RealSensePositionSensor(DesignObjectLookup *lookup, const Model &model, ProgressInfo *log, QObject *parent=nullptr)
Constructs the position sensor.
void setLocationFromSLAM(const Matrix< fltp08 > &slam, fltp08 time)
Updates the position from a SLAM-derived transformation matrix.
bool m_request_reset
Whether a position reset has been requested.
void addDeploymentSegment(fltp08) override
Adds a new deployment segment at the current position.
void requestReset(bool reset_requested)
Requests a position sensor reset.
static Time SystemTime()
Retrieves the current system time which is a combination of std::chrono::steady_clock to ensure smoot...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
Definition Angle.h:388
@ deletion_allowed
Whether the user is allowed to delete this object.
@ guid
A 128-bit globally unique identifier for the object.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
A single position reading from the RealSense T265 tracking camera.
uint01 tracker_confidence
Pose confidence 0x0 - Failed, 0x1 - Low, 0x2 - Medium, 0x3 - High.
Vertex< 3, fltp08 > position
The 3D position of the sensor.
Ray< 3, fltp08 > acceleration
The 3D acceleration of the sensor.
Vertex< 3, fltp08 > positionAt(fltp08 t)
Extrapolates the position at a given time using velocity and acceleration.
fltp08 confidence() const
Computes a confidence score based on tracker confidence and motion magnitude.
fltp08 time
The timestamp of this reading in milliseconds.
Ray< 3, fltp08 > velocity
The 3D velocity of the sensor.
uint01 mapper_confidence
Pose map confidence 0x0 - Failed, 0x1 - Low, 0x2 - Medium, 0x3 - High.
PositionReading()
Constructs a default (empty) position reading.
PositionReading(Vertex< 3, fltp08 > position, Ray< 3, fltp08 > velocity, Ray< 3, fltp08 > acceleration, uint01 tracker_confidence, uint01 mapper_confidence, fltp08 time)
Constructs a position reading with all fields.