|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
19 #define _USE_MATH_DEFINES
69 if (!config.
check(
"ROS"))
87 if (!rosGroup.
check(
"useROS"))
90 Allowed values are true, false, ROS_only";
94 std::string ros_use_type = rosGroup.
find(
"useROS").
asString();
95 if (ros_use_type ==
"false")
101 else if (ros_use_type ==
"true")
106 else if (ros_use_type ==
"only")
113 yCInfo(
RANGEFINDER2DWRAPPER) << partName <<
"useROS parameter is set to invalid value ('" << ros_use_type <<
"'), supported values are 'true', 'false', 'only'";
119 if (!rosGroup.
check(
"ROS_nodeName"))
129 if (!rosGroup.
check(
"ROS_topicName"))
135 rosTopicName = rosGroup.
find(
"ROS_topicName").
asString();
139 if (!rosGroup.
check(
"frame_id"))
151 bool Rangefinder2DWrapper::initialize_ROS()
153 bool success =
false;
166 if (!rosPublisherPort.topic(rosTopicName))
202 if (device2attach.
size() != 1)
212 Idevice2attach->
view(sens_p);
213 Idevice2attach->
view(iTimed);
216 if (
nullptr == sens_p)
223 if(!sens_p->getDistanceRange(minDistance, maxDistance))
229 if(!sens_p->getScanLimits(minAngle, maxAngle))
235 if (!sens_p->getHorizontalResolution(resolution))
241 PeriodicThread::setPeriod(_period);
242 return PeriodicThread::start();
247 if (PeriodicThread::isRunning())
249 PeriodicThread::stop();
262 if (PeriodicThread::isRunning())
264 PeriodicThread::stop();
273 bool ok = in.
read(connection);
274 if (!ok)
return false;
291 if (sens_p->getDeviceInfo(info))
310 if (sens_p->getDistanceRange(min, max))
330 if (sens_p->getScanLimits(min, max))
349 if (sens_p->getHorizontalResolution(step))
367 if (sens_p->getScanRate(rate))
394 sens_p->setDistanceRange(min, max);
404 sens_p->setScanLimits(min, max);
413 sens_p->setScanRate(rate);
422 sens_p->setHorizontalResolution(step);
448 if (returnToSender !=
nullptr) {
449 out.
write(*returnToSender);
475 if (!config.
check(
"period"))
481 _period = config.
find(
"period").
asInt32() / 1000.0;
483 if (!config.
check(
"name"))
492 rpcPortName = streamingPortName +
"/rpc:i";
493 setId(
"Rangefinder2DWrapper");
496 checkROSParams(config);
498 if(!initialize_YARP(config) )
506 if (!initialize_ROS())
511 if(config.
check(
"subdevice"))
518 if(!driver.open(p) || !driver.isValid())
524 driverlist.
push(&driver,
"1");
525 if(!attachAll(driverlist))
530 isDeviceOwned =
true;
539 if (!streamingPort.open(streamingPortName))
544 if (!rpcPort.open(rpcPortName))
549 rpcPort.setReader(*
this);
556 streamingPort.interrupt();
557 streamingPort.close();
569 ret &= sens_p->getRawData(ranges);
570 ret &= sens_p->getDeviceStatus(status);
575 lastStateStamp = iTimed->getLastInputStamp();
579 int ranges_size = ranges.
size();
589 streamingPort.setEnvelope(lastStateStamp);
590 streamingPort.write();
607 rosData.
ranges.resize(ranges_size);
610 for (
int i = 0; i < ranges_size; i++)
614 if (std::isnan(ranges[i]))
616 rosData.
ranges[i] = std::numeric_limits<double>::infinity();
621 rosData.
ranges[i] = ranges[i];
625 rosPublisherPort.write();
638 if (PeriodicThread::isRunning())
640 PeriodicThread::stop();
A simple collection of objects that can be described and transmitted in a portable way.
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
constexpr yarp::conf::vocab32_t VOCAB_ILASER2D
void clear()
Empties the bottle of any objects it contains.
A base class for nested structures that can be searched.
double angle_max
last angle of the scan [deg]
bool detachAll() override
Detach the object (you must have first called attach).
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
constexpr yarp::conf::vocab32_t VOCAB_LASER_SCAN_RATE
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
yarp::conf::float32_t time_increment
bool isValid() const
Check if device is valid.
#define YARP_LOG_COMPONENT(name,...)
constexpr yarp::conf::vocab32_t VOCAB_GET
yarp::conf::float32_t scan_time
A generic interface for planar laser range finders.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
define control board standard interfaces
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
void attach(yarp::dev::IRangefinder2D *s)
void push(PolyDriver *p, const char *k)
bool check(const std::string &key) const override
Check if there exists a property of the given name.
const yarp::os::LogComponent & RANGEFINDER2DWRAPPER()
constexpr yarp::conf::vocab32_t VOCAB_SET
yarp::conf::float32_t angle_max
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
An interface for writing to a network connection.
void setId(const std::string &id)
yarp::rosmsg::std_msgs::Header header
virtual std::string asString() const
Get string value.
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
A container for a device driver.
yarp::conf::float32_t range_max
constexpr yarp::conf::vocab32_t VOCAB_FAILED
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
double range_max
the maximum distance of the scan [m]
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
std::vector< yarp::conf::float32_t > ranges
constexpr yarp::conf::vocab32_t VOCAB_LASER_DISTANCE_RANGE
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_STEP
void addString(const char *str)
Places a string in the bottle, at the end of the list.
yarp::conf::float32_t angle_increment
std::vector< yarp::conf::float32_t > intensities
An abstraction for a periodic thread.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
yarp::conf::float32_t range_min
bool isNull() const override
Checks if the object is invalid.
An interface for reading from a network connection.
bool threadInit() override
Initialization method.
double angle_min
first angle of the scan [deg]
#define yCError(component,...)
constexpr yarp::conf::vocab32_t VOCAB_DEVICE_INFO
virtual std::int32_t asInt32() const
Get 32-bit integer value.
bool close() override
Close the DeviceDriver.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define DEFAULT_THREAD_PERIOD
constexpr yarp::conf::vocab32_t VOCAB_LASER_ANGULAR_RANGE
void threadRelease() override
Release method.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void interrupt()
interrupt delegates the call to the Node port interrupt.
yarp::conf::float32_t angle_min
Rangefinder2DWrapper: Documentation to be added
#define yCTrace(component,...)
constexpr yarp::conf::vocab32_t VOCAB_IS
yarp::sig::Vector scans
the scan data, measured in [m].
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
double range_min
the minimum distance of the scan [m]
void run() override
Loop function.
A class for storing options and configuration information.