YARP
Yet Another Robot Platform
ControlBoardRemapperHelpers.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_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
10 #define YARP_DEV_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
11 
12 
13 #include <yarp/os/PortablePair.h>
14 #include <yarp/os/BufferedPort.h>
15 #include <yarp/os/Time.h>
16 #include <yarp/os/Network.h>
17 #include <yarp/os/Stamp.h>
18 #include <yarp/os/Vocab.h>
19 
23 #include <yarp/dev/PolyDriver.h>
25 
26 
27 #include <yarp/sig/Vector.h>
28 
29 #include <mutex>
30 #include <string>
31 #include <vector>
32 
33 
34 #ifdef MSVC
35  #pragma warning(disable:4355)
36 #endif
37 
38 /*
39  * Helper class for the ControlBoardRemapper.
40  * It contains all the data structure related
41  * to a given controlboard used by the remapper.
42  */
44 {
45 public:
46  std::string id;
47 
69 
71 
72  bool attach(yarp::dev::PolyDriver *d, const std::string &id);
73  void detach();
74 
75  inline void setVerbose(bool _verbose) {_subDevVerbose = _verbose; }
76 
77  bool isAttached()
78  { return attachedF; }
79 
80 private:
81  bool _subDevVerbose;
82  bool attachedF;
83 };
84 
90 {
91 public:
97 
102 };
103 
105 {
106 public:
110  std::vector<RemappedSubControlBoard> subdevices;
111 
115  std::vector<RemappedAxis> lut;
116 
124  {
125  return &(subdevices[i]);
126  }
127 
128  size_t getNrOfSubControlBoards() const
129  {
130  return subdevices.size();
131  }
132 
133  size_t getNrOfRemappedAxes() const
134  {
135  return lut.size();
136  }
137 };
138 
140 {
141 public:
142  std::mutex mutex;
143  std::vector<int> controlBoardModes;
144  std::vector<double> dummyBuffer;
146 
147 };
148 
157 {
158 public:
163  bool configure(const RemappedControlBoards & remappedControlBoards);
164 
169  void fillSubControlBoardBuffersFromCompleteJointVector(const double * full, const RemappedControlBoards & remappedControlBoards);
170 
171 
178  const RemappedControlBoards & remappedControlBoards);
179 
187  const RemappedControlBoards & remappedControlBoards);
188 
193  void fillCompleteJointVectorFromSubControlBoardBuffers(double * full, const RemappedControlBoards & remappedControlBoards);
194 
203  const RemappedControlBoards & remappedControlBoards);
204 
213  const RemappedControlBoards & remappedControlBoards);
214 
215 
219  std::mutex mutex;
220 
221  // Buffer to be used in MultiJoint version of the
223  std::vector<int> m_nJointsInSubControlBoard;
224  std::vector< std::vector<int> > m_jointsInSubControlBoard;
225 
226 
227  std::vector< std::vector<double> > m_bufferForSubControlBoard;
228  std::vector< std::vector<int> > m_bufferForSubControlBoardControlModes;
229  std::vector< std::vector<yarp::dev::InteractionModeEnum> > m_bufferForSubControlBoardInteractionModes;
230 
231  std::vector<int> m_counterForControlBoard;
232 };
233 
244 {
249  void createListOfJointsDecomposition(const int n_joints, const int *joints, const RemappedControlBoards & remappedControlBoards);
250 
251 public:
256  bool configure(const RemappedControlBoards & remappedControlBoards);
257 
258 
263  void fillSubControlBoardBuffersFromArbitraryJointVector(const double * arbitraryVec,
264  const int n_joints,
265  const int *joints,
266  const RemappedControlBoards & remappedControlBoards);
267 
273  void fillSubControlBoardBuffersFromArbitraryJointVector(const int * arbitraryVec,
274  const int n_joints,
275  const int *joints,
276  const RemappedControlBoards & remappedControlBoards);
277 
284  const int n_joints,
285  const int *joints,
286  const RemappedControlBoards & remappedControlBoards);
287 
292  void resizeSubControlBoardBuffers(const int n_joints,
293  const int *joints,
294  const RemappedControlBoards & remappedControlBoards);
295 
302  void fillArbitraryJointVectorFromSubControlBoardBuffers(double * arbitraryVec,
303  const int n_joints, const int *joints,
304  const RemappedControlBoards & remappedControlBoards);
305 
314  const int n_joints, const int *joints,
315  const RemappedControlBoards & remappedControlBoards);
316 
325  const int n_joints, const int *joints,
326  const RemappedControlBoards & remappedControlBoards);
327 
331  std::mutex mutex;
332 
333  // Total number of axes in the remapped controlboard
335 
336  // Vector of size getNrOfSubControlBoards
337  std::vector<int> m_nJointsInSubControlBoard;
338  std::vector< std::vector<int> > m_jointsInSubControlBoard;
339 
340  // Buffers for the control board (the size of each one should
341  // match the size of m_nJointsInSubControlBoard[ctrlBoard] and
342  // the size of m_jointsInSubControlBoard[ctrlBoard].size()
343  std::vector< std::vector<double> > m_bufferForSubControlBoard;
344  std::vector< std::vector<int> > m_bufferForSubControlBoardControlModes;
345  std::vector< std::vector<yarp::dev::InteractionModeEnum> > m_bufferForSubControlBoardInteractionModes;
346 
347 
348  // Counter used when converting a full vector to
349  // the subcontrolboard buffers
350  std::vector<int> m_counterForControlBoard;
351 };
352 
353 #endif // YARP_DEV_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
yarp::dev::IRemoteVariables
IRemoteVariables interface.
Definition: IRemoteVariables.h:51
ControlBoardSubControlBoardAxesDecomposition::m_jointsInSubControlBoard
std::vector< std::vector< int > > m_jointsInSubControlBoard
Definition: ControlBoardRemapperHelpers.h:224
Network.h
RemappedSubControlBoard::vel
yarp::dev::IVelocityControl * vel
Definition: ControlBoardRemapperHelpers.h:51
RemappedSubControlBoard::iVar
yarp::dev::IRemoteVariables * iVar
Definition: ControlBoardRemapperHelpers.h:66
Vector.h
contains the definition of a Vector type
yarp::dev::IImpedanceControl
Interface for control boards implementing impedance control.
Definition: IImpedanceControl.h:75
RemappedControlBoards::getNrOfRemappedAxes
size_t getNrOfRemappedAxes() const
Definition: ControlBoardRemapperHelpers.h:133
RemappedControlBoards::getSubControlBoard
RemappedSubControlBoard * getSubControlBoard(size_t i)
Given a controlboard index between 0 and getNrOfSubControlBoards()-1, return the relative SubControlB...
Definition: ControlBoardRemapperHelpers.h:123
RemappedSubControlBoard::imotor
yarp::dev::IMotor * imotor
Definition: ControlBoardRemapperHelpers.h:65
ControlBoardArbitraryAxesDecomposition::configure
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
Definition: ControlBoardRemapperHelpers.cpp:356
ControlBoardSubControlBoardAxesDecomposition::fillCompleteJointVectorFromSubControlBoardBuffers
void fillCompleteJointVectorFromSubControlBoardBuffers(double *full, const RemappedControlBoards &remappedControlBoards)
Fill a vector of joints of the ControlBoardRemapper from the buffers of the SubControlBoard .
Definition: ControlBoardRemapperHelpers.cpp:281
RemappedSubControlBoard::iImpedance
yarp::dev::IImpedanceControl * iImpedance
Definition: ControlBoardRemapperHelpers.h:60
IPreciselyTimed.h
RemappedSubControlBoard::lim
yarp::dev::IControlLimits * lim
Definition: ControlBoardRemapperHelpers.h:55
ControlBoardRemapperBuffers::stamp
yarp::os::Stamp stamp
Definition: ControlBoardRemapperHelpers.h:145
RemappedSubControlBoard::pid
yarp::dev::IPidControl * pid
Definition: ControlBoardRemapperHelpers.h:49
RemappedSubControlBoard::iMode
yarp::dev::IControlMode * iMode
Definition: ControlBoardRemapperHelpers.h:61
RemappedSubControlBoard::iTorque
yarp::dev::ITorqueControl * iTorque
Definition: ControlBoardRemapperHelpers.h:59
RemappedSubControlBoard::posDir
yarp::dev::IPositionDirect * posDir
Definition: ControlBoardRemapperHelpers.h:63
ControlBoardInterfaces.h
define control board standard interfaces
RemappedSubControlBoard::iInteract
yarp::dev::IInteractionMode * iInteract
Definition: ControlBoardRemapperHelpers.h:64
PortablePair.h
RemappedSubControlBoard::iPwm
yarp::dev::IPWMControl * iPwm
Definition: ControlBoardRemapperHelpers.h:67
RemappedAxis::subControlBoardIndex
size_t subControlBoardIndex
The index of the SubControlBoard of the remapped axis in the RemappedControlBoards class.
Definition: ControlBoardRemapperHelpers.h:96
RemappedSubControlBoard::isAttached
bool isAttached()
Definition: ControlBoardRemapperHelpers.h:77
RemappedSubControlBoard::iTimed
yarp::dev::IPreciselyTimed * iTimed
Definition: ControlBoardRemapperHelpers.h:58
yarp::dev::IInteractionMode
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
Definition: IInteractionMode.h:43
RemappedControlBoards::getNrOfSubControlBoards
size_t getNrOfSubControlBoards() const
Definition: ControlBoardRemapperHelpers.h:128
ControlBoardArbitraryAxesDecomposition::mutex
std::mutex mutex
Mutex to grab to use this class.
Definition: ControlBoardRemapperHelpers.h:331
ControlBoardArbitraryAxesDecomposition::fillArbitraryJointVectorFromSubControlBoardBuffers
void fillArbitraryJointVectorFromSubControlBoardBuffers(double *arbitraryVec, const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Fill a vector of joints of the ControlBoardRemapper from the buffers of the SubControlBoard .
Definition: ControlBoardRemapperHelpers.cpp:402
yarp::dev::IControlMode
Interface for setting control mode in control board.
Definition: IControlMode.h:28
RemappedSubControlBoard::amp
yarp::dev::IAmplifierControl * amp
Definition: ControlBoardRemapperHelpers.h:54
yarp::dev::IControlCalibration
Interface for control devices, calibration commands.
Definition: IControlCalibration.h:85
yarp::dev::IAxisInfo
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:43
ControlBoardSubControlBoardAxesDecomposition::fillSubControlBoardBuffersFromCompleteJointVector
void fillSubControlBoardBuffersFromCompleteJointVector(const double *full, const RemappedControlBoards &remappedControlBoards)
Fill buffers for the SubControlBoard from a vector of joints of the RemappedControlBoards.
Definition: ControlBoardRemapperHelpers.cpp:266
PolyDriver.h
RemappedSubControlBoard::RemappedSubControlBoard
RemappedSubControlBoard()
Definition: ControlBoardRemapperHelpers.cpp:21
ControlBoardSubControlBoardAxesDecomposition::m_counterForControlBoard
std::vector< int > m_counterForControlBoard
Definition: ControlBoardRemapperHelpers.h:231
RemappedSubControlBoard::info
yarp::dev::IAxisInfo * info
Definition: ControlBoardRemapperHelpers.h:62
Stamp.h
ControlBoardArbitraryAxesDecomposition::fillSubControlBoardBuffersFromArbitraryJointVector
void fillSubControlBoardBuffersFromArbitraryJointVector(const double *arbitraryVec, const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Fill buffers for the SubControlBoard from a vector of joints of the RemappedControlBoards.
Definition: ControlBoardRemapperHelpers.cpp:421
RemappedSubControlBoard::attach
bool attach(yarp::dev::PolyDriver *d, const std::string &id)
Definition: ControlBoardRemapperHelpers.cpp:81
yarp::dev::IControlLimits
Interface for control devices, commands to get/set position and veloity limits.
Definition: IControlLimits.h:33
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
ControlBoardSubControlBoardAxesDecomposition::m_bufferForSubControlBoardControlModes
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
Definition: ControlBoardRemapperHelpers.h:228
yarp::dev::InteractionModeEnum
InteractionModeEnum
Definition: IInteractionMode.h:21
ControlBoardSubControlBoardAxesDecomposition::mutex
std::mutex mutex
Mutex to grab to use this class.
Definition: ControlBoardRemapperHelpers.h:219
RemappedControlBoards::subdevices
std::vector< RemappedSubControlBoard > subdevices
Vector of dimension getNrOfSubControlBoards .
Definition: ControlBoardRemapperHelpers.h:110
RemappedSubControlBoard::setVerbose
void setVerbose(bool _verbose)
Definition: ControlBoardRemapperHelpers.h:75
ControlBoardSubControlBoardAxesDecomposition::m_nrOfControlledAxesInRemappedCtrlBrd
int m_nrOfControlledAxesInRemappedCtrlBrd
Definition: ControlBoardRemapperHelpers.h:222
RemappedSubControlBoard::iMotEnc
yarp::dev::IMotorEncoders * iMotEnc
Definition: ControlBoardRemapperHelpers.h:53
yarp::dev::IPWMControl
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition: IPWMControl.h:28
ControlBoardArbitraryAxesDecomposition::m_nJointsInSubControlBoard
std::vector< int > m_nJointsInSubControlBoard
Definition: ControlBoardRemapperHelpers.h:337
RemappedSubControlBoard
Definition: ControlBoardRemapperHelpers.h:44
ControlBoardRemapperBuffers::controlBoardModes
std::vector< int > controlBoardModes
Definition: ControlBoardRemapperHelpers.h:143
RemappedAxis
Information in how an axis is remapped on an axis of a SubControlBoard.
Definition: ControlBoardRemapperHelpers.h:90
BufferedPort.h
ControlBoardRemapperBuffers::dummyBuffer
std::vector< double > dummyBuffer
Definition: ControlBoardRemapperHelpers.h:144
ControlBoardArbitraryAxesDecomposition::m_counterForControlBoard
std::vector< int > m_counterForControlBoard
Definition: ControlBoardRemapperHelpers.h:350
ControlBoardSubControlBoardAxesDecomposition::m_nJointsInSubControlBoard
std::vector< int > m_nJointsInSubControlBoard
Definition: ControlBoardRemapperHelpers.h:223
yarp::dev::IMotorEncoders
Control board, encoder interface.
Definition: IMotorEncoders.h:155
ControlBoardArbitraryAxesDecomposition
Class storing the decomposition of a subset of the total remapped axes of the remapped controlboard i...
Definition: ControlBoardRemapperHelpers.h:244
yarp::dev::IAmplifierControl
Interface for control devices, amplifier commands.
Definition: IAmplifierControl.h:33
yarp::dev::IMotor
Control board, encoder interface.
Definition: IMotor.h:99
RemappedSubControlBoard::detach
void detach()
Definition: ControlBoardRemapperHelpers.cpp:54
yarp::dev::IVelocityControl
Interface for control boards implementing velocity control.
Definition: IVelocityControl.h:160
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
ControlBoardRemapperBuffers
Definition: ControlBoardRemapperHelpers.h:140
ControlBoardArbitraryAxesDecomposition::m_bufferForSubControlBoard
std::vector< std::vector< double > > m_bufferForSubControlBoard
Definition: ControlBoardRemapperHelpers.h:343
RemappedSubControlBoard::iJntEnc
yarp::dev::IEncodersTimed * iJntEnc
Definition: ControlBoardRemapperHelpers.h:52
yarp::dev::ICurrentControl
Interface for control boards implementing current control.
Definition: ICurrentControl.h:28
ControlBoardSubControlBoardAxesDecomposition::m_bufferForSubControlBoard
std::vector< std::vector< double > > m_bufferForSubControlBoard
Definition: ControlBoardRemapperHelpers.h:227
yarp::dev::IPidControl
Interface for a generic control board device implementing a PID controller, with scaled arguments.
Definition: IPidControl.h:211
IControlLimits2.h
RemappedSubControlBoard::pos
yarp::dev::IPositionControl * pos
Definition: ControlBoardRemapperHelpers.h:50
yarp::dev::IPositionDirect
Interface for a generic control board device implementing position control.
Definition: IPositionDirect.h:32
yarp::dev::IEncodersTimed
Control board, extend encoder interface with timestamps.
Definition: IEncodersTimed.h:59
ControlBoardRemapperBuffers::mutex
std::mutex mutex
Definition: ControlBoardRemapperHelpers.h:142
RemappedSubControlBoard::iCurr
yarp::dev::ICurrentControl * iCurr
Definition: ControlBoardRemapperHelpers.h:68
RemappedControlBoards::lut
std::vector< RemappedAxis > lut
Vector of dimension getNrOfRemappedAxes .
Definition: ControlBoardRemapperHelpers.h:115
ControlBoardSubControlBoardAxesDecomposition::m_bufferForSubControlBoardInteractionModes
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
Definition: ControlBoardRemapperHelpers.h:229
Vocab.h
Time.h
yarp::dev::ITorqueControl
Interface for control boards implementing torque control.
Definition: ITorqueControl.h:39
IInteractionMode.h
RemappedSubControlBoard::remcalib
yarp::dev::IRemoteCalibrator * remcalib
Definition: ControlBoardRemapperHelpers.h:57
yarp::dev::IRemoteCalibrator
IRemoteCalibrator interface is meant to remotize the access of the calibration device in order to all...
Definition: IRemoteCalibrator.h:30
RemappedSubControlBoard::subdevice
yarp::dev::PolyDriver * subdevice
Definition: ControlBoardRemapperHelpers.h:48
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
ControlBoardArbitraryAxesDecomposition::m_nrOfControlledAxesInRemappedCtrlBrd
int m_nrOfControlledAxesInRemappedCtrlBrd
Definition: ControlBoardRemapperHelpers.h:334
yarp::dev::IPositionControl
Interface for a generic control board device implementing position control.
Definition: IPositionControl.h:257
ControlBoardArbitraryAxesDecomposition::m_bufferForSubControlBoardInteractionModes
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
Definition: ControlBoardRemapperHelpers.h:345
ControlBoardArbitraryAxesDecomposition::resizeSubControlBoardBuffers
void resizeSubControlBoardBuffers(const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Resize buffers to have the dimension of specified by the method (used for multi joint methods that re...
Definition: ControlBoardRemapperHelpers.cpp:539
ControlBoardSubControlBoardAxesDecomposition
Class storing the decomposition of all the axes in the Remapped ControlBoard in the SubControlBoard,...
Definition: ControlBoardRemapperHelpers.h:157
ControlBoardArbitraryAxesDecomposition::m_bufferForSubControlBoardControlModes
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
Definition: ControlBoardRemapperHelpers.h:344
ControlBoardSubControlBoardAxesDecomposition::configure
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
Definition: ControlBoardRemapperHelpers.cpp:216
RemappedAxis::axisIndexInSubControlBoard
size_t axisIndexInSubControlBoard
The index of the remapped axis in the SubControlBoard.
Definition: ControlBoardRemapperHelpers.h:101
RemappedControlBoards
Definition: ControlBoardRemapperHelpers.h:105
ControlBoardArbitraryAxesDecomposition::m_jointsInSubControlBoard
std::vector< std::vector< int > > m_jointsInSubControlBoard
Definition: ControlBoardRemapperHelpers.h:338
RemappedSubControlBoard::calib
yarp::dev::IControlCalibration * calib
Definition: ControlBoardRemapperHelpers.h:56
RemappedSubControlBoard::id
std::string id
Definition: ControlBoardRemapperHelpers.h:46