YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ICurrentControlTest.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 ICURRENTCONTROLTEST_H
7#define ICURRENTCONTROLTEST_H
8
9#include <yarp/os/Time.h>
10
13#include <catch2/catch_amalgamated.hpp>
14
15#include <memory>
16#include <numeric>
17#include <vector>
18
19#include "TestUtils.h"
20
21using namespace yarp::dev;
22using namespace yarp::os;
23
24namespace yarp::dev::tests
25{
27 {
28 REQUIRE(icurr != nullptr);
29 REQUIRE(icmd != nullptr);
30
31 bool b = false;
32 int axis = 0;
33 double val = 0;
34 double min = 0;
35 double max = 0;
36
37 b = icurr->getNumberOfMotors(&axis);
38 CHECK (b);
39
40 b = icurr->getCurrent(0, &val);
41 CHECK(b);
42
43 b = icurr->getRefCurrent(0, &val);
44 CHECK(b);
45 CHECK(val != 100);
46
47 b = icurr->setRefCurrent(0, 100);
48 CHECK(b);
49 wait_safe(); // Allow some time for the command to take effect
50
51 b = icurr->getRefCurrent(0, &val);
52 CHECK(b);
53 CHECK(val == 100);
54
55 b = icurr->getCurrentRange(0, &min, &max);
56 CHECK(b);
57
58 auto mins = std::vector< double >(axis);
59 auto maxs = std::vector< double >(axis);
60 auto currs = std::vector< double >(axis);
61
62 auto refs = std::vector< double >(axis);
63 auto refs_check = std::vector< double >(axis);
64
65 b = icurr->getCurrentRanges(mins.data(), maxs.data());
66 CHECK(b);
67
68 b = icurr->getCurrents(currs.data());
69 CHECK(b);
70
71 set_vector_crescent(axis, refs.data(), 10.0);
72 set_vector_crescent(axis, refs_check.data(), 10.0);
73 b = icurr->setRefCurrents(refs.data());
74 CHECK(b);
75 wait_safe(); // Allow some time for the command to take effect
76
77
78 b = icurr->getRefCurrents(refs.data());
79 CHECK(b);
80 CHECK(vectors_equal(axis, refs.data(), refs_check.data()));
81 }
82}
83
84#endif
Interface for setting control mode in control board.
Interface for control boards implementing current control.
A mini-server for performing network communication in the background.
bool vectors_equal(const std::vector< double > &a, const std::vector< double > &b)
Definition TestUtils.cpp:23
void set_vector_crescent(std::vector< double > &a, double val)
Definition TestUtils.cpp:65
void exec_iCurrentControl_test_1(ICurrentControl *icurr, IControlMode *icmd)
void wait_safe(const double seconds)
Definition TestUtils.cpp:17
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.