YARP
Yet Another Robot Platform
Navigation2DClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_DEV_NAVIGATION2DCLIENT_H
20 #define YARP_DEV_NAVIGATION2DCLIENT_H
21 
22 #include <yarp/os/Network.h>
25 #include <yarp/sig/Vector.h>
26 #include <yarp/os/Time.h>
27 #include <yarp/dev/PolyDriver.h>
28 #include <yarp/dev/INavigation2D.h>
29 
30 #include <mutex>
31 #include <string>
32 
33 #define DEFAULT_THREAD_PERIOD 20 //ms
34 
35 
56 {
57 protected:
58  std::mutex m_mutex;
63  std::string m_local_name;
67  int m_period;
68 
69 private:
70  std::string m_current_goal_name;
71  bool reset_current_goal_name();
72  bool set_current_goal_name(const std::string& name);
73  bool get_current_goal_name(std::string& name);
74 
75 private: //math stuff
76  double normalize_angle(double angle);
77 
78 public:
79 
80  /* DeviceDriver methods */
81  bool open(yarp::os::Searchable& config) override;
82  bool close() override;
83 
84  /* RPC responder */
85  bool parse_respond_string(const yarp::os::Bottle& command, yarp::os::Bottle& reply);
86  virtual bool read(yarp::os::ConnectionReader& connection) override;
87 
88  /* The following methods belong to INavigation2D interface */
89  virtual bool checkInsideArea(yarp::dev::Nav2D::Map2DArea area) override;
90  virtual bool checkInsideArea(std::string area_name) override;
91  virtual bool checkNearToLocation(yarp::dev::Nav2D::Map2DLocation loc, double linear_tolerance, double angular_tolerance = std::numeric_limits<double>::infinity()) override;
92  virtual bool checkNearToLocation(std::string location_name, double linear_tolerance, double angular_tolerance = std::numeric_limits<double>::infinity()) override;
93 
95  bool gotoTargetByLocationName(std::string location_name) override;
96  bool gotoTargetByRelativeLocation(double x, double y, double theta) override;
97  bool gotoTargetByRelativeLocation(double x, double y) override;
98  bool applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout = 0.1) override;
99  bool recomputeCurrentNavigationPath() override;
100 
102  bool getNameOfCurrentTarget(std::string& location_name) override;
103  bool getRelativeLocationOfCurrentTarget(double& x, double& y, double& theta) override;
104 
106  bool getEstimatedOdometry(yarp::dev::OdometryData& odom) override;
107  bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc) override;
109  bool getEstimatedPoses(std::vector<yarp::dev::Nav2D::Map2DLocation>& poses) override;
110  bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc, const yarp::sig::Matrix& cov) override;
112  bool startLocalizationService() override;
113  bool stopLocalizationService() override;
114 
115  bool storeCurrentPosition(std::string location_name) override;
116  bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override;
117  bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation& loc) override;
118  bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea& area) override;
119  bool deleteLocation(std::string location_name) override;
120  bool getLocationsList(std::vector<std::string>& locations) override;
121 
123  bool clearAllLocations() override;
124  bool stopNavigation() override;
125  bool suspendNavigation(const double time_s) override;
126  bool resumeNavigation() override;
130 };
131 
132 #endif // YARP_DEV_NAVIGATION2DCLIENT_H
INavigation2D.h
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Navigation2DClient::gotoTargetByAbsoluteLocation
bool gotoTargetByAbsoluteLocation(yarp::dev::Nav2D::Map2DLocation loc) override
Ask the robot to reach a position defined in the world reference frame.
Definition: Navigation2DClient.cpp:556
Navigation2DClient::getNavigationStatus
bool getNavigationStatus(yarp::dev::Nav2D::NavigationStatusEnum &status) override
Gets the current status of the navigation task.
Definition: Navigation2DClient.cpp:526
Navigation2DClient::getAbsoluteLocationOfCurrentTarget
bool getAbsoluteLocationOfCurrentTarget(yarp::dev::Nav2D::Map2DLocation &loc) override
Gets the last navigation target in the world reference frame.
Definition: Navigation2DClient.cpp:947
Network.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Navigation2DClient::m_map_locations_server_name
std::string m_map_locations_server_name
Definition: Navigation2DClient.h:65
Vector.h
contains the definition of a Vector type
Navigation2DClient::getRelativeLocationOfCurrentTarget
bool getRelativeLocationOfCurrentTarget(double &x, double &y, double &theta) override
Gets the last navigation target in the robot reference frame.
Definition: Navigation2DClient.cpp:994
Navigation2DClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: Navigation2DClient.cpp:62
Navigation2DClient::storeLocation
bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
Definition: Navigation2DClient.cpp:1084
Navigation2DClient::suspendNavigation
bool suspendNavigation(const double time_s) override
Ask to the robot to suspend the current navigation task for a defined amount of time.
Definition: Navigation2DClient.cpp:921
Navigation2DClient::stopLocalizationService
bool stopLocalizationService() override
Stops the localization service.
Definition: Navigation2DClient.cpp:1619
Navigation2DClient::recomputeCurrentNavigationPath
bool recomputeCurrentNavigationPath() override
Forces the navigation system to recompute the path from the current robot position to the current goa...
Definition: Navigation2DClient.cpp:751
Navigation2DClient::getAllNavigationWaypoints
bool getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath &waypoints) override
Returns the list of waypoints generated by the navigation algorithm.
Definition: Navigation2DClient.cpp:1335
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::Nav2D::TrajectoryTypeEnum
TrajectoryTypeEnum
Definition: INavigation2D.h:52
Navigation2DClient::m_rpc_port_map_locations_server
yarp::os::Port m_rpc_port_map_locations_server
Definition: Navigation2DClient.h:60
yarp::dev::Nav2D::INavigation2D
An interface to control the navigation of a mobile robot in a 2D environment.
Definition: INavigation2D.h:201
Navigation2DClient::checkInsideArea
virtual bool checkInsideArea(yarp::dev::Nav2D::Map2DArea area) override
Check if the robot is currently inside the specified area.
Definition: Navigation2DClient.cpp:617
Navigation2DClient::getEstimatedPoses
bool getEstimatedPoses(std::vector< yarp::dev::Nav2D::Map2DLocation > &poses) override
Gets a set of pose estimates computed by the localization algorithm.
Definition: Navigation2DClient.cpp:1527
ControlBoardHelpers.h
Navigation2DClient::m_period
int m_period
Definition: Navigation2DClient.h:67
Navigation2DClient::parse_respond_string
bool parse_respond_string(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
Definition: Navigation2DClient.cpp:189
Navigation2DClient::gotoTargetByLocationName
bool gotoTargetByLocationName(std::string location_name) override
Ask the robot to reach a previously stored location/area.
Definition: Navigation2DClient.cpp:660
yarp::dev::Nav2D::LocalizationStatusEnum
LocalizationStatusEnum
Definition: ILocalization2D.h:25
yarp::dev::Nav2D::NavigationStatusEnum
NavigationStatusEnum
Definition: INavigation2D.h:32
Navigation2DClient::getLocation
bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location previously stored by the user.
Definition: Navigation2DClient.cpp:1159
ControlBoardInterfaces.h
define control board standard interfaces
Navigation2DClient
navigation2DClient: A device which allows a client application to perform navigation tasks,...
Definition: Navigation2DClient.h:56
Navigation2DClient::m_rpc_port_user_commands
yarp::os::Port m_rpc_port_user_commands
Definition: Navigation2DClient.h:62
yarp::dev::OdometryData
Definition: OdometryData.h:27
Navigation2DClient::applyVelocityCommand
bool applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1) override
Apply a velocity command.
Definition: Navigation2DClient.cpp:1496
Navigation2DClient::getCurrentNavigationMap
bool getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, yarp::dev::Nav2D::MapGrid2D &map) override
Returns the current navigation map processed by the navigation algorithm.
Definition: Navigation2DClient.cpp:1427
Navigation2DClient::getLocationsList
bool getLocationsList(std::vector< std::string > &locations) override
Get a list of all stored locations.
Definition: Navigation2DClient.cpp:1115
Navigation2DClient::stopNavigation
bool stopNavigation() override
Terminates the current navigation task.
Definition: Navigation2DClient.cpp:1285
Navigation2DClient::setInitialPose
bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation &loc) override
Sets the initial pose for the localization algorithm which estimates the current position of the robo...
Definition: Navigation2DClient.cpp:776
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
Navigation2DClient::getLocalizationStatus
bool getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum &status) override
Gets the current status of the localization task.
Definition: Navigation2DClient.cpp:1466
Navigation2DClient::m_navigation_server_name
std::string m_navigation_server_name
Definition: Navigation2DClient.h:64
Navigation2DClient::m_rpc_port_navigation_server
yarp::os::Port m_rpc_port_navigation_server
Definition: Navigation2DClient.h:59
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::dev::Nav2D::MapGrid2D
Definition: MapGrid2D.h:32
PolyDriver.h
Navigation2DClient::gotoTargetByRelativeLocation
bool gotoTargetByRelativeLocation(double x, double y, double theta) override
Ask the robot to reach a position defined in the robot reference frame.
Definition: Navigation2DClient.cpp:721
Navigation2DClient::getEstimatedOdometry
bool getEstimatedOdometry(yarp::dev::OdometryData &odom) override
Gets the estimated odometry the robot, including its velocity expressed in the world and in the local...
Definition: Navigation2DClient.cpp:882
Navigation2DClient::m_rpc_port_localization_server
yarp::os::Port m_rpc_port_localization_server
Definition: Navigation2DClient.h:61
Navigation2DClient::read
virtual bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Navigation2DClient.cpp:500
yarp::dev::Nav2D::Map2DPath
Definition: Map2DPath.h:27
Navigation2DClient::close
bool close() override
Close the DeviceDriver.
Definition: Navigation2DClient.cpp:180
Navigation2DClient::deleteLocation
bool deleteLocation(std::string location_name) override
Delete a location.
Definition: Navigation2DClient.cpp:1232
yarp::dev::Nav2D::Map2DLocation
Definition: Map2DLocation.h:30
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
Navigation2DClient::storeCurrentPosition
bool storeCurrentPosition(std::string location_name) override
Store the current location of the robot.
Definition: Navigation2DClient.cpp:1026
yarp::dev::Nav2D::NavigationMapTypeEnum
NavigationMapTypeEnum
Definition: INavigation2D.h:46
Navigation2DClient::startLocalizationService
bool startLocalizationService() override
Starts the localization service.
Definition: Navigation2DClient.cpp:1594
Navigation2DClient::checkNearToLocation
virtual bool checkNearToLocation(yarp::dev::Nav2D::Map2DLocation loc, double linear_tolerance, double angular_tolerance=std::numeric_limits< double >::infinity()) override
Check if the robot is currently near to the specified area.
Definition: Navigation2DClient.cpp:586
Navigation2DClient::m_local_name
std::string m_local_name
Definition: Navigation2DClient.h:63
yarp::dev::Nav2D::Map2DArea
Definition: Map2DArea.h:30
Time.h
Navigation2DClient::getArea
bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area previously stored by the user.
Definition: Navigation2DClient.cpp:1193
Navigation2DClient::getCurrentPosition
bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation &loc) override
Gets the current position of the robot w.r.t world reference frame.
Definition: Navigation2DClient.cpp:888
Navigation2DClient::getNameOfCurrentTarget
bool getNameOfCurrentTarget(std::string &location_name) override
Gets the name of the current target, if available (set by gotoTargetByLocationName)
Definition: Navigation2DClient.cpp:980
Navigation2DClient::m_mutex
std::mutex m_mutex
Definition: Navigation2DClient.h:58
Navigation2DClient::clearAllLocations
bool clearAllLocations() override
Delete all stored locations.
Definition: Navigation2DClient.cpp:1259
Navigation2DClient::m_localization_server_name
std::string m_localization_server_name
Definition: Navigation2DClient.h:66
Navigation2DClient::resumeNavigation
bool resumeNavigation() override
Resume a previously suspended navigation task.
Definition: Navigation2DClient.cpp:1310
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46
Navigation2DClient::getCurrentNavigationWaypoint
bool getCurrentNavigationWaypoint(yarp::dev::Nav2D::Map2DLocation &curr_waypoint) override
Returns the current waypoint pursued by the navigation algorithm.
Definition: Navigation2DClient.cpp:1385