YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ControlBoardRemapperHelpers.cpp
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
8
9#include <yarp/os/LogStream.h>
10
11
12using namespace yarp::os;
13using namespace yarp::dev;
14using namespace yarp::sig;
15
16
18{
19 id = "";
20 attachedF=false;
21 _subDevVerbose = false;
22}
23
24
26{
27 subdevice=nullptr;
28
29 pid=nullptr;
30 pos=nullptr;
31 posDir=nullptr;
32 vel=nullptr;
33 amp = nullptr;
34 iJntEnc=nullptr;
35 iMotEnc=nullptr;
36 lim=nullptr;
37 calib=nullptr;
38 info=nullptr;
39 iTorque=nullptr;
40 iImpedance=nullptr;
41 iMode=nullptr;
42 iTimed=nullptr;
43 iInteract=nullptr;
44 imotor=nullptr;
45 iVar = nullptr;
46 iPwm = nullptr;
47 iCurr = nullptr;
48 iBrake = nullptr;
49 iVelDir = nullptr;
50
51 attachedF=false;
52}
53
55{
56 if (id!=k)
57 {
58 yCError(CONTROLBOARDREMAPPER) << "Wrong device" << k.c_str();
59 return false;
60 }
61
62 if (d==nullptr)
63 {
64 yCError(CONTROLBOARDREMAPPER) << "Invalid device (null pointer)";
65 return false;
66 }
67
68 subdevice=d;
69
70 if (subdevice->isValid())
71 {
95 }
96 else
97 {
98 yCError(CONTROLBOARDREMAPPER) << "Invalid device" << k << "(isValid() returned false)";
99 return false;
100 }
101
102 if ((iTorque==nullptr) && (_subDevVerbose))
103 {
104 yCWarning(CONTROLBOARDREMAPPER) << "iTorque not valid interface";
105 }
106
107 if ((iImpedance==nullptr) && (_subDevVerbose))
108 {
109 yCWarning(CONTROLBOARDREMAPPER) << "iImpedance not valid interface";
110 }
111
112 if ((iInteract==nullptr) && (_subDevVerbose))
113 {
114 yCWarning(CONTROLBOARDREMAPPER) << "iInteractionMode not valid interface";
115 }
116
117 if ((iMotEnc==nullptr) && (_subDevVerbose))
118 {
119 yCWarning(CONTROLBOARDREMAPPER) << "IMotorEncoders not valid interface";
120 }
121
122 if ((imotor==nullptr) && (_subDevVerbose))
123 {
124 yCWarning(CONTROLBOARDREMAPPER) << "IMotor not valid interface";
125 }
126
127 if ((iVar == nullptr) && (_subDevVerbose))
128 {
129 yCWarning(CONTROLBOARDREMAPPER) << "IRemoveVariables not valid interface";
130 }
131
132 if ((info == nullptr) && (_subDevVerbose))
133 {
134 yCWarning(CONTROLBOARDREMAPPER) << "IAxisInfo not valid interface";
135 }
136
137 if ((iPwm == nullptr) && (_subDevVerbose))
138 {
139 yCWarning(CONTROLBOARDREMAPPER) << "IPWMControl not valid interface";
140 }
141
142 if ((iCurr == nullptr) && (_subDevVerbose))
143 {
144 yCWarning(CONTROLBOARDREMAPPER) << "ICurrentControl not valid interface";
145 }
146
147 if ((iFault == nullptr) && (_subDevVerbose))
148 {
149 yCWarning(CONTROLBOARDREMAPPER) << "IJointFault not valid interface";
150 }
151
152 if ((iBrake == nullptr) && (_subDevVerbose)) {
153 yCWarning(CONTROLBOARDREMAPPER) << "IJointBrake not valid interface";
154 }
155
156 if ((iVelDir == nullptr) && (_subDevVerbose))
157 {
158 yCWarning(CONTROLBOARDREMAPPER) << "IVelocityDirect not valid interface";
159 }
160
161 // checking minimum set of interfaces required
162 if( !(pos) )
163 {
164 yCWarning(CONTROLBOARDREMAPPER, "IPositionControl interface was not found in subdevice");
165 }
166
167 if( ! (vel) )
168 {
169 yCWarning(CONTROLBOARDREMAPPER, "IVelocityControl interface was not found in subdevice");
170 }
171
172 if(!iJntEnc)
173 {
174 yCWarning(CONTROLBOARDREMAPPER, "IEncoderTimed interface was not found in subdevice");
175 }
176
177 if(!iMode)
178 {
179 yCWarning(CONTROLBOARDREMAPPER, "IControlMode interface was not found in subdevice");
180 }
181
182 int deviceJoints=0;
183 if (pos!=nullptr)
184 {
185 if (!pos->getAxes(&deviceJoints))
186 {
187 yCError(CONTROLBOARDREMAPPER) << "failed to get axes number for subdevice" << k.c_str();
188 return false;
189 }
190 if(deviceJoints <= 0)
191 {
192 yCError(CONTROLBOARDREMAPPER, "attached device has an invalid number of joints (%d)", deviceJoints);
193 return false;
194 }
195 }
196 else if(info!=nullptr)
197 {
198 if (!info->getAxes(&deviceJoints))
199 {
200 yCError(CONTROLBOARDREMAPPER) << "failed to get axes number for subdevice" << k.c_str();
201 return false;
202 }
203 if(deviceJoints <= 0)
204 {
205 yCError(CONTROLBOARDREMAPPER, "attached device has an invalid number of joints (%d)", deviceJoints);
206 return false;
207 }
208 }
209 else
210 {
211 yCError(CONTROLBOARDREMAPPER, "attached device has no IPositionControl nor IAxisInfo interface");
212 return false;
213 }
214
215 attachedF=true;
216 return true;
217}
218
220{
221 // Resize buffers
223
224 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
225
228
232
234
235 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
236 {
242 }
243
244 // Fill buffers
245 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
246 {
247 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
248 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
249
252 }
253
254 // Allocate enough space in buffers
255 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
256 {
260
262 }
263
264 return true;
265}
266
267
268
270{
271 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
272 {
274 }
275
276 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
277 {
278 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
279
281 }
282}
283
285{
286 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
287 {
289 }
290
291 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
292 {
293 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
296 }
297}
298
300{
301 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
302 {
304 }
305
306 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
307 {
308 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
309
311 }
312}
313
315{
316 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
317 {
319 }
320
321 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
322 {
323 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
326 }
327}
328
330{
331 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
332 {
334 }
335
336 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
337 {
338 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
339
341 }
342}
343
345{
346 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
347 {
349 }
350
351 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
352 {
353 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
356 }
357}
358
360{
361 // Resize buffers
362 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
363
369
371
372 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
373 {
378
379 }
380
381 // Count the maximum number of joints
382 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
383 {
384 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
385
387 }
388
389 // Allocate enough space in buffers
390 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
391 {
395
398 }
399
400 return true;
401}
402
403
404
406 const int n_joints,
407 const int *joints,
408 const RemappedControlBoards& remappedControlBoards)
409{
410 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
411 {
413 }
414
415 for(int j=0; j < n_joints; j++)
416 {
417 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
420 }
421}
422
423
425 const int n_joints,
426 const int *joints,
427 const RemappedControlBoards& remappedControlBoards)
428{
429 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
430
431 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
432 {
434 }
435
436 for(int j=0; j < n_joints; j++)
437 {
438 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
440 }
441}
442
443
445 const int n_joints,
446 const int *joints,
447 const RemappedControlBoards& remappedControlBoards)
448{
449 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
450 {
452 }
453
454 for(int j=0; j < n_joints; j++)
455 {
456 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
459 }
460}
461
462
464 const int n_joints,
465 const int *joints,
466 const RemappedControlBoards& remappedControlBoards)
467{
468 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
469
470 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
471 {
473 }
474
475 for(int j=0; j < n_joints; j++)
476 {
477 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
479 }
480}
481
482
484 const int n_joints,
485 const int *joints,
486 const RemappedControlBoards& remappedControlBoards)
487{
488 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
489 {
491 }
492
493 for(int j=0; j < n_joints; j++)
494 {
495 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
498 }
499}
500
501
503 const int n_joints,
504 const int *joints,
505 const RemappedControlBoards& remappedControlBoards)
506{
507 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
508
509 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
510 {
512 }
513
514 for(int j=0; j < n_joints; j++)
515 {
516 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
518 }
519}
520
521
522void ControlBoardArbitraryAxesDecomposition::createListOfJointsDecomposition(const int n_joints, const int* joints, const RemappedControlBoards & remappedControlBoards)
523{
524 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
525 {
528 }
529
530 // Fill buffers
531 for(int j=0; j < n_joints; j++)
532 {
533 int off=(int)remappedControlBoards.lut[joints[j]].axisIndexInSubControlBoard;
534 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
535
538 }
539
540}
541
542void ControlBoardArbitraryAxesDecomposition::resizeSubControlBoardBuffers(const int n_joints, const int *joints, const RemappedControlBoards & remappedControlBoards)
543{
544 // Properly populate the m_nJointsInSubControlBoard and m_jointsInSubControlBoard methods
545 createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
546
547 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
548 {
551 }
552}
const yarp::os::LogComponent & CONTROLBOARDREMAPPER()
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 .
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
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
std::vector< RemappedAxis > lut
Vector of dimension getNrOfRemappedAxes .
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::IJointFault * iFault
yarp::dev::IVelocityDirect * iVelDir
yarp::dev::IPositionDirect * posDir
yarp::dev::IRemoteCalibrator * remcalib
bool attach(yarp::dev::PolyDriver *d, const std::string &id)
yarp::dev::IControlLimits * lim
yarp::dev::IJointBrake * iBrake
yarp::dev::IControlCalibration * calib
yarp::dev::PolyDriver * subdevice
yarp::dev::IMotorEncoders * iMotEnc
yarp::dev::IPreciselyTimed * iTimed
bool view(T *&x)
Get an interface to the device driver.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define yCAssert(component, x)
#define yCWarning(component,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.