Skip to content

Commit

Permalink
Merge pull request #3 from robotology/fixcompatyarp310
Browse files Browse the repository at this point in the history
Fix compatibility with YARP 3.10
  • Loading branch information
traversaro authored Oct 11, 2024
2 parents e98fcc3 + 1e6d30b commit 5aa2269
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/devices/Rangefinder2D_nws_ros/Rangefinder2D_nws_ros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <yarp/sig/Vector.h>

#include <yarp/dev/LaserScan2D.h>
#include <yarp/dev/IRangefinder2D.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/DeviceDriver.h>
Expand Down
4 changes: 2 additions & 2 deletions src/devices/laserFromRosTopic/LaserFromRosTopic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void InputPortProcessor::onRead(yarp::rosmsg::sensor_msgs::LaserScan& b)
m_port_mutex.unlock();
}

inline void InputPortProcessor::getLast(yarp::dev::LaserScan2D& data, Stamp& stmp)
inline void InputPortProcessor::getLast(yarp::sig::LaserScan2D& data, Stamp& stmp)
{
//this blocks untils the first data is received;
size_t counter =0;
Expand Down Expand Up @@ -336,7 +336,7 @@ bool LaserFromRosTopic::threadInit()
return true;
}

void LaserFromRosTopic::calculate(yarp::dev::LaserScan2D scan_data, yarp::sig::Matrix m)
void LaserFromRosTopic::calculate(yarp::sig::LaserScan2D scan_data, yarp::sig::Matrix m)
{
yarp::sig::Vector temp(3);
temp = yarp::math::dcm2rpy(m);
Expand Down
30 changes: 25 additions & 5 deletions src/devices/laserFromRosTopic/LaserFromRosTopic.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <yarp/os/Stamp.h>
#include <yarp/dev/ControlBoardInterfaces.h>
#include <yarp/dev/IRangefinder2D.h>
#include <yarp/dev/LaserScan2D.h>
#include <yarp/dev/Lidar2DDeviceBase.h>
#include <yarp/sig/Vector.h>
#include <yarp/dev/IFrameTransform.h>
Expand All @@ -30,6 +29,27 @@
#include <string>
#include <vector>

// Compatibility with both YARP 3.9 and 3.10
// See https://github.com/robotology/yarp/pull/3130
#if __has_include (<yarp/dev/LaserScan2D.h>)

// YARP 3.9 case
#include <yarp/dev/LaserScan2D.h>

namespace yarp {
namespace sig {
typedef yarp::dev::LaserScan2D LaserScan2D;
}
}

#else

// YARP 3.10 case
#include <yarp/sig/LaserScan2D.h>

#endif


typedef unsigned char byte;

//---------------------------------------------------------------------------------------------------------------
Expand All @@ -44,7 +64,7 @@ class InputPortProcessor :
public yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>
{
std::mutex m_port_mutex;
yarp::dev::LaserScan2D m_lastScan;
yarp::sig::LaserScan2D m_lastScan;
yarp::os::Stamp m_lastStamp;
bool m_contains_data;

Expand All @@ -60,7 +80,7 @@ class InputPortProcessor :
InputPortProcessor();
using yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>::onRead;
virtual void onRead(yarp::rosmsg::sensor_msgs::LaserScan& v) override;
void getLast(yarp::dev::LaserScan2D& data, yarp::os::Stamp& stmp);
void getLast(yarp::sig::LaserScan2D& data, yarp::os::Stamp& stmp);
};

/**
Expand All @@ -78,7 +98,7 @@ class LaserFromRosTopic : public yarp::dev::Lidar2DDeviceBase,
yarp::os::Node* m_ros_node = nullptr;
std::vector<InputPortProcessor> m_input_ports;
std::vector <yarp::os::Stamp> m_last_stamp;
std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
std::vector <yarp::sig::LaserScan2D> m_last_scan_data;
yarp::dev::PolyDriver m_tc_driver;
yarp::dev::IFrameTransform* m_iTc = nullptr;

Expand All @@ -87,7 +107,7 @@ class LaserFromRosTopic : public yarp::dev::Lidar2DDeviceBase,
yarp::sig::Vector m_empty_laser_data;
base_enum m_base_type;

void calculate(yarp::dev::LaserScan2D scan, yarp::sig::Matrix m);
void calculate(yarp::sig::LaserScan2D scan, yarp::sig::Matrix m);

public:
LaserFromRosTopic(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
Expand Down

0 comments on commit 5aa2269

Please sign in to comment.