YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
remoteControlBoardRemapper_t2_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Time.h>
11
12#include <vector>
13
16#include <catch2/catch_amalgamated.hpp>
17#include <harness.h>
18
19using namespace yarp::os;
20using namespace yarp::dev;
21
22const char *fmcA_file_content = "device fakeMotionControl\n"
23 "[GENERAL]\n"
24 "Joints 2\n"
25 "\n"
26 "AxisName (\"axisA1\" \"axisA2\") \n";
27
28const char *fmcB_file_content = "device fakeMotionControl\n"
29 "[GENERAL]\n"
30 "Joints 3\n"
31 "\n"
32 "AxisName (\"axisB1\" \"axisB2\" \"axisB3\") \n";
33
34const char *fmcC_file_content = "device fakeMotionControl\n"
35 "[GENERAL]\n"
36 "Joints 4\n"
37 "\n"
38 "AxisName (\"axisC1\" \"axisC2\" \"axisC3\" \"axisC4\") \n";
39
40const char *wrapperA_file_content = "device controlBoard_nws_yarp\n"
41 "name /testRemapperRobot/a\n"
42 "period 0.01\n";
43
44const char *wrapperB_file_content = "device controlBoard_nws_yarp\n"
45 "name /testRemapperRobot/b\n"
46 "period 0.01\n";
47
48const char *wrapperC_file_content = "device controlBoard_nws_yarp\n"
49 "name /testRemapperRobot/c\n"
50 "period 0.01\n";
51
52
53TEST_CASE("dev::remotecontrolboardremapperTest2", "[yarp::dev]")
54{
55 YARP_REQUIRE_PLUGIN("fakeMotionControl", "device");
56 YARP_REQUIRE_PLUGIN("remotecontrolboardremapper", "device");
57
58 Network::setLocalMode(true);
59
60 SECTION("Test the invalid configurations of remotecontrolboardremapper")
61 {
62 // We first allocate three fakeMotionControl boards
63 // and their wrappers that we will remap using the remapper
64 std::vector<std::unique_ptr<PolyDriver>> fmcbs;
65 std::vector<std::unique_ptr<PolyDriver>> wrappers;
66 fmcbs.resize(3);
67 wrappers.resize(3);
68
69 std::vector<int> fmcbsSizes;
70 fmcbsSizes.push_back(2);
71 fmcbsSizes.push_back(3);
72 fmcbsSizes.push_back(4);
73
74 std::vector<std::string> fmcbsNames;
75 fmcbsNames.push_back("fakeControlBoardA");
76 fmcbsNames.push_back("fakeControlBoardB");
77 fmcbsNames.push_back("fakeControlBoardC");
78
79 std::vector<std::string> wrapperNetworks;
80 wrapperNetworks.push_back("net_a");
81 wrapperNetworks.push_back("net_b");
82 wrapperNetworks.push_back("net_c");
83
84
85 for(int i=0; i < 3; i++)
86 {
87 fmcbs[i] = std::make_unique<PolyDriver>();
88
89 Property p;
90
91 if(i==0) { p.fromConfig(fmcA_file_content); }
92 if(i==1) { p.fromConfig(fmcB_file_content); }
93 if(i==2) { p.fromConfig(fmcC_file_content); }
94
95 REQUIRE(fmcbs[i]->open(p)); // fakeMotionControlBoard open reported successful
96
97 IPositionControl *pos = nullptr;
98 REQUIRE(fmcbs[i]->view(pos)); // interface position correctly opened
99 REQUIRE(pos);
100
101 size_t axes = 0;
102 pos->getAxes(axes);
103 CHECK(axes == fmcbsSizes[i]); // fakeMotionControlBoard seems functional
104
105 // Open the wrapper
106 wrappers[i] = std::make_unique<PolyDriver>();
107
108 if(i==0) { p.fromConfig(wrapperA_file_content); }
109 if(i==1) { p.fromConfig(wrapperB_file_content); }
110 if(i==2) { p.fromConfig(wrapperC_file_content); }
111
112 REQUIRE(wrappers[i]->open(p)); // controlBoard_nws_yarp open reported successful
113
115 REQUIRE(wrappers[i]->view(iwrap)); // interface for multiple wrapper correctly opened for the controlBoard_nws_yarp
116 REQUIRE(iwrap);
117
119 pdList.push(fmcbs[i].get(), wrapperNetworks[i].c_str());
120
121 REQUIRE(iwrap->attachAll(pdList)); // controlBoard_nws_yarp attached successfully to the device
122 }
123
124 // Create a list containing all the fake controlboards
126
127 for(int i=0; i < 3; i++)
128 {
129 fmcList.push(fmcbs[i].get(),fmcbsNames[i].c_str());
130 }
131
132 // Open the remotecontrolboardremapper
135 pRemoteRemapper.put("device","remotecontrolboardremapper");
136 pRemoteRemapper.addGroup("axesNames");
137 Bottle & remoteAxesList = pRemoteRemapper.findGroup("axesNames").addList();
138 remoteAxesList.addString("axisA1");
139 remoteAxesList.addString("axisB1");
140 remoteAxesList.addString("axisC1_INVALID");
141 remoteAxesList.addString("axisB3");
142 remoteAxesList.addString("axisC3");
143 remoteAxesList.addString("axisA2");
144 size_t nrOfRemappedAxes = 6;
145
148 remoteControlBoardsList.addString("/testRemapperRobot/a");
149 remoteControlBoardsList.addString("/testRemapperRobot/b");
150 remoteControlBoardsList.addString("/testRemapperRobot/c");
151 pRemoteRemapper.put("remoteControlBoards",remoteControlBoards.get(0));
152
153 pRemoteRemapper.put("localPortPrefix","/test/remoteControlBoardRemapper");
154
155 Property & opts = pRemoteRemapper.addGroup("REMOTE_CONTROLBOARD_OPTIONS");
156 opts.put("writeStrict","on");
157
159 //This must fail because of axisC1_INVALID which does not exists
161
162 // Close devices
164
165 for(int i=0; i < 3; i++)
166 {
167 wrappers[i]->close();
168 }
169 for(int i=0; i < 3; i++)
170 {
171 fmcbs[i]->close();
172 }
173 }
174
175 Network::setLocalMode(false);
176}
define control board standard interfaces
Interface for an object that can wrap/attach to to another.
Interface for a generic control board device implementing position control.
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
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
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:32
void fromConfig(const char *txt, bool wipe=true)
Parses text in the configuration format described in fromConfigFile().
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
const char * wrapperC_file_content
TEST_CASE("dev::remotecontrolboardremapperTest2", "[yarp::dev]")
const char * fmcA_file_content
const char * fmcB_file_content
const char * fmcC_file_content
const char * wrapperA_file_content
const char * wrapperB_file_content