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#include "TestUtils.h"
17
18using namespace yarp::dev;
19using namespace yarp::os;
20
21namespace yarp::dev::tests
22{
24 {
25 REQUIRE(ipos != nullptr);
26 REQUIRE(icmd != nullptr);
27
28 bool b;
29 size_t ax=0;
30
31 b = ipos->getAxes(ax);
32 CHECK(b);
33 REQUIRE(ax > 0);
34
35 for (size_t i = 0; i < ax; i++)
36 {
38 CHECK(b);
39 wait_safe(); // Allow some time for the command to take effect
40
42 b = icmd->getControlMode(i, mode_ret);
43 CHECK(b);
45 }
46
47 {
48 double ref = 0;
49 auto refs = std::vector<double>(ax);
50 auto joints = std::vector<int>(ax);
51 std::iota(joints.begin(), joints.end(), 0);
52
53 b = ipos->setTrajSpeed(0, ref);
54 CHECK(b);
55
56 b = ipos->setTrajSpeeds(refs.data());
57 CHECK(b);
58
59 b = ipos->setTrajSpeeds(ax, joints.data(), refs.data());
60 CHECK(b);
61
62 b = ipos->setTrajAcceleration(0, ref);
63 CHECK(b);
64
65 b = ipos->setTrajAccelerations(refs.data());
66 CHECK(b);
67
68 b = ipos->setTrajAccelerations(ax, joints.data(), refs.data());
69 CHECK(b);
70 }
71 {
72 double ref = 0;
73 auto refs = std::vector<double>(ax);
74 auto joints = std::vector<int>(ax);
75 std::iota(joints.begin(), joints.end(), 0);
76
77 b = ipos->getTrajSpeed(0,&ref);
78 CHECK(b);
79
80 b = ipos->getTrajSpeeds(refs.data());
81 CHECK(b);
82
83 b = ipos->getTrajSpeeds(ax, joints.data(), refs.data());
84 CHECK(b);
85
86 b = ipos->getTrajAcceleration(0, &ref);
87 CHECK(b);
88
89 b = ipos->getTrajAccelerations(refs.data());
90 CHECK(b);
91
92 b = ipos->getTrajAccelerations(ax, joints.data(), refs.data());
93 CHECK(b);
94
95 b = ipos->getTargetPosition(0, &ref);
96 CHECK(b);
97
98 b = ipos->getTargetPositions(refs.data());
99 CHECK(b);
100
101 b = ipos->getTargetPositions(ax, joints.data(), refs.data());
102 CHECK(b);
103 }
104
105 {
106 double ref = 0;
107 auto refs = std::vector<double>(ax);
108 auto joints = std::vector<int>(ax);
109 std::iota(joints.begin(), joints.end(), 0);
110 b = ipos->positionMove(0, ref);
111 CHECK(b);
112
113 b = ipos->positionMove(refs.data());
114 CHECK(b);
115
116 b = ipos->positionMove(ax, joints.data(), refs.data());
117 CHECK(b);
118
119 b = ipos->relativeMove(0, ref);
120 CHECK(b);
121
122 b = ipos->relativeMove(refs.data());
123 CHECK(b);
124
125 b = ipos->relativeMove(ax, joints.data(), refs.data());
126 CHECK(b);
127 }
128
129 {
130 bool flag;
131
132 auto joints = std::vector<int>(ax);
133 std::iota(joints.begin(), joints.end(), 0);
134 b = ipos->checkMotionDone(0,flag);
135 CHECK(b);
136
137 b = ipos->checkMotionDone(flag);
138 CHECK(b);
139
140 b = ipos->checkMotionDone(joints,flag);
141 CHECK(b);
142 }
143
144 {
145 b = ipos->stop();
146 CHECK(b);
147 }
148 }
149
151 {
152 REQUIRE(ipos != nullptr);
153 REQUIRE(icmd != nullptr);
154
155 bool b;
156 size_t ax=0;
157
158 b = ipos->getAxes(ax);
159 CHECK(b);
160 REQUIRE(ax > 0);
161
162 for (size_t i = 0; i < ax; i++)
163 {
165 //CHECK(b); //this will fail
166 }
167
168 double ref = 0;
169 b = ipos->getTrajSpeed(0, &ref);
170 CHECK(!b);
171
172 b = ipos->getTrajAcceleration(0, &ref);
173 CHECK(!b);
174
175 b = ipos->getTargetPosition(0, &ref);
176 CHECK(!b);
177 }
178}
179
180#endif
Interface for setting control mode in control board.
virtual yarp::dev::ReturnValue getControlMode(int j, yarp::dev::ControlModeEnum &mode)=0
Get the current control mode.
virtual yarp::dev::ReturnValue setControlMode(int j, yarp::dev::SelectableControlModeEnum mode)=0
Set the current control mode.
Interface for a generic control board device implementing position control.
virtual yarp::dev::ReturnValue getTargetPosition(const int joint, double *ref)=0
Get the last position reference for the specified axis.
virtual yarp::dev::ReturnValue setTrajSpeed(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual yarp::dev::ReturnValue getTargetPositions(double *refs)=0
Get the last position reference for all axes.
virtual yarp::dev::ReturnValue setTrajAcceleration(int j, double acc)=0
Set reference acceleration for a joint.
virtual yarp::dev::ReturnValue relativeMove(int j, double delta)=0
Set relative position.
virtual yarp::dev::ReturnValue getTrajSpeeds(double *spds)=0
Get reference speed of all joints.
virtual yarp::dev::ReturnValue setTrajSpeeds(const double *spds)=0
Set reference speed on all joints.
virtual yarp::dev::ReturnValue positionMove(int j, double ref)=0
Set new reference point for a single axis.
virtual yarp::dev::ReturnValue getTrajAccelerations(double *accs)=0
Get reference acceleration of all joints.
virtual yarp::dev::ReturnValue checkMotionDone(int j, bool &flag)=0
Check if the current trajectory is terminated.
virtual yarp::dev::ReturnValue getAxes(size_t &ax)=0
Get the number of controlled axes.
virtual yarp::dev::ReturnValue getTrajSpeed(int j, double *ref)=0
Get reference speed for a joint.
virtual yarp::dev::ReturnValue setTrajAccelerations(const double *accs)=0
Set reference acceleration on all joints.
virtual yarp::dev::ReturnValue stop(int j)=0
Stop motion, single joint.
virtual yarp::dev::ReturnValue getTrajAcceleration(int j, double *acc)=0
Get reference acceleration for a joint.
A mini-server for performing network communication in the background.
void wait_safe(const double seconds)
Definition TestUtils.cpp:17
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.
Definition OSTestMsg.cpp:13