YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
fakeJointCoupling_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>
9
10#include <catch2/catch_amalgamated.hpp>
11#include <harness.h>
12
13using namespace yarp::dev;
14using namespace yarp::os;
15
16TEST_CASE("dev::fakeJointCoupling", "[yarp::dev]")
17{
18 YARP_REQUIRE_PLUGIN("fakeJointCoupling", "device");
19
20 Network::setLocalMode(true);
21
22 SECTION("Checking fakeJointCoupling device")
23 {
25 IJointCoupling* ijc=nullptr;
26 {
28 p_cfg.put("device", "fakeJointCoupling");
30 }
31
32 REQUIRE(ddjc.view(ijc));
33 REQUIRE(ijc!=nullptr);
36 CHECK(ijc->getCoupledPhysicalJoints(coupled_physical_joints));
37 CHECK(coupled_physical_joints.size() == 2);
40
43 CHECK(ijc->getCoupledActuatedAxes(coupled_actuated_axes));
44 CHECK(coupled_actuated_axes.size() == 1);
46
47 size_t nr_of_physical_joints{0};
48 CHECK(ijc->getNrOfPhysicalJoints(nr_of_physical_joints));
50
51 size_t nr_of_actuated_axes{0};
52 CHECK(ijc->getNrOfActuatedAxes(nr_of_actuated_axes));
54
55 std::string physical_joint_name;
56 CHECK(ijc->getPhysicalJointName(0, physical_joint_name));
57 CHECK(physical_joint_name == "phys_joint_0");
58 CHECK(ijc->getPhysicalJointName(1, physical_joint_name));
59 CHECK(physical_joint_name == "phys_joint_1");
60 CHECK(ijc->getPhysicalJointName(2, physical_joint_name));
61 CHECK(physical_joint_name == "phys_joint_2");
62 CHECK(ijc->getPhysicalJointName(3, physical_joint_name));
63 CHECK(physical_joint_name == "phys_joint_3");
64 CHECK_FALSE(ijc->getPhysicalJointName(4, physical_joint_name));
65
66 std::string actuated_axis_name;
67 CHECK(ijc->getActuatedAxisName(0, actuated_axis_name));
68 CHECK(actuated_axis_name == "act_axes_0");
69 CHECK(ijc->getActuatedAxisName(1, actuated_axis_name));
70 CHECK(actuated_axis_name == "act_axes_1");
71 CHECK(ijc->getActuatedAxisName(2, actuated_axis_name));
72 CHECK(actuated_axis_name == "act_axes_2");
73 CHECK_FALSE(ijc->getActuatedAxisName(3, actuated_axis_name));
74
75 yarp::sig::Vector physJointsPos{0.0, 1.0, 2.0, 3.0};
76 yarp::sig::Vector actAxesPos{0.0, 0.0, 0.0};
77 yarp::sig::Vector physJointsVel{0.0, 1.0, 2.0, 3.0};
78 yarp::sig::Vector actAxesVel{0.0, 0.0, 0.0};
79 yarp::sig::Vector physJointsAcc{0.0, 1.0, 2.0, 3.0};
80 yarp::sig::Vector actAxesAcc{0.0, 0.0, 0.0};;
81
82 CHECK(ijc->convertFromPhysicalJointsToActuatedAxesPos(physJointsPos, actAxesPos));
83 CHECK(actAxesPos[0] == 0.0);
84 CHECK(actAxesPos[1] == 1.0);
85 CHECK(actAxesPos[2] == 5.0);
86
87 CHECK(ijc->convertFromPhysicalJointsToActuatedAxesVel(physJointsPos, physJointsVel, actAxesVel));
88 CHECK(actAxesVel[0] == 0.0);
89 CHECK(actAxesVel[1] == 1.0);
90 CHECK(actAxesVel[2] == 10.0);
91
92 CHECK(ijc->convertFromPhysicalJointsToActuatedAxesAcc(physJointsPos, physJointsVel, physJointsAcc, actAxesAcc));
93 CHECK(actAxesAcc[0] == 0.0);
94 CHECK(actAxesAcc[1] == 1.0);
95 CHECK(actAxesAcc[2] == 15.0);
96
97 CHECK_FALSE(ijc->convertFromPhysicalJointsToActuatedAxesTrq(physJointsPos, physJointsAcc, actAxesAcc));
98
99 CHECK(ijc->convertFromActuatedAxesToPhysicalJointsPos(actAxesPos, physJointsPos));
100 CHECK(physJointsPos[0] == 0.0);
101 CHECK(physJointsPos[1] == 1.0);
102 CHECK(physJointsPos[2] == 2.5);
103 CHECK(physJointsPos[3] == 2.5);
104
105 CHECK(ijc->convertFromActuatedAxesToPhysicalJointsVel(actAxesPos, actAxesVel, physJointsVel));
106 CHECK(physJointsVel[0] == 0.0);
107 CHECK(physJointsVel[1] == 1.0);
108 CHECK(physJointsVel[2] == -2.5);
109 CHECK(physJointsVel[3] == 7.5);
110
111 CHECK(ijc->convertFromActuatedAxesToPhysicalJointsAcc(actAxesPos, actAxesVel, actAxesAcc, physJointsAcc));
112 CHECK(physJointsAcc[0] == 0.0);
113 CHECK(physJointsAcc[1] == 1.0);
114 CHECK(physJointsAcc[2] == -10.0);
115 CHECK(physJointsAcc[3] == 15.0);
116
117 CHECK_FALSE(ijc->convertFromActuatedAxesToPhysicalJointsTrq(actAxesPos, actAxesAcc, physJointsAcc));
118
119 double min{0.0}, max{0.0};
120 CHECK(ijc->getPhysicalJointLimits(0, min, max));
121 CHECK(min == -30.0);
122 CHECK(max == 30.0);
123 CHECK(ijc->getPhysicalJointLimits(1, min, max));
124 CHECK(min == -10.0);
125 CHECK(max == 10.0);
126 CHECK(ijc->getPhysicalJointLimits(2, min, max));
127 CHECK(min == -32.0);
128 CHECK(max == 33.0);
129 CHECK(ijc->getPhysicalJointLimits(3, min, max));
130 CHECK(min == 0.0);
131 CHECK(max == 120.0);
132
133
134
135
136 //"Close all polydrivers and check"
137 {
138 CHECK(ddjc.close());
139 }
140 }
141
142 Network::setLocalMode(false);
143}
A container for a device driver.
Definition PolyDriver.h:23
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
TEST_CASE("dev::fakeJointCoupling", "[yarp::dev]")
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.