YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IControlModeTest.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 ICONTROLMODETEST_H
7#define ICONTROLMODETEST_H
8
11#include <yarp/dev/IAxisInfo.h>
12#include <catch2/catch_amalgamated.hpp>
13
14using namespace yarp::dev;
15using namespace yarp::os;
16
17#define COMMAND_DELAY 1.0
18
19void test_single_joint(IControlMode* icmd, IAxisInfo* iinfo, int mode)
20{
21 REQUIRE(icmd != nullptr);
22 bool b = false;
23 b = icmd->setControlMode(0, mode);
24 CHECK(b);
26 int ret=0;
27 b = icmd->getControlMode(0, &ret);
28 CHECK(b);
29 CHECK(mode==ret);
30}
31
32void test_all_joints(IControlMode* icmd, IAxisInfo* iinfo, int mode)
33{
34 REQUIRE(icmd != nullptr);
35 REQUIRE(iinfo != nullptr);
36 int ax = 0; bool bax = false;
37 bax = iinfo->getAxes(&ax);
38 REQUIRE(bax);
39 REQUIRE(ax==2);
40
41 bool b = false;
42 int modes[2];
43 modes[0]=mode;
44 modes[1]=mode;
45 b = icmd->setControlModes(modes);
46 CHECK(b);
48 int rets[2] = {0,-0};
49 b = icmd->getControlModes(rets);
50 CHECK(b);
51 CHECK(mode == rets[0]);
52 CHECK(mode == rets[1]);
53}
54
55void test_multi_joint(IControlMode* icmd, IAxisInfo* iinfo, int mode)
56{
57 REQUIRE(icmd != nullptr);
58 REQUIRE(iinfo != nullptr);
59 int ax=0; bool bax= false;
60 bax=iinfo->getAxes(&ax);
61 REQUIRE (bax);
62 REQUIRE (ax==2);
63
64 bool b = false;
65 int modes[2];
66 modes[0] = mode;
67 modes[1] = mode;
68 int joints[2];
69 joints[0] = 0;
70 joints[1] = 1;
71 b = icmd->setControlModes(2,joints,modes);
72 CHECK(b);
74 int rets[2] = { 0,-0 };
75 b = icmd->getControlModes(2,joints,rets);
76 CHECK(b);
77 CHECK(mode == rets[0]);
78 CHECK(mode == rets[1]);
79}
80
81void test_joint(IControlMode* icmd, IAxisInfo* iinfo, int mode)
82{
83 REQUIRE(icmd != nullptr);
84 test_single_joint(icmd, iinfo, mode);
85 test_all_joints(icmd, iinfo, mode);
86 test_multi_joint(icmd, iinfo, mode);
87}
88
89namespace yarp::dev::tests
90{
92 {
93 REQUIRE(icmd != nullptr);
94 REQUIRE(iinfo != nullptr);
95
96 bool b= false;
97 int ax=0;
98 std::string name_ret;
100
101 b = iinfo->getAxes(&ax);
102 CHECK(b); CHECK(ax>0);
103 b = iinfo->getAxisName(0, name_ret);
104 CHECK(b); CHECK (!name_ret.empty());
105 b = iinfo->getJointType(0, jointtype_ret);
107
108 test_joint(icmd, iinfo, VOCAB_CM_IDLE);
109 test_joint(icmd, iinfo, VOCAB_CM_TORQUE);
110 test_joint(icmd, iinfo, VOCAB_CM_POSITION);
112 test_joint(icmd, iinfo, VOCAB_CM_VELOCITY);
113 test_joint(icmd, iinfo, VOCAB_CM_CURRENT);
114 test_joint(icmd, iinfo, VOCAB_CM_PWM);
117 test_joint(icmd, iinfo, VOCAB_CM_MIXED);
118 }
119}
120
121#endif
define control board standard interfaces
void test_joint(IControlMode *icmd, IAxisInfo *iinfo, int mode)
void test_single_joint(IControlMode *icmd, IAxisInfo *iinfo, int mode)
#define COMMAND_DELAY
void test_multi_joint(IControlMode *icmd, IAxisInfo *iinfo, int mode)
void test_all_joints(IControlMode *icmd, IAxisInfo *iinfo, int mode)
constexpr yarp::conf::vocab32_t VOCAB_CM_MIXED
constexpr yarp::conf::vocab32_t VOCAB_CM_TORQUE
constexpr yarp::conf::vocab32_t VOCAB_CM_PWM
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_VEL
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
constexpr yarp::conf::vocab32_t VOCAB_CM_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_POS
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY
bool ret
Interface for getting information about specific axes, if available.
Definition IAxisInfo.h:36
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
Definition IAxisInfo.h:63
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 setControlModes(const int n_joint, const int *joints, int *modes)=0
Set the current control mode for a subset of axes.
virtual bool getControlModes(int *modes)=0
Get the current control mode (multiple joints).
virtual bool getControlMode(int j, int *mode)=0
Get the current control mode.
A mini-server for performing network communication in the background.
static void delaySystem(double seconds)
void exec_iControlMode_test_1(IControlMode *icmd, IAxisInfo *iinfo)
For streams capable of holding different kinds of content, check what they actually have.
@ VOCAB_JOINTTYPE_REVOLUTE
Definition IAxisInfo.h:24
An interface to the operating system, including Port based communication.