iCub-main
Loading...
Searching...
No Matches
PassThroughInertial.cpp
Go to the documentation of this file.
2#include <yarp/os/Property.h>
3#include <yarp/os/LogStream.h>
4
5namespace yarp {
6namespace dev {
7
9 proxyIAccel{nullptr},
10 proxyIMagn{nullptr},
11 proxyIOrient{nullptr}
12{
13}
14
19
20bool PassThroughInertial::open(yarp::os::Searchable& config) //TODO: still to be discussed
21{
22 bool ok = true;
23
24 if (config.check("subdevice") && config.find("subdevice").isString())
25 {
26 ownSubdevice = true;
27 ok &= config.check("proxy_remote");
28 ok &= config.check("proxy_local");
29 ok &= config.find("proxy_remote").isString();
30 ok &= config.find("proxy_local").isString();
31 if(!ok)
32 {
33 yError()<<"PassThroughInertial: proxy conf malformed";
34 return false;
35 }
36 auto subdeviceName = config.find("subdevice").asString();
37 yarp::os::Property masClientProp;
38 masClientProp.fromString(config.toString());
39 masClientProp.put("device", subdeviceName); // "multipleanalogsensorsclient"
40 masClientProp.put("local", config.find("proxy_local").asString());
41 masClientProp.put("remote", config.find("proxy_remote").asString());
42
43 ok &= proxyDevice.open(masClientProp);
44 if (!ok) {
45 yError()<<"PassThroughInertial: failed to open the proxy device";
46 return false;
47 }
48
49 ok &= proxyDevice.view(proxyIGyro);
50 ok &= proxyDevice.view(proxyIAccel);
51 ok &= proxyDevice.view(proxyIMagn);
53
54 if (!ok) {
55 yError()<<"PassThroughInertial: the view of one interface failed";
56 return false;
57 }
58
59 }
60
61 yInfo("Finish PassThroughInertial::open");
62 return true;
63}
64
66{
67 if (ownSubdevice)
68 return proxyDevice.close();
69 else
70 return detachAll();
71}
72
73
75{
76 if (!proxyIGyro)
77 return false;
78 return proxyIGyro->getNrOfThreeAxisGyroscopes();
79}
80
81
82yarp::dev::MAS_status PassThroughInertial::getThreeAxisGyroscopeStatus(size_t sens_index) const
83{
84 if (!proxyIGyro)
85 return yarp::dev::MAS_ERROR;
86 return proxyIGyro->getThreeAxisGyroscopeStatus(sens_index);
87}
88
89bool PassThroughInertial::getThreeAxisGyroscopeName(size_t sens_index, std::string& name) const
90{
91 if (!proxyIGyro)
92 return false;
93 return proxyIGyro->getThreeAxisGyroscopeName(sens_index, name);
94}
95
96bool PassThroughInertial::getThreeAxisGyroscopeFrameName(size_t sens_index, std::string& frameName) const
97{
98 if (!proxyIGyro)
99 return false;
100 return proxyIGyro->getThreeAxisGyroscopeFrameName(sens_index, frameName);
101}
102
103bool PassThroughInertial::getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const
104{
105 if (!proxyIGyro)
106 return false;
107 return proxyIGyro->getThreeAxisGyroscopeMeasure(sens_index, out, timestamp);
108}
109
110
112{
113 if (!proxyIAccel)
114 return false;
115 return proxyIAccel->getNrOfThreeAxisLinearAccelerometers();
116}
117
118
119yarp::dev::MAS_status PassThroughInertial::getThreeAxisLinearAccelerometerStatus(size_t sens_index) const
120{
121 if (!proxyIAccel)
122 return yarp::dev::MAS_ERROR;
123 return proxyIAccel->getThreeAxisLinearAccelerometerStatus(sens_index);
124}
125
126bool PassThroughInertial::getThreeAxisLinearAccelerometerName(size_t sens_index, std::string& name) const
127{
128 if (!proxyIAccel)
129 return false;
130 return proxyIAccel->getThreeAxisLinearAccelerometerName(sens_index, name);
131}
132
133bool PassThroughInertial::getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string& frameName) const
134{
135 if (!proxyIAccel)
136 return false;
137 return proxyIAccel->getThreeAxisLinearAccelerometerFrameName(sens_index, frameName);
138}
139
140bool PassThroughInertial::getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const
141{
142 if (!proxyIAccel)
143 return false;
144 return proxyIAccel->getThreeAxisLinearAccelerometerMeasure(sens_index, out, timestamp);
145}
146
147
149{
150 if (!proxyIOrient)
151 return false;
152 return proxyIOrient->getNrOfOrientationSensors();
153}
154
155yarp::dev::MAS_status PassThroughInertial::getOrientationSensorStatus(size_t sens_index) const
156{
157 if (!proxyIOrient)
158 return yarp::dev::MAS_ERROR;
159 return proxyIOrient->getOrientationSensorStatus(sens_index);
160}
161
162bool PassThroughInertial::getOrientationSensorName(size_t sens_index, std::string& name) const
163{
164 if (!proxyIOrient)
165 return false;
166 return proxyIOrient->getOrientationSensorName(sens_index, name);
167}
168
169bool PassThroughInertial::getOrientationSensorFrameName(size_t sens_index, std::string& frameName) const
170{
171 if (!proxyIOrient)
172 return false;
173 return proxyIOrient->getOrientationSensorFrameName(sens_index, frameName);
174}
175
176bool PassThroughInertial::getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector& rpy, double& timestamp) const
177{
178 if (!proxyIOrient)
179 return false;
180 return proxyIOrient->getOrientationSensorMeasureAsRollPitchYaw(sens_index, rpy, timestamp);
181}
182
184{
185 if (!proxyIMagn)
186 return false;
187 return proxyIMagn->getNrOfThreeAxisMagnetometers();
188}
189
190yarp::dev::MAS_status PassThroughInertial::getThreeAxisMagnetometerStatus(size_t sens_index) const
191{
192 if (!proxyIMagn)
193 return yarp::dev::MAS_ERROR;
194 return proxyIMagn->getThreeAxisMagnetometerStatus(sens_index);
195}
196
197bool PassThroughInertial::getThreeAxisMagnetometerName(size_t sens_index, std::string& name) const
198{
199 if (!proxyIMagn)
200 return false;
201 return proxyIMagn->getThreeAxisMagnetometerName(sens_index, name);
202}
203
204bool PassThroughInertial::getThreeAxisMagnetometerFrameName(size_t sens_index, std::string& frameName) const
205{
206 if (!proxyIMagn)
207 return false;
208 return proxyIMagn->getThreeAxisMagnetometerFrameName(sens_index, frameName);
209}
210
211bool PassThroughInertial::getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const
212{
213 if (!proxyIMagn)
214 return false;
215 return proxyIMagn->getThreeAxisMagnetometerMeasure(sens_index, out, timestamp);
216}
217
218bool PassThroughInertial::attachAll(const yarp::dev::PolyDriverList& p)
219{
220 if (ownSubdevice)
221 {
222 yError()<<"PassThroughInertial: holding a subdevice, attach not allowed";
223 return false;
224 }
225 // Attach the device
226 if (p.size() > 1)
227 {
228 yError("PassThroughInertial: this device only supports exposing a "
229 "single PassThroughInertial device on YARP ports, but %d devices have been passed in attachAll.", p.size());
230 yError("PassThroughInertial: please use the multipleanalogsensorsremapper device to combine several device in a new device.");
231 detachAll();
232 return false;
233 }
234
235 if (p.size() == 0)
236 {
237 yError("PassThroughInertial: no device passed to attachAll, please pass a device to expose on YARP ports.");
238 return false;
239 }
240
241 yarp::dev::PolyDriver* poly = p[0]->poly;
242
243 if (!poly)
244 {
245 yError("PassThroughInertial: null pointer passed to attachAll.");
246 return false;
247 }
248
249 bool ok = true;
250 // View all the interfaces
251 ok &= poly->view(proxyIGyro);
252 ok &= poly->view(proxyIAccel);
253 ok &= poly->view(proxyIMagn);
254 ok &= poly->view(proxyIOrient);
255
256 if(!ok)
257 {
258 detachAll();
259 return false;
260 }
261
262 yInfo()<<"PassThroughInertial: attach finished with success";
263
264
265 return ok;
266}
267
269{
270 proxyIGyro = nullptr;
271 proxyIMagn = nullptr;
272 proxyIOrient = nullptr;
273 proxyIAccel = nullptr;
274 return true;
275}
276
277
278} // namespace dev
279} // namespace yarp
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
size_t getNrOfThreeAxisMagnetometers() const override
bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override
size_t getNrOfOrientationSensors() const override
bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
bool attachAll(const yarp::dev::PolyDriverList &p) override
bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override
size_t getNrOfThreeAxisGyroscopes() const override
bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double &timestamp) const override
yarp::dev::IThreeAxisGyroscopes * proxyIGyro
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
yarp::dev::IThreeAxisLinearAccelerometers * proxyIAccel
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override
bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
yarp::dev::IThreeAxisMagnetometers * proxyIMagn
bool open(yarp::os::Searchable &config) override
yarp::dev::IOrientationSensors * proxyIOrient
size_t getNrOfThreeAxisLinearAccelerometers() const override
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Copyright (C) 2008 RobotCub Consortium.
out
Definition sine.m:8