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)
83 double last_ts_gyro = 0;
97 gyro_angle.
x = gyro_data.x;
98 gyro_angle.
y = gyro_data.y;
99 gyro_angle.
z = gyro_data.z;
102 double dt_gyro = (ts - last_ts_gyro) / 1000.0;
106 gyro_angle = gyro_angle * dt_gyro;
109 std::lock_guard<std::mutex> lock(theta_mtx);
110 theta.
add(-gyro_angle.
z, -gyro_angle.
y, gyro_angle.
x);
119 accel_angle.
z = atan2(accel_data.y, accel_data.z);
120 accel_angle.
x = atan2(accel_data.x, sqrt(accel_data.y * accel_data.y + accel_data.z * accel_data.z));
124 std::lock_guard<std::mutex> lock(theta_mtx);
140 theta.
x = theta.
x * alpha + accel_angle.
x * (1 - alpha);
141 theta.
z = theta.
z * alpha + accel_angle.
z * (1 - alpha);
148 std::lock_guard<std::mutex> lock(theta_mtx);
159 std::stringstream ss;
160 ss <<
"Device information: " << std::endl;
162 for (
int i = 0; i < static_cast<int>(RS2_CAMERA_INFO_COUNT); i++) {
163 auto info_type =
static_cast<rs2_camera_info
>(i);
164 ss <<
" " << std::left << std::setw(20) << info_type <<
" : ";
166 if (dev.supports(info_type))
167 ss << dev.get_info(info_type) << std::endl;
169 ss <<
"N/A" << std::endl;
174 static bool setOption(rs2_option option,
const rs2::sensor* sensor,
float value)
182 if (!sensor->supports(option)) {
183 yCError(REALSENSE2WITHIMU) <<
"The option" << rs2_option_to_string(option) <<
"is not supported by this sensor";
189 sensor->set_option(option, value);
190 }
catch (
const rs2::error& e) {
193 yCError(REALSENSE2WITHIMU) <<
"Failed to set option " << rs2_option_to_string(option) <<
". (" << e.what() <<
")";
199 static bool getOption(rs2_option option,
const rs2::sensor* sensor,
float& value)
206 if (!sensor->supports(option)) {
207 yCError(REALSENSE2WITHIMU) <<
"The option" << rs2_option_to_string(option) <<
"is not supported by this sensor";
213 value = sensor->get_option(option);
214 }
catch (
const rs2::error& e) {
217 yCError(REALSENSE2WITHIMU) <<
"Failed to get option " << rs2_option_to_string(option) <<
". (" << e.what() <<
")";
225 yCError(REALSENSE2WITHIMU) << error.c_str();
241 }
catch (
const rs2::error& e) {
242 yCError(REALSENSE2WITHIMU) <<
"Failed to start the pipeline:"
243 <<
"(" << e.what() <<
")";
254 }
catch (
const rs2::error& e) {
255 yCError(REALSENSE2WITHIMU) <<
"Failed to stop the pipeline:"
256 <<
"(" << e.what() <<
")";
265 std::lock_guard<std::mutex> guard(
m_mutex);
277 yCWarning(REALSENSE2WITHIMU) <<
"Format not supported, use --verbose for more details. Setting the fallback format";
285 yCWarning(REALSENSE2WITHIMU) <<
"This software module is experimental.";
286 yCWarning(REALSENSE2WITHIMU) <<
"It is provided with uncomplete documentation and it may be modified/renamed/removed without any notice.";
288 string sensor_is =
"d435i";
291 if (sensor_is ==
"d435")
297 else if (sensor_is ==
"d435i")
302 m_cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
303 m_cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);
321 yCError(REALSENSE2WITHIMU) <<
"Unkwnon device";
349 if (sens_index != 0) {
return false; }
356 if (sens_index != 0) {
return false; }
363 if (sens_index != 0) {
368 rs2::frameset dataframe =
m_pipeline.wait_for_frames();
369 auto fg = dataframe.first(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);
370 rs2::motion_frame gyro = fg.as<rs2::motion_frame>();
395 if (sens_index != 0) {
return false; }
402 if (sens_index != 0) {
return false; }
409 std::lock_guard<std::mutex> guard(
m_mutex);
410 rs2::frameset dataframe =
m_pipeline.wait_for_frames();
411 auto fa = dataframe.first(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
412 rs2::motion_frame accel = fa.as<rs2::motion_frame>();
443 if (sens_index != 0) {
return false; }
454 if (sens_index != 0) {
return false; }
462 if (sens_index != 0) {
return false; }
465 std::lock_guard<std::mutex> guard(
m_mutex);
466 rs2::frameset dataframe =
m_pipeline.wait_for_frames();
467 auto motion = dataframe.as<rs2::motion_frame>();
468 if (motion && motion.get_profile().stream_type() == RS2_STREAM_GYRO &&
469 motion.get_profile().format() == RS2_FORMAT_MOTION_XYZ32F)
472 double ts = motion.get_timestamp();
474 rs2_vector gyro_data = motion.get_motion_data();
479 if (motion && motion.get_profile().stream_type() == RS2_STREAM_ACCEL &&
480 motion.get_profile().format() == RS2_FORMAT_MOTION_XYZ32F)
483 rs2_vector accel_data = motion.get_motion_data();
489 rpy[0] = 0 + theta.
x * 180.0 /
M_PI;
490 rpy[1] = 0 + theta.
y * 180.0 /
M_PI;
491 rpy[2] = 0 + theta.
z * 180.0 /
M_PI;
realsense2 : driver for realsense2 compatible devices.
rs2_intrinsics m_color_intrin
rs2::pipeline_profile m_profile
rs2_intrinsics m_depth_intrin
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get the last reading of the specified sensor.
realsense2withIMUDriver()
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors exposed by this device.
bool m_sensor_has_orientation_estimator
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers exposed by this device.
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
std::string m_accelFrameName
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name 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 close() override
Close the DeviceDriver.
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
const std::string m_accel_sensor_tag
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get the last reading of the gyroscope.
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
const std::string m_gyro_sensor_tag
rotation_estimator * m_rotation_estimator
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes exposed by this 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.
std::string m_gyroFrameName
std::string m_inertial_sensor_name_prefix
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
std::string m_orientationFrameName
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
const std::string m_orientation_sensor_tag
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of the specified sensor.
void process_gyro(rs2_vector gyro_data, double ts)
void process_accel(rs2_vector accel_data)
A base class for nested structures that can be searched.
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.
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)