YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
controlBoard_nws_yarp_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
6#include <yarp/os/Network.h>
7#include <yarp/os/Port.h>
10#include <yarp/dev/PolyDriver.h>
13
14#include <ControlBoardMsgs.h>
15
16#include <catch2/catch_amalgamated.hpp>
17#include <harness.h>
18
19using namespace yarp::dev;
20using namespace yarp::os;
21
22TEST_CASE("dev::controlBoard_nws_yarp", "[yarp::dev]")
23{
24 YARP_REQUIRE_PLUGIN("controlBoard_nws_yarp", "device");
25
26 Network::setLocalMode(true);
27
28 SECTION("Checking controlBoard_nws_yarp device")
29 {
31
33 {
35 pcfg.put("device", "controlBoard_nws_yarp");
36 pcfg.put("name", "/controlboard");
39 }
40
41 //"Close all polydrivers and check"
42 {
43 CHECK(ddnws.close());
44 }
45 }
46
47 SECTION("Test the controlBoard_nws_yarp device with fakeMotionControl device attached")
48 {
53
54 //open
55 p_nws.put("device", "controlBoard_nws_yarp");
56 p_nws.put("name", "/controlboard");
57 p_fake.put("device", "fakeMotionControl");
60
62
63 //attach
64 {
67 bool result_att = ww_nws->attach(&dd_fake);
69 }
70
72
73 //Close all polydrivers and check
74 {
77 }
78 }
79
80 SECTION("IControlMode getters are exposed on the RPC interface")
81 {
86
87 //open
88 p_nws.put("device", "controlBoard_nws_yarp");
89 p_nws.put("name", "/controlboard");
90 p_fake.put("device", "fakeMotionControl");
91 p_fake.addGroup("GENERAL").put("Joints", 4);
94
96
97 //attach
98 {
101 bool result_att = ww_nws->attach(&dd_fake);
103 }
104
106
107 size_t nAxes = 0;
108 {
109 yarp::dev::IEncoders* ienc = nullptr;
110 dd_fake.view(ienc);
111 REQUIRE(ienc);
112 REQUIRE(ienc->getAxes(nAxes));
113 REQUIRE(nAxes >= 2);
114 }
115
116 //talk to the RPC port, like `yarp rpc` does
118 REQUIRE(rpc.open("/test/controlboard/rpc"));
119 REQUIRE(yarp::os::Network::connect(rpc.getName(), "/controlboard/nws/rpc:i"));
120
122 REQUIRE(rpc_client.yarp().attachAsClient(rpc));
123
124 //set a known mode on axis 0 through the existing RPC setter
126
127 //read it back through the new RPC getters
128 {
129 return_getControlModeOne reply = rpc_client.getControlModeOneRPC(0);
130 CHECK(reply.ret == ReturnValue_ok);
132 }
133
134 {
135 return_getControlModeAll reply = rpc_client.getControlModeAllRPC();
136 CHECK(reply.ret == ReturnValue_ok);
137 CHECK(reply.modes.size() == nAxes);
139 }
140
141 {
142 return_getControlModeGroup reply = rpc_client.getControlModeGroupRPC({0, 1});
143 CHECK(reply.ret == ReturnValue_ok);
144 CHECK(reply.modes.size() == 2);
146 }
147
148 rpc.close();
149
150 //Close all polydrivers and check
151 {
152 CHECK(dd_nws.close());
154 }
155 }
156
157 SECTION("Test the controlBoard_nws_yarp device with a non-attachable device")
158 {
163
164 //open
165 p_nws.put("device", "controlBoard_nws_yarp");
166 p_nws.put("name", "/controlboard");
167 p_fake2.put("device", "fakeSpeaker");
170
172
173 //attach
174 {
177 bool result_att = ww_nws->attach(&dd_fake2);
179 }
180
182
183 //Close all polydrivers and check
184 {
185 CHECK(dd_nws.close());
187 }
188 }
189
190 SECTION("Test the controlBoard_nws_yarp device with a device attached which does not implement motion control interfaces")
191 {
196
197 //open
198 p_nws.put("device", "controlBoard_nws_yarp");
199 p_nws.put("name", "/controlboard");
200 p_fake.put("device", "fakeMotionControlMicro");
203
205
206 //attach
207 {
210 bool result_att = ww_nws->attach(&dd_fake);
212 }
213
215
216 //Close all polydrivers and check
217 {
218 CHECK(dd_nws.close());
220 }
221 }
222
223 Network::setLocalMode(false);
224}
#define ReturnValue_ok
Definition ReturnValue.h:82
std::vector< yarp::dev::ControlModeEnum > modes
std::vector< yarp::dev::ControlModeEnum > modes
yarp::dev::ControlModeEnum mode
Control board, encoder interface.
Definition IEncoders.h:117
virtual yarp::dev::ReturnValue getAxes(size_t &ax)=0
Get the number of controlled axes.
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
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.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:784
A mini-server for network communication.
Definition Port.h:46
A class for storing options and configuration information.
Definition Property.h:32
static void delaySystem(double seconds)
TEST_CASE("dev::controlBoard_nws_yarp", "[yarp::dev]")
void exec_params_test(yarp::dev::PolyDriver *pdrv)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.