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
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:43
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:28
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:99
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition: IPWMControl.h:28
Interface for a generic control board device implementing a PID controller, with scaled arguments.
Definition: IPidControl.h:211
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:27
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25