6#define _USE_MATH_DEFINES
50 if (!config.
check(
"node_name"))
56 if(nodeName[0] !=
'/'){
63 if (!config.
check(
"topic_name"))
69 if(topicName[0] !=
'/'){
76 if (!config.
check(
"frame_id"))
87bool Rangefinder2D_nws_ros::initialize_ROS()
95 if (!publisherPort.
topic(topicName))
111 driver->
view(sens_p);
114 if (
nullptr == sens_p)
139 PeriodicThread::setPeriod(_period);
140 return PeriodicThread::start();
150 if (PeriodicThread::isRunning())
152 PeriodicThread::stop();
168 if (!config.
check(
"period"))
175 checkROSParams(config);
178 if (!initialize_ROS())
183 if(config.
check(
"subdevice"))
200 isDeviceOwned =
true;
208 publisherPort.
close();
218 double synchronized_timestamp=0;
224 if (std::isnan(synchronized_timestamp) ==
false)
226 lastStateStamp.
update(synchronized_timestamp);
233 int ranges_size = ranges.
size();
237 rosData.header.seq = msgCounter++;
238 rosData.header.stamp = lastStateStamp.
getTime();
239 rosData.header.frame_id = frame_id;
241 rosData.angle_min = minAngle *
M_PI / 180.0;
242 rosData.angle_max = maxAngle *
M_PI / 180.0;
243 rosData.angle_increment = resolution *
M_PI / 180.0;
244 rosData.time_increment = 0;
246 rosData.range_min = minDistance;
247 rosData.range_max = maxDistance;
248 rosData.ranges.resize(ranges_size);
249 rosData.intensities.resize(ranges_size);
251 for (
int i = 0; i < ranges_size; i++)
255 if (std::isnan(ranges[i]))
257 rosData.ranges[i] = std::numeric_limits<double>::infinity();
258 rosData.intensities[i] = 0.0;
262 rosData.ranges[i] = ranges[i];
263 rosData.intensities[i] = 0.0;
266 publisherPort.
write();
278 if (PeriodicThread::isRunning())
280 PeriodicThread::stop();
define control board standard interfaces
constexpr double DEFAULT_THREAD_PERIOD
const yarp::os::LogComponent & RANGEFINDER2D_NWS_ROS()
rangefinder2D_nws_ros: A Network grabber for 2D Rangefinder devices. This device will publish data on...
bool close() override
Close the DeviceDriver.
void threadRelease() override
Release method.
bool detach() override
Detach the object (you must have first called attach).
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
void attach(yarp::dev::IRangefinder2D *s)
bool threadInit() override
Initialization method.
void run() override
Loop function.
bool view(T *&x)
Get an interface to the device driver.
A generic interface for planar laser range finders.
virtual bool getDistanceRange(double &min, double &max)=0
get the device detection range
virtual bool getScanLimits(double &min, double &max)=0
get the scan angular range.
virtual bool getHorizontalResolution(double &step)=0
get the angular step between two measurements.
virtual bool getRawData(yarp::sig::Vector &data, double *timestamp=nullptr)=0
Get the device measurements.
virtual bool getDeviceStatus(Device_status &status)=0
get the device status
A container for a device driver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
void interrupt()
interrupt delegates the call to the Node port interrupt.
An abstraction for a periodic thread.
double getPeriod() const
Return the current period of the thread.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void close() override
Stop port activity.
bool topic(const std::string &name)
Set topic to publish to.
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
double getTime() const
Get the time stamp.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
yarp::rosmsg::sensor_msgs::LaserScan LaserScan
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.