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 return true;
72}
73
75{
76 std::lock_guard <std::mutex> lg(m_mutex);
77 return m_RPC.set_initial_pose1_RPC(loc);
78}
79
81{
82 if (cov.rows() != 3 || cov.cols() != 3)
83 {
84 yCError(LOCALIZATION2D_NWC_YARP) << "Covariance matrix is expected to have size (3,3)";
85 return ReturnValue::return_code::return_value_error_method_failed;
86 }
87
88 std::lock_guard <std::mutex> lg(m_mutex);
89 return m_RPC.set_initial_pose2_RPC(loc,cov);
90}
91
93{
94 std::lock_guard <std::mutex> lg(m_mutex);
96 if (!retrpc.ret)
97 {
98 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
99 return retrpc.ret;
100 }
101 odom = retrpc.odom;
102 return retrpc.ret;
103}
104
106{
107 std::lock_guard <std::mutex> lg(m_mutex);
109 if (!retrpc.ret)
110 {
111 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
112 return retrpc.ret;
113 }
114 loc = retrpc.loc;
115 return retrpc.ret;
116}
117
119{
120 std::lock_guard <std::mutex> lg(m_mutex);
122 if (!retrpc.ret)
123 {
124 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
125 return retrpc.ret;
126 }
127 loc = retrpc.loc;
128 cov = retrpc.cov;
129 return retrpc.ret;
130}
131
133{
134 std::lock_guard <std::mutex> lg(m_mutex);
136 if (!retrpc.ret)
137 {
138 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
139 return retrpc.ret;
140 }
141 poses = retrpc.poses;
142 return retrpc.ret;
143}
144
146{
147 std::lock_guard <std::mutex> lg(m_mutex);
149 if (!retrpc.ret)
150 {
151 yCError(LOCALIZATION2D_NWC_YARP, "Unable to set transformation");
152 return retrpc.ret;
153 }
155 return retrpc.ret;
156}
157
163
169
#define ReturnValue_ok
Definition ReturnValue.h:77
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 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: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: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 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.