YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IPositionControlTest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef IPOSITIONCONTROLTEST_H
7#define IPOSITIONCONTROLTEST_H
8
9#include <memory>
10#include <numeric>
11#include <vector>
12
15#include <catch2/catch_amalgamated.hpp>
16
17using namespace yarp::dev;
18using namespace yarp::os;
19
20namespace yarp::dev::tests
21{
23 {
24 REQUIRE(ipos != nullptr);
25 REQUIRE(icmd != nullptr);
26
27 bool b;
28 int ax;
29
30 b = ipos->getAxes(&ax);
31 CHECK(b);
32 REQUIRE(ax > 0);
33
34 for (size_t i = 0; i < ax; i++)
35 {
37 CHECK(b);
38 }
39
40 {
41 double ref = 0;
42 auto refs = std::vector<double>(ax);
43 auto joints = std::vector<int>(ax);
44 std::iota(joints.begin(), joints.end(), 0);
45
46 b = ipos->setRefSpeed(0, ref);
47 CHECK(b);
48
49 b = ipos->setRefSpeeds(refs.data());
50 CHECK(b);
51
52 b = ipos->setRefSpeeds(ax, joints.data(), refs.data());
53 CHECK(b);
54
55 b = ipos->setRefAcceleration(0, ref);
56 CHECK(b);
57
58 b = ipos->setRefAccelerations(refs.data());
59 CHECK(b);
60
61 b = ipos->setRefAccelerations(ax, joints.data(), refs.data());
62 CHECK(b);
63 }
64 {
65 double ref = 0;
66 auto refs = std::vector<double>(ax);
67 auto joints = std::vector<int>(ax);
68 std::iota(joints.begin(), joints.end(), 0);
69
70 b = ipos->getRefSpeed(0,&ref);
71 CHECK(b);
72
73 b = ipos->getRefSpeeds(refs.data());
74 CHECK(b);
75
76 b = ipos->getRefSpeeds(ax, joints.data(), refs.data());
77 CHECK(b);
78
79 b = ipos->getRefAcceleration(0, &ref);
80 CHECK(b);
81
82 b = ipos->getRefAccelerations(refs.data());
83 CHECK(b);
84
85 b = ipos->getRefAccelerations(ax, joints.data(), refs.data());
86 CHECK(b);
87
88 b = ipos->getTargetPosition(0, &ref);
89 CHECK(b);
90
91 b = ipos->getTargetPositions(refs.data());
92 CHECK(b);
93
94 b = ipos->getTargetPositions(ax, joints.data(), refs.data());
95 CHECK(b);
96 }
97
98 {
99 double ref = 0;
100 auto refs = std::vector<double>(ax);
101 auto joints = std::vector<int>(ax);
102 std::iota(joints.begin(), joints.end(), 0);
103 b = ipos->positionMove(0, ref);
104 CHECK(b);
105
106 b = ipos->positionMove(refs.data());
107 CHECK(b);
108
109 b = ipos->positionMove(ax, joints.data(), refs.data());
110 CHECK(b);
111
112 b = ipos->relativeMove(0, ref);
113 CHECK(b);
114
115 b = ipos->relativeMove(refs.data());
116 CHECK(b);
117
118 b = ipos->relativeMove(ax, joints.data(), refs.data());
119 CHECK(b);
120 }
121
122 {
123 bool flag;
124 auto flags = std::make_unique<bool>(ax);
125 auto joints = std::vector<int>(ax);
126 std::iota(joints.begin(), joints.end(), 0);
127 b = ipos->checkMotionDone(0,&flag);
128 CHECK(b);
129
130 b = ipos->checkMotionDone(flags.get());
131 CHECK(b);
132
133 b = ipos->checkMotionDone(ax,joints.data(),flags.get());
134 CHECK(b);
135 }
136
137 {
138 b = ipos->stop();
139 CHECK(b);
140 }
141 }
142
144 {
145 REQUIRE(ipos != nullptr);
146 REQUIRE(icmd != nullptr);
147
148 bool b;
149 int ax;
150
151 b = ipos->getAxes(&ax);
152 CHECK(b);
153 REQUIRE(ax > 0);
154
155 for (size_t i = 0; i < ax; i++)
156 {
157 b = icmd->setControlMode(i, VOCAB_CM_POSITION);
158 //CHECK(b); //this will fail
159 }
160
161 double ref = 0;
162 b = ipos->getRefSpeed(0, &ref);
163 CHECK(!b);
164
165 b = ipos->getRefAcceleration(0, &ref);
166 CHECK(!b);
167
168 b = ipos->getTargetPosition(0, &ref);
169 CHECK(!b);
170 }
171}
172
173#endif
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
Interface for setting control mode in control board.
virtual bool setControlMode(const int j, const int mode)=0
Set the current control mode.
Interface for a generic control board device implementing position control.
virtual bool getRefAcceleration(int j, double *acc)=0
Get reference acceleration for a joint.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool setRefSpeed(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual bool setRefAcceleration(int j, double acc)=0
Set reference acceleration for a joint.
virtual bool relativeMove(int j, double delta)=0
Set relative position.
virtual bool getTargetPosition(const int joint, double *ref)
Get the last position reference for the specified axis.
virtual bool setRefSpeeds(const double *spds)=0
Set reference speed on all joints.
virtual bool checkMotionDone(int j, bool *flag)=0
Check if the current trajectory is terminated.
virtual bool getRefSpeeds(double *spds)=0
Get reference speed of all joints.
virtual bool stop(int j)=0
Stop motion, single joint.
virtual bool setRefAccelerations(const double *accs)=0
Set reference acceleration on all joints.
virtual bool getRefAccelerations(double *accs)=0
Get reference acceleration of all joints.
virtual bool getRefSpeed(int j, double *ref)=0
Get reference speed for a joint.
virtual bool positionMove(int j, double ref)=0
Set new reference point for a single axis.
virtual bool getTargetPositions(double *refs)
Get the last position reference for all axes.
A mini-server for performing network communication in the background.
void exec_iPositionControl_test_1(IPositionControl *ipos, IControlMode *icmd)
void exec_iPositionControl_test_unimplemented_interface(IPositionControl *ipos, IControlMode *icmd)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.