YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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 if (!parseParams(config)) { return false; }
29
30 std::string
35
36 local_rpc = m_local + "/localization/rpc";
37 remote_rpc = m_remote + "/rpc";
38 remote_streaming_name = m_remote + "/stream:o";
39 local_streaming_name = m_local + "/stream:i";
40
42 {
43 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not open rpc port %s, chlocal_streaming_nameeck network", local_rpc.c_str());
44 return false;
45 }
46
47 /*
48 //currently unused
49 bool ok=Network::connect(remote_streaming_name.c_str(), local_streaming_name.c_str(), "tcp");
50 if (!ok)
51 {
52 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not connect to %s", remote_streaming_name.c_str());
53 return false;
54 }*/
55
56 bool ok = true;
57
58 ok = Network::connect(local_rpc, remote_rpc);
59 if (!ok)
60 {
61 yCError(LOCALIZATION2D_NWC_YARP, "open() error could not connect to %s", remote_rpc.c_str());
62 return false;
63 }
64
66 {
67 yCError(LOCALIZATION2D_NWC_YARP, "Error! Cannot attach the port as a client");
68 return false;
69 }
70
71 //Check the protocol version
72 if (!m_RPC.checkProtocolVersion()) { return false; }
73
74 yCInfo(LOCALIZATION2D_NWC_YARP) << "Opening of NWC successful";
75 return true;
76}
77
79{
80 std::lock_guard <std::mutex> lg(m_mutex);
81 return m_RPC.set_initial_pose1_RPC(loc);
82}
83
85{
86 if (cov.rows() != 3 || cov.cols() != 3)
87 {
88 yCError(LOCALIZATION2D_NWC_YARP) << "Covariance matrix is expected to have size (3,3)";
89 return ReturnValue::return_code::return_value_error_method_failed;
90 }
91
92 std::lock_guard <std::mutex> lg(m_mutex);
93 return m_RPC.set_initial_pose2_RPC(loc,cov);
94}
95
97{
98 std::lock_guard <std::mutex> lg(m_mutex);
100 if (!retrpc.ret)
101 {
102 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
103 return retrpc.ret;
104 }
105 odom = retrpc.odom;
106 return retrpc.ret;
107}
108
110{
111 std::lock_guard <std::mutex> lg(m_mutex);
113 if (!retrpc.ret)
114 {
115 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
116 return retrpc.ret;
117 }
118 loc = retrpc.loc;
119 return retrpc.ret;
120}
121
123{
124 std::lock_guard <std::mutex> lg(m_mutex);
126 if (!retrpc.ret)
127 {
128 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
129 return retrpc.ret;
130 }
131 loc = retrpc.loc;
132 cov = retrpc.cov;
133 return retrpc.ret;
134}
135
137{
138 std::lock_guard <std::mutex> lg(m_mutex);
140 if (!retrpc.ret)
141 {
142 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
143 return retrpc.ret;
144 }
145 poses = retrpc.poses;
146 return retrpc.ret;
147}
148
150{
151 std::lock_guard <std::mutex> lg(m_mutex);
153 if (!retrpc.ret)
154 {
155 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
156 return retrpc.ret;
157 }
159 return retrpc.ret;
160}
161
167
173
#define ReturnValue_ok
Definition ReturnValue.h:80
virtual return_get_estimated_poses get_estimated_poses_RPC()
virtual yarp::dev::ReturnValue set_initial_pose1_RPC(const yarp::dev::Nav2D::Map2DLocation &loc)
virtual return_get_current_position1 get_current_position1_RPC()
virtual return_get_estimated_odometry get_estimated_odometry_RPC()
virtual return_get_localization_status get_localization_status_RPC()
virtual yarp::dev::ReturnValue stop_localization_service_RPC()
virtual yarp::dev::ReturnValue set_initial_pose2_RPC(const yarp::dev::Nav2D::Map2DLocation &loc, const yarp::sig::Matrix &cov)
virtual bool checkProtocolVersion()
virtual return_get_current_position2 get_current_position2_RPC()
virtual yarp::dev::ReturnValue start_localization_service_RPC()
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue setInitialPose(const yarp::dev::Nav2D::Map2DLocation &loc) override
Sets the initial pose for the localization algorithm which estimates the current position of the robo...
yarp::dev::ReturnValue getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum &status) override
Gets the current status of the localization task.
yarp::dev::ReturnValue 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
yarp::dev::ReturnValue getEstimatedPoses(std::vector< yarp::dev::Nav2D::Map2DLocation > &poses) override
Gets a set of pose estimates computed by the localization algorithm.
yarp::dev::ReturnValue stopLocalizationService() override
Stops the localization service.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue startLocalizationService() override
Starts the localization service.
yarp::dev::ReturnValue getEstimatedOdometry(yarp::dev::OdometryData &odom) override
Gets the estimated odometry the robot, including its velocity expressed in the world and in the local...
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
Definition Port.cpp:330
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:31
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 yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.