YARP
Yet Another Robot Platform
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
21 pid = nullptr;
22 pos = nullptr;
23 posDir = nullptr;
24 vel = nullptr;
25 iJntEnc = nullptr;
26 iMotEnc = nullptr;
27 amp = nullptr;
28 lim = nullptr;
29 calib = nullptr;
30 remcalib = nullptr;
31 iTimed= nullptr;
32 info = nullptr;
33 iTorque=nullptr;
34 iImpedance=nullptr;
35 iMode=nullptr;
36 iInteract=nullptr;
37 imotor=nullptr;
38 iVar = nullptr;
39 iPwm = nullptr;
40 iCurr = nullptr;
41
42 subdevice=nullptr;
43
44
45 attachedF=false;
46 _subDevVerbose = false;
47}
48
49
51{
52 subdevice=nullptr;
53
54 pid=nullptr;
55 pos=nullptr;
56 posDir=nullptr;
57 vel=nullptr;
58 amp = nullptr;
59 iJntEnc=nullptr;
60 iMotEnc=nullptr;
61 lim=nullptr;
62 calib=nullptr;
63 info=nullptr;
64 iTorque=nullptr;
65 iImpedance=nullptr;
66 iMode=nullptr;
67 iTimed=nullptr;
68 iInteract=nullptr;
69 imotor=nullptr;
70 iVar = nullptr;
71 iPwm = nullptr;
72 iCurr = nullptr;
73
74 attachedF=false;
75}
76
78{
79 if (id!=k)
80 {
81 yCError(CONTROLBOARDREMAPPER) << "Wrong device" << k.c_str();
82 return false;
83 }
84
85 if (d==nullptr)
86 {
87 yCError(CONTROLBOARDREMAPPER) << "Invalid device (null pointer)";
88 return false;
89 }
90
91 subdevice=d;
92
93 if (subdevice->isValid())
94 {
116 }
117 else
118 {
119 yCError(CONTROLBOARDREMAPPER) << "Invalid device" << k << "(isValid() returned false)";
120 return false;
121 }
122
123 if ((iTorque==nullptr) && (_subDevVerbose))
124 {
125 yCWarning(CONTROLBOARDREMAPPER) << "iTorque not valid interface";
126 }
127
128 if ((iImpedance==nullptr) && (_subDevVerbose))
129 {
130 yCWarning(CONTROLBOARDREMAPPER) << "iImpedance not valid interface";
131 }
132
133 if ((iInteract==nullptr) && (_subDevVerbose))
134 {
135 yCWarning(CONTROLBOARDREMAPPER) << "iInteractionMode not valid interface";
136 }
137
138 if ((iMotEnc==nullptr) && (_subDevVerbose))
139 {
140 yCWarning(CONTROLBOARDREMAPPER) << "IMotorEncoders not valid interface";
141 }
142
143 if ((imotor==nullptr) && (_subDevVerbose))
144 {
145 yCWarning(CONTROLBOARDREMAPPER) << "IMotor not valid interface";
146 }
147
148 if ((iVar == nullptr) && (_subDevVerbose))
149 {
150 yCWarning(CONTROLBOARDREMAPPER) << "IRemoveVariables not valid interface";
151 }
152
153 if ((info == nullptr) && (_subDevVerbose))
154 {
155 yCWarning(CONTROLBOARDREMAPPER) << "IAxisInfo not valid interface";
156 }
157
158 if ((iPwm == nullptr) && (_subDevVerbose))
159 {
160 yCWarning(CONTROLBOARDREMAPPER) << "IPWMControl not valid interface";
161 }
162
163 if ((iCurr == nullptr) && (_subDevVerbose))
164 {
165 yCWarning(CONTROLBOARDREMAPPER) << "ICurrentControl not valid interface";
166 }
167
168 if ((iFault == nullptr) && (_subDevVerbose))
169 {
170 yCWarning(CONTROLBOARDREMAPPER) << "IJointFault not valid interface";
171 }
172
173
174 // checking minimum set of interfaces required
175 if( !(pos) )
176 {
177 yCError(CONTROLBOARDREMAPPER, "IPositionControl interface was not found in subdevice. Quitting");
178 return false;
179 }
180
181 if( ! (vel) )
182 {
183 yCError(CONTROLBOARDREMAPPER, "IVelocityControl interface was not found in subdevice. Quitting");
184 return false;
185 }
186
187 if(!iJntEnc)
188 {
189 yCError(CONTROLBOARDREMAPPER, "IEncoderTimed interface was not found in subdevice, exiting.");
190 return false;
191 }
192
193 if(!iMode)
194 {
195 yCError(CONTROLBOARDREMAPPER, "IControlMode interface was not found in subdevice, exiting.");
196 return false;
197 }
198
199 int deviceJoints=0;
200 if (pos!=nullptr)
201 {
202 if (!pos->getAxes(&deviceJoints))
203 {
204 yCError(CONTROLBOARDREMAPPER) << "failed to get axes number for subdevice" << k.c_str();
205 return false;
206 }
207 if(deviceJoints <= 0)
208 {
209 yCError(CONTROLBOARDREMAPPER, "attached device has an invalid number of joints (%d)", deviceJoints);
210 return false;
211 }
212 }
213
214 attachedF=true;
215 return true;
216}
217
219{
220 // Resize buffers
222
223 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
224
225 m_nJointsInSubControlBoard.resize(nrOfSubControlBoards,0);
226 m_jointsInSubControlBoard.resize(nrOfSubControlBoards);
227
228 m_bufferForSubControlBoard.resize(nrOfSubControlBoards);
229 m_bufferForSubControlBoardControlModes.resize(nrOfSubControlBoards);
230 m_bufferForSubControlBoardInteractionModes.resize(nrOfSubControlBoards);
231
232 m_counterForControlBoard.resize(nrOfSubControlBoards);
233
234 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
235 {
236 m_nJointsInSubControlBoard[ctrlBrd] = 0;
237 m_jointsInSubControlBoard[ctrlBrd].clear();
238 m_bufferForSubControlBoard[ctrlBrd].clear();
241 }
242
243 // Fill buffers
244 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
245 {
246 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
247 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
248
249 m_nJointsInSubControlBoard[subIndex]++;
250 m_jointsInSubControlBoard[subIndex].push_back(off);
251 }
252
253 // Allocate enough space in buffers
254 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
255 {
259
260 m_counterForControlBoard[ctrlBrd] = 0;
261 }
262
263 return true;
264}
265
266
267
269{
270 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
271 {
272 m_bufferForSubControlBoard[ctrlBrd].clear();
273 }
274
275 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
276 {
277 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
278
279 m_bufferForSubControlBoard[subIndex].push_back(full[j]);
280 }
281}
282
284{
285 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
286 {
287 m_counterForControlBoard[ctrlBrd] = 0;
288 }
289
290 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
291 {
292 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
293 full[j] = m_bufferForSubControlBoard[subIndex][m_counterForControlBoard[subIndex]];
294 m_counterForControlBoard[subIndex]++;
295 }
296}
297
299{
300 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
301 {
303 }
304
305 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
306 {
307 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
308
309 m_bufferForSubControlBoardControlModes[subIndex].push_back(full[j]);
310 }
311}
312
314{
315 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
316 {
317 m_counterForControlBoard[ctrlBrd] = 0;
318 }
319
320 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
321 {
322 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
324 m_counterForControlBoard[subIndex]++;
325 }
326}
327
329{
330 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
331 {
333 }
334
335 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
336 {
337 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
338
339 m_bufferForSubControlBoardInteractionModes[subIndex].push_back(full[j]);
340 }
341}
342
344{
345 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
346 {
347 m_counterForControlBoard[ctrlBrd] = 0;
348 }
349
350 for(int j=0; j < m_nrOfControlledAxesInRemappedCtrlBrd; j++)
351 {
352 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
354 m_counterForControlBoard[subIndex]++;
355 }
356}
357
359{
360 // Resize buffers
361 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
362
363 m_nJointsInSubControlBoard.resize(nrOfSubControlBoards,0);
364 m_jointsInSubControlBoard.resize(nrOfSubControlBoards);
365 m_bufferForSubControlBoard.resize(nrOfSubControlBoards);
366 m_bufferForSubControlBoardControlModes.resize(nrOfSubControlBoards);
367 m_bufferForSubControlBoardInteractionModes.resize(nrOfSubControlBoards);
368
369 m_counterForControlBoard.resize(nrOfSubControlBoards);
370
371 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
372 {
373 m_jointsInSubControlBoard[ctrlBrd].clear();
374 m_bufferForSubControlBoard[ctrlBrd].clear();
377
378 }
379
380 // Count the maximum number of joints
381 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
382 {
383 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
384
385 m_nJointsInSubControlBoard[subIndex]++;
386 }
387
388 // Allocate enough space in buffers
389 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
390 {
394
395 m_counterForControlBoard[ctrlBrd] = 0;
397 }
398
399 return true;
400}
401
402
403
405 const int n_joints,
406 const int *joints,
407 const RemappedControlBoards& remappedControlBoards)
408{
409 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
410 {
411 m_counterForControlBoard[ctrlBrd] = 0;
412 }
413
414 for(int j=0; j < n_joints; j++)
415 {
416 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
417 arbitraryVec[j] = m_bufferForSubControlBoard[subIndex][m_counterForControlBoard[subIndex]];
418 m_counterForControlBoard[subIndex]++;
419 }
420}
421
422
424 const int n_joints,
425 const int *joints,
426 const RemappedControlBoards& remappedControlBoards)
427{
428 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
429
430 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
431 {
432 m_bufferForSubControlBoard[ctrlBrd].clear();
433 }
434
435 for(int j=0; j < n_joints; j++)
436 {
437 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
438 m_bufferForSubControlBoard[subIndex].push_back(arbitraryVec[j]);
439 }
440}
441
442
444 const int n_joints,
445 const int *joints,
446 const RemappedControlBoards& remappedControlBoards)
447{
448 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
449 {
450 m_counterForControlBoard[ctrlBrd] = 0;
451 }
452
453 for(int j=0; j < n_joints; j++)
454 {
455 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
456 arbitraryVec[j] = m_bufferForSubControlBoardControlModes[subIndex][m_counterForControlBoard[subIndex]];
457 m_counterForControlBoard[subIndex]++;
458 }
459}
460
461
463 const int n_joints,
464 const int *joints,
465 const RemappedControlBoards& remappedControlBoards)
466{
467 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
468
469 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
470 {
472 }
473
474 for(int j=0; j < n_joints; j++)
475 {
476 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
477 m_bufferForSubControlBoardControlModes[subIndex].push_back(arbitraryVec[j]);
478 }
479}
480
481
483 const int n_joints,
484 const int *joints,
485 const RemappedControlBoards& remappedControlBoards)
486{
487 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
488 {
489 m_counterForControlBoard[ctrlBrd] = 0;
490 }
491
492 for(int j=0; j < n_joints; j++)
493 {
494 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
495 arbitraryVec[j] = m_bufferForSubControlBoardInteractionModes[subIndex][m_counterForControlBoard[subIndex]];
496 m_counterForControlBoard[subIndex]++;
497 }
498}
499
500
502 const int n_joints,
503 const int *joints,
504 const RemappedControlBoards& remappedControlBoards)
505{
506 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
507
508 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
509 {
511 }
512
513 for(int j=0; j < n_joints; j++)
514 {
515 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
516 m_bufferForSubControlBoardInteractionModes[subIndex].push_back(arbitraryVec[j]);
517 }
518}
519
520
521void ControlBoardArbitraryAxesDecomposition::createListOfJointsDecomposition(const int n_joints, const int* joints, const RemappedControlBoards & remappedControlBoards)
522{
523 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
524 {
525 m_nJointsInSubControlBoard[ctrlBrd] = 0;
526 m_jointsInSubControlBoard[ctrlBrd].clear();
527 }
528
529 // Fill buffers
530 for(int j=0; j < n_joints; j++)
531 {
532 int off=(int)remappedControlBoards.lut[joints[j]].axisIndexInSubControlBoard;
533 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
534
535 m_nJointsInSubControlBoard[subIndex]++;
536 m_jointsInSubControlBoard[subIndex].push_back(off);
537 }
538
539}
540
541void ControlBoardArbitraryAxesDecomposition::resizeSubControlBoardBuffers(const int n_joints, const int *joints, const RemappedControlBoards & remappedControlBoards)
542{
543 // Properly populate the m_nJointsInSubControlBoard and m_jointsInSubControlBoard methods
544 createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
545
546 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
547 {
550 }
551}
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::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
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
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.
Definition: PolyDriver.cpp:196
#define yCError(component,...)
Definition: LogComponent.h:213
#define yCAssert(component, x)
Definition: LogComponent.h:240
#define yCWarning(component,...)
Definition: LogComponent.h:192
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.