6 #define _USE_MATH_DEFINES
35 #define DEFAULT_THREAD_PERIOD 0.01
59 yCError(LOCALIZATION2D_NWS_YARP,
"Subdevice passed to attach method is invalid");
76 yCWarning(LOCALIZATION2D_NWS_YARP) <<
"Localization data not yet available during server initialization";
80 return PeriodicThread::start();
85 if (PeriodicThread::isRunning())
87 PeriodicThread::stop();
97 yCDebug(LOCALIZATION2D_NWS_YARP) <<
"Configuration: \n" << config.
toString().c_str();
99 if (config.
check(
"GENERAL") ==
false)
101 yCWarning(LOCALIZATION2D_NWS_YARP) <<
"Missing GENERAL group, assuming default options";
105 if (!general_group.
check(
"period"))
113 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Period requested: " <<
m_period;
116 if (!general_group.
check(
"publish_odometry"))
121 if (!general_group.
check(
"publish_location"))
127 if (!general_group.
check(
"retrieve_position_periodically"))
129 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Missing 'retrieve_position_periodically' parameter. Using default value: true. Period:" <<
m_period ;
136 {
yCInfo(LOCALIZATION2D_NWS_YARP) <<
"retrieve_position_periodically requested, Period:" <<
m_period; }
138 {
yCInfo(LOCALIZATION2D_NWS_YARP) <<
"retrieve_position_periodically NOT requested. Localization data obtained asynchronously."; }
141 if (!general_group.
check(
"name"))
143 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Missing 'name' parameter. Using default value:" <<
m_local_name;
148 if (
m_local_name.c_str()[0] !=
'/') {
yCError(LOCALIZATION2D_NWS_YARP) <<
"Missing '/' in name parameter" ;
return false; }
156 if (config.
check(
"subdevice"))
164 yCError(LOCALIZATION2D_NWS_YARP) <<
"Failed to open subdevice.. check params";
170 yCError(LOCALIZATION2D_NWS_YARP) <<
"Failed to open subdevice.. check params";
176 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Waiting for device to attach";
182 yCError(LOCALIZATION2D_NWS_YARP) <<
"Error initializing YARP ports";
215 yCTrace(LOCALIZATION2D_NWS_YARP,
"Close");
216 if (PeriodicThread::isRunning())
218 PeriodicThread::stop();
230 yCDebug(LOCALIZATION2D_NWS_YARP) <<
"Execution terminated";
238 bool ok = command.
read(connection);
326 for (
size_t i = 0; i < 3; i++) {
for (
size_t j = 0; j < 3; j++) { mc.
addFloat64(cov[i][j]); } }
337 if (mc!=
nullptr && mc->
size() == 9)
339 for (
size_t i = 0; i < 3; i++) {
for (
size_t j = 0; j < 3; j++) { cov[i][j] = mc->
get(i * 3 + j).
asFloat64(); } }
377 std::vector<Map2DLocation> poses;
381 for (
size_t i=0; i<poses.size(); i++)
397 yCError(LOCALIZATION2D_NWS_YARP) <<
"Invalid vocab received";
404 reply.
addString(
"Available commands are:");
406 reply.
addString(
"initLoc <map_name> <x> <y> <angle in degrees>");
412 std::string s = std::string(
"Current Location is: ") + curr_loc.
toString();
423 std::string s = std::string(
"Localization initialized to: ") + init_loc.
toString();
428 yCError(LOCALIZATION2D_NWS_YARP) <<
"Invalid command type";
433 if (returnToSender !=
nullptr)
435 reply.
write(*returnToSender);
446 yCInfo(LOCALIZATION2D_NWS_YARP) <<
"Running";
455 yCError(LOCALIZATION2D_NWS_YARP) <<
"getLocalizationStatus() failed";
463 yCError(LOCALIZATION2D_NWS_YARP) <<
"getCurrentPosition() failed";
481 yCWarning(LOCALIZATION2D_NWS_YARP,
"The system is not properly localized!");
486 publish_odometry_on_yarp_port();
489 publish_2DLocation_on_yarp_port();
493 void Localization2D_nws_yarp::publish_odometry_on_yarp_port()
506 void Localization2D_nws_yarp::publish_2DLocation_on_yarp_port()
518 temp_loc.
x = std::nan(
"");
519 temp_loc.
y = std::nan(
"");
520 temp_loc.
theta = std::nan(
"");
define control board standard interfaces
constexpr yarp::conf::vocab32_t VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_ERR
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LOCALIZER_POSES
constexpr yarp::conf::vocab32_t VOCAB_INAVIGATION
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCALIZATION_STOP
constexpr yarp::conf::vocab32_t VOCAB_NAV_SET_INITIAL_POSCOV
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_CURRENT_POS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LOCALIZER_STATUS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_ESTIMATED_ODOM
constexpr yarp::conf::vocab32_t VOCAB_NAV_SET_INITIAL_POS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_CURRENT_POSCOV
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCALIZATION_START
#define DEFAULT_THREAD_PERIOD
contains the definition of a Vector type
yarp::os::Stamp m_loc_stamp
void run() override
Loop function.
yarp::dev::OdometryData m_current_odometry
yarp::os::Stamp m_odom_stamp
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 m_getdata_using_periodic_thread
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.
Localization2D_nws_yarp()
bool detach() override
Detach the object (you must have first called attach).
bool m_enable_publish_location
yarp::dev::Nav2D::LocalizationStatusEnum m_current_status
yarp::dev::Nav2D::Map2DLocation m_current_position
yarp::os::BufferedPort< yarp::dev::Nav2D::Map2DLocation > m_2DLocationPort
bool view(T *&x)
Get an interface to the device driver.
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 getEstimatedPoses(std::vector< yarp::dev::Nav2D::Map2DLocation > &poses)=0
Gets a set of pose estimates computed by the localization algorithm.
virtual bool startLocalizationService()=0
Starts the localization service.
virtual bool stopLocalizationService()=0
Stops the localization service.
virtual bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation &loc)=0
Sets the initial pose for the localization algorithm which estimates the current position of the robo...
virtual bool getLocalizationStatus(LocalizationStatusEnum &status)=0
Gets the current status of the localization task.
double base_vel_x
velocity of the robot [m/s] expressed in the robot reference frame
double odom_vel_y
velocity of the robot [m/s] expressed in the world reference frame
double base_vel_theta
angular velocity of the robot [deg/s] expressed in the robot reference frame
double odom_vel_theta
angular velocity of the robot [deg/s] expressed in the world reference frame
double base_vel_y
velocity of the robot [m/s] expressed in the robot reference frame
double odom_x
position of the robot [m], expressed in the world reference frame
double odom_y
position of the robot [m], expressed in the world reference frame
double odom_theta
orientation the robot [deg], expressed in the world reference frame
double odom_vel_x
velocity of the robot [m/s] expressed in the world reference frame
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.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string 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.
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.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to 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 isString() const
Checks if value is a string.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual bool asBool() const
Get boolean value.
virtual Bottle * asList() const
Get list value.
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
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
An interface for the device drivers.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
std::string toString() const
Returns text representation of the location.