YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ControlBoardCouplingHandler_t1_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Time.h>
12
13#include <vector>
14
15#include <catch2/catch_amalgamated.hpp>
16#include <harness.h>
17
18using namespace yarp::os;
19using namespace yarp::dev;
20
21
22TEST_CASE("dev::ControlBoardCouplingHandlerTest", "[yarp::dev]")
23{
24 YARP_REQUIRE_PLUGIN("fakeJointCoupling", "device");
25 YARP_REQUIRE_PLUGIN("controlBoardCouplingHandler", "device");
26 YARP_REQUIRE_PLUGIN("controlBoard_nws_yarp", "device");
27 YARP_REQUIRE_PLUGIN("fakeMotionControl", "device");
28
29 Network::setLocalMode(true);
30
31 SECTION("Test the controlboard coupling handler")
32 {
34 IEncodersTimed* iet=nullptr;
35 IAxisInfo* iai=nullptr, *iaifmc=nullptr;
36 IPositionControl* ipc=nullptr;
38
40 {
42 p_cfg.put("device", "fakeMotionControl");
43 Property& grp = p_cfg.addGroup("GENERAL");
44 grp.put("Joints", 3);
46 REQUIRE(ddfmc.view(ipc));
47 REQUIRE(ipc!=nullptr);
48 REQUIRE(ddfmc.view(iaifmc));
49 }
50 {
52 p_cfg.put("device", "controlBoardCouplingHandler");
53 p_cfg.put("coupling_device", "fakeJointCoupling"); // 3 act axes, 4 phys joints
55 }
56 //attach
57 {
60 bool result_att = ww_nws->attach(&ddfmc);
62 }
63 {
64 REQUIRE(ddcch.view(iet));
65 REQUIRE(iet!=nullptr);
66 REQUIRE(ddcch.view(iai));
67 REQUIRE(iai!=nullptr);
68 }
69 {
70 int axes = 0;
71 CHECK(iaifmc->getAxes(&axes));
72 CHECK(axes == 3);
73 }
74 {
75 int axes = 0;
76 std::string physical_joint_name;
77 CHECK(iai->getAxes(&axes));
78 CHECK(axes == 4);
79 CHECK(iai->getAxisName(0, physical_joint_name));
80 CHECK(physical_joint_name == "phys_joint_0");
81 CHECK(iai->getAxisName(1, physical_joint_name));
82 CHECK(physical_joint_name == "phys_joint_1");
83 CHECK(iai->getAxisName(2, physical_joint_name));
84 CHECK(physical_joint_name == "phys_joint_2");
85 CHECK(iai->getAxisName(3, physical_joint_name));
86 CHECK(physical_joint_name == "phys_joint_3");
87 }
88 {
89 int axes = 0;
90 CHECK(iaifmc->getAxes(&axes));
91 CHECK(axes == 3);
92 }
93
94 {
95 // Let's move the underlyng motor control and check the coupling
96 CHECK(ipc->setRefSpeed(0, 1000));
97 CHECK(ipc->setRefSpeed(1, 1000));
98 CHECK(ipc->setRefSpeed(2, 1000));
99 CHECK(ipc->positionMove(0, 10));
100 CHECK(ipc->positionMove(1, 20));
101 CHECK(ipc->positionMove(2, 30));
103 std::vector<double> physJointsPos;
104 physJointsPos.resize(4);
105 CHECK(iet->getEncoders(physJointsPos.data()));
106 CHECK(physJointsPos[0] == 10);
107 CHECK(physJointsPos[1] == 20);
108 CHECK(physJointsPos[2] == 15);
109 CHECK(physJointsPos[3] == 15);
110 double singleEncVal {0};
111 CHECK(iet->getEncoder(0, &singleEncVal));
112 CHECK(singleEncVal == 10);
113 CHECK(iet->getEncoder(1, &singleEncVal));
114 CHECK(singleEncVal == 20);
115 CHECK(iet->getEncoder(2, &singleEncVal));
116 CHECK(singleEncVal == 15);
117 CHECK(iet->getEncoder(3, &singleEncVal));
118 CHECK(singleEncVal == 15);
119 }
120 {
121 std::vector<double> physJointsVel,physJointsAcc;
122 physJointsVel.resize(4);
123 physJointsAcc.resize(4);
124 CHECK(iet->getEncoderSpeeds(physJointsVel.data()));
125 CHECK(iet->getEncoderAccelerations(physJointsAcc.data()));
126 CHECK(physJointsVel[0] == 0);
127 CHECK(physJointsVel[1] == 0);
128 CHECK(physJointsVel[2] == 15);
129 CHECK(physJointsVel[3] == 15);
130 CHECK(physJointsAcc[0] == 0);
131 CHECK(physJointsAcc[1] == 0);
132 CHECK(physJointsAcc[2] == 15);
133 CHECK(physJointsAcc[3] == 15);
134 }
135
136 }
137
138 Network::setLocalMode(false);
139}
TEST_CASE("dev::ControlBoardCouplingHandlerTest", "[yarp::dev]")
define control board standard interfaces
Interface for getting information about specific axes, if available.
Definition IAxisInfo.h:36
Control board, extend encoder interface with timestamps.
Interface for a generic control board device implementing position control.
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.
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
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.