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
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 yCWarning(CONTROLBOARDREMAPPER, "IPositionControl interface was not found in subdevice");
178 }
179
180 if( ! (vel) )
181 {
182 yCWarning(CONTROLBOARDREMAPPER, "IVelocityControl interface was not found in subdevice");
183 }
184
185 if(!iJntEnc)
186 {
187 yCWarning(CONTROLBOARDREMAPPER, "IEncoderTimed interface was not found in subdevice");
188 }
189
190 if(!iMode)
191 {
192 yCWarning(CONTROLBOARDREMAPPER, "IControlMode interface was not found in subdevice");
193 }
194
195 int deviceJoints=0;
196 if (pos!=nullptr)
197 {
198 if (!pos->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 if(info!=nullptr)
210 {
211 if (!info->getAxes(&deviceJoints))
212 {
213 yCError(CONTROLBOARDREMAPPER) << "failed to get axes number for subdevice" << k.c_str();
214 return false;
215 }
216 if(deviceJoints <= 0)
217 {
218 yCError(CONTROLBOARDREMAPPER, "attached device has an invalid number of joints (%d)", deviceJoints);
219 return false;
220 }
221 }
222 else
223 {
224 yCError(CONTROLBOARDREMAPPER, "attached device has no IPositionControl nor IAxisInfo interface");
225 return false;
226 }
227
228 attachedF=true;
229 return true;
230}
231
233{
234 // Resize buffers
236
237 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
238
241
245
247
248 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
249 {
255 }
256
257 // Fill buffers
258 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
259 {
260 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
261 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
262
265 }
266
267 // Allocate enough space in buffers
268 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
269 {
273
275 }
276
277 return true;
278}
279
280
281
283{
284 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
285 {
287 }
288
290 {
291 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
292
294 }
295}
296
298{
299 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
300 {
302 }
303
305 {
306 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
309 }
310}
311
313{
314 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
315 {
317 }
318
320 {
321 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
322
324 }
325}
326
328{
329 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
330 {
332 }
333
335 {
336 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
339 }
340}
341
343{
344 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
345 {
347 }
348
350 {
351 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
352
354 }
355}
356
371
373{
374 // Resize buffers
375 size_t nrOfSubControlBoards = remappedControlBoards.getNrOfSubControlBoards();
376
382
384
385 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
386 {
391
392 }
393
394 // Count the maximum number of joints
395 for(size_t j=0; j < remappedControlBoards.getNrOfRemappedAxes(); j++)
396 {
397 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
398
400 }
401
402 // Allocate enough space in buffers
403 for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
404 {
408
411 }
412
413 return true;
414}
415
416
417
419 const int n_joints,
420 const int *joints,
421 const RemappedControlBoards& remappedControlBoards)
422{
423 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
424 {
426 }
427
428 for(int j=0; j < n_joints; j++)
429 {
430 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
433 }
434}
435
436
438 const int n_joints,
439 const int *joints,
440 const RemappedControlBoards& remappedControlBoards)
441{
442 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
443
444 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
445 {
447 }
448
449 for(int j=0; j < n_joints; j++)
450 {
451 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
453 }
454}
455
456
458 const int n_joints,
459 const int *joints,
460 const RemappedControlBoards& remappedControlBoards)
461{
462 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
463 {
465 }
466
467 for(int j=0; j < n_joints; j++)
468 {
469 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
472 }
473}
474
475
477 const int n_joints,
478 const int *joints,
479 const RemappedControlBoards& remappedControlBoards)
480{
481 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
482
483 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
484 {
486 }
487
488 for(int j=0; j < n_joints; j++)
489 {
490 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
492 }
493}
494
495
497 const int n_joints,
498 const int *joints,
499 const RemappedControlBoards& remappedControlBoards)
500{
501 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
502 {
504 }
505
506 for(int j=0; j < n_joints; j++)
507 {
508 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
511 }
512}
513
514
516 const int n_joints,
517 const int *joints,
518 const RemappedControlBoards& remappedControlBoards)
519{
520 this->createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
521
522 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
523 {
525 }
526
527 for(int j=0; j < n_joints; j++)
528 {
529 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
531 }
532}
533
534
535void ControlBoardArbitraryAxesDecomposition::createListOfJointsDecomposition(const int n_joints, const int* joints, const RemappedControlBoards & remappedControlBoards)
536{
537 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
538 {
541 }
542
543 // Fill buffers
544 for(int j=0; j < n_joints; j++)
545 {
546 int off=(int)remappedControlBoards.lut[joints[j]].axisIndexInSubControlBoard;
547 size_t subIndex=remappedControlBoards.lut[joints[j]].subControlBoardIndex;
548
551 }
552
553}
554
555void ControlBoardArbitraryAxesDecomposition::resizeSubControlBoardBuffers(const int n_joints, const int *joints, const RemappedControlBoards & remappedControlBoards)
556{
557 // Properly populate the m_nJointsInSubControlBoard and m_jointsInSubControlBoard methods
558 createListOfJointsDecomposition(n_joints,joints,remappedControlBoards);
559
560 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
561 {
564 }
565}
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::IControlLimits * lim
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.