YARP
Yet Another Robot Platform
ControlBoardWrapperCommon.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPERCOMMON_H
10 #define YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPERCOMMON_H
11 
12 #include "MultiJointData.h"
13 
14 constexpr int PROTOCOL_VERSION_MAJOR = 1;
15 constexpr int PROTOCOL_VERSION_MINOR = 9;
16 constexpr int PROTOCOL_VERSION_TWEAK = 0;
17 
19 {
20 public:
21 // COMMON MEMBERS
23  size_t controlledJoints {0};
24  std::string partName; // to open ports and print more detailed debug messages
25 
26  // RPC calls are concurrent from multiple clients, data used inside the calls has to be protected
27  std::mutex rpcDataMutex; // mutex to avoid concurrency between more clients using rppc port
28  MultiJointData rpcData; // Structure used to re-arrange data from "multiple_joints" calls.
29 
30  std::mutex timeMutex; // mutex to protect access to time member
31  yarp::os::Stamp time; // envelope to attach to the state port
32 
33 // METHODS SHARED BY MULTIPLE INTERFACES
34  /*
35  * IEncodersTimed
36  * IImpedanceControl
37  * IPositionControl
38  * IPositionDirect
39  * ITorqueControl
40  * IVelocityControl
41  */
42  bool getAxes(int* ax);
43 
44  /*
45  * IPositionControl
46  * IVelocityControl
47  */
48  bool setRefAcceleration(int j, double acc);
49  bool setRefAccelerations(const double* accs);
50  bool setRefAccelerations(const int n_joints, const int* joints, const double* accs);
51  bool getRefAcceleration(int j, double* acc);
52  bool getRefAccelerations(double* accs);
53  bool getRefAccelerations(const int n_joints, const int* joints, double* accs);
54  bool stop(int j);
55  bool stop();
56  bool stop(const int n_joint, const int* joints);
57 
58  /*
59  * IMotor
60  * IPWMControl
61  */
62  bool getNumberOfMotors(int* num);
63 
64  /*
65  * IAmplifierControl
66  * ICurrentControl
67  */
68  bool getCurrent(int m, double* curr);
69  bool getCurrents(double* currs);
70 
71 // UTILITIES
72  inline void printError(const std::string& func_name, const std::string& info, bool result)
73  {
74  // FIXME: Check if it is still required.
75  // This method was commented out by these commits:
76  // afc039962f3667cc954e7a50ce6963ec60886611
77  // 0c0de4a9331b9b843ac4b3d3746c074dd0427249
78 
79  // If result is false, this means that en error occurred in function named func_name, otherwise means that the device doesn't implement the interface to witch func_name belongs to.
80  // if(false == result) {
81  // yCError(CONTROLBOARDREMAPPER) << "CBW(" << partName << "): " << func_name.c_str() << " on device" << info.c_str() << " returns false";
82  // } else {
83  // Commented in order to maintain the old behaviour (none message appear if device desn't implement the interface)
84  // yCError(CONTROLBOARDREMAPPER) << "CBW(" << partName << "): " << func_name.c_str() << " on device" << info.c_str() << ": the interface is not available.";
85  // }
86  }
87 };
88 
89 #endif // YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPERCOMMON_H
ControlBoardWrapperCommon::rpcData
MultiJointData rpcData
Definition: ControlBoardWrapperCommon.h:28
ControlBoardWrapperCommon::time
yarp::os::Stamp time
Definition: ControlBoardWrapperCommon.h:31
ControlBoardWrapperCommon::stop
bool stop()
Definition: ControlBoardWrapperCommon.cpp:236
WrappedDevice
Definition: SubDevice.h:123
ControlBoardWrapperCommon::timeMutex
std::mutex timeMutex
Definition: ControlBoardWrapperCommon.h:30
ControlBoardWrapperCommon::getCurrent
bool getCurrent(int m, double *curr)
Definition: ControlBoardWrapperCommon.cpp:327
MultiJointData.h
ControlBoardWrapperCommon::getRefAcceleration
bool getRefAcceleration(int j, double *acc)
Definition: ControlBoardWrapperCommon.cpp:113
MultiJointData
Definition: MultiJointData.h:15
ControlBoardWrapperCommon::partName
std::string partName
Definition: ControlBoardWrapperCommon.h:24
ControlBoardWrapperCommon::controlledJoints
size_t controlledJoints
Definition: ControlBoardWrapperCommon.h:23
PROTOCOL_VERSION_MINOR
constexpr int PROTOCOL_VERSION_MINOR
Definition: ControlBoardWrapperCommon.h:15
ControlBoardWrapperCommon
Definition: ControlBoardWrapperCommon.h:19
PROTOCOL_VERSION_TWEAK
constexpr int PROTOCOL_VERSION_TWEAK
Definition: ControlBoardWrapperCommon.h:16
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
PROTOCOL_VERSION_MAJOR
constexpr int PROTOCOL_VERSION_MAJOR
Definition: ControlBoardWrapperCommon.h:14
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
ControlBoardWrapperCommon::getCurrents
bool getCurrents(double *currs)
Definition: ControlBoardWrapperCommon.cpp:296
ControlBoardWrapperCommon::getNumberOfMotors
bool getNumberOfMotors(int *num)
Definition: ControlBoardWrapperCommon.cpp:289
ControlBoardWrapperCommon::setRefAcceleration
bool setRefAcceleration(int j, double acc)
Definition: ControlBoardWrapperCommon.cpp:21
ControlBoardWrapperCommon::getAxes
bool getAxes(int *ax)
Definition: ControlBoardWrapperCommon.cpp:14
ControlBoardWrapperCommon::setRefAccelerations
bool setRefAccelerations(const double *accs)
Definition: ControlBoardWrapperCommon.cpp:45
ControlBoardWrapperCommon::rpcDataMutex
std::mutex rpcDataMutex
Definition: ControlBoardWrapperCommon.h:27
ControlBoardWrapperCommon::getRefAccelerations
bool getRefAccelerations(double *accs)
Definition: ControlBoardWrapperCommon.cpp:138
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72