YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MagneticFieldRosPublisher.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
8YARP_LOG_COMPONENT(GENERICSENSORROSPUBLISHER, "yarp.device.MagneticFieldRosPublisher")
9
10bool MagneticFieldRosPublisher::viewInterfaces()
11{
12 // View all the interfaces
13 bool ok = true;
14 ok = m_poly->view(m_iThreeAxisMagnetometers);
15 if (!ok) {
16 yCError(GENERICSENSORROSPUBLISHER) << "IThreeAxisMagnetometers interface is not available";
17 return false;
18 }
19
20 ok = m_iThreeAxisMagnetometers->getThreeAxisMagnetometerFrameName(0, m_framename);
21 return ok;
22}
23
25{
27 {
28 yarp::sig::Vector vecmagn(3);
29 yarp::rosmsg::sensor_msgs::MagneticField& magfield_ros_data = m_publisher.prepare();
31 magfield_ros_data.clear();
32 magfield_ros_data.header.frame_id = m_framename;;
33 magfield_ros_data.header.seq = m_msg_counter++;
34 magfield_ros_data.header.stamp = m_timestamp;
35 magfield_ros_data.magnetic_field.x = vecmagn[0];
36 magfield_ros_data.magnetic_field.y = vecmagn[1];
37 magfield_ros_data.magnetic_field.z = vecmagn[2];
38 //magfield_ros_data.magnetic_field_covariance = 0;
40 }
41 }
const yarp::os::LogComponent & GENERICSENSORROSPUBLISHER()
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::MagneticField > m_publisher
MagneticFieldRosPublisher: This wrapper connects to a device and publishes a ROS topic of type sensor...
yarp::dev::IThreeAxisMagnetometers * m_iThreeAxisMagnetometers
void run() override
Loop function.
bool view(T *&x)
Get an interface to the device driver.
virtual bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const =0
Get the last reading of the specified sensor.
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
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)