YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
multipleAnalogSensorsClient_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
8
9#include <yarp/os/Time.h>
10#include <yarp/dev/PolyDriver.h>
13
14#include <cmath>
15#include <chrono>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21using namespace yarp::os;
22using namespace yarp::dev;
23
24
25TEST_CASE("dev::MultipleAnalogSensorsClientTest", "[yarp::dev]")
26{
27 YARP_REQUIRE_PLUGIN("fakeIMU", "device");
28 YARP_REQUIRE_PLUGIN("multipleanalogsensorsserver", "device");
29 YARP_REQUIRE_PLUGIN("multipleanalogsensorsclient", "device");
30
31//#if defined(DISABLE_FAILING_TESTS)
32// YARP_SKIP_TEST("Skipping failing tests")
33//#endif
34
35 Network::setLocalMode(true);
36
37 SECTION("Test the multiple analog sensors device on a single IMU (deferred attach)")
38 {
39 // We first allocate a single fakeImu
42
43 Property p;
44 p.put("device", "fakeIMU");
45 p.put("constantValue", 1);
46
47 REQUIRE(imuSensor.open(p)); // sensor open reported successful
48
50 REQUIRE(imuSensor.view(orientSens)); // IOrientationSensors of fakeIMU correctly opened
52 int nrOfSensors = orientSens->getNrOfOrientationSensors();
53 CHECK(nrOfSensors == 1); // getNrOfOrientationSensors of fakeIMU works correctly
54
56 pWrapper.put("device", "multipleanalogsensorsserver");
57 std::string serverPrefix = "/test/mas/server";
58 pWrapper.put("name", serverPrefix);
59 pWrapper.put("period", 10);
60 REQUIRE(wrapper.open(pWrapper)); // multipleanalogsensorsserver open reported successful
61
63 REQUIRE(wrapper.view(iwrap)); // IMultipleWrapper interface correctly opened for the multipleanalogsensorsserver
65
67 pdList.push(&imuSensor, "pdlist_key");
68 REQUIRE(iwrap->attachAll(pdList)); // multipleanalogsensorsserver attached successfully to the device
69
70 // Open the client
72 pClient.put("device", "multipleanalogsensorsclient");
73 pClient.put("remote", serverPrefix);
74 pClient.put("local", "/test/mas/client");
75 // Increase timeout time because we don't know the load of the machine on which the test will run
76 pClient.put("timeout", 1.0);
77
78 PolyDriver client;
79 REQUIRE(client.open(pClient)); // multipleanalogsensorsclient open reported successful
80
81 // Let make sure that the data get read by the client
82 std::this_thread::sleep_for(std::chrono::milliseconds(100));
83
84 // Compare the readings of actual device and client device
86 REQUIRE(client.view(clientOrientSens)); // IOrientationSensors of multipleanalogsensorsclient correctly opened
88
90
91 // Close devices
92 client.close();
93 INFO("multipleanalogsensorsclient closed");
95
96 iwrap->detachAll();
97 wrapper.close();
98 INFO("multipleanalogsensorsserver closed");
100
102 INFO("fakeIMU closed");
104
105 INFO("Test complete");
106 }
107
108 Network::setLocalMode(false);
109}
bool view(T *&x)
Get an interface to the device driver.
Interface for an object that can wrap/attach to to another.
Device interface to one or multiple orientation sensors, such as IMUs with on board estimation algori...
A container for a device driver.
Definition PolyDriver.h:23
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Definition Property.h:33
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
TEST_CASE("dev::MultipleAnalogSensorsClientTest", "[yarp::dev]")
void exec_IOrientationSensors_test_1(IOrientationSensors *ios)
For streams capable of holding different kinds of content, check what they actually have.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.
std::string INFO
Definition ymanager.cpp:51