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>
15
16#include <catch2/catch_amalgamated.hpp>
17#include <harness.h>
18
19using namespace yarp::os;
20using namespace yarp::dev;
21
22
23TEST_CASE("dev::ControlBoardCouplingHandlerTest", "[yarp::dev]")
24{
25 YARP_REQUIRE_PLUGIN("fakeJointCoupling", "device");
26 YARP_REQUIRE_PLUGIN("controlBoardCouplingHandler", "device");
27 YARP_REQUIRE_PLUGIN("controlBoard_nws_yarp", "device");
28 YARP_REQUIRE_PLUGIN("fakeMotionControl", "device");
29
30 Network::setLocalMode(true);
31
32 SECTION("Test the controlboard coupling handler")
33 {
35 IEncodersTimed* iet=nullptr;
36 IAxisInfo* iai=nullptr, *iaifmc=nullptr;
37 IPositionControl* ipc=nullptr;
39
41 {
43 p_cfg.put("device", "fakeMotionControl");
44 Property& grp = p_cfg.addGroup("GENERAL");
45 grp.put("Joints", 3);
47 REQUIRE(ddfmc.view(ipc));
48 REQUIRE(ipc!=nullptr);
49 REQUIRE(ddfmc.view(iaifmc));
50 }
51 {
53 p_cfg.put("device", "controlBoardCouplingHandler");
54 p_cfg.put("coupling_device", "fakeJointCoupling"); // 3 act axes, 4 phys joints
57 }
58 //attach
59 {
62 bool result_att = ww_nws->attach(&ddfmc);
64 }
65 {
66 REQUIRE(ddcch.view(iet));
67 REQUIRE(iet!=nullptr);
68 REQUIRE(ddcch.view(iai));
69 REQUIRE(iai!=nullptr);
70 }
71 {
72 size_t axes = 0;
73 CHECK(iaifmc->getAxes(axes));
74 CHECK(axes == 3);
75 }
76 {
77 size_t axes = 0;
78 std::string physical_joint_name;
79 CHECK(iai->getAxes(axes));
80 CHECK(axes == 4);
81 CHECK(iai->getAxisName(0, physical_joint_name));
82 CHECK(physical_joint_name == "phys_joint_0");
83 CHECK(iai->getAxisName(1, physical_joint_name));
84 CHECK(physical_joint_name == "phys_joint_1");
85 CHECK(iai->getAxisName(2, physical_joint_name));
86 CHECK(physical_joint_name == "phys_joint_2");
87 CHECK(iai->getAxisName(3, physical_joint_name));
88 CHECK(physical_joint_name == "phys_joint_3");
89 }
90 {
91 size_t axes = 0;
92 CHECK(iaifmc->getAxes(axes));
93 CHECK(axes == 3);
94 }
95
96 {
97 // Let's move the underlying motor control and check the coupling
98 CHECK(ipc->setTrajSpeed(0, 1000));
99 CHECK(ipc->setTrajSpeed(1, 1000));
100 CHECK(ipc->setTrajSpeed(2, 1000));
101 CHECK(ipc->positionMove(0, 10));
102 CHECK(ipc->positionMove(1, 20));
103 CHECK(ipc->positionMove(2, 30));
105 std::vector<double> physJointsPos;
106 physJointsPos.resize(4);
107 CHECK(iet->getEncoders(physJointsPos.data()));
108 CHECK(physJointsPos[0] == 10);
109 CHECK(physJointsPos[1] == 20);
110 CHECK(physJointsPos[2] == 15);
111 CHECK(physJointsPos[3] == 15);
112 double singleEncVal {0};
113 CHECK(iet->getEncoder(0, &singleEncVal));
114 CHECK(singleEncVal == 10);
115 CHECK(iet->getEncoder(1, &singleEncVal));
116 CHECK(singleEncVal == 20);
117 CHECK(iet->getEncoder(2, &singleEncVal));
118 CHECK(singleEncVal == 15);
119 CHECK(iet->getEncoder(3, &singleEncVal));
120 CHECK(singleEncVal == 15);
121 }
122 {
123 std::vector<double> physJointsVel,physJointsAcc;
124 physJointsVel.resize(4);
125 physJointsAcc.resize(4);
126 CHECK(iet->getEncoderSpeeds(physJointsVel.data()));
127 CHECK(iet->getEncoderAccelerations(physJointsAcc.data()));
128 CHECK(physJointsVel[0] == 0);
129 CHECK(physJointsVel[1] == 0);
130 CHECK(physJointsVel[2] == 15);
131 CHECK(physJointsVel[3] == 15);
132 CHECK(physJointsAcc[0] == 0);
133 CHECK(physJointsAcc[1] == 0);
134 CHECK(physJointsAcc[2] == 15);
135 CHECK(physJointsAcc[3] == 15);
136 }
137
138 }
139
140 Network::setLocalMode(false);
141}
TEST_CASE("dev::ControlBoardCouplingHandlerTest", "[yarp::dev]")
define control board standard interfaces
Interface for getting information about specific axes, if available.
Definition IAxisInfo.h:37
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
void exec_params_test(yarp::dev::PolyDriver *pdrv)
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.
Definition OSTestMsg.cpp:13