YARP
Yet Another Robot Platform
Localization2D_nwc_yarp.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
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
11#include <mutex>
12
15using namespace yarp::dev;
16using namespace yarp::dev::Nav2D;
17using namespace yarp::os;
18using namespace yarp::sig;
19
20namespace {
21YARP_LOG_COMPONENT(LOCALIZATION2D_NWC_YARP, "yarp.device.Localization2D_nwc_yarp")
22}
23
24//------------------------------------------------------------------------------------------------------------------------------
25
27{
28 m_local_name.clear();
29 m_remote_name.clear();
30
31 m_local_name = config.find("local").asString();
32 m_remote_name = config.find("remote").asString();
33
34 if (m_local_name == "")
35 {
36 yCError(LOCALIZATION2D_NWC_YARP, "open() error you have to provide a valid 'local' param");
37 return false;
38 }
39
40 if (m_remote_name == "")
41 {
42 yCError(LOCALIZATION2D_NWC_YARP, "open() error you have to provide valid 'remote' param");
43 return false;
44 }
45
46 std::string
47 local_rpc,
48 remote_rpc,
49 remote_streaming_name,
50 local_streaming_name;
51
52 local_rpc = m_local_name + "/localization/rpc";
53 remote_rpc = m_remote_name + "/rpc";
54 remote_streaming_name = m_remote_name + "/stream:o";
55 local_streaming_name = m_local_name + "/stream:i";
56
58 {
59 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not open rpc port %s, chlocal_streaming_nameeck network", local_rpc.c_str());
60 return false;
61 }
62
63 /*
64 //currently unused
65 bool ok=Network::connect(remote_streaming_name.c_str(), local_streaming_name.c_str(), "tcp");
66 if (!ok)
67 {
68 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not connect to %s", remote_streaming_name.c_str());
69 return false;
70 }*/
71
72 bool ok = true;
73
74 ok = Network::connect(local_rpc, remote_rpc);
75 if (!ok)
76 {
77 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not connect to %s", remote_rpc.c_str());
78 return false;
79 }
80
82 {
83 yCError(LOCALIZATION2D_NWC_YARP, "Error! Cannot attach the port as a client");
84 return false;
85 }
86
87 return true;
88}
89
91{
92 std::lock_guard <std::mutex> lg(m_mutex);
93 return m_RPC.set_initial_pose1_RPC(loc);
94}
95
97{
98 if (cov.rows() != 3 || cov.cols() != 3)
99 {
100 yCError(LOCALIZATION2D_NWC_YARP) << "Covariance matrix is expected to have size (3,3)";
101 return false;
102 }
103
104 std::lock_guard <std::mutex> lg(m_mutex);
105 return m_RPC.set_initial_pose2_RPC(loc,cov);
106}
107
109{
110 std::lock_guard <std::mutex> lg(m_mutex);
112 if (!ret.ret)
113 {
114 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
115 return false;
116 }
117 odom = ret.odom;
118 return true;
119}
120
122{
123 std::lock_guard <std::mutex> lg(m_mutex);
125 if (!ret.ret)
126 {
127 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
128 return false;
129 }
130 loc = ret.loc;
131 return true;
132}
133
135{
136 std::lock_guard <std::mutex> lg(m_mutex);
138 if (!ret.ret)
139 {
140 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
141 return false;
142 }
143 loc = ret.loc;
144 cov = ret.cov;
145 return true;
146}
147
148bool Localization2D_nwc_yarp::getEstimatedPoses(std::vector<Map2DLocation>& poses)
149{
150 std::lock_guard <std::mutex> lg(m_mutex);
152 if (!ret.ret)
153 {
154 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
155 return false;
156 }
157 poses = ret.poses;
158 return true;
159}
160
162{
163 std::lock_guard <std::mutex> lg(m_mutex);
165 if (!ret.ret)
166 {
167 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
168 return false;
169 }
171 return true;
172}
173
175{
176 std::lock_guard <std::mutex> lg(m_mutex);
178}
179
181{
182 std::lock_guard <std::mutex> lg(m_mutex);
184}
185
187{
189 return true;
190}
bool ret
virtual return_get_estimated_poses get_estimated_poses_RPC()
virtual return_get_current_position1 get_current_position1_RPC()
virtual bool start_localization_service_RPC()
virtual return_get_estimated_odometry get_estimated_odometry_RPC()
virtual return_get_localization_status get_localization_status_RPC()
virtual bool set_initial_pose1_RPC(const yarp::dev::Nav2D::Map2DLocation &loc)
virtual return_get_current_position2 get_current_position2_RPC()
virtual bool set_initial_pose2_RPC(const yarp::dev::Nav2D::Map2DLocation &loc, const yarp::sig::Matrix &cov)
virtual bool stop_localization_service_RPC()
bool stopLocalizationService() override
Stops the localization service.
bool getEstimatedPoses(std::vector< yarp::dev::Nav2D::Map2DLocation > &poses) override
Gets a set of pose estimates computed by the localization algorithm.
bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation &loc) override
Gets the current position of the robot w.r.t world reference frame.
yarp::os::Port m_rpc_port_localization_server
bool getEstimatedOdometry(yarp::dev::OdometryData &odom) override
Gets the estimated odometry the robot, including its velocity expressed in the world and in the local...
bool close() override
Close the DeviceDriver.
bool startLocalizationService() override
Starts the localization service.
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...
bool getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum &status) override
Gets the current status of the localization task.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void close() override
Stop port activity.
Definition: Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:79
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:28
A class for a Matrix.
Definition: Matrix.h:39
size_t cols() const
Return number of columns.
Definition: Matrix.h:94
size_t rows() const
Return number of rows.
Definition: Matrix.h:88
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.