YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Rangefinder2DServerImpl.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>
8
10
11using namespace yarp::os;
12using namespace yarp::dev;
13using namespace std;
14
15namespace {
16YARP_LOG_COMPONENT(RANGEFINDER2D_RPC, "yarp.device.rangefinder2D_nws_yarp.IRangeFinder2DRPCd")
17}
18
19#define CHECK_POINTER(xxx) {if (xxx==nullptr) {yCError(MAP2D_RPC, "Invalid interface"); return false;}}
20
21
22
24{
25 std::lock_guard <std::mutex> lg(m_mutex);
26
27 if (m_irf == nullptr)
28 {
29 yCError(RANGEFINDER2D_RPC, "Invalid interface");
30 return ReturnValue::return_code::return_value_error_not_ready;
31 }
32
33 auto rr = m_irf->setScanRate(rate);
34 if (!rr)
35 {
36 yCError(RANGEFINDER2D_RPC, "Unable to setScanRate");
37 return rr;
38 }
39 return rr;
40}
41
43{
44 std::lock_guard<std::mutex> lg(m_mutex);
45
46 {
47 if (m_irf == nullptr) {
48 yCError(RANGEFINDER2D_RPC, "Invalid interface");
49 return ReturnValue::return_code::return_value_error_not_ready;
50 }
51 }
52
53 auto rr = m_irf->setHorizontalResolution(resolution);
54 if (!rr) {
55 yCError(RANGEFINDER2D_RPC, "Unable to setHorizontalResolution");
56 return rr;
57 }
58 return rr;
59}
60
61ReturnValue IRangefinder2DRPCd::setScanLimits_RPC(const double min, const double max)
62{
63 std::lock_guard<std::mutex> lg(m_mutex);
64
65 {
66 if (m_irf == nullptr) {
67 yCError(RANGEFINDER2D_RPC, "Invalid interface");
68 return ReturnValue::return_code::return_value_error_not_ready;
69 }
70 }
71
72 auto rr = m_irf->setScanLimits(min, max);
73 if (!rr)
74 {
75 yCError(RANGEFINDER2D_RPC, "Unable to setScanLimits");
76 return rr;
77 }
78 return rr;
79}
80
81ReturnValue IRangefinder2DRPCd::setDistanceRange_RPC(const double min, const double max)
82{
83 std::lock_guard<std::mutex> lg(m_mutex);
84
85 {
86 if (m_irf == nullptr) {
87 yCError(RANGEFINDER2D_RPC, "Invalid interface");
88 return ReturnValue::return_code::return_value_error_not_ready;
89 }
90 }
91
92 auto rr = m_irf->setDistanceRange(min, max);
93 if (!rr)
94 {
95 yCError(RANGEFINDER2D_RPC, "Unable to setDistanceRange");
96 return rr;
97 }
98 return rr;
99}
100
102{
103 std::lock_guard <std::mutex> lg(m_mutex);
104
106 if (m_irf == nullptr)
107 {
108 yCError(RANGEFINDER2D_RPC, "Invalid interface");
109 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
110 return ret;
111 }
112
114 auto rr = m_irf->getDeviceStatus(status);
115 if (!rr)
116 {
117 yCError(RANGEFINDER2D_RPC, "Unable to getDeviceStatus_RPC");
118 ret.retval = rr;
119 }
120 else
121 {
122 ret.retval = rr;
123 ret.status = status;
124 }
125 return ret;
126}
127
129{
130 std::lock_guard<std::mutex> lg(m_mutex);
131
133 if (m_irf == nullptr)
134 {
135 yCError(RANGEFINDER2D_RPC, "Invalid interface");
136 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
137 return ret;
138 }
139
140 double min, max;
141 auto rr = m_irf->getDistanceRange(min, max);
142 if (!rr)
143 {
144 yCError(RANGEFINDER2D_RPC, "Unable to getDistanceRange_RPC");
145 ret.retval = rr;
146 }
147 else
148 {
149 ret.retval = rr;
150 ret.min = min;
151 ret.max = max;
152 }
153 return ret;
154}
155
157{
158 std::lock_guard<std::mutex> lg(m_mutex);
159
161 if (m_irf == nullptr)
162 {
163 yCError(RANGEFINDER2D_RPC, "Invalid interface");
164 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
165 return ret;
166 }
167
168 double min, max;
169 auto rr = m_irf->getScanLimits(min, max);
170 if (!rr)
171 {
172 yCError(RANGEFINDER2D_RPC, "Unable to getScanLimits_RPC");
173 ret.retval = rr;
174 }
175 else
176 {
177 ret.retval = rr;
178 ret.min = min;
179 ret.max = max;
180 }
181 return ret;
182}
183
185{
186 std::lock_guard<std::mutex> lg(m_mutex);
187
189 if (m_irf == nullptr)
190 {
191 yCError(RANGEFINDER2D_RPC, "Invalid interface");
192 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
193 return ret;
194 }
195
196 double step;
197 auto rr = m_irf->getHorizontalResolution(step);
198 if (!rr)
199 {
200 yCError(RANGEFINDER2D_RPC, "Unable to getHorizontalResolution_RPC");
201 ret.retval = rr;
202 }
203 else
204 {
205 ret.retval = rr;
206 ret.step = step;
207 }
208 return ret;
209}
210
212{
213 std::lock_guard<std::mutex> lg(m_mutex);
214
216 if (m_irf == nullptr)
217 {
218 yCError(RANGEFINDER2D_RPC, "Invalid interface");
219 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
220 return ret;
221 }
222
223 double rate;
224 auto rr = m_irf->getScanRate(rate);
225 if (!rr)
226 {
227 yCError(RANGEFINDER2D_RPC, "Unable to getScanRate_RPC");
228 ret.retval = rr;
229 }
230 else
231 {
232 ret.retval = rr;
233 ret.rate = rate;
234 }
235 return ret;
236}
237
239{
240 std::lock_guard<std::mutex> lg(m_mutex);
241
243 if (m_irf == nullptr)
244 {
245 yCError(RANGEFINDER2D_RPC, "Invalid interface");
246 ret.retval = ReturnValue::return_code::return_value_error_not_ready;
247 return ret;
248 }
249
250 std::string info;
251 auto rr = m_irf->getDeviceInfo(info);
252 if (!rr)
253 {
254 yCError(RANGEFINDER2D_RPC, "Unable to getDeviceInfo_RPC");
255 ret.retval = rr;
256 }
257 else
258 {
259 ret.retval = rr;
260 ret.device_info = info;
261 }
262 return ret;
263}
bool ret
return_getDeviceInfo getDeviceInfo_RPC() override
return_getDeviceStatus getDeviceStatus_RPC() override
yarp::dev::ReturnValue setScanRate_RPC(const double rate) override
yarp::dev::ReturnValue setHorizontalResolution_RPC(const double step) override
yarp::dev::ReturnValue setDistanceRange_RPC(const double min, const double max) override
yarp::dev::ReturnValue setScanLimits_RPC(const double min, const double max) override
return_getDistanceRange getDistanceRange_RPC() override
return_getScanLimits getScanLimits_RPC() override
return_getScanRate getScanRate_RPC() override
return_getHorizontalResolution getHorizontalResolution_RPC() override
virtual ReturnValue getDistanceRange(double &min, double &max)=0
get the device detection range
virtual ReturnValue setDistanceRange(double min, double max)=0
set the device detection range.
virtual ReturnValue getDeviceInfo(std::string &device_info)=0
get the device hardware characteristics
virtual ReturnValue getScanRate(double &rate)=0
get the scan rate (scans per seconds)
virtual ReturnValue setScanLimits(double min, double max)=0
set the scan angular range.
virtual ReturnValue getScanLimits(double &min, double &max)=0
get the scan angular range.
virtual ReturnValue getHorizontalResolution(double &step)=0
get the angular step between two measurements.
virtual ReturnValue getDeviceStatus(Device_status &status)=0
get the device status
virtual ReturnValue setHorizontalResolution(double step)=0
get the angular step between two measurements (if available)
virtual ReturnValue setScanRate(double rate)=0
set the scan rate (scans per seconds)
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
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.