YARP
Yet Another Robot Platform
ControlBoardRemapperHelpers.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_DEV_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
7 #define YARP_DEV_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
8 
9 
10 #include <yarp/os/PortablePair.h>
11 #include <yarp/os/BufferedPort.h>
12 #include <yarp/os/Time.h>
13 #include <yarp/os/Network.h>
14 #include <yarp/os/Stamp.h>
15 #include <yarp/os/Vocab.h>
16 
20 #include <yarp/dev/PolyDriver.h>
22 #include <yarp/dev/IControlMode.h>
23 
24 
25 #include <yarp/sig/Vector.h>
26 
27 #include <mutex>
28 #include <string>
29 #include <vector>
30 
31 
32 #ifdef MSVC
33  #pragma warning(disable:4355)
34 #endif
35 
36 /*
37  * Helper class for the ControlBoardRemapper.
38  * It contains all the data structure related
39  * to a given controlboard used by the remapper.
40  */
42 {
43 public:
44  std::string id;
45 
67 
69 
70  bool attach(yarp::dev::PolyDriver *d, const std::string &id);
71  void detach();
72 
73  inline void setVerbose(bool _verbose) {_subDevVerbose = _verbose; }
74 
75  bool isAttached()
76  { return attachedF; }
77 
78 private:
79  bool _subDevVerbose;
80  bool attachedF;
81 };
82 
88 {
89 public:
95 
100 };
101 
103 {
104 public:
108  std::vector<RemappedSubControlBoard> subdevices;
109 
113  std::vector<RemappedAxis> lut;
114 
122  {
123  return &(subdevices[i]);
124  }
125 
126  size_t getNrOfSubControlBoards() const
127  {
128  return subdevices.size();
129  }
130 
131  size_t getNrOfRemappedAxes() const
132  {
133  return lut.size();
134  }
135 };
136 
138 {
139 public:
140  std::mutex mutex;
141  std::vector<int> controlBoardModes;
142  std::vector<double> dummyBuffer;
144 
145 };
146 
155 {
156 public:
161  bool configure(const RemappedControlBoards & remappedControlBoards);
162 
167  void fillSubControlBoardBuffersFromCompleteJointVector(const double * full, const RemappedControlBoards & remappedControlBoards);
168 
169 
176  const RemappedControlBoards & remappedControlBoards);
177 
185  const RemappedControlBoards & remappedControlBoards);
186 
191  void fillCompleteJointVectorFromSubControlBoardBuffers(double * full, const RemappedControlBoards & remappedControlBoards);
192 
201  const RemappedControlBoards & remappedControlBoards);
202 
211  const RemappedControlBoards & remappedControlBoards);
212 
213 
217  std::mutex mutex;
218 
219  // Buffer to be used in MultiJoint version of the
221  std::vector<int> m_nJointsInSubControlBoard;
222  std::vector< std::vector<int> > m_jointsInSubControlBoard;
223 
224 
225  std::vector< std::vector<double> > m_bufferForSubControlBoard;
226  std::vector< std::vector<int> > m_bufferForSubControlBoardControlModes;
227  std::vector< std::vector<yarp::dev::InteractionModeEnum> > m_bufferForSubControlBoardInteractionModes;
228 
229  std::vector<int> m_counterForControlBoard;
230 };
231 
242 {
247  void createListOfJointsDecomposition(const int n_joints, const int *joints, const RemappedControlBoards & remappedControlBoards);
248 
249 public:
254  bool configure(const RemappedControlBoards & remappedControlBoards);
255 
256 
261  void fillSubControlBoardBuffersFromArbitraryJointVector(const double * arbitraryVec,
262  const int n_joints,
263  const int *joints,
264  const RemappedControlBoards & remappedControlBoards);
265 
271  void fillSubControlBoardBuffersFromArbitraryJointVector(const int * arbitraryVec,
272  const int n_joints,
273  const int *joints,
274  const RemappedControlBoards & remappedControlBoards);
275 
282  const int n_joints,
283  const int *joints,
284  const RemappedControlBoards & remappedControlBoards);
285 
290  void resizeSubControlBoardBuffers(const int n_joints,
291  const int *joints,
292  const RemappedControlBoards & remappedControlBoards);
293 
300  void fillArbitraryJointVectorFromSubControlBoardBuffers(double * arbitraryVec,
301  const int n_joints, const int *joints,
302  const RemappedControlBoards & remappedControlBoards);
303 
312  const int n_joints, const int *joints,
313  const RemappedControlBoards & remappedControlBoards);
314 
323  const int n_joints, const int *joints,
324  const RemappedControlBoards & remappedControlBoards);
325 
329  std::mutex mutex;
330 
331  // Total number of axes in the remapped controlboard
333 
334  // Vector of size getNrOfSubControlBoards
335  std::vector<int> m_nJointsInSubControlBoard;
336  std::vector< std::vector<int> > m_jointsInSubControlBoard;
337 
338  // Buffers for the control board (the size of each one should
339  // match the size of m_nJointsInSubControlBoard[ctrlBoard] and
340  // the size of m_jointsInSubControlBoard[ctrlBoard].size()
341  std::vector< std::vector<double> > m_bufferForSubControlBoard;
342  std::vector< std::vector<int> > m_bufferForSubControlBoardControlModes;
343  std::vector< std::vector<yarp::dev::InteractionModeEnum> > m_bufferForSubControlBoardInteractionModes;
344 
345 
346  // Counter used when converting a full vector to
347  // the subcontrolboard buffers
348  std::vector<int> m_counterForControlBoard;
349 };
350 
351 #endif // YARP_DEV_CONTROLBOARDREMAPPER_CONTROLBOARDREMAPPERHELPERS_H
define control board standard interfaces
define control board standard interfaces
contains the definition of a Vector type
Class storing the decomposition of a subset of the total remapped axes of the remapped controlboard i...
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
std::vector< std::vector< double > > m_bufferForSubControlBoard
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
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.
std::vector< std::vector< int > > m_jointsInSubControlBoard
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...
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
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 .
std::mutex mutex
Mutex to grab to use this class.
Class storing the decomposition of all the axes in the Remapped ControlBoard in the SubControlBoard,...
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
std::mutex mutex
Mutex to grab to use this class.
std::vector< std::vector< int > > m_jointsInSubControlBoard
void fillCompleteJointVectorFromSubControlBoardBuffers(double *full, const RemappedControlBoards &remappedControlBoards)
Fill a vector of joints of the ControlBoardRemapper from the buffers of the SubControlBoard .
void fillSubControlBoardBuffersFromCompleteJointVector(const double *full, const RemappedControlBoards &remappedControlBoards)
Fill buffers for the SubControlBoard from a vector of joints of the RemappedControlBoards.
std::vector< std::vector< double > > m_bufferForSubControlBoard
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
Information in how an axis is remapped on an axis of a SubControlBoard.
size_t axisIndexInSubControlBoard
The index of the remapped axis in the SubControlBoard.
size_t subControlBoardIndex
The index of the SubControlBoard of the remapped axis in the RemappedControlBoards class.
std::vector< RemappedSubControlBoard > subdevices
Vector of dimension getNrOfSubControlBoards .
std::vector< RemappedAxis > lut
Vector of dimension getNrOfRemappedAxes .
RemappedSubControlBoard * getSubControlBoard(size_t i)
Given a controlboard index between 0 and getNrOfSubControlBoards()-1, return the relative SubControlB...
yarp::dev::IPositionControl * pos
yarp::dev::IImpedanceControl * iImpedance
yarp::dev::IAmplifierControl * amp
yarp::dev::IEncodersTimed * iJntEnc
yarp::dev::IInteractionMode * iInteract
yarp::dev::IRemoteVariables * iVar
yarp::dev::ICurrentControl * iCurr
yarp::dev::ITorqueControl * iTorque
yarp::dev::IVelocityControl * vel
yarp::dev::IControlMode * iMode
yarp::dev::IPositionDirect * posDir
yarp::dev::IRemoteCalibrator * remcalib
bool attach(yarp::dev::PolyDriver *d, const std::string &id)
yarp::dev::IPidControl * pid
yarp::dev::IControlLimits * lim
yarp::dev::IPWMControl * iPwm
yarp::dev::IControlCalibration * calib
yarp::dev::PolyDriver * subdevice
yarp::dev::IMotorEncoders * iMotEnc
yarp::dev::IPreciselyTimed * iTimed
Interface for control devices, amplifier commands.
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:40
Interface for control devices, calibration commands.
Interface for control devices, commands to get/set position and veloity limits.
Interface for setting control mode in control board.
Definition: IControlMode.h:25
Interface for control boards implementing current control.
Control board, extend encoder interface with timestamps.
Interface for control boards implementing impedance control.
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
Control board, encoder interface.
Control board, encoder interface.
Definition: IMotor.h:96
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition: IPWMControl.h:25
Interface for a generic control board device implementing a PID controller, with scaled arguments.
Definition: IPidControl.h:208
Interface for a generic control board device implementing position control.
Interface for a generic control board device implementing position control.
IRemoteCalibrator interface is meant to remotize the access of the calibration device in order to all...
IRemoteVariables interface.
Interface for control boards implementing torque control.
Interface for control boards implementing velocity control.
A container for a device driver.
Definition: PolyDriver.h:24
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22