YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PoseStampedRosPublisher.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
7#include <yarp/sig/Matrix.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.PoseStampedRosPublisher")
15
16bool PoseStampedRosPublisher::viewInterfaces()
17{
18 // View all the interfaces
19 bool ok = true;
20 ok = m_poly->view(m_iOrientationSensors);
21 if (!ok) {
22 yCError(GENERICSENSORROSPUBLISHER) << "IOrientationSensors interface is not available";
23 return false;
24 }
25 ok = m_poly->view(m_iPositionSensors);
26 if (!ok) {
27 yCError(GENERICSENSORROSPUBLISHER) << "IPositionSensors interface is not available";
28 return false;
29 }
30 ok = m_iPositionSensors->getPositionSensorFrameName(m_sens_index, m_framename);
31 return ok;
32}
33
35{
37 {
38 yarp::sig::Vector vecpos(3);
39 yarp::sig::Vector vecrpy(3);
40 yarp::rosmsg::geometry_msgs::PoseStamped& pose_data = m_publisher.prepare();
41 m_iPositionSensors->getPositionSensorMeasure(m_sens_index, vecpos, m_timestamp);
43 pose_data.clear();
44 pose_data.header.frame_id = m_framename;
45 pose_data.header.seq = m_msg_counter++;
46 pose_data.header.stamp = m_timestamp;
47 pose_data.pose.position.x = vecpos[0];
48 pose_data.pose.position.y = vecpos[1];
49 pose_data.pose.position.z = vecpos[2];
50 vecrpy[0] = vecrpy[0] * M_PI / 180.0;
51 vecrpy[1] = vecrpy[1] * M_PI / 180.0;
52 vecrpy[2] = vecrpy[2] * M_PI / 180.0;
55 pose_data.pose.orientation.x = q.x();
56 pose_data.pose.orientation.y = q.y();
57 pose_data.pose.orientation.z = q.z();
58 pose_data.pose.orientation.w = q.w();
59 //imu_ros_data.orientation_covariance = 0;
61 }
62 }
#define M_PI
contains the definition of a Matrix type
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
yarp::os::Publisher< yarp::rosmsg::geometry_msgs::PoseStamped > m_publisher
PoseStampedRosPublisher: This wrapper connects to a device and publishes a ROS topic of type geometry...
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 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.
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