YARP
Yet Another Robot Platform
MagneticFieldRosPublisher.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 
11 YARP_LOG_COMPONENT(GENERICSENSORROSPUBLISHER, "yarp.device.MagneticFieldRosPublisher")
12 
13 bool MagneticFieldRosPublisher::viewInterfaces()
14 {
15  // View all the interfaces
16  bool ok = true;
17  ok &= m_poly->view(m_iThreeAxisMagnetometers);
18  m_iThreeAxisMagnetometers->getThreeAxisMagnetometerFrameName(0, m_framename);
19  return ok;
20 }
21 
23 {
24  if (m_publisher.asPort().isOpen())
25  {
26  yarp::sig::Vector vecmagn(3);
27  yarp::rosmsg::sensor_msgs::MagneticField& magfield_ros_data = m_publisher.prepare();
29  magfield_ros_data.clear();
30  magfield_ros_data.header.frame_id = m_framename;;
31  magfield_ros_data.header.seq = m_msg_counter++;
32  magfield_ros_data.header.stamp = m_timestamp;
33  magfield_ros_data.magnetic_field.x = vecmagn[0];
34  magfield_ros_data.magnetic_field.y = vecmagn[1];
35  magfield_ros_data.magnetic_field.z = vecmagn[2];
36  //magfield_ros_data.magnetic_field_covariance = 0;
37  m_publisher.write();
38  }
39  }
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::MagneticField > m_publisher
This wrapper connects to a device and publishes a ROS topic of type sensor_msgs::MagneticField.
yarp::dev::IThreeAxisMagnetometers * m_iThreeAxisMagnetometers
void run() override
Loop function.
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:77
virtual bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const =0
Get the last reading of the specified sensor.
yarp::conf::float64_t y
Definition: Vector3.h:41
yarp::conf::float64_t z
Definition: Vector3.h:42
yarp::conf::float64_t x
Definition: Vector3.h:40
yarp::rosmsg::std_msgs::Header header
Definition: MagneticField.h:54
yarp::rosmsg::geometry_msgs::Vector3 magnetic_field
Definition: MagneticField.h:55
yarp::rosmsg::TickTime stamp
Definition: Header.h:48
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80