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;
56  }
57  }
yarp::rosmsg::geometry_msgs::Quaternion::y
yarp::conf::float64_t y
Definition: Quaternion.h:38
GenericSensorRosPublisher< yarp::rosmsg::geometry_msgs::PoseStamped >::m_framename
std::string m_framename
Definition: GenericSensorRosPublisher.h:60
GenericSensorRosPublisher< yarp::rosmsg::geometry_msgs::PoseStamped >::m_publisher
yarp::os::Publisher< yarp::rosmsg::geometry_msgs::PoseStamped > m_publisher
Definition: GenericSensorRosPublisher.h:56
yarp::rosmsg::geometry_msgs::Point::z
yarp::conf::float64_t z
Definition: Point.h:37
PoseStampedRosPublisher.h
yarp::math::Quaternion::fromRotationMatrix
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
Definition: Quaternion.cpp:154
yarp::math::Quaternion::y
double y() const
Definition: Quaternion.cpp:80
yarp::rosmsg::geometry_msgs::Pose::position
yarp::rosmsg::geometry_msgs::Point position
Definition: Pose.h:36
yarp::math::Quaternion::z
double z() const
Definition: Quaternion.cpp:85
YARP_LOG_COMPONENT
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80
M_PI
#define M_PI
Definition: PoseStampedRosPublisher.cpp:14
yarp::rosmsg::std_msgs::Header::frame_id
std::string frame_id
Definition: Header.h:49
Matrix.h
contains the definition of a Matrix type
yarp::rosmsg::geometry_msgs::Quaternion::x
yarp::conf::float64_t x
Definition: Quaternion.h:37
yarp::dev::DeviceDriver::view
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:77
yarp::rosmsg::geometry_msgs::Pose::orientation
yarp::rosmsg::geometry_msgs::Quaternion orientation
Definition: Pose.h:37
yarp::math::rpy2dcm
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
yarp::dev::IPositionSensors::getPositionSensorMeasure
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.
yarp::math::Quaternion::x
double x() const
Definition: Quaternion.cpp:75
yarp::sig::VectorOf< double >
yarp::rosmsg::std_msgs::Header::seq
std::uint32_t seq
Definition: Header.h:47
yarp::rosmsg::geometry_msgs::PoseStamped::header
yarp::rosmsg::std_msgs::Header header
Definition: PoseStamped.h:36
GenericSensorRosPublisher< yarp::rosmsg::geometry_msgs::PoseStamped >::m_sens_index
const size_t m_sens_index
Definition: GenericSensorRosPublisher.h:61
yarp::os::Publisher::write
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
Definition: Publisher.h:152
Math.h
GenericSensorRosPublisher< yarp::rosmsg::geometry_msgs::PoseStamped >::m_timestamp
double m_timestamp
Definition: GenericSensorRosPublisher.h:59
yarp::rosmsg::geometry_msgs::PoseStamped
Definition: PoseStamped.h:34
yarp::math::Quaternion
Definition: Quaternion.h:27
PoseStampedRosPublisher
PoseStampedRosPublisher: This wrapper connects to a device and publishes a ROS topic of type geometry...
Definition: PoseStampedRosPublisher.h:33
PoseStampedRosPublisher::run
void run() override
Loop function.
Definition: PoseStampedRosPublisher.cpp:29
yarp::rosmsg::geometry_msgs::Quaternion::w
yarp::conf::float64_t w
Definition: Quaternion.h:40
yarp::os::Publisher::asPort
Port & asPort() override
Get the concrete Port being used for communication.
Definition: Publisher.h:172
GENERICSENSORROSPUBLISHER
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
Definition: PoseStampedRosPublisher.cpp:17
yarp::dev::IOrientationSensors::getOrientationSensorMeasureAsRollPitchYaw
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.
yarp::rosmsg::geometry_msgs::Quaternion::z
yarp::conf::float64_t z
Definition: Quaternion.h:39
yarp::math::Quaternion::w
double w() const
Definition: Quaternion.cpp:70
yarp::rosmsg::geometry_msgs::PoseStamped::pose
yarp::rosmsg::geometry_msgs::Pose pose
Definition: PoseStamped.h:37
yarp::rosmsg::geometry_msgs::Point::y
yarp::conf::float64_t y
Definition: Point.h:36
yarp::rosmsg::std_msgs::Header::stamp
yarp::rosmsg::TickTime stamp
Definition: Header.h:48
yarp::rosmsg::geometry_msgs::PoseStamped::clear
void clear()
Definition: PoseStamped.h:45
GenericSensorRosPublisher< yarp::rosmsg::geometry_msgs::PoseStamped >::m_msg_counter
size_t m_msg_counter
Definition: GenericSensorRosPublisher.h:58
yarp::os::Publisher::prepare
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
Definition: Publisher.h:127
yarp::os::Port::isOpen
bool isOpen() const
Check if the port has been opened.
Definition: Port.cpp:671
yarp::rosmsg::geometry_msgs::Point::x
yarp::conf::float64_t x
Definition: Point.h:35
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46