YARP
Yet Another Robot Platform
PoseStampedRosPublisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
10 #include <yarp/sig/Matrix.h>
11 #include <yarp/math/Math.h>
12 
13 #ifndef M_PI
14 #define M_PI (3.14159265358979323846)
15 #endif
16 
17 YARP_LOG_COMPONENT(GENERICSENSORROSPUBLISHER, "yarp.device.PoseStampedRosPublisher")
18 
19 bool PoseStampedRosPublisher::viewInterfaces()
20 {
21  // View all the interfaces
22  bool ok = true;
23  ok &= m_poly->view(m_iOrientationSensors);
24  ok &= m_poly->view(m_iPositionSensors);
25  m_iPositionSensors->getPositionSensorFrameName(m_sens_index, m_framename);
26  return ok;
27 }
28 
30 {
31  if (m_publisher.asPort().isOpen())
32  {
33  yarp::sig::Vector vecpos(3);
34  yarp::sig::Vector vecrpy(3);
36  m_iPositionSensors->getPositionSensorMeasure(m_sens_index, vecpos, m_timestamp);
38  pose_data.clear();
39  pose_data.header.frame_id = m_framename;
40  pose_data.header.seq = m_msg_counter++;
41  pose_data.header.stamp = m_timestamp;
42  pose_data.pose.position.x = vecpos[0];
43  pose_data.pose.position.y = vecpos[1];
44  pose_data.pose.position.z = vecpos[2];
45  vecrpy[0] = vecrpy[0] * M_PI / 180.0;
46  vecrpy[1] = vecrpy[1] * M_PI / 180.0;
47  vecrpy[2] = vecrpy[2] * M_PI / 180.0;
48  yarp::sig::Matrix matrix = yarp::math::rpy2dcm(vecrpy);
50  pose_data.pose.orientation.x = q.x();
51  pose_data.pose.orientation.y = q.y();
52  pose_data.pose.orientation.z = q.z();
53  pose_data.pose.orientation.w = q.w();
54  //imu_ros_data.orientation_covariance = 0;
55  m_publisher.write();
56  }
57  }
contains the definition of a Matrix type
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
#define M_PI
yarp::os::Publisher< yarp::rosmsg::geometry_msgs::PoseStamped > m_publisher
This wrapper connects to a device and publishes a ROS topic of type geometry_msgs::PoseStamped.
void run() override
Loop function.
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:77
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 getPositionSensorMeasure(size_t sens_index, yarp::sig::Vector &xyz, double &timestamp) const =0
Get the last reading of the position sensor as x y z.
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
Definition: Quaternion.cpp:154
double x() const
Definition: Quaternion.cpp:75
double z() const
Definition: Quaternion.cpp:85
double w() const
Definition: Quaternion.cpp:70
double y() const
Definition: Quaternion.cpp:80
yarp::conf::float64_t y
Definition: Point.h:36
yarp::conf::float64_t x
Definition: Point.h:35
yarp::conf::float64_t z
Definition: Point.h:37
yarp::rosmsg::geometry_msgs::Pose pose
Definition: PoseStamped.h:37
yarp::rosmsg::std_msgs::Header header
Definition: PoseStamped.h:36
yarp::rosmsg::geometry_msgs::Point position
Definition: Pose.h:36
yarp::rosmsg::geometry_msgs::Quaternion orientation
Definition: Pose.h:37
yarp::rosmsg::TickTime stamp
Definition: Header.h:48
A class for a Matrix.
Definition: Matrix.h:46
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80
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:818