YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IMURosPublisher.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "IMURosPublisher.h"
8#include "yarp/math/Math.h"
9
10#ifndef M_PI
11#define M_PI (3.14159265358979323846)
12#endif
13
14YARP_LOG_COMPONENT(GENERICSENSORROSPUBLISHER, "yarp.device.IMURosPublisher")
15
16bool IMURosPublisher::viewInterfaces()
17{
18 // View all the interfaces
19 bool ok = true;
20 ok = m_poly->view(m_iThreeAxisGyroscopes);
21 if (!ok) {
22 yCError(GENERICSENSORROSPUBLISHER) << "IThreeAxisGyroscopes interface is not available";
23 return false;
24 }
25 ok = m_poly->view(m_iThreeAxisLinearAccelerometers);
26 if (!ok) {
27 yCError(GENERICSENSORROSPUBLISHER) << "IThreeAxisLinearAccelerometers interface is not available";
28 return false;
29 }
30 ok = m_poly->view(m_iThreeAxisMagnetometers);
31 if (!ok) {
32 yCError(GENERICSENSORROSPUBLISHER) << "IThreeAxisMagnetometers interface is not available";
33 return false;
34 }
35 ok = m_poly->view(m_iOrientationSensors);
36 if (!ok) {
37 yCError(GENERICSENSORROSPUBLISHER) << "IOrientationSensors interface is not available";
38 return false;
39 }
40
41 ok = m_iThreeAxisGyroscopes->getThreeAxisGyroscopeFrameName(m_sens_index, m_framename);
42 return ok;
43}
44
46{
48 {
49 yarp::sig::Vector vecgyr(3);
50 yarp::sig::Vector vecacc(3);
51 yarp::sig::Vector vecrpy(3);
52 yarp::rosmsg::sensor_msgs::Imu& imu_ros_data = m_publisher.prepare();
53 m_iThreeAxisGyroscopes->getThreeAxisGyroscopeMeasure(m_sens_index, vecgyr, m_timestamp);
54 m_iThreeAxisLinearAccelerometers->getThreeAxisLinearAccelerometerMeasure(m_sens_index, vecacc, m_timestamp);
56 imu_ros_data.clear();
57 imu_ros_data.header.frame_id = m_framename;
58 imu_ros_data.header.seq = m_msg_counter++;
59 imu_ros_data.header.stamp = m_timestamp;
60 imu_ros_data.angular_velocity.x = vecgyr[0] * M_PI / 180.0;
61 imu_ros_data.angular_velocity.y = vecgyr[1] * M_PI / 180.0;
62 imu_ros_data.angular_velocity.z = vecgyr[2] * M_PI / 180.0;
63 imu_ros_data.linear_acceleration.x = vecacc[0];
64 imu_ros_data.linear_acceleration.y = vecacc[1];
65 imu_ros_data.linear_acceleration.z = vecacc[2];
66 vecrpy[0] = vecrpy[0] * M_PI / 180.0;
67 vecrpy[1] = vecrpy[1] * M_PI / 180.0;
68 vecrpy[2] = vecrpy[2] * M_PI / 180.0;
71 imu_ros_data.orientation.x = q.x();
72 imu_ros_data.orientation.y = q.y();
73 imu_ros_data.orientation.z = q.z();
74 imu_ros_data.orientation.w = q.w();
75
76 //imu_ros_data.orientation_covariance = 0;
78 }
79 }
#define M_PI
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::Imu > m_publisher
IMURosPublisher: This wrapper connects to a device and publishes a ROS topic of type sensor_msgs::Imu...
void run() override
Loop function.
bool view(T *&x)
Get an interface to the device driver.
virtual bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double &timestamp) const =0
Get the last reading of the orientation sensor as roll pitch yaw.
virtual bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const =0
Get the last reading of the gyroscope.
virtual bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const =0
Get the last reading of the specified sensor.
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
bool isOpen() const
Check if the port has been opened.
Definition Port.cpp:677
Port & asPort() override
Get the concrete Port being used for communication.
Definition Publisher.h:169
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
Definition Publisher.h:148
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
Definition Publisher.h:123
A class for a Matrix.
Definition Matrix.h:39
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
yarp::sig::Matrix rpy2dcm(const yarp::sig::Vector &rpy)
Converts roll-pitch-yaw angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
Definition math.cpp:847