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) { yCError(RANGEFINDER2D_RPC, "Invalid interface"); return false; }}
28
29 if (!m_irf->setScanRate(rate))
30 {
31 yCError(RANGEFINDER2D_RPC, "Unable to setScanRate");
32 return false;
33 }
34 return true;
35}
36
38{
39 std::lock_guard<std::mutex> lg(m_mutex);
40
41 {
42 if (m_irf == nullptr) {
43 yCError(RANGEFINDER2D_RPC, "Invalid interface");
44 return false;
45 }
46 }
47
48 if (!m_irf->setHorizontalResolution(resolution)) {
49 yCError(RANGEFINDER2D_RPC, "Unable to setHorizontalResolution");
50 return false;
51 }
52 return true;
53}
54
55bool IRangefinder2DRPCd::setScanLimits_RPC(const double min, const double max)
56{
57 std::lock_guard<std::mutex> lg(m_mutex);
58
59 {
60 if (m_irf == nullptr) {
61 yCError(RANGEFINDER2D_RPC, "Invalid interface");
62 return false;
63 }
64 }
65
66 if (!m_irf->setScanLimits(min, max)) {
67 yCError(RANGEFINDER2D_RPC, "Unable to setScanLimits");
68 return false;
69 }
70 return true;
71}
72
73bool IRangefinder2DRPCd::setDistanceRange_RPC(const double min, const double max)
74{
75 std::lock_guard<std::mutex> lg(m_mutex);
76
77 {
78 if (m_irf == nullptr) {
79 yCError(RANGEFINDER2D_RPC, "Invalid interface");
80 return false;
81 }
82 }
83
84 if (!m_irf->setDistanceRange(min, max)) {
85 yCError(RANGEFINDER2D_RPC, "Unable to setDistanceRange");
86 return false;
87 }
88 return true;
89}
90
92{
93 std::lock_guard <std::mutex> lg(m_mutex);
94
96 {if (m_irf == nullptr) { yCError(RANGEFINDER2D_RPC, "Invalid interface"); return ret; }}
98 if (!m_irf->getDeviceStatus(status))
99 {
100 yCError(RANGEFINDER2D_RPC, "Unable to getDeviceStatus_RPC");
101 ret.retval = false;
102 }
103 else
104 {
105 ret.retval = true;
106 ret.status = status;
107 }
108 return ret;
109}
110
112{
113 std::lock_guard<std::mutex> lg(m_mutex);
114
116 {
117 if (m_irf == nullptr) {
118 yCError(RANGEFINDER2D_RPC, "Invalid interface");
119 return ret;
120 }
121 }
122 double min, max;
123 if (!m_irf->getDistanceRange(min, max)) {
124 yCError(RANGEFINDER2D_RPC, "Unable to getDistanceRange_RPC");
125 ret.retval = false;
126 } else {
127 ret.retval = true;
128 ret.min = min;
129 ret.max = max;
130 }
131 return ret;
132}
133
135{
136 std::lock_guard<std::mutex> lg(m_mutex);
137
139 {
140 if (m_irf == nullptr) {
141 yCError(RANGEFINDER2D_RPC, "Invalid interface");
142 return ret;
143 }
144 }
145 double min, max;
146 if (!m_irf->getScanLimits(min, max)) {
147 yCError(RANGEFINDER2D_RPC, "Unable to getScanLimits_RPC");
148 ret.retval = false;
149 } else {
150 ret.retval = true;
151 ret.min = min;
152 ret.max = max;
153 }
154 return ret;
155}
156
158{
159 std::lock_guard<std::mutex> lg(m_mutex);
160
162 {
163 if (m_irf == nullptr) {
164 yCError(RANGEFINDER2D_RPC, "Invalid interface");
165 return ret;
166 }
167 }
168 double step;
169 if (!m_irf->getHorizontalResolution(step)) {
170 yCError(RANGEFINDER2D_RPC, "Unable to getHorizontalResolution_RPC");
171 ret.retval = false;
172 } else {
173 ret.retval = true;
174 ret.step = step;
175 }
176 return ret;
177}
178
180{
181 std::lock_guard<std::mutex> lg(m_mutex);
182
184 {
185 if (m_irf == nullptr) {
186 yCError(RANGEFINDER2D_RPC, "Invalid interface");
187 return ret;
188 }
189 }
190 double rate;
191 if (!m_irf->getScanRate(rate)) {
192 yCError(RANGEFINDER2D_RPC, "Unable to getScanRate_RPC");
193 ret.retval = false;
194 } else {
195 ret.retval = true;
196 ret.rate = rate;
197 }
198 return ret;
199}
200
202{
203 std::lock_guard<std::mutex> lg(m_mutex);
204
206 {
207 if (m_irf == nullptr) {
208 yCError(RANGEFINDER2D_RPC, "Invalid interface");
209 return ret;
210 }
211 }
212 std::string info;
213 if (!m_irf->getDeviceInfo(info)) {
214 yCError(RANGEFINDER2D_RPC, "Unable to getDeviceInfo_RPC");
215 ret.retval = false;
216 } else {
217 ret.retval = true;
218 ret.device_info = info;
219 }
220 return ret;
221}
bool ret
return_getDeviceInfo getDeviceInfo_RPC() override
return_getDeviceStatus getDeviceStatus_RPC() override
bool setHorizontalResolution_RPC(const double step) override
return_getDistanceRange getDistanceRange_RPC() override
return_getScanLimits getScanLimits_RPC() override
return_getScanRate getScanRate_RPC() override
return_getHorizontalResolution getHorizontalResolution_RPC() override
bool setScanRate_RPC(const double rate) override
bool setDistanceRange_RPC(const double min, const double max) override
bool setScanLimits_RPC(const double min, const double max) override
virtual bool setScanLimits(double min, double max)=0
set the scan angular range.
virtual bool setScanRate(double rate)=0
set the scan rate (scans per seconds)
virtual bool getDistanceRange(double &min, double &max)=0
get the device detection range
virtual bool setHorizontalResolution(double step)=0
get the angular step between two measurements (if available)
virtual bool setDistanceRange(double min, double max)=0
set the device detection range.
virtual bool getDeviceInfo(std::string &device_info)=0
get the device hardware characteristics
virtual bool getScanRate(double &rate)=0
get the scan rate (scans per seconds)
virtual bool getScanLimits(double &min, double &max)=0
get the scan angular range.
virtual bool getHorizontalResolution(double &step)=0
get the angular step between two measurements.
virtual bool getDeviceStatus(Device_status &status)=0
get the device status
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.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.