6 #define _USE_MATH_DEFINES
35 #define DEFAULT_THREAD_PERIOD 0.01
60 yCError(LOCALIZATION2D_NWS_YARP,
"Subdevice passed to attach method is invalid");
77 yCWarning(LOCALIZATION2D_NWS_YARP) <<
"Localization data not yet available during server initialization";
81 return PeriodicThread::start();
86 if (PeriodicThread::isRunning())
88 PeriodicThread::stop();
98 yCDebug(LOCALIZATION2D_NWS_YARP) <<
"Configuration: \n" << config.
toString().c_str();
100 if (config.
check(
"GENERAL") ==
false)
102 yCWarning(LOCALIZATION2D_NWS_YARP) <<
"Missing GENERAL group, assuming default options";
106 if (!general_group.
check(
"period"))
114 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Period requested: " <<
m_period;
117 if (!general_group.
check(
"publish_odometry"))
122 if (!general_group.
check(
"publish_location"))
128 if (!general_group.
check(
"retrieve_position_periodically"))
130 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Missing 'retrieve_position_periodically' parameter. Using default value: true. Period:" <<
m_period ;
137 {
yCInfo(LOCALIZATION2D_NWS_YARP) <<
"retrieve_position_periodically requested, Period:" <<
m_period; }
139 {
yCInfo(LOCALIZATION2D_NWS_YARP) <<
"retrieve_position_periodically NOT requested. Localization data obtained asynchronously."; }
142 if (!general_group.
check(
"name"))
144 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Missing 'name' parameter. Using default value:" <<
m_local_name;
149 if (
m_local_name.c_str()[0] !=
'/') {
yCError(LOCALIZATION2D_NWS_YARP) <<
"Missing '/' in name parameter" ;
return false; }
157 if (config.
check(
"subdevice"))
165 yCError(LOCALIZATION2D_NWS_YARP) <<
"Failed to open subdevice.. check params";
171 yCError(LOCALIZATION2D_NWS_YARP) <<
"Failed to attach subdevice.. check params";
177 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Waiting for device to attach";
183 yCError(LOCALIZATION2D_NWS_YARP) <<
"Error initializing YARP ports";
216 yCTrace(LOCALIZATION2D_NWS_YARP,
"Close");
217 if (PeriodicThread::isRunning())
219 PeriodicThread::stop();
231 yCDebug(LOCALIZATION2D_NWS_YARP) <<
"Execution terminated";
244 yCDebug(LOCALIZATION2D_NWS_YARP) <<
"read() Command failed";
254 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Running";
266 yCError(LOCALIZATION2D_NWS_YARP) <<
"getLocalizationStatus() failed";
274 yCError(LOCALIZATION2D_NWS_YARP) <<
"getCurrentPosition() failed";
292 yCWarning(LOCALIZATION2D_NWS_YARP,
"The system is not properly localized!");
299 publish_odometry_on_yarp_port();
302 publish_2DLocation_on_yarp_port();
306 void Localization2D_nws_yarp::publish_odometry_on_yarp_port()
319 void Localization2D_nws_yarp::publish_2DLocation_on_yarp_port()
331 temp_loc.
x = std::nan(
"");
332 temp_loc.
y = std::nan(
"");
333 temp_loc.
theta = std::nan(
"");
define control board standard interfaces
#define DEFAULT_THREAD_PERIOD
contains the definition of a Vector type
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::dev::OdometryData m_current_odometry
yarp::os::Stamp m_odom_stamp
void setInterface(yarp::dev::Nav2D::ILocalization2D *_iloc)
yarp::dev::Nav2D::LocalizationStatusEnum m_current_status
yarp::os::Stamp m_loc_stamp
bool m_getdata_using_periodic_thread
yarp::dev::Nav2D::Map2DLocation m_current_position
void run() override
Loop function.
yarp::os::BufferedPort< yarp::dev::OdometryData > m_odometryPort
std::string m_rpcPortName
bool m_enable_publish_odometry
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::dev::PolyDriver pLoc
std::string m_2DLocationPortName
yarp::dev::Nav2D::ILocalization2D * iLoc
std::string m_odometryPortName
bool initialize_YARP(yarp::os::Searchable &config)
bool open(yarp::os::Searchable &prop) override
Open the DeviceDriver.
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool close() override
Close the DeviceDriver.
ILocalization2DRPCd m_RPC
Localization2D_nws_yarp()
bool detach() override
Detach the object (you must have first called attach).
bool m_enable_publish_location
yarp::os::BufferedPort< yarp::dev::Nav2D::Map2DLocation > m_2DLocationPort
bool view(T *&x)
Get an interface to the device driver.
double theta
orientation [deg] in the map reference frame
double y
y position of the location [m], expressed in the map reference frame
double x
x position of the location [m], expressed in the map reference frame
virtual bool getEstimatedOdometry(yarp::dev::OdometryData &odom)=0
Gets the estimated odometry the robot, including its velocity expressed in the world and in the local...
virtual bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation &loc)=0
Gets the current position of the robot w.r.t world reference frame.
virtual bool getLocalizationStatus(LocalizationStatusEnum &status)=0
Gets the current status of the localization task.
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.
A simple collection of objects that can be described and transmitted in a portable way.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void close() override
Stop port activity.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
int getOutputCount() override
Determine how many output connections this port has.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An interface for reading from a network connection.
An abstraction for a periodic thread.
void setReader(PortReader &reader) override
Set an external reader for port data.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
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.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
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 Bottle & findGroup(const std::string &key) const =0
Gets a list 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...
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool asBool() const
Get boolean value.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
@ localization_status_localized_ok
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.