YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IVelocityDirectTest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef IVELOCITYDIRECTTEST_H
7#define IVELOCITYDIRECTTEST_H
8
9#include <memory>
10#include <numeric>
11#include <vector>
12
13#include <yarp/os/Time.h>
16#include <catch2/catch_amalgamated.hpp>
17
18using namespace yarp::dev;
19using namespace yarp::os;
20
21namespace yarp::dev::tests
22{
23 // Utility function to compare two int vectors for equality
24 inline bool vectors_equal(const std::vector<double>& a, const std::vector<double>& b)
25 {
26 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
27 }
28
30 {
31 REQUIRE(ivdir != nullptr);
32 REQUIRE(icmd != nullptr);
33
34 bool b=false;
35 size_t ax=0;
36
37 b = ivdir->getAxes(ax);
38 CHECK(b);
39 REQUIRE(ax != 0);
40
41 for (size_t i = 0; i < ax; i++)
42 {
44 CHECK(b);
45 yarp::os::Time::delay(0.020); // Allow some time for the command to take effect
46
47 int mode_ret = 0;
48 b = icmd->getControlMode(i, &mode_ret);
49 CHECK(b);
51 }
52
53 {
54 double ref = 12;
55 double ref_check = 12;
56 auto refs = std::vector<double>(ax);
57 auto refs_check = std::vector<double>(ax);
58 auto joints = std::vector<int>(ax);
59 std::iota(joints.begin(), joints.end(), 0);
60
61 b = ivdir->setDesiredVelocity(0, ref);
62 CHECK(b);
63 yarp::os::Time::delay(0.020); // Allow some time for the command to take effect
64
65 b = ivdir->getDesiredVelocity(0, ref);
66 CHECK(b);
67 CHECK(ref == ref_check);
68
69 std::iota(refs.begin(), refs.end(), 1.0);
70 std::iota(refs_check.begin(), refs_check.end(), 1.0);
71
72 b = ivdir->setDesiredVelocity(refs);
73 CHECK(b);
74 yarp::os::Time::delay(0.020); // Allow some time for the command to take effect
75
76 b = ivdir->getDesiredVelocity(refs);
77 CHECK(b);
79
80 std::iota(refs.begin(), refs.end(), 10.0);
81 std::iota(refs_check.begin(), refs_check.end(), 10.0);
82
83 b = ivdir->setDesiredVelocity(joints, refs);
84 CHECK(b);
85 yarp::os::Time::delay(0.020); // Allow some time for the command to take effect
86
87 b = ivdir->getDesiredVelocity(joints, refs);
88 CHECK(b);
90 }
91 }
92}
93
94#endif
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY_DIRECT
Interface for setting control mode in control board.
virtual bool setControlMode(const int j, const int mode)=0
Set the current control mode.
virtual bool getControlMode(int j, int *mode)=0
Get the current control mode.
Interface for control boards implementing direct velocity control.
A mini-server for performing network communication in the background.
bool vectors_equal(const std::vector< double > &a, const std::vector< double > &b)
void exec_iVelocityDirect_test_1(IVelocityDirect *ivdir, IControlMode *icmd)
For streams capable of holding different kinds of content, check what they actually have.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.