YARP
Yet Another Robot Platform
ILocalization2DServerImpl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7#include <yarp/os/LogStream.h>
10
13using namespace yarp::os;
14using namespace yarp::dev;
15using namespace yarp::dev::Nav2D;
16using namespace std;
17
18#define DEFAULT_THREAD_PERIOD 0.01
19
20#ifndef M_PI
21#define M_PI 3.14159265358979323846
22#endif
23
24namespace {
25YARP_LOG_COMPONENT(LOCALIZATION2DSERVER, "yarp.device.localization2DServer")
26}
27
28#define CHECK_POINTER(xxx) {if (xxx==nullptr) {yCError(LOCALIZATION2DSERVER, "Invalid interface"); return false;}}
29
31{
32 std::lock_guard <std::mutex> lg(m_mutex);
33
34 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return false; }}
35
36 if (!m_iLoc->startLocalizationService())
37 {
38 yCError(LOCALIZATION2DSERVER, "Unable to startLocalizationService");
39 return false;
40 }
41 return true;
42}
43
45{
46 std::lock_guard <std::mutex> lg(m_mutex);
47
48 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return false; }}
49
50 if (!m_iLoc->stopLocalizationService())
51 {
52 yCError(LOCALIZATION2DSERVER, "Unable to stopLocalizationService");
53 return false;
54 }
55 return true;
56}
57
59{
60 std::lock_guard <std::mutex> lg(m_mutex);
61
64 {
65 ret.ret = true;
67 return ret;
68 }
69
70 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return ret; }}
71
73 if (!m_iLoc->getLocalizationStatus(status))
74 {
75 yCError(LOCALIZATION2DSERVER, "Unable to getLocalizationStatus");
76 ret.ret=false;
78 }
79 else
80 {
81 ret.ret=true;
83 }
84 return ret;
85}
86
88{
89 std::lock_guard <std::mutex> lg(m_mutex);
90
92 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return ret; }}
93 std::vector<yarp::dev::Nav2D::Map2DLocation> poses;
94 if (!m_iLoc->getEstimatedPoses(poses))
95 {
96 yCError(LOCALIZATION2DSERVER, "Unable to getEstimatedPoses");
97 ret.ret = false;
98 }
99 else
100 {
101 ret.ret = true;
102 ret.poses=poses;
103 }
104 return ret;
105}
106
108{
109 std::lock_guard <std::mutex> lg(m_mutex);
110
113 {
114 ret.ret = true;
115 ret.loc = this->m_current_position;
116 return ret;
117 }
118
119 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return ret; }}
120
122 if (!m_iLoc->getCurrentPosition(pos))
123 {
124 yCError(LOCALIZATION2DSERVER, "Unable to getCurrentPosition");
125 ret.ret = false;
126 }
127 else
128 {
129 ret.ret = true;
130 ret.loc = pos;
131 }
132 return ret;
133}
134
136{
137 std::lock_guard <std::mutex> lg(m_mutex);
138
140 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return ret; }}
143 if (!m_iLoc->getCurrentPosition(pos,cov))
144 {
145 yCError(LOCALIZATION2DSERVER, "Unable to getCurrentPosition");
146 ret.ret = false;
147 }
148 else
149 {
150 ret.ret = true;
151 ret.loc=pos;
152 ret.cov=cov;
153 }
154 return ret;
155}
156
158{
159 std::lock_guard <std::mutex> lg(m_mutex);
160
163 {
164 ret.ret = true;
165 ret.odom = this->m_current_odometry;
166 return ret;
167 }
168
169 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return ret; }}
170
172 if (!m_iLoc->getEstimatedOdometry(odom))
173 {
174 yCError(LOCALIZATION2DSERVER, "Unable to getEstimatedOdometry");
175 ret.ret = false;
176 }
177 else
178 {
179 ret.ret = true;
180 ret.odom = odom;
181 }
182 return ret;
183}
184
186{
187 std::lock_guard <std::mutex> lg(m_mutex);
188
189 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return false; }}
190 if (!m_iLoc->setInitialPose(loc))
191 {
192 yCError(LOCALIZATION2DSERVER, "Unable to setInitialPose");
193 return false;
194 }
195 return true;
196}
197
199{
200 std::lock_guard <std::mutex> lg(m_mutex);
201
202 {if (m_iLoc == nullptr) { yCError(LOCALIZATION2DSERVER, "Invalid interface"); return false; }}
203
204 if (!m_iLoc->setInitialPose(loc,cov))
205 {
206 yCError(LOCALIZATION2DSERVER, "Unable to setInitialPose");
207 return false;
208 }
209 return true;
210}
bool ret
bool start_localization_service_RPC() override
yarp::dev::OdometryData m_current_odometry
return_get_current_position1 get_current_position1_RPC() override
return_get_current_position2 get_current_position2_RPC() override
yarp::dev::Nav2D::LocalizationStatusEnum m_current_status
bool set_initial_pose2_RPC(const yarp::dev::Nav2D::Map2DLocation &loc, const yarp::sig::Matrix &cov) override
bool stop_localization_service_RPC() override
return_get_estimated_odometry get_estimated_odometry_RPC() override
bool set_initial_pose1_RPC(const yarp::dev::Nav2D::Map2DLocation &loc) override
return_get_localization_status get_localization_status_RPC() override
yarp::dev::Nav2D::Map2DLocation m_current_position
return_get_estimated_poses get_estimated_poses_RPC() override
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.
A class for a Matrix.
Definition: Matrix.h:39
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.