YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IVelocityControlTest.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 IVELOCITYCONTROLTEST_H
7#define IVELOCITYCONTROLTEST_H
8
9#include <memory>
10#include <numeric>
11
14#include <yarp/os/Time.h>
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(ivel != nullptr);
26 REQUIRE(icmd != nullptr);
27
28 bool b;
29 size_t ax=0;
30
31 b = ivel->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 const double ref_test=1.123;
48 double ref=0;
49 b = ivel->setTrajAcceleration(0, ref_test);
50 CHECK(b);
51 b = ivel->getTrajAcceleration(0, &ref);
52 CHECK(b);
53 CHECK(fabs(ref-ref_test)<0.001);
54
55 b = ivel->velocityMove(0, ref_test);
56 CHECK(b);
57 wait_safe();
58 b = ivel->getTargetVelocity(0,&ref);
59 CHECK(b);
60 CHECK(fabs(ref - ref_test) < 0.001);
61
62 b = ivel->stop();
63 CHECK(b);
64 }
65
67 {
68 REQUIRE(ivel != nullptr);
69 REQUIRE(icmd != nullptr);
70
71 bool b;
72 size_t ax=0;
73 b = ivel->getAxes(ax);
74 CHECK(b);
75 REQUIRE(ax > 0);
76
77 double ref = 0;
78 auto refs = std::vector<double>(ax);
79
80 for (size_t i = 0; i < ax; i++)
81 {
83 //CHECK(b); //this will fail
84 }
85
86 b = ivel->setTrajAcceleration(0, ref);
87 CHECK(!b);
88 b = ivel->getTrajAcceleration(0, &ref);
89 CHECK(!b);
90 b = ivel->setTrajAccelerations( refs.data());
91 CHECK(!b);
92 b = ivel->getTrajAccelerations( refs.data());
93 CHECK(!b);
94
95 b = ivel->velocityMove(0, ref);
96 CHECK(!b);
97
98 b = ivel->getTargetVelocity(0, &ref);
99 CHECK(!b);
100 b = ivel->getTargetVelocities(refs.data());
101 CHECK(!b);
102
103 b = ivel->stop();
104 CHECK(!b);
105 }
106}
107
108#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 control boards implementing velocity control.
A mini-server for performing network communication in the background.
void exec_iVelocityControl_test_unimplemented_interface(IVelocityControl *ivel, IControlMode *icmd)
void wait_safe(const double seconds)
Definition TestUtils.cpp:17
void exec_iVelocityControl_test_1(IVelocityControl *ivel, 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.