23 #include <librealsense2/rsutil.h>
24 #include <librealsense2/rs.hpp>
50 return { x *
t, y *
t, z *
t };
55 return { x -
t, y -
t, z -
t };
65 void add(
float t1,
float t2,
float t3)
80 ss <<
"Device information: " << std::endl;
82 for (
int i = 0; i < static_cast<int>(RS2_CAMERA_INFO_COUNT); i++) {
83 auto info_type =
static_cast<rs2_camera_info
>(i);
84 ss <<
" " << std::left << std::setw(20) << info_type <<
" : ";
86 if (dev.supports(info_type))
87 ss << dev.get_info(info_type) << std::endl;
89 ss <<
"N/A" << std::endl;
94 static bool setOption(rs2_option option,
const rs2::sensor* sensor,
float value)
102 if (!sensor->supports(option)) {
103 yCError(REALSENSE2TRACKING) <<
"The option" << rs2_option_to_string(option) <<
"is not supported by this sensor";
109 sensor->set_option(option, value);
110 }
catch (
const rs2::error& e) {
113 yCError(REALSENSE2TRACKING) <<
"Failed to set option " << rs2_option_to_string(option) <<
". (" << e.what() <<
")";
119 static bool getOption(rs2_option option,
const rs2::sensor* sensor,
float& value)
126 if (!sensor->supports(option)) {
127 yCError(REALSENSE2TRACKING) <<
"The option" << rs2_option_to_string(option) <<
"is not supported by this sensor";
133 value = sensor->get_option(option);
134 }
catch (
const rs2::error& e) {
137 yCError(REALSENSE2TRACKING) <<
"Failed to get option " << rs2_option_to_string(option) <<
". (" << e.what() <<
")";
145 yCError(REALSENSE2TRACKING) << error.c_str();
154 bool realsense2Tracking::pipelineStartup()
157 m_profile = m_pipeline.start(m_cfg);
158 }
catch (
const rs2::error& e) {
159 yCError(REALSENSE2TRACKING) <<
"Failed to start the pipeline:"
160 <<
"(" << e.what() <<
")";
161 m_lastError = e.what();
167 bool realsense2Tracking::pipelineShutdown()
171 }
catch (
const rs2::error& e) {
172 yCError(REALSENSE2TRACKING) <<
"Failed to stop the pipeline:"
173 <<
"(" << e.what() <<
")";
174 m_lastError = e.what();
180 bool realsense2Tracking::pipelineRestart()
182 std::lock_guard<std::mutex> guard(m_mutex);
183 if (!pipelineShutdown())
186 return pipelineStartup();
191 yCWarning(REALSENSE2TRACKING) <<
"This software module is experimental.";
192 yCWarning(REALSENSE2TRACKING) <<
"It is provided with uncomplete documentation and it may be modified/renamed/removed without any notice.";
194 string sensor_is =
"t265";
195 m_timestamp_type = timestamp_enumtype::yarp_timestamp;
196 if (config.
check(
"timestamp"))
199 if (temp ==
"yarp") m_timestamp_type = timestamp_enumtype::yarp_timestamp;
200 if (temp ==
"realsense") m_timestamp_type = timestamp_enumtype::rs_timestamp;
203 yCError(REALSENSE2TRACKING) <<
"Invalid value for option 'timestamp'. Valid values are 'yarp','realsense'";
210 m_cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
211 m_cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);
212 m_cfg.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
213 b &= pipelineStartup();
216 yCError(REALSENSE2TRACKING) <<
"Pipeline initialization failed";
244 if (sens_index != 0) {
return false; }
245 name = m_inertial_sensor_name_prefix +
"/" + m_gyro_sensor_tag;
251 if (sens_index != 0) {
return false; }
252 frameName = m_gyroFrameName;
258 if (sens_index != 0) {
262 std::lock_guard<std::mutex> guard(m_mutex);
263 rs2::frameset dataframe = m_pipeline.wait_for_frames();
264 auto fg = dataframe.first_or_default(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);
265 rs2::motion_frame gyro = fg.as<rs2::motion_frame>();
267 else if (m_timestamp_type == rs_timestamp) { timestamp = gyro.get_timestamp(); }
269 m_last_gyro = gyro.get_motion_data();
271 out[0] = m_last_gyro.x;
272 out[1] = m_last_gyro.y;
273 out[2] = m_last_gyro.z;
293 if (sens_index != 0) {
return false; }
294 name = m_inertial_sensor_name_prefix +
"/" + m_accel_sensor_tag;
300 if (sens_index != 0) {
return false; }
301 frameName = m_accelFrameName;
307 if (sens_index != 0) {
return false; }
309 std::lock_guard<std::mutex> guard(m_mutex);
310 rs2::frameset dataframe = m_pipeline.wait_for_frames();
311 auto fa = dataframe.first_or_default(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
312 rs2::motion_frame accel = fa.as<rs2::motion_frame>();
313 m_last_accel = accel.get_motion_data();
315 else if (m_timestamp_type == rs_timestamp) { timestamp = accel.get_timestamp(); }
318 out[0] = m_last_accel.x;
319 out[1] = m_last_accel.y;
320 out[2] = m_last_accel.z;
340 if (sens_index != 0) {
return false; }
341 name = m_inertial_sensor_name_prefix +
"/" + m_orientation_sensor_tag;
347 if (sens_index != 0) {
return false; }
348 frameName = m_orientationFrameName;
355 if (sens_index != 0) {
return false; }
357 std::lock_guard<std::mutex> guard(m_mutex);
358 rs2::frameset dataframe = m_pipeline.wait_for_frames();
359 auto fa = dataframe.first_or_default(RS2_STREAM_POSE);
360 rs2::pose_frame pose = fa.as<rs2::pose_frame>();
361 m_last_pose = pose.get_pose_data();
363 else if (m_timestamp_type == rs_timestamp) { timestamp = pose.get_timestamp(); }
365 yarp::math::Quaternion q(m_last_pose.rotation.x, m_last_pose.rotation.y, m_last_pose.rotation.z, m_last_pose.rotation.w);
369 rpy[0] = 0 + rpy_temp[0] * 180 /
M_PI;
370 rpy[1] = 0 + rpy_temp[1] * 180 /
M_PI;
371 rpy[2] = 0 + rpy_temp[2] * 180 /
M_PI;
391 if (sens_index != 0) {
return false; }
392 name = m_inertial_sensor_name_prefix +
"/" + m_pose_sensor_tag;
398 if (sens_index != 0) {
return false; }
399 frameName = m_poseFrameName;
406 if (sens_index != 0) {
return false; }
408 std::lock_guard<std::mutex> guard(m_mutex);
409 rs2::frameset dataframe = m_pipeline.wait_for_frames();
410 auto fa = dataframe.first_or_default(RS2_STREAM_POSE);
411 rs2::pose_frame pose = fa.as<rs2::pose_frame>();
412 m_last_pose = pose.get_pose_data();
414 else if (m_timestamp_type == rs_timestamp) { timestamp = pose.get_timestamp(); }
417 xyz[0] = m_last_pose.translation.x;
418 xyz[1] = m_last_pose.translation.y;
419 xyz[2] = m_last_pose.translation.z;
426 size_t realsense2Tracking::getNrOfPoseSensors()
const
437 bool realsense2Tracking::getPoseSensorName(
size_t sens_index, std::string& name)
const
439 if (sens_index != 0) {
return false; }
440 name = m_inertial_sensor_name_prefix +
"/" + m_pose_sensor_tag;
444 bool realsense2Tracking::getPoseSensorFrameName(
size_t sens_index, std::string& frameName)
const
446 if (sens_index != 0) {
return false; }
447 frameName = m_poseFrameName;
451 bool realsense2Tracking::getPoseSensorMeasureAsXYZRPY(
size_t sens_index,
yarp::sig::Vector& xyzrpy,
double& timestamp)
const
453 std::lock_guard<std::mutex> guard(m_mutex);
454 rs2::frameset dataframe = m_pipeline.wait_for_frames();
455 auto fa = dataframe.first_or_default(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
456 rs2::pose_frame pose = fa.as<rs2::pose_frame>();
457 m_last_pose = pose.get_pose_data();
459 xyzrpy[0] = m_last_pose.translation.x;
460 xyzrpy[1] = m_last_pose.translation.y;
461 xyzrpy[2] = m_last_pose.translation.z;
462 yarp::math::Quaternion q(m_last_pose.rotation.x, m_last_pose.rotation.y, m_last_pose.rotation.z, m_last_pose.rotation.w);
465 xyzrpy[3] = 0 + rpy[0] * 180 /
M_PI;
466 xyzrpy[4] = 0 + rpy[1] * 180 /
M_PI;
467 xyzrpy[5] = 0 + rpy[2] * 180 /
M_PI;
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
size_t getNrOfPositionSensors() const override
Get the number of position sensors exposed by this device.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getPositionSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers exposed by this device.
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors exposed by this device.
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get the last reading of the specified sensor.
bool close() override
Close the DeviceDriver.
bool getPositionSensorMeasure(size_t sens_index, yarp::sig::Vector &xyz, double ×tamp) const override
Get the last reading of the position sensor as x y z.
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getPositionSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double ×tamp) const override
Get the last reading of the orientation sensor as roll pitch yaw.
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get the last reading of the gyroscope.
yarp::dev::MAS_status getPositionSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes exposed by this sensor.
yarp::sig::Matrix toRotationMatrix3x3() const
Converts a quaternion to a rotation matrix.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string asString() const
Get string value.
void resize(size_t size) override
Resize the vector.
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.
@ MAS_UNKNOWN
The sensor is in an unknown state.
@ MAS_OK
The sensor is working correctly.
yarp::sig::Vector dcm2rpy(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to roll-pitch-yaw angles (defined in Math....
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
static bool setOption(rs2_option option, const rs2::sensor *sensor, float value)
static bool getOption(rs2_option option, const rs2::sensor *sensor, float &value)
static std::string get_device_information(const rs2::device &dev)
static void settingErrorMsg(const string &error, bool &ret)
float3 operator-(float t)
void add(float t1, float t2, float t3)
float3 operator*(float t)