YARP
Yet Another Robot Platform
ControlBoardRemapper.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 
6 #include "ControlBoardRemapper.h"
9 
10 #include <yarp/os/Log.h>
11 #include <yarp/os/LogStream.h>
12 
13 #include <algorithm>
14 #include <iostream>
15 #include <map>
16 #include <mutex>
17 #include <cassert>
18 
19 using namespace yarp::os;
20 using namespace yarp::dev;
21 using namespace yarp::sig;
22 
24 {
25  return detachAll();
26 }
27 
29 {
30  Property prop;
31  prop.fromString(config.toString());
32 
33  _verb = (prop.check("verbose","if present, give detailed output"));
34  if (_verb)
35  {
36  yCInfo(CONTROLBOARDREMAPPER, "running with verbose output");
37  }
38 
39  if(!parseOptions(prop))
40  {
41  return false;
42  }
43 
44  return true;
45 }
46 
47 bool ControlBoardRemapper::parseOptions(Property& prop)
48 {
49  bool ok = true;
50 
51  usingAxesNamesForAttachAll = prop.check("axesNames", "list of networks merged by this wrapper");
52  usingNetworksForAttachAll = prop.check("networks", "list of networks merged by this wrapper");
53 
54 
55  if( usingAxesNamesForAttachAll &&
56  usingNetworksForAttachAll )
57  {
58  yCError(CONTROLBOARDREMAPPER) << "Both axesNames and networks option present, this is not supported.";
59  return false;
60  }
61 
62  if( !usingAxesNamesForAttachAll &&
63  !usingNetworksForAttachAll )
64  {
65  yCError(CONTROLBOARDREMAPPER) << "axesNames option not found";
66  return false;
67  }
68 
69  if( usingAxesNamesForAttachAll )
70  {
71  ok = parseAxesNames(prop);
72  }
73 
74  if( usingNetworksForAttachAll )
75  {
76  ok = parseNetworks(prop);
77  }
78 
79  return ok;
80 }
81 
82 bool ControlBoardRemapper::parseAxesNames(const Property& prop)
83 {
84  Bottle *propAxesNames=prop.find("axesNames").asList();
85  if(propAxesNames==nullptr)
86  {
87  yCError(CONTROLBOARDREMAPPER) << "Parsing parameters: \"axesNames\" should be followed by a list";
88  return false;
89  }
90 
91  axesNames.resize(propAxesNames->size());
92  for(size_t ax=0; ax < propAxesNames->size(); ax++)
93  {
94  axesNames[ax] = propAxesNames->get(ax).asString();
95  }
96 
97  this->setNrOfControlledAxes(axesNames.size());
98 
99  return true;
100 }
101 
102 bool ControlBoardRemapper::parseNetworks(const Property& prop)
103 {
104  Bottle *nets=prop.find("networks").asList();
105  if(nets==nullptr)
106  {
107  yCError(CONTROLBOARDREMAPPER) << "Parsing parameters: \"networks\" should be followed by a list";
108  return false;
109  }
110 
111  if (!prop.check("joints", "number of joints of the part"))
112  {
113  yCError(CONTROLBOARDREMAPPER) << "joints options not found when reading networks option";
114  return false;
115  }
116 
117  this->setNrOfControlledAxes((size_t)prop.find("joints").asInt32());
118 
119  int nsubdevices=nets->size();
120  remappedControlBoards.lut.resize(controlledJoints);
121  remappedControlBoards.subdevices.resize(nsubdevices);
122 
123  // configure the devices
124  for(size_t k=0;k<nets->size();k++)
125  {
126  Bottle parameters;
127  int wBase;
128  int wTop;
129  int base;
130  int top;
131 
132  parameters=prop.findGroup(nets->get(k).asString());
133 
134  if(parameters.size()==2)
135  {
136  Bottle *bot=parameters.get(1).asList();
137  Bottle tmpBot;
138  if(bot==nullptr)
139  {
140  // probably data are not passed in the correct way, try to read them as a string.
141  std::string bString(parameters.get(1).asString());
142  tmpBot.fromString(bString);
143 
144  if(tmpBot.size() != 4)
145  {
147  << "Check network parameters in part description"
148  << "--> I was expecting" << nets->get(k).asString() << "followed by a list of four integers in parenthesis"
149  << "Got:" << parameters.toString();
150  return false;
151  }
152  else
153  {
154  bot = &tmpBot;
155  }
156  }
157 
158  // If I came here, bot is correct
159  wBase=bot->get(0).asInt32();
160  wTop=bot->get(1).asInt32();
161  base=bot->get(2).asInt32();
162  top=bot->get(3).asInt32();
163  }
164  else if (parameters.size()==5)
165  {
166  // yCError(CONTROLBOARDREMAPPER) << "Parameter networks use deprecated syntax";
167  wBase=parameters.get(1).asInt32();
168  wTop=parameters.get(2).asInt32();
169  base=parameters.get(3).asInt32();
170  top=parameters.get(4).asInt32();
171  }
172  else
173  {
175  << "Check network parameters in part description"
176  << "--> I was expecting" << nets->get(k).asString() << "followed by a list of four integers in parenthesis"
177  << "Got:" << parameters.toString();
178  return false;
179  }
180 
181  RemappedSubControlBoard *tmpDevice=remappedControlBoards.getSubControlBoard((size_t)k);
182  tmpDevice->setVerbose(_verb);
183 
184  if( (wTop-wBase) != (top-base) )
185  {
187  << "Check network parameters in network " << nets->get(k).asString().c_str()
188  << "I was expecting a well form quadruple of numbers, got instead: "<< parameters.toString().c_str();
189  }
190 
191  tmpDevice->id = nets->get(k).asString();
192 
193  for(int j=wBase;j<=wTop;j++)
194  {
195  int off = j-wBase;
196  remappedControlBoards.lut[j].subControlBoardIndex=k;
197  remappedControlBoards.lut[j].axisIndexInSubControlBoard=base+off;
198  }
199  }
200 
201  return true;
202 }
203 
204 void ControlBoardRemapper::setNrOfControlledAxes(const size_t nrOfControlledAxes)
205 {
206  controlledJoints = nrOfControlledAxes;
207  buffers.controlBoardModes.resize(nrOfControlledAxes,0);
208  buffers.dummyBuffer.resize(nrOfControlledAxes,0.0);
209 }
210 
211 
212 bool ControlBoardRemapper::updateAxesName()
213 {
214  bool ret = true;
215  axesNames.resize(controlledJoints);
216 
217  for(int l=0; l < controlledJoints; l++)
218  {
219  std::string axNameYARP;
220  bool ok = this->getAxisName(l,axNameYARP);
221  if( ok )
222  {
223  axesNames[l] = axNameYARP;
224  }
225 
226  ret = ret && ok;
227  }
228 
229  return ret;
230 }
231 
233 {
234  // For both cases, now configure everything that need
235  // all the attribute to be correctly configured
236  bool ok = false;
237 
238  if( usingAxesNamesForAttachAll )
239  {
240  ok = attachAllUsingAxesNames(polylist);
241  }
242 
243  if( usingNetworksForAttachAll )
244  {
245  ok = attachAllUsingNetworks(polylist);
246  }
247 
248  //check if all devices are attached to the driver
249  bool ready=true;
250  for(unsigned int k=0; k<remappedControlBoards.getNrOfSubControlBoards(); k++)
251  {
252  if (!remappedControlBoards.subdevices[k].isAttached())
253  {
254  ready=false;
255  }
256  }
257 
258  if (!ready)
259  {
260  yCError(CONTROLBOARDREMAPPER, "AttachAll failed, some subdevice was not found or its attach failed");
261  return false;
262  }
263 
264  if( ok )
265  {
266  configureBuffers();
267  }
268 
269  return ok;
270 }
271 
272 // First we store a map between each axes name
273 // in the passed PolyDriverList and the device in which they belong and their index
275 {
276  std::string subDeviceKey;
279 };
280 
281 
282 bool ControlBoardRemapper::attachAllUsingAxesNames(const PolyDriverList& polylist)
283 {
284  std::map<std::string, axisLocation> axesLocationMap;
285 
286  for(int p=0;p<polylist.size();p++)
287  {
288  // If there is a device with a specific device key, use it
289  // as a calibrator, otherwise rely on the subcontrolboards
290  // as usual
291  std::string deviceKey=polylist[p]->key;
292  if(deviceKey == "Calibrator" || deviceKey == "calibrator")
293  {
294  // Set the IRemoteCalibrator interface, the wrapper must point to the calibrator rdevice
295  yarp::dev::IRemoteCalibrator *calibrator;
296  polylist[p]->poly->view(calibrator);
297 
298  IRemoteCalibrator::setCalibratorDevice(calibrator);
299  continue;
300  }
301 
302  // find if one of the desired axis is in this device
303  yarp::dev::IAxisInfo *iaxinfos = nullptr;
304  yarp::dev::IEncoders *iencs = nullptr;
305  polylist[p]->poly->view(iaxinfos);
306  polylist[p]->poly->view(iencs);
307 
308  if( !iencs ||
309  !iaxinfos )
310  {
311  yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required IAxisInfo or IEncoders interfaces";
312  return false;
313  }
314 
315  int nrOfSubdeviceAxes;
316  bool ok = iencs->getAxes(&nrOfSubdeviceAxes);
317 
318  if( !ok )
319  {
320  yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required getAxes method";
321  return false;
322  }
323 
324  for(int axInSubDevice =0; axInSubDevice < nrOfSubdeviceAxes; axInSubDevice++)
325  {
326  std::string axNameYARP;
327  ok = iaxinfos->getAxisName(axInSubDevice,axNameYARP);
328 
329  std::string axName = axNameYARP;
330 
331  if( !ok )
332  {
333  yCError(CONTROLBOARDREMAPPER) << "subdevice" << deviceKey << "does not implemented the required getAxisName method";
334  return false;
335  }
336 
337  auto it = axesLocationMap.find(axName);
338  if( it != axesLocationMap.end() )
339  {
341  << "multiple axes have the same name" << axName
342  << "on on device " << polylist[p]->key << "with index" << axInSubDevice
343  <<"and another on device" << it->second.subDeviceKey << "with index" << it->second.indexInSubDevice;
344  return false;
345  }
346 
347  axisLocation newLocation;
348  newLocation.subDeviceKey = polylist[p]->key;
349  newLocation.indexInSubDevice = axInSubDevice;
350  newLocation.indexOfSubDeviceInPolyDriverList = p;
351  axesLocationMap[axName] = newLocation;
352  }
353  }
354 
355  // We store the key of all the devices that we actually use in the remapped control device
356  std::vector<std::string> subControlBoardsKeys;
357  std::map<std::string, size_t> subControlBoardKey2IndexInPolyDriverList;
358  std::map<std::string, size_t> subControlBoardKey2IndexInRemappedControlBoards;
359 
360 
361  // Once we build the axis map, we build the mapping between the remapped axes and
362  // the couple subControlBoard, axis in subControlBoard
363  for(const auto& axesName : axesNames)
364  {
365  auto it = axesLocationMap.find(axesName);
366  if( it == axesLocationMap.end() )
367  {
369  << "axis " << axesName
370  << "specified in axesNames was not found in the axes of the controlboards passed to attachAll, attachAll failed.";
371  return false;
372  }
373 
374  axisLocation loc = it->second;
375  std::string key = loc.subDeviceKey;
376 
377  if(std::find(subControlBoardsKeys.begin(), subControlBoardsKeys.end(), key) == subControlBoardsKeys.end())
378  {
379  /* subControlBoardsKeys does not contain key */
380  subControlBoardKey2IndexInRemappedControlBoards[key] = subControlBoardsKeys.size();
381  subControlBoardsKeys.push_back(key);
382  subControlBoardKey2IndexInPolyDriverList[key] = loc.indexOfSubDeviceInPolyDriverList;
383  }
384  }
385 
386  assert(controlledJoints == (int) axesNames.size());
387 
388  // We have now the number of controlboards to attach to
389  size_t nrOfSubControlBoards = subControlBoardsKeys.size();
390  remappedControlBoards.lut.resize(controlledJoints);
391  remappedControlBoards.subdevices.resize(nrOfSubControlBoards);
392 
393  // Open the controlboards
394  for(size_t ctrlBrd=0; ctrlBrd < nrOfSubControlBoards; ctrlBrd++)
395  {
396  size_t p = subControlBoardKey2IndexInPolyDriverList[subControlBoardsKeys[ctrlBrd]];
397  RemappedSubControlBoard *tmpDevice = remappedControlBoards.getSubControlBoard(ctrlBrd);
398  tmpDevice->setVerbose(_verb);
399  tmpDevice->id = subControlBoardsKeys[ctrlBrd];
400  bool ok = tmpDevice->attach(polylist[p]->poly,subControlBoardsKeys[ctrlBrd]);
401 
402  if( !ok )
403  {
404  return false;
405  }
406  }
407 
408 
409  for(size_t l=0; l < axesNames.size(); l++)
410  {
411  axisLocation loc = axesLocationMap[axesNames[l]];
412  remappedControlBoards.lut[l].subControlBoardIndex = subControlBoardKey2IndexInRemappedControlBoards[loc.subDeviceKey];
413  remappedControlBoards.lut[l].axisIndexInSubControlBoard = (size_t)loc.indexInSubDevice;
414  }
415 
416  return true;
417 }
418 
419 
420 bool ControlBoardRemapper::attachAllUsingNetworks(const PolyDriverList &polylist)
421 {
422  for(int p=0;p<polylist.size();p++)
423  {
424  // look if we have to attach to a calibrator
425  std::string subDeviceKey = polylist[p]->key;
426  if(subDeviceKey == "Calibrator" || subDeviceKey == "calibrator")
427  {
428  // Set the IRemoteCalibrator interface, the wrapper must point to the calibrator rdevice
429  yarp::dev::IRemoteCalibrator *calibrator;
430  polylist[p]->poly->view(calibrator);
431 
432  IRemoteCalibrator::setCalibratorDevice(calibrator);
433  continue;
434  }
435 
436  // find appropriate entry in list of subdevices and attach
437  unsigned int k=0;
438  for(k=0; k<remappedControlBoards.getNrOfSubControlBoards(); k++)
439  {
440  if (remappedControlBoards.subdevices[k].id==subDeviceKey)
441  {
442  if (!remappedControlBoards.subdevices[k].attach(polylist[p]->poly, subDeviceKey))
443  {
444  yCError(CONTROLBOARDREMAPPER, "attach to subdevice %s failed", polylist[p]->key.c_str());
445  return false;
446  }
447  }
448  }
449  }
450 
451  bool ok = updateAxesName();
452 
453  if( !ok )
454  {
455  yCWarning(CONTROLBOARDREMAPPER) << "unable to update axesNames";
456  }
457 
458  return true;
459 }
460 
461 
463 {
464  //check if we already instantiated a subdevice previously
465  int devices=remappedControlBoards.getNrOfSubControlBoards();
466  for (int k = 0; k < devices; k++) {
467  remappedControlBoards.getSubControlBoard(k)->detach();
468  }
469 
470  IRemoteCalibrator::releaseCalibratorDevice();
471  return true;
472 }
473 
474 void ControlBoardRemapper::configureBuffers()
475 {
476  allJointsBuffers.configure(remappedControlBoards);
477  selectedJointsBuffers.configure(remappedControlBoards);
478 }
479 
480 
481 bool ControlBoardRemapper::setControlModeAllAxes(const int cm)
482 {
483  std::lock_guard<std::mutex> lock(buffers.mutex);
484 
485  for(int j=0; j < controlledJoints; j++)
486  {
487  buffers.controlBoardModes[j] = cm;
488  }
489 
490  return this->setControlModes(buffers.controlBoardModes.data());
491 }
492 
496 
497 //
498 // IPid Interface
499 //
500 bool ControlBoardRemapper::setPid(const PidControlTypeEnum& pidtype, int j, const Pid &p)
501 {
502  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
503  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
504 
505  RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
506  if (!s)
507  {
508  return false;
509  }
510 
511  if (s->pid)
512  {
513  return s->pid->setPid(pidtype, off, p);
514  }
515 
516  return false;
517 }
518 
519 bool ControlBoardRemapper::setPids(const PidControlTypeEnum& pidtype, const Pid *ps)
520 {
521  bool ret=true;
522 
523  for(int l=0;l<controlledJoints;l++)
524  {
525  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
526 
527  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
528 
529  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
530  if (!p)
531  {
532  return false;
533  }
534 
535  if (p->pid)
536  {
537  bool ok = p->pid->setPid(pidtype, off, ps[l]);
538  ret=ret&&ok;
539  }
540  else
541  {
542  ret=false;
543  }
544  }
545  return ret;
546 }
547 
548 bool ControlBoardRemapper::setPidReference(const PidControlTypeEnum& pidtype, int j, double ref)
549 {
550  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
551  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
552 
553  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
554 
555  if (!p)
556  {
557  return false;
558  }
559 
560  if (p->pid)
561  {
562  return p->pid->setPidReference(pidtype, off, ref);
563  }
564 
565  return false;
566 }
567 
568 bool ControlBoardRemapper::setPidReferences(const PidControlTypeEnum& pidtype, const double *refs)
569 {
570  bool ret=true;
571 
572  for(int l=0;l<controlledJoints;l++)
573  {
574  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
575 
576  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
577 
578  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
579  if (!p)
580  {
581  return false;
582  }
583 
584  if (p->pid)
585  {
586  bool ok = p->pid->setPidReference(pidtype, off, refs[l]);
587  ret=ret&&ok;
588  }
589  else
590  {
591  ret=false;
592  }
593  }
594  return ret;
595 }
596 
597 bool ControlBoardRemapper::setPidErrorLimit(const PidControlTypeEnum& pidtype, int j, double limit)
598 {
599  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
600  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
601 
602  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
603  if (!p)
604  {
605  return false;
606  }
607 
608  if (p->pid)
609  {
610  return p->pid->setPidErrorLimit(pidtype, off, limit);
611  }
612 
613  return false;
614 }
615 
616 bool ControlBoardRemapper::setPidErrorLimits(const PidControlTypeEnum& pidtype, const double *limits)
617 {
618  bool ret=true;
619 
620  for(int l=0;l<controlledJoints;l++)
621  {
622  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
623 
624  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
625 
626  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
627  if (!p)
628  {
629  return false;
630  }
631 
632  if (p->pid)
633  {
634  bool ok = p->pid->setPidErrorLimit(pidtype, off, limits[l]);
635  ret=ret&&ok;
636  }
637  else
638  {
639  ret=false;
640  }
641  }
642  return ret;
643 }
644 
645 bool ControlBoardRemapper::getPidError(const PidControlTypeEnum& pidtype, int j, double *err)
646 {
647  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
648  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
649 
650  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
651 
652  if (!p)
653  {
654  return false;
655  }
656 
657  if (p->pid)
658  {
659  return p->pid->getPidError(pidtype, off, err);
660  }
661 
662  return false;
663 }
664 
665 bool ControlBoardRemapper::getPidErrors(const PidControlTypeEnum& pidtype, double *errs)
666 {
667  bool ret=true;
668 
669  for(int l=0;l<controlledJoints;l++)
670  {
671  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
672  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
673 
674  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
675  if (!p)
676  {
677  return false;
678  }
679 
680  if (p->pid)
681  {
682  bool ok = p->pid->getPidError(pidtype, off, errs+l);
683  ret=ret&&ok;
684  }
685  else
686  {
687  ret=false;
688  }
689  }
690  return ret;
691 }
692 
693 bool ControlBoardRemapper::getPidOutput(const PidControlTypeEnum& pidtype, int j, double *out)
694 {
695  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
696  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
697 
698  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
699  if (!p)
700  {
701  return false;
702  }
703 
704  if (p->pid)
705  {
706  return p->pid->getPidOutput(pidtype, off, out);
707  }
708 
709  return false;
710 }
711 
712 bool ControlBoardRemapper::getPidOutputs(const PidControlTypeEnum& pidtype, double *outs)
713 {
714  bool ret=true;
715 
716  for(int l=0;l<controlledJoints;l++)
717  {
718  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
719 
720  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
721 
722  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
723  if (!p)
724  {
725  return false;
726  }
727 
728  if (p->pid)
729  {
730  ret=ret&&p->pid->getPidOutput(pidtype, off, outs+l);
731  }
732  else
733  {
734  ret=false;
735  }
736  }
737  return ret;
738 }
739 
740 bool ControlBoardRemapper::setPidOffset(const PidControlTypeEnum& pidtype, int j, double v)
741 {
742  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
743  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
744 
745  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
746  if (!p)
747  {
748  return false;
749  }
750 
751  if (p->pid)
752  {
753  return p->pid->setPidOffset(pidtype, off, v);
754  }
755 
756  return false;
757 }
758 
759 bool ControlBoardRemapper::getPid(const PidControlTypeEnum& pidtype, int j, Pid *p)
760 {
761  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
762  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
763 
764  RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
765  if (!s)
766  {
767  return false;
768  }
769 
770  if (s->pid)
771  {
772  return s->pid->getPid(pidtype, off, p);
773  }
774 
775  return false;
776 }
777 
779 {
780  bool ret=true;
781 
782  for(int l=0;l<controlledJoints;l++)
783  {
784  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
785  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
786 
787  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
788  if (!p)
789  {
790  return false;
791  }
792 
793  if (p->pid)
794  {
795  bool ok = p->pid->getPid(pidtype, off, pids+l);
796  ret = ok && ret;
797  }
798  else
799  {
800  ret=false;
801  }
802  }
803 
804  return ret;
805 }
806 
807 bool ControlBoardRemapper::getPidReference(const PidControlTypeEnum& pidtype, int j, double *ref)
808 {
809  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
810  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
811 
812  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
813  if (!p)
814  {
815  return false;
816  }
817 
818  if (p->pid)
819  {
820  return p->pid->getPidReference(pidtype, off, ref);
821  }
822 
823  return false;
824 }
825 
827 {
828  bool ret=true;
829 
830  for(int l=0;l<controlledJoints;l++)
831  {
832  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
833 
834  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
835 
836  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
837  if (!p)
838  {
839  return false;
840  }
841 
842  if (p->pid)
843  {
844  bool ok = p->pid->getPidReference(pidtype, off, refs+l);
845  ret=ret && ok;
846  }
847  else
848  {
849  ret=false;
850  }
851  }
852  return ret;
853 }
854 
855 bool ControlBoardRemapper::getPidErrorLimit(const PidControlTypeEnum& pidtype, int j, double *limit)
856 {
857  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
858  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
859 
860  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
861 
862  if (!p)
863  {
864  return false;
865  }
866 
867  if (p->pid)
868  {
869  return p->pid->getPidErrorLimit(pidtype, off, limit);
870  }
871  return false;
872 }
873 
875 {
876  bool ret=true;
877 
878  for(int l=0;l<controlledJoints;l++)
879  {
880  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
881 
882  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
883 
884  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
885 
886  if (!p)
887  {
888  return false;
889  }
890 
891  if (p->pid)
892  {
893  bool ok = p->pid->getPidErrorLimit(pidtype, off, limits+l);
894  ret=ret&&ok;
895  }
896  else
897  {
898  ret=false;
899  }
900  }
901  return ret;
902 }
903 
905 {
906  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
907  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
908 
909  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
910 
911  if (!p)
912  {
913  return false;
914  }
915 
916  if (p->pid)
917  {
918  return p->pid->resetPid(pidtype, off);
919  }
920 
921  return false;
922 }
923 
925 {
926  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
927  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
928 
929  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
930 
931  if (!p)
932  {
933  return false;
934  }
935 
936  return p->pid->disablePid(pidtype, off);
937 }
938 
940 {
941  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
942  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
943 
944  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
945 
946  if (!p)
947  {
948  return false;
949  }
950 
951  if (p->pid)
952  {
953  return p->pid->enablePid(pidtype, off);
954  }
955 
956  return false;
957 }
958 
959 bool ControlBoardRemapper::isPidEnabled(const PidControlTypeEnum& pidtype, int j, bool* enabled)
960 {
961  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
962  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
963 
964  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
965 
966  if (!p)
967  {
968  return false;
969  }
970 
971  if (p->pid)
972  {
973  return p->pid->isPidEnabled(pidtype, off, enabled);
974  }
975 
976  return false;
977 }
978 
979 /* IPositionControl */
981 {
982  *ax=controlledJoints;
983  return true;
984 }
985 
986 bool ControlBoardRemapper::positionMove(int j, double ref)
987 {
988  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
989  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
990 
991  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
992 
993  if (!p)
994  {
995  return false;
996  }
997 
998  if (p->pos)
999  {
1000  return p->pos->positionMove(off, ref);
1001  }
1002 
1003  return false;
1004 }
1005 
1006 bool ControlBoardRemapper::positionMove(const double *refs)
1007 {
1008  bool ret=true;
1009  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1010 
1011  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(refs,remappedControlBoards);
1012 
1013  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1014  {
1015  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1016 
1017  bool ok = p->pos->positionMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1018  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1019  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1020  ret = ret && ok;
1021  }
1022 
1023  return ret;
1024 }
1025 
1026 bool ControlBoardRemapper::positionMove(const int n_joints, const int *joints, const double *refs)
1027 {
1028  bool ret=true;
1029  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1030 
1031  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(refs,n_joints,joints,remappedControlBoards);
1032 
1033  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1034  {
1035  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1036 
1037  bool ok = p->pos->positionMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1038  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1039  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1040  ret = ret && ok;
1041  }
1042 
1043  return ret;
1044 }
1045 
1046 bool ControlBoardRemapper::getTargetPosition(const int j, double* ref)
1047 {
1048  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1049  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1050 
1051  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1052 
1053  if (!p)
1054  {
1055  return false;
1056  }
1057 
1058  if (p->pos)
1059  {
1060  bool ret = p->pos->getTargetPosition(off, ref);
1061  return ret;
1062  }
1063 
1064  return false;
1065 }
1066 
1068 {
1069  bool ret=true;
1070  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1071 
1072  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1073  {
1074  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1075 
1076  bool ok = true;
1077 
1078  if( p->pos )
1079  {
1080  ok = p->pos->getTargetPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1081  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1082  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1083  }
1084  else
1085  {
1086  ok = false;
1087  }
1088 
1089  ret = ret && ok;
1090  }
1091 
1092  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
1093 
1094  return ret;
1095 }
1096 
1097 
1098 bool ControlBoardRemapper::getTargetPositions(const int n_joints, const int *joints, double *targets)
1099 {
1100  bool ret=true;
1101  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1102 
1103  // Resize the input buffers
1104  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1105 
1106  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1107  {
1108  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1109 
1110  bool ok = true;
1111 
1112  if( p->pos )
1113  {
1114  ok = p->pos->getTargetPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1115  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1116  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1117  }
1118  else
1119  {
1120  ok = false;
1121  }
1122 
1123  ret = ret && ok;
1124  }
1125 
1126  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(targets,n_joints,joints,remappedControlBoards);
1127 
1128  return ret;
1129 }
1130 
1131 bool ControlBoardRemapper::relativeMove(int j, double delta)
1132 {
1133  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1134  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1135 
1136  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1137 
1138  if (!p)
1139  {
1140  return false;
1141  }
1142 
1143  if (p->pos)
1144  {
1145  return p->pos->relativeMove(off, delta);
1146  }
1147 
1148  return false;
1149 }
1150 
1151 bool ControlBoardRemapper::relativeMove(const double *deltas)
1152 {
1153  bool ret=true;
1154  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1155 
1156  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(deltas,remappedControlBoards);
1157 
1158  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1159  {
1160  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1161 
1162  bool ok = p->pos->relativeMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1163  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1164  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1165  ret = ret && ok;
1166  }
1167 
1168  return ret;
1169 }
1170 
1171 bool ControlBoardRemapper::relativeMove(const int n_joints, const int *joints, const double *deltas)
1172 {
1173  bool ret=true;
1174  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1175 
1176  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(deltas,n_joints,joints,remappedControlBoards);
1177 
1178  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1179  {
1180  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1181 
1182  bool ok = p->pos->relativeMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1183  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1184  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1185  ret = ret && ok;
1186  }
1187 
1188  return ret;
1189 }
1190 
1192 {
1193  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1194  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1195 
1196  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1197 
1198  if (!p)
1199  {
1200  return false;
1201  }
1202 
1203  if (p->pos)
1204  {
1205  return p->pos->checkMotionDone(off, flag);
1206  }
1207 
1208  return false;
1209 }
1210 
1212 {
1213  bool ret=true;
1214  *flag=true;
1215 
1216  for(int l=0;l<controlledJoints;l++)
1217  {
1218  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1219  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1220 
1221  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1222 
1223  if (!p)
1224  {
1225  return false;
1226  }
1227 
1228  if (p->pos)
1229  {
1230  bool singleJointMotionDone =false;
1231  bool ok = p->pos->checkMotionDone(off, &singleJointMotionDone);
1232  ret = ret && ok;
1233  *flag = *flag && singleJointMotionDone;
1234  }
1235  else
1236  {
1237  ret = false;
1238  }
1239  }
1240  return ret;
1241 }
1242 
1243 bool ControlBoardRemapper::checkMotionDone(const int n_joints, const int *joints, bool *flag)
1244 {
1245  bool ret=true;
1246  *flag=true;
1247 
1248  for(int j=0;j<n_joints;j++)
1249  {
1250  int l = joints[j];
1251 
1252  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1253  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1254 
1255  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1256 
1257  if (!p)
1258  {
1259  return false;
1260  }
1261 
1262  if (p->pos)
1263  {
1264  bool singleJointMotionDone =false;
1265  bool ok = p->pos->checkMotionDone(off, &singleJointMotionDone);
1266  ret = ret && ok;
1267  *flag = *flag && singleJointMotionDone;
1268  }
1269  else
1270  {
1271  ret = false;
1272  }
1273  }
1274 
1275  return ret;
1276 }
1277 
1279 {
1280  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1281  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1282 
1283  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1284 
1285  if (!p)
1286  {
1287  return false;
1288  }
1289 
1290  if (p->pos)
1291  {
1292  return p->pos->setRefSpeed(off, sp);
1293  }
1294 
1295  return false;
1296 }
1297 
1298 bool ControlBoardRemapper::setRefSpeeds(const double *spds)
1299 {
1300  bool ret=true;
1301  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1302 
1303  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(spds,remappedControlBoards);
1304 
1305  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1306  {
1307  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1308 
1309  bool ok = p->pos->setRefSpeeds(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1310  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1311  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1312  ret = ret && ok;
1313  }
1314 
1315  return ret;
1316 }
1317 
1318 bool ControlBoardRemapper::setRefSpeeds(const int n_joints, const int *joints, const double *spds)
1319 {
1320  bool ret=true;
1321  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1322 
1323  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(spds,n_joints,joints,remappedControlBoards);
1324 
1325  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1326  {
1327  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1328 
1329  bool ok = p->pos->setRefSpeeds(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1330  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1331  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1332  ret = ret && ok;
1333  }
1334 
1335  return ret;
1336 }
1337 
1339 {
1340  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1341  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1342 
1343  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1344 
1345  if (!p)
1346  {
1347  return false;
1348  }
1349 
1350  if (p->pos)
1351  {
1352  return p->pos->setRefAcceleration(off, acc);
1353  }
1354 
1355  return false;
1356 }
1357 
1359 {
1360  bool ret=true;
1361  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1362 
1363  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(accs,remappedControlBoards);
1364 
1365  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1366  {
1367  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1368 
1369  bool ok = p->pos->setRefAccelerations(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1370  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1371  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1372  ret = ret && ok;
1373  }
1374 
1375  return ret;
1376 }
1377 
1378 bool ControlBoardRemapper::setRefAccelerations(const int n_joints, const int *joints, const double *accs)
1379 {
1380  bool ret=true;
1381  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1382 
1383  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(accs,n_joints,joints,remappedControlBoards);
1384 
1385  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1386  {
1387  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1388 
1389  bool ok = p->pos->setRefAccelerations(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1390  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1391  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1392  ret = ret && ok;
1393  }
1394 
1395  return ret;
1396 }
1397 
1398 bool ControlBoardRemapper::getRefSpeed(int j, double *ref)
1399 {
1400  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1401  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1402 
1403  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1404 
1405  if (!p)
1406  {
1407  return false;
1408  }
1409 
1410  if (p->pos)
1411  {
1412  return p->pos->getRefSpeed(off, ref);
1413  }
1414 
1415  return false;
1416 }
1417 
1419 {
1420  bool ret=true;
1421  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1422 
1423  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1424  {
1425  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1426 
1427  bool ok = true;
1428 
1429  if( p->pos )
1430  {
1431  ok = p->pos->getRefSpeeds(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1432  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1433  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1434  }
1435  else
1436  {
1437  ok = false;
1438  }
1439 
1440  ret = ret && ok;
1441  }
1442 
1443  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
1444 
1445  return ret;
1446 }
1447 
1448 
1449 bool ControlBoardRemapper::getRefSpeeds(const int n_joints, const int *joints, double *spds)
1450 {
1451  bool ret=true;
1452  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1453 
1454  // Resize the input buffers
1455  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1456 
1457  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1458  {
1459  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1460 
1461  bool ok = true;
1462 
1463  if( p->pos )
1464  {
1465  ok = p->pos->getRefSpeeds(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1466  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1467  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1468  }
1469  else
1470  {
1471  ok = false;
1472  }
1473 
1474  ret = ret && ok;
1475  }
1476 
1477  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(spds,n_joints,joints,remappedControlBoards);
1478 
1479  return ret;
1480 }
1481 
1483 {
1484  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1485  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1486 
1487  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1488 
1489  if (!p)
1490  {
1491  return false;
1492  }
1493 
1494  if (p->pos)
1495  {
1496  return p->pos->getRefAcceleration(off, acc);
1497  }
1498 
1499  return false;
1500 }
1501 
1503 {
1504  bool ret=true;
1505  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1506 
1507  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1508  {
1509  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1510 
1511  bool ok = true;
1512 
1513  if( p->pos )
1514  {
1515  ok = p->pos->getRefAccelerations(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1516  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1517  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1518  }
1519  else
1520  {
1521  ok = false;
1522  }
1523 
1524  ret = ret && ok;
1525  }
1526 
1527  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(accs,remappedControlBoards);
1528 
1529  return ret;
1530 }
1531 
1532 bool ControlBoardRemapper::getRefAccelerations(const int n_joints, const int *joints, double *accs)
1533 {
1534  bool ret=true;
1535  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1536 
1537  // Resize the input buffers
1538  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1539 
1540  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1541  {
1542  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1543 
1544  bool ok = true;
1545 
1546  if( p->pos )
1547  {
1548  ok = p->pos->getRefAccelerations(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1549  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1550  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1551  }
1552  else
1553  {
1554  ok = false;
1555  }
1556 
1557  ret = ret && ok;
1558  }
1559 
1560  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(accs,n_joints,joints,remappedControlBoards);
1561 
1562  return ret;
1563 }
1564 
1566 {
1567  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1568  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1569 
1570  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1571 
1572  if (!p)
1573  {
1574  return false;
1575  }
1576 
1577  if (p->pos)
1578  {
1579  return p->pos->stop(off);
1580  }
1581 
1582  return false;
1583 }
1584 
1586 {
1587  bool ret=true;
1588  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1589 
1590  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1591  {
1592  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1593 
1594  bool ok = true;
1595 
1596  ok = p->pos ? p->pos->stop(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1597  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data()) : false;
1598 
1599  ret = ret && ok;
1600  }
1601 
1602  return ret;
1603 }
1604 
1605 bool ControlBoardRemapper::stop(const int n_joints, const int *joints)
1606 {
1607  bool ret=true;
1608  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1609  std::lock_guard<std::mutex> lock2(buffers.mutex);
1610 
1611 
1612  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(buffers.dummyBuffer.data(),n_joints,joints,remappedControlBoards);
1613 
1614  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1615  {
1616  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1617 
1618  bool ok = p->pos->stop(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1619  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data());
1620  ret = ret && ok;
1621  }
1622 
1623  return ret;
1624 }
1625 
1626 
1627 /* IVelocityControl */
1628 
1630 {
1631  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1632  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1633 
1634  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1635 
1636  if (!p)
1637  {
1638  return false;
1639  }
1640 
1641  if (p->vel)
1642  {
1643  return p->vel->velocityMove(off, v);
1644  }
1645 
1646  return false;
1647 }
1648 
1650 {
1651  bool ret=true;
1652  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1653 
1654  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(v,remappedControlBoards);
1655 
1656  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1657  {
1658  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1659 
1660  bool ok = p->vel->velocityMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1661  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1662  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1663  ret = ret && ok;
1664  }
1665 
1666  return ret;
1667 }
1668 
1669 /* IEncoders */
1671 {
1672  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1673  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1674 
1675  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1676  if (!p)
1677  {
1678  return false;
1679  }
1680 
1681  if (p->iJntEnc)
1682  {
1683  return p->iJntEnc->resetEncoder(off);
1684  }
1685 
1686  return false;
1687 }
1688 
1690 {
1691  bool ret=true;
1692 
1693  for(int l=0;l<controlledJoints;l++)
1694  {
1695  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1696  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1697 
1698  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1699  if (!p)
1700  {
1701  return false;
1702  }
1703 
1704  if (p->iJntEnc)
1705  {
1706  bool ok = p->iJntEnc->resetEncoder(off);
1707  ret = ret && ok;
1708  }
1709  else
1710  {
1711  ret=false;
1712  }
1713  }
1714  return ret;
1715 }
1716 
1717 bool ControlBoardRemapper::setEncoder(int j, double val)
1718 {
1719  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1720  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1721 
1722  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1723 
1724  if (!p)
1725  {
1726  return false;
1727  }
1728 
1729  if (p->iJntEnc)
1730  {
1731  return p->iJntEnc->setEncoder(off,val);
1732  }
1733 
1734  return false;
1735 }
1736 
1737 bool ControlBoardRemapper::setEncoders(const double *vals)
1738 {
1739  bool ret=true;
1740 
1741  for(int l=0;l<controlledJoints;l++)
1742  {
1743  int off = (int) remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1744  size_t subIndex = remappedControlBoards.lut[l].subControlBoardIndex;
1745 
1746  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
1747 
1748  if (!p)
1749  {
1750  return false;
1751  }
1752 
1753  if (p->iJntEnc)
1754  {
1755  bool ok = p->iJntEnc->setEncoder(off, vals[l]);
1756  ret = ret && ok;
1757  }
1758  else
1759  {
1760  ret = false;
1761  }
1762  }
1763  return ret;
1764 }
1765 
1766 bool ControlBoardRemapper::getEncoder(int j, double *v)
1767 {
1768  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1769  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1770 
1771  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1772 
1773  if (!p)
1774  {
1775  return false;
1776  }
1777 
1778  if (p->iJntEnc)
1779  {
1780  return p->iJntEnc->getEncoder(off, v);
1781  }
1782 
1783  return false;
1784 }
1785 
1787 {
1788  bool ret=true;
1789 
1790  for(int l=0;l<controlledJoints;l++)
1791  {
1792  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1793  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1794 
1795  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1796 
1797  if (!p)
1798  {
1799  return false;
1800  }
1801 
1802  if (p->iJntEnc)
1803  {
1804  bool ok = p->iJntEnc->getEncoder(off, encs+l);
1805  ret = ret && ok;
1806  }
1807  else
1808  {
1809  ret = false;
1810  }
1811  }
1812  return ret;
1813 }
1814 
1815 bool ControlBoardRemapper::getEncodersTimed(double *encs, double *t)
1816 {
1817  bool ret=true;
1818 
1819  for(int l=0;l<controlledJoints;l++)
1820  {
1821  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1822  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1823 
1824  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1825 
1826  if (!p)
1827  {
1828  return false;
1829  }
1830 
1831  if (p->iJntEnc)
1832  {
1833  bool ok = p->iJntEnc->getEncoderTimed(off, encs+l, t+l);
1834  ret = ret && ok;
1835  }
1836  else
1837  {
1838  ret = false;
1839  }
1840  }
1841  return ret;
1842 }
1843 
1844 bool ControlBoardRemapper::getEncoderTimed(int j, double *v, double *t)
1845 {
1846  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1847  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1848 
1849  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1850 
1851  if (!p)
1852  {
1853  return false;
1854  }
1855 
1856  if (p->iJntEnc)
1857  {
1858  return p->iJntEnc->getEncoderTimed(off, v, t);
1859  }
1860 
1861  return false;
1862 }
1863 
1865 {
1866  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1867  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1868 
1869  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1870 
1871  if (!p)
1872  {
1873  return false;
1874  }
1875 
1876  if (p->iJntEnc)
1877  {
1878  return p->iJntEnc->getEncoderSpeed(off, sp);
1879  }
1880 
1881  return false;
1882 }
1883 
1885 {
1886  bool ret=true;
1887 
1888  for(int l=0;l<controlledJoints;l++)
1889  {
1890  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1891  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1892 
1893  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1894 
1895  if (!p)
1896  {
1897  return false;
1898  }
1899 
1900  if (p->iJntEnc)
1901  {
1902  bool ok = p->iJntEnc->getEncoderSpeed(off, spds+l);
1903  ret = ret && ok;
1904  }
1905  else
1906  {
1907  ret = false;
1908  }
1909  }
1910  return ret;
1911 }
1912 
1914 {
1915  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1916  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1917 
1918  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1919 
1920  if (!p)
1921  {
1922  return false;
1923  }
1924 
1925  if (p->iJntEnc)
1926  {
1927  return p->iJntEnc->getEncoderAcceleration(off,acc);
1928  }
1929 
1930  return false;
1931 }
1932 
1934 {
1935  bool ret=true;
1936 
1937  for(int l=0;l<controlledJoints;l++)
1938  {
1939  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1940  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1941 
1942  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1943 
1944  if (!p)
1945  {
1946  return false;
1947  }
1948 
1949  if (p->iJntEnc)
1950  {
1951  bool ok = p->iJntEnc->getEncoderAcceleration(off, accs+l);
1952  ret = ret && ok;
1953  }
1954  else
1955  {
1956  ret = false;
1957  }
1958  }
1959  return ret;
1960 }
1961 
1962 /* IMotor */
1964 {
1965  *num=controlledJoints;
1966  return true;
1967 }
1968 
1970 {
1971  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
1972  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
1973 
1974  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1975 
1976  if (!p)
1977  {
1978  return false;
1979  }
1980 
1981  if (p->imotor)
1982  {
1983  return p->imotor->getTemperature(off, val);
1984  }
1985 
1986  return false;
1987 }
1988 
1990 {
1991  bool ret=true;
1992  for(int l=0;l<controlledJoints;l++)
1993  {
1994  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1995  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1996 
1997  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1998  if (!p)
1999  {
2000  return false;
2001  }
2002 
2003  if (p->imotor)
2004  {
2005  ret=ret&&p->imotor->getTemperature(off, vals+l);
2006  }
2007  else
2008  {
2009  ret=false;
2010  }
2011  }
2012  return ret;
2013 }
2014 
2016 {
2017  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2018  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2019 
2020  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2021 
2022  if (!p)
2023  {
2024  return false;
2025  }
2026 
2027  if (p->imotor)
2028  {
2029  return p->imotor->getTemperatureLimit(off, val);
2030  }
2031 
2032  return false;
2033 }
2034 
2035 bool ControlBoardRemapper::setTemperatureLimit (int m, const double val)
2036 {
2037  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2038  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2039 
2040  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2041 
2042  if (!p)
2043  {
2044  return false;
2045  }
2046 
2047  if (p->imotor)
2048  {
2049  return p->imotor->setTemperatureLimit(off,val);
2050  }
2051 
2052  return false;
2053 }
2054 
2056 {
2057  int off = (int)remappedControlBoards.lut[m].subControlBoardIndex;
2058  size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2059 
2060  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2061 
2062  if (!p)
2063  {
2064  return false;
2065  }
2066 
2067  if (p->imotor)
2068  {
2069  return p->imotor->getGearboxRatio(off, val);
2070  }
2071 
2072  return false;
2073 }
2074 
2075 bool ControlBoardRemapper::setGearboxRatio(int m, const double val)
2076 {
2077  int off = (int)remappedControlBoards.lut[m].subControlBoardIndex;
2078  size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2079 
2080  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2081 
2082  if (!p)
2083  {
2084  return false;
2085  }
2086 
2087  if (p->imotor)
2088  {
2089  return p->imotor->setGearboxRatio(off, val);
2090  }
2091 
2092  return false;
2093 }
2094 
2095 /* IRemoteVariables */
2097 {
2098  yCWarning(CONTROLBOARDREMAPPER, "getRemoteVariable is not properly implemented, use at your own risk.");
2099 
2100  bool b = true;
2101 
2102  for (unsigned int i = 0; i < remappedControlBoards.getNrOfSubControlBoards(); i++)
2103  {
2104  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(i);
2105 
2106  if (!p)
2107  {
2108  return false;
2109  }
2110 
2111  if (!p->iVar)
2112  {
2113  return false;
2114  }
2115 
2116  yarp::os::Bottle tmpval;
2117  bool ok = p->iVar->getRemoteVariable(key, tmpval);
2118 
2119  if (ok)
2120  {
2121  val.append(tmpval);
2122  }
2123 
2124  b = b && ok;
2125  }
2126 
2127  return b;
2128 }
2129 
2131 {
2132  yCWarning(CONTROLBOARDREMAPPER, "setRemoteVariable is not properly implemented, use at your own risk.");
2133 
2134  size_t bottle_size = val.size();
2135  size_t device_size = remappedControlBoards.getNrOfSubControlBoards();
2136  if (bottle_size != device_size)
2137  {
2138  yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable bottle_size != device_size failure");
2139  return false;
2140  }
2141 
2142  bool b = true;
2143  for (unsigned int i = 0; i < device_size; i++)
2144  {
2145  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(i);
2146  if (!p) { yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable !p failure"); return false; }
2147  if (!p->iVar) { yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable !p->iVar failure"); return false; }
2148  Bottle* partial_val = val.get(i).asList();
2149  if (partial_val)
2150  {
2151  b &= p->iVar->setRemoteVariable(key, *partial_val);
2152  }
2153  else
2154  {
2155  yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable general failure");
2156  return false;
2157  }
2158  }
2159 
2160  return b;
2161 }
2162 
2164 {
2165  yCWarning(CONTROLBOARDREMAPPER, "getRemoteVariablesList is not properly implemented, use at your own risk.");
2166 
2167  size_t subIndex = remappedControlBoards.lut[0].subControlBoardIndex;
2168  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2169 
2170  if (!p)
2171  {
2172  return false;
2173  }
2174 
2175  if (p->iVar)
2176  {
2177  return p->iVar->getRemoteVariablesList(listOfKeys);
2178  }
2179 
2180  return false;
2181 }
2182 
2183 /* IMotorEncoders */
2184 
2186 {
2187  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2188  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2189 
2190  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2191 
2192  if (!p)
2193  {
2194  return false;
2195  }
2196 
2197  if (p->iMotEnc)
2198  {
2199  return p->iMotEnc->resetMotorEncoder(off);
2200  }
2201 
2202  return false;
2203 }
2204 
2206 {
2207  bool ret=true;
2208 
2209  for(int l=0;l<controlledJoints;l++)
2210  {
2211  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2212  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2213 
2214  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2215  if (!p)
2216  {
2217  return false;
2218  }
2219 
2220  if (p->iMotEnc)
2221  {
2222  bool ok = p->iMotEnc->resetMotorEncoder(off);
2223  ret= ret && ok;
2224  }
2225  else
2226  {
2227  ret=false;
2228  }
2229  }
2230 
2231  return ret;
2232 }
2233 
2234 bool ControlBoardRemapper::setMotorEncoder(int m, const double val)
2235 {
2236  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2237  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2238 
2239  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2240 
2241  if (!p)
2242  {
2243  return false;
2244  }
2245 
2246  if (p->iMotEnc)
2247  {
2248  return p->iMotEnc->setMotorEncoder(off,val);
2249  }
2250 
2251  return false;
2252 }
2253 
2255 {
2256  bool ret=true;
2257 
2258  for(int l=0;l<controlledJoints;l++)
2259  {
2260  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2261  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2262 
2263  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2264 
2265  if (!p)
2266  {
2267  return false;
2268  }
2269 
2270  if (p->iMotEnc)
2271  {
2272  bool ok = p->iMotEnc->setMotorEncoder(off, vals[l]);
2273  ret = ret && ok;
2274  }
2275  else
2276  {
2277  ret=false;
2278  }
2279  }
2280 
2281  return ret;
2282 }
2283 
2285 {
2286  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2287  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2288 
2289  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2290 
2291  if (!p)
2292  {
2293  return false;
2294  }
2295 
2296  if (p->iMotEnc)
2297  {
2298  return p->iMotEnc->setMotorEncoderCountsPerRevolution(off,cpr);
2299  }
2300 
2301  return false;
2302 }
2303 
2305 {
2306  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2307  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2308 
2309  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2310 
2311  if (!p)
2312  {
2313  return false;
2314  }
2315 
2316  if (p->iMotEnc)
2317  {
2318  return p->iMotEnc->getMotorEncoderCountsPerRevolution(off, cpr);
2319  }
2320 
2321  return false;
2322 }
2323 
2325 {
2326  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2327  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2328 
2329  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2330 
2331  if (!p)
2332  {
2333  return false;
2334  }
2335 
2336  if (p->iMotEnc)
2337  {
2338  return p->iMotEnc->getMotorEncoder(off, v);
2339  }
2340 
2341  return false;
2342 }
2343 
2345 {
2346  bool ret=true;
2347 
2348  for(int l=0;l<controlledJoints;l++)
2349  {
2350  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2351  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2352 
2353  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2354  if (!p) {
2355  return false;
2356  }
2357 
2358  if (p->iMotEnc)
2359  {
2360  ret=ret&&p->iMotEnc->getMotorEncoder(off, encs+l);
2361  } else {
2362  ret = false;
2363  }
2364  }
2365  return ret;
2366 }
2367 
2369 {
2370  bool ret=true;
2371 
2372  for(int l=0;l<controlledJoints;l++)
2373  {
2374  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2375  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2376 
2377  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2378 
2379  if (!p)
2380  {
2381  return false;
2382  }
2383 
2384  if (p->iMotEnc)
2385  {
2386  bool ok = p->iMotEnc->getMotorEncoderTimed(off, encs, t);
2387  ret = ret && ok;
2388  }
2389  else
2390  {
2391  ret = false;
2392  }
2393  }
2394  return ret;
2395 }
2396 
2397 bool ControlBoardRemapper::getMotorEncoderTimed(int m, double *v, double *t)
2398 {
2399  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2400  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2401 
2402  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2403 
2404  if (!p)
2405  {
2406  return false;
2407  }
2408 
2409  if (p->iMotEnc)
2410  {
2411  return p->iMotEnc->getMotorEncoderTimed(off, v, t);
2412  }
2413 
2414  return false;
2415 }
2416 
2418 {
2419  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2420  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2421 
2422  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2423 
2424  if (!p)
2425  {
2426  return false;
2427  }
2428 
2429  if (p->iMotEnc)
2430  {
2431  return p->iMotEnc->getMotorEncoderSpeed(off, sp);
2432  }
2433 
2434  return false;
2435 }
2436 
2438 {
2439  bool ret=true;
2440 
2441  for(int l=0;l<controlledJoints;l++)
2442  {
2443  int off = (int) remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2444  size_t subIndex = remappedControlBoards.lut[l].subControlBoardIndex;
2445 
2446  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2447 
2448  if (!p)
2449  {
2450  return false;
2451  }
2452 
2453  if (p->iMotEnc)
2454  {
2455  bool ok = p->iMotEnc->getMotorEncoderSpeed(off, spds + l);
2456  ret = ret && ok;
2457  }
2458  else
2459  {
2460  ret = false;
2461  }
2462  }
2463  return ret;
2464 }
2465 
2467 {
2468  int off = (int) remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2469  size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2470 
2471  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2472 
2473  if (!p)
2474  {
2475  return false;
2476  }
2477 
2478  if (p->iMotEnc)
2479  {
2480  return p->iMotEnc->getMotorEncoderAcceleration(off,acc);
2481  }
2482  *acc=0.0;
2483  return false;
2484 }
2485 
2487 {
2488  bool ret=true;
2489 
2490  for(int l=0;l<controlledJoints;l++)
2491  {
2492  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2493  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2494 
2495  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2496 
2497  if (!p)
2498  {
2499  return false;
2500  }
2501 
2502  if (p->iMotEnc)
2503  {
2504  bool ok = p->iMotEnc->getMotorEncoderAcceleration(off, accs+l);
2505  ret=ret && ok;
2506  }
2507  else
2508  {
2509  ret=false;
2510  }
2511  }
2512 
2513  return ret;
2514 }
2515 
2516 
2518 {
2519  *num=controlledJoints;
2520  return true;
2521 }
2522 
2523 /* IAmplifierControl */
2525 {
2526  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2527  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2528 
2529  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2530 
2531  if (!p)
2532  {
2533  return false;
2534  }
2535 
2536  if (p->amp)
2537  {
2538  return p->amp->enableAmp(off);
2539  }
2540 
2541  return false;
2542 }
2543 
2545 {
2546  return this->setControlMode(j, VOCAB_CM_IDLE);
2547 }
2548 
2550 {
2551  bool ret=true;
2552 
2553  for(int l=0;l<controlledJoints;l++)
2554  {
2555  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2556  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2557 
2558  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2559 
2560  if (!p)
2561  {
2562  return false;
2563  }
2564 
2565  if (p->amp)
2566  {
2567  bool ok = p->amp->getAmpStatus(off, st+l);
2568  ret = ret && ok;
2569  }
2570  else
2571  {
2572  ret=false;
2573  }
2574  }
2575 
2576  return ret;
2577 }
2578 
2580 {
2581  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2582  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2583 
2584  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2585 
2586  if (!p)
2587  {
2588  return false;
2589  }
2590 
2591  if (p->amp)
2592  {
2593  return p->amp->getAmpStatus(off,v);
2594  }
2595 
2596  return false;
2597 }
2598 
2600 {
2601  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2602  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2603 
2604  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2605 
2606  if (!p)
2607  {
2608  return false;
2609  }
2610 
2611  if (p->amp)
2612  {
2613  return p->amp->setMaxCurrent(off,v);
2614  }
2615 
2616  return false;
2617 }
2618 
2620 {
2621  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2622  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2623 
2624  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2625 
2626  if (!p)
2627  {
2628  return false;
2629  }
2630 
2631  if (p->amp)
2632  {
2633  return p->amp->getMaxCurrent(off,v);
2634  }
2635 
2636  return false;
2637 }
2638 
2640 {
2641  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2642  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2643 
2644  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2645 
2646  if(!p)
2647  {
2648  return false;
2649  }
2650 
2651  if(!p->amp)
2652  {
2653  return false;
2654  }
2655 
2656  return p->amp->getNominalCurrent(off, val);
2657 }
2658 
2660 {
2661  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2662  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2663 
2664  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2665 
2666  if(!p)
2667  {
2668  return false;
2669  }
2670 
2671  if(!p->amp)
2672  {
2673  return false;
2674  }
2675 
2676  return p->amp->getPeakCurrent(off, val);
2677 }
2678 
2679 bool ControlBoardRemapper::setPeakCurrent(int m, const double val)
2680 {
2681  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2682  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2683 
2684  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2685 
2686  if (!p)
2687  {
2688  return false;
2689  }
2690 
2691  if (!p->amp)
2692  {
2693  return false;
2694  }
2695 
2696  return p->amp->setPeakCurrent(off, val);
2697 }
2698 
2699 bool ControlBoardRemapper::setNominalCurrent(int m, const double val)
2700 {
2701  int off = (int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2702  size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2703 
2704  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2705 
2706  if (!p)
2707  {
2708  return false;
2709  }
2710 
2711  if (!p->amp)
2712  {
2713  return false;
2714  }
2715 
2716  return p->amp->setNominalCurrent(off, val);
2717 }
2718 
2719 bool ControlBoardRemapper::getPWM(int m, double* val)
2720 {
2721  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2722  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2723 
2724  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2725 
2726  if(!p)
2727  {
2728  return false;
2729  }
2730 
2731  if(!p->amp)
2732  {
2733  return false;
2734  }
2735 
2736  return p->amp->getPWM(off, val);
2737 }
2738 bool ControlBoardRemapper::getPWMLimit(int m, double* val)
2739 {
2740  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2741  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2742 
2743  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2744 
2745  if(!p)
2746  {
2747  return false;
2748  }
2749 
2750  if(!p->amp)
2751  {
2752  return false;
2753  }
2754 
2755  return p->amp->getPWMLimit(off, val);
2756 }
2757 
2758 bool ControlBoardRemapper::setPWMLimit(int m, const double val)
2759 {
2760  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2761  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2762 
2763  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2764 
2765  if (!p)
2766  {
2767  return false;
2768  }
2769 
2770  if (!p->amp)
2771  {
2772  return false;
2773  }
2774 
2775  return p->amp->setPWMLimit(off, val);
2776 }
2777 
2779 {
2780  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2781  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2782 
2783  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2784 
2785  if(!p)
2786  {
2787  return false;
2788  }
2789 
2790  if(!p->amp)
2791  {
2792  return false;
2793  }
2794 
2795  return p->amp->getPowerSupplyVoltage(off, val);
2796 }
2797 
2798 
2799 /* IControlLimits */
2800 
2801 bool ControlBoardRemapper::setLimits(int j, double min, double max)
2802 {
2803  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2804  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2805 
2806  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2807 
2808  if (!p)
2809  {
2810  return false;
2811  }
2812 
2813  if (p->lim)
2814  {
2815  return p->lim->setLimits(off,min, max);
2816  }
2817 
2818  return false;
2819 }
2820 
2821 bool ControlBoardRemapper::getLimits(int j, double *min, double *max)
2822 {
2823  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2824  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2825 
2826  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2827 
2828  if (!p)
2829  {
2830  return false;
2831  }
2832 
2833  if (p->lim)
2834  {
2835  return p->lim->getLimits(off,min, max);
2836  }
2837 
2838  return false;
2839 }
2840 
2841 bool ControlBoardRemapper::setVelLimits(int j, double min, double max)
2842 {
2843  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2844  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2845 
2846  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2847 
2848  if (!p)
2849  {
2850  return false;
2851  }
2852 
2853  if (!p->lim)
2854  {
2855  return false;
2856  }
2857 
2858  return p->lim->setVelLimits(off,min, max);
2859 }
2860 
2861 bool ControlBoardRemapper::getVelLimits(int j, double *min, double *max)
2862 {
2863  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2864  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2865 
2866  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2867 
2868  if (!p)
2869  {
2870  return false;
2871  }
2872 
2873  if(!p->lim)
2874  {
2875  return false;
2876  }
2877 
2878  return p->lim->getVelLimits(off,min, max);
2879 }
2880 
2881 /* IRemoteCalibrator */
2883 {
2885 }
2886 
2888 {
2890 }
2891 
2893 {
2894  if(!getCalibratorDevice())
2895  {
2896  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2897  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
2898 
2899  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
2900  if (!s)
2901  {
2902  return false;
2903  }
2904 
2905  if (s->remcalib)
2906  {
2907  return s->remcalib->calibrateSingleJoint(off);
2908  }
2909 
2910  return false;
2911  }
2912  else
2913  {
2914  return IRemoteCalibrator::getCalibratorDevice()->calibrateSingleJoint(j);
2915  }
2916 }
2917 
2919 {
2920  if(!getCalibratorDevice())
2921  {
2922  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
2923  {
2924  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
2925  if (!s)
2926  {
2927  return false;
2928  }
2929 
2930  if (s->remcalib)
2931  {
2932  return s->remcalib->calibrateWholePart();
2933  }
2934  }
2935 
2936  return false;
2937  }
2938  else
2939  {
2940  return IRemoteCalibrator::getCalibratorDevice()->calibrateWholePart();
2941  }
2942 }
2943 
2945 {
2946  if(!getCalibratorDevice())
2947  {
2948  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2949  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
2950 
2951  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
2952  if (!s)
2953  {
2954  return false;
2955  }
2956 
2957  if (s->remcalib)
2958  {
2959  return s->remcalib->homingSingleJoint(off);
2960  }
2961 
2962  return false;
2963  }
2964  else
2965  {
2966  return IRemoteCalibrator::getCalibratorDevice()->homingSingleJoint(j);
2967  }
2968 }
2969 
2971 {
2972  if(!getCalibratorDevice())
2973  {
2974  bool ret = true;
2975  for(int l=0;l<controlledJoints;l++)
2976  {
2977  bool ok = this->homingSingleJoint(l);
2978  ret = ret && ok;
2979  }
2980 
2981  return ret;
2982  }
2983  else
2984  {
2985  return IRemoteCalibrator::getCalibratorDevice()->homingWholePart();
2986  }
2987 }
2988 
2990 {
2991  if(!getCalibratorDevice())
2992  {
2993  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2994  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
2995 
2996  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
2997  if (!s)
2998  {
2999  return false;
3000  }
3001 
3002  if (s->remcalib)
3003  {
3004  return s->remcalib->parkSingleJoint(off,_wait);
3005  }
3006 
3007  return false;
3008  }
3009  else
3010  {
3011  return getCalibratorDevice()->parkSingleJoint(j, _wait);
3012  }
3013 }
3014 
3016 {
3017  if(!getCalibratorDevice())
3018  {
3019  bool ret = true;
3020 
3021  for(int l=0; l<controlledJoints; l++)
3022  {
3023  bool _wait = false;
3024  bool ok = this->parkSingleJoint(l,_wait);
3025  ret = ret && ok;
3026  }
3027 
3028  return ret;
3029  }
3030  else
3031  {
3032  return getCalibratorDevice()->parkWholePart();
3033  }
3034 }
3035 
3037 {
3038  if(!getCalibratorDevice())
3039  {
3040  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3041  {
3042  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
3043  if (!s)
3044  {
3045  return false;
3046  }
3047 
3048  if (s->remcalib)
3049  {
3050  return s->remcalib->quitCalibrate();
3051  }
3052  }
3053 
3054  return false;
3055  }
3056  else
3057  {
3058  return IRemoteCalibrator::getCalibratorDevice()->quitCalibrate();
3059  }
3060 }
3061 
3063 {
3064  if(!getCalibratorDevice())
3065  {
3066  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3067  {
3068  RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
3069  if (!s)
3070  {
3071  return false;
3072  }
3073 
3074  if (s->remcalib)
3075  {
3076  return s->remcalib->quitPark();
3077  }
3078  }
3079 
3080  return false;
3081  }
3082  else
3083  {
3084  return IRemoteCalibrator::getCalibratorDevice()->quitPark();
3085  }
3086 }
3087 
3088 
3089 /* IControlCalibration */
3090 bool ControlBoardRemapper::calibrateAxisWithParams(int j, unsigned int ui, double v1, double v2, double v3)
3091 {
3092  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3093  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3094 
3095  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3096 
3097  if (p && p->calib)
3098  {
3099  return p->calib->calibrateAxisWithParams(off, ui,v1,v2,v3);
3100  }
3101  return false;
3102 }
3103 
3105 {
3106  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3107  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3108 
3109  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3110 
3111  if (p && p->calib)
3112  {
3113  return p->calib->setCalibrationParameters(off, params);
3114  }
3115 
3116  return false;
3117 }
3118 
3120 {
3121  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3122  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3123 
3124  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3125 
3126  if (!p)
3127  {
3128  return false;
3129  }
3130 
3131  if (p->calib)
3132  {
3133  return p->calib->calibrationDone(off);
3134  }
3135 
3136  return false;
3137 }
3138 
3140 {
3141  yCError(CONTROLBOARDREMAPPER, "Calling abortPark -- not implemented");
3142  return false;
3143 }
3144 
3146 {
3147  yCError(CONTROLBOARDREMAPPER, "Calling abortCalibration -- not implemented");
3148  return false;
3149 }
3150 
3151 /* IAxisInfo */
3152 
3153 bool ControlBoardRemapper::getAxisName(int j, std::string& name)
3154 {
3155  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3156  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3157 
3158  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3159 
3160  if (!p)
3161  {
3162  return false;
3163  }
3164 
3165  if (p->info)
3166  {
3167  return p->info->getAxisName(off, name);
3168  }
3169 
3170  return false;
3171 }
3172 
3174 {
3175  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3176  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3177 
3178  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3179 
3180  if (!p)
3181  {
3182  return false;
3183  }
3184 
3185  if (p->info)
3186  {
3187  return p->info->getJointType(off, type);
3188  }
3189 
3190  return false;
3191 }
3192 
3194 {
3195  bool ret=true;
3196 
3197  for(int l=0;l<controlledJoints;l++)
3198  {
3199  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3200  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3201 
3202  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3203 
3204  if (!p)
3205  {
3206  return false;
3207  }
3208 
3209  if (p->iTorque)
3210  {
3211  bool ok = p->iTorque->getRefTorque(off, refs+l);
3212  ret = ret && ok;
3213  }
3214  else
3215  {
3216  ret = false;
3217  }
3218  }
3219  return ret;
3220 }
3221 
3223 {
3224  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3225  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3226 
3227  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3228 
3229  if (!p)
3230  {
3231  return false;
3232  }
3233 
3234  if (p->iTorque)
3235  {
3236  return p->iTorque->getRefTorque(off, t);
3237  }
3238  return false;
3239 }
3240 
3242 {
3243  bool ret=true;
3244  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3245 
3246  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(t,remappedControlBoards);
3247 
3248  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3249  {
3250  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3251 
3252  bool ok;
3253 
3254  if( p->iTorque )
3255  {
3256  ok = p->iTorque->setRefTorques(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3257  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3258  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3259  }
3260  else
3261  {
3262  ok = false;
3263  }
3264 
3265  ret = ret && ok;
3266  }
3267 
3268  return ret;
3269 }
3270 
3272 {
3273  int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3274  size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3275 
3276  RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3277  if (!p)
3278  {
3279  return false;
3280  }
3281 
3282  if (p->iTorque)
3283  {
3284  return p->iTorque->setRefTorque(off, t);
3285  }
3286  return false;
3287 }
3288 
3289 bool ControlBoardRemapper::setRefTorques(const int n_joints, const int *joints, const double *t)
3290 {
3291  bool ret=true;
3292  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3293 
3294  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(t,n_joints,joints,remappedControlBoards);
3295 
3296  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3297  {
3298  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3299 
3300  bool ok = p->iTorque->setRefTorques(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3301  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3302  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3303  ret = ret && ok;
3304  }
3305 
3306  return ret;
3307 }
3308 
3310 {
3311  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3312  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3313 
3314  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3315 
3316  if (!p)
3317  {
3318  return false;
3319  }
3320 
3321  if (p->iTorque)
3322  {
3323  return p->iTorque->getMotorTorqueParams(off, params);
3324  }
3325 
3326  return false;
3327 }
3328 
3330 {
3331  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3332  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3333 
3334  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3335 
3336  if (!p)
3337  {
3338  return false;
3339  }
3340 
3341  if (p->iTorque)
3342  {
3343  return p->iTorque->setMotorTorqueParams(off, params);
3344  }
3345 
3346  return false;
3347 }
3348 
3349 bool ControlBoardRemapper::setImpedance(int j, double stiff, double damp)
3350 {
3351  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3352  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3353 
3354  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3355 
3356  if (!p)
3357  {
3358  return false;
3359  }
3360 
3361  if (p->iImpedance)
3362  {
3363  return p->iImpedance->setImpedance(off, stiff, damp);
3364  }
3365 
3366  return false;
3367 }
3368 
3370 {
3371  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3372  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3373 
3374  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3375 
3376  if (!p)
3377  {
3378  return false;
3379  }
3380 
3381  if (p->iImpedance)
3382  {
3383  return p->iImpedance->setImpedanceOffset(off, offset);
3384  }
3385 
3386  return false;
3387 }
3388 
3390 {
3391  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3392  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3393 
3394  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3395 
3396  if (!p)
3397  {
3398  return false;
3399  }
3400 
3401  if (p->iTorque)
3402  {
3403  return p->iTorque->getTorque(off, t);
3404  }
3405 
3406  return false;
3407 }
3408 
3410 {
3411  bool ret=true;
3412 
3413  for(int l=0;l<controlledJoints;l++)
3414  {
3415  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3416  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3417 
3418  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3419 
3420  if (!p)
3421  {
3422  return false;
3423  }
3424 
3425  if (p->iTorque)
3426  {
3427  bool ok = p->iTorque->getTorque(off, t+l);
3428  ret = ret && ok;
3429  }
3430  else
3431  {
3432  ret=false;
3433  }
3434  }
3435 
3436  return ret;
3437  }
3438 
3439 bool ControlBoardRemapper::getTorqueRange(int j, double *min, double *max)
3440 {
3441  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3442  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3443 
3444  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3445 
3446  if (!p)
3447  {
3448  return false;
3449  }
3450 
3451  if (p->iTorque)
3452  {
3453  return p->iTorque->getTorqueRange(off, min, max);
3454  }
3455 
3456  return false;
3457 }
3458 
3459 bool ControlBoardRemapper::getTorqueRanges(double *min, double *max)
3460 {
3461  bool ret=true;
3462 
3463  for(int l=0;l<controlledJoints;l++)
3464  {
3465  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3466  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3467 
3468  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3469 
3470  if (!p)
3471  {
3472  return false;
3473  }
3474 
3475  if (p->iTorque)
3476  {
3477  bool ok = p->iTorque->getTorqueRange(off, min+l, max+l);
3478  ret = ret && ok;
3479  }
3480  else
3481  {
3482  ret=false;
3483  }
3484  }
3485  return ret;
3486  }
3487 
3488 bool ControlBoardRemapper::getImpedance(int j, double* stiff, double* damp)
3489 {
3490  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3491  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3492 
3493  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3494 
3495  if (!p)
3496  {
3497  return false;
3498  }
3499 
3500  if (p->iImpedance)
3501  {
3502  return p->iImpedance->getImpedance(off, stiff, damp);
3503  }
3504 
3505  return false;
3506 }
3507 
3508 bool ControlBoardRemapper::getImpedanceOffset(int j, double* offset)
3509 {
3510  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3511  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3512 
3513  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3514 
3515  if (!p)
3516  {
3517  return false;
3518  }
3519 
3520  if (p->iImpedance)
3521  {
3522  return p->iImpedance->getImpedanceOffset(off, offset);
3523  }
3524 
3525  return false;
3526 }
3527 
3528 bool ControlBoardRemapper::getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)
3529 {
3530  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3531  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3532 
3533  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3534 
3535  if (!p)
3536  {
3537  return false;
3538  }
3539 
3540  if (p->iImpedance)
3541  {
3542  return p->iImpedance->getCurrentImpedanceLimit(off, min_stiff, max_stiff, min_damp, max_damp);
3543  }
3544 
3545  return false;
3546 }
3547 
3549 {
3550  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3551  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3552 
3553  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3554  if (!p) {
3555  return false;
3556  }
3557 
3558  return p->iMode->getControlMode(off, mode);
3559 
3560 }
3561 
3563 {
3564  bool ret=true;
3565  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3566 
3567  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3568  {
3569  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3570 
3571  bool ok;
3572 
3573  if( p->iMode )
3574  {
3575  ok = p->iMode->getControlModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3576  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3577  allJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3578  }
3579  else
3580  {
3581  ok = false;
3582  }
3583 
3584  ret = ret && ok;
3585  }
3586 
3587  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(modes,remappedControlBoards);
3588 
3589  return ret;
3590 }
3591 
3592 // IControlMode interface
3593 bool ControlBoardRemapper::getControlModes(const int n_joints, const int *joints, int *modes)
3594 {
3595  bool ret=true;
3596  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3597 
3598  // Resize the input buffers
3599  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
3600 
3601  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3602  {
3603  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3604 
3605  bool ok;
3606 
3607  if( p->iMode )
3608  {
3609  ok = p->iMode->getControlModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3610  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3611  selectedJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3612  }
3613  else
3614  {
3615  ok = false;
3616  }
3617 
3618  ret = ret && ok;
3619  }
3620 
3621  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(modes,n_joints,joints,remappedControlBoards);
3622 
3623  return ret;
3624 }
3625 
3626 bool ControlBoardRemapper::setControlMode(const int j, const int mode)
3627 {
3628  bool ret = true;
3629 
3630  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3631  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3632 
3633  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3634 
3635  if (!p)
3636  {
3637  return false;
3638  }
3639 
3640  ret = p->iMode->setControlMode(off, mode);
3641 
3642  return ret;
3643 }
3644 
3645 bool ControlBoardRemapper::setControlModes(const int n_joints, const int *joints, int *modes)
3646 {
3647  bool ret=true;
3648  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3649 
3650  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(modes,n_joints,joints,remappedControlBoards);
3651 
3652  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3653  {
3654  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3655 
3656  bool ok = p->iMode->setControlModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3657  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3658  selectedJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3659  ret = ret && ok;
3660  }
3661 
3662  return ret;
3663 }
3664 
3666 {
3667  bool ret=true;
3668  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3669 
3670  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(modes,remappedControlBoards);
3671 
3672  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3673  {
3674  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3675 
3676  bool ok = p->iMode->setControlModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3677  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3678  allJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3679  ret = ret && ok;
3680  }
3681 
3682  return ret;
3683 }
3684 
3685 bool ControlBoardRemapper::setPosition(int j, double ref)
3686 {
3687  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3688  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3689 
3690  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3691 
3692  if (!p)
3693  {
3694  return false;
3695  }
3696 
3697  if (p->posDir)
3698  {
3699  return p->posDir->setPosition(off, ref);
3700  }
3701 
3702  return false;
3703 }
3704 
3705 bool ControlBoardRemapper::setPositions(const int n_joints, const int *joints, const double *dpos)
3706 {
3707  bool ret=true;
3708  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3709 
3710  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(dpos,n_joints,joints,remappedControlBoards);
3711 
3712  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3713  {
3714  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3715 
3716  bool ok = p->posDir->setPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3717  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3718  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3719  ret = ret && ok;
3720  }
3721 
3722  return ret;
3723 }
3724 
3725 bool ControlBoardRemapper::setPositions(const double *refs)
3726 {
3727  bool ret=true;
3728  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3729 
3730  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(refs,remappedControlBoards);
3731 
3732  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3733  {
3734  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3735 
3736  bool ok = p->posDir->setPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3737  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3738  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3739  ret = ret && ok;
3740  }
3741 
3742  return ret;
3743 }
3744 
3746 {
3747  double averageTimestamp = 0.0;
3748  int collectedTimestamps = 0;
3749 
3750  for(int l=0;l<controlledJoints;l++)
3751  {
3752  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3753 
3754  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3755 
3756  if (!p)
3757  {
3758  return Stamp();
3759  }
3760 
3761  if(p->iTimed)
3762  {
3763  averageTimestamp = averageTimestamp + p->iTimed->getLastInputStamp().getTime();
3764  collectedTimestamps++;
3765  }
3766  }
3767 
3768 
3769  std::lock_guard<std::mutex> lock(buffers.mutex);
3770 
3771  if( collectedTimestamps > 0 )
3772  {
3773  buffers.stamp.update(averageTimestamp/collectedTimestamps);
3774  }
3775  else
3776  {
3777  buffers.stamp.update();
3778  }
3779 
3780  return buffers.stamp;
3781 }
3782 
3783 bool ControlBoardRemapper::getRefPosition(const int j, double* ref)
3784 {
3785  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3786  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3787 
3788  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3789 
3790  if (!p)
3791  {
3792  return false;
3793  }
3794 
3795  if (p->posDir)
3796  {
3797  bool ret = p->posDir->getRefPosition(off, ref);
3798  return ret;
3799  }
3800 
3801  return false;
3802 }
3803 
3805 {
3806  bool ret=true;
3807  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3808 
3809  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3810  {
3811  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3812 
3813  bool ok = true;
3814 
3815  if( p->posDir )
3816  {
3817  ok = p->posDir->getRefPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3818  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3819  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3820  }
3821  else
3822  {
3823  ok = false;
3824  }
3825 
3826  ret = ret && ok;
3827  }
3828 
3829  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
3830 
3831  return ret;
3832 }
3833 
3834 
3835 bool ControlBoardRemapper::getRefPositions(const int n_joints, const int *joints, double *targets)
3836 {
3837  bool ret=true;
3838  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3839 
3840  // Resize the input buffers
3841  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
3842 
3843  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3844  {
3845  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3846 
3847  bool ok = true;
3848 
3849  if( p->posDir )
3850  {
3851  ok = p->posDir->getRefPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3852  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3853  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3854  }
3855  else
3856  {
3857  ok = false;
3858  }
3859 
3860  ret = ret && ok;
3861  }
3862 
3863  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(targets,n_joints,joints,remappedControlBoards);
3864 
3865  return ret;
3866 }
3867 
3868 
3869 
3870 // IVelocityControl interface
3871 bool ControlBoardRemapper::velocityMove(const int n_joints, const int *joints, const double *spds)
3872 {
3873  bool ret=true;
3874  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3875 
3876  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(spds,n_joints,joints,remappedControlBoards);
3877 
3878  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3879  {
3880  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3881 
3882  bool ok = p->vel->velocityMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3883  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3884  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3885  ret = ret && ok;
3886  }
3887 
3888  return ret;
3889 }
3890 
3891 bool ControlBoardRemapper::getRefVelocity(const int j, double* vel)
3892 {
3893  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3894  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3895 
3896  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3897 
3898  if (!p)
3899  {
3900  return false;
3901  }
3902 
3903  if (p->vel)
3904  {
3905  bool ret = p->vel->getRefVelocity(off, vel);
3906  return ret;
3907  }
3908 
3909  return false;
3910 }
3911 
3912 
3914 {
3915  bool ret=true;
3916  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3917 
3918  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3919  {
3920  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3921 
3922  bool ok = true;
3923 
3924  if( p->vel )
3925  {
3926  ok = p->vel->getRefVelocities(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3927  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3928  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3929  }
3930  else
3931  {
3932  ok = false;
3933  }
3934 
3935  ret = ret && ok;
3936  }
3937 
3938  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(vels,remappedControlBoards);
3939 
3940  return ret;
3941 }
3942 
3943 bool ControlBoardRemapper::getRefVelocities(const int n_joints, const int* joints, double* vels)
3944 {
3945  bool ret=true;
3946  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3947 
3948  // Resize the input buffers
3949  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
3950 
3951  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3952  {
3953  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3954 
3955  bool ok = true;
3956 
3957  if( p->vel )
3958  {
3959  ok = p->vel->getRefVelocities(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3960  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3961  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3962  }
3963  else
3964  {
3965  ok = false;
3966  }
3967 
3968  ret = ret && ok;
3969  }
3970 
3971  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(vels,n_joints,joints,remappedControlBoards);
3972 
3973  return ret;
3974 }
3975 
3977 {
3978  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3979  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3980 
3981  RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
3982 
3983  if (!s)
3984  {
3985  return false;
3986  }
3987 
3988  if (s->iInteract)
3989  {
3990  return s->iInteract->getInteractionMode(off, mode);
3991  }
3992 
3993  return false;
3994 }
3995 
3997 {
3998  bool ret=true;
3999  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4000 
4001  // Resize the input buffers
4002  selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
4003 
4004  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4005  {
4006  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4007 
4008  bool ok = true;
4009 
4010  if( p->iMode )
4011  {
4012  ok = p->iInteract->getInteractionModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4013  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4014  selectedJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4015  }
4016  else
4017  {
4018  ok = false;
4019  }
4020 
4021  ret = ret && ok;
4022  }
4023 
4024  selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(modes,n_joints,joints,remappedControlBoards);
4025 
4026  return ret;
4027 }
4028 
4030 {
4031  bool ret=true;
4032  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4033 
4034  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4035  {
4036  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4037 
4038  bool ok = true;
4039 
4040  if( p->iMode )
4041  {
4042  ok = p->iInteract->getInteractionModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4043  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4044  allJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4045  }
4046  else
4047  {
4048  ok = false;
4049  }
4050 
4051  ret = ret && ok;
4052  }
4053 
4054  allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(modes,remappedControlBoards);
4055 
4056  return ret;
4057 }
4058 
4060 {
4061  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4062  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4063 
4064  RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
4065 
4066  if (!s)
4067  {
4068  return false;
4069  }
4070 
4071  if (s->iInteract)
4072  {
4073  return s->iInteract->setInteractionMode(off, mode);
4074  }
4075 
4076  return false;
4077 }
4078 
4080 {
4081  bool ret=true;
4082  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4083 
4084  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(modes,n_joints,joints,remappedControlBoards);
4085 
4086  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4087  {
4088  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4089 
4090  bool ok = p->iInteract->setInteractionModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4091  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4092  selectedJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4093  ret = ret && ok;
4094  }
4095 
4096  return ret;
4097 }
4098 
4100 {
4101  bool ret=true;
4102  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4103 
4104  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(modes,remappedControlBoards);
4105 
4106  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4107  {
4108  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4109 
4110  bool ok = p->iInteract->setInteractionModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4111  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4112  allJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4113  ret = ret && ok;
4114  }
4115 
4116  return ret;
4117 }
4118 
4120 {
4121  bool ret = false;
4122 
4123  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4124 
4125  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4126 
4127  if (p && p->iPwm)
4128  {
4129  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4130  ret = p->iPwm->setRefDutyCycle(off, ref);
4131  }
4132 
4133  return ret;
4134 }
4135 
4137 {
4138  bool ret=true;
4139 
4140  for(int l=0;l<controlledJoints;l++)
4141  {
4142  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4143  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4144 
4145  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4146 
4147  if (!p)
4148  {
4149  return false;
4150  }
4151 
4152  if (p->iPwm)
4153  {
4154  bool ok = p->iPwm->setRefDutyCycle(off, refs[l]);
4155  ret = ret && ok;
4156  }
4157  else
4158  {
4159  ret=false;
4160  }
4161  }
4162 
4163  return ret;
4164 }
4165 
4167 {
4168  bool ret = false;
4169 
4170  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4171 
4172  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4173 
4174  if (p && p->iPwm)
4175  {
4176  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4177  ret = p->iPwm->getRefDutyCycle(off, ref);
4178  }
4179 
4180  return ret;
4181 }
4182 
4184 {
4185  bool ret=true;
4186 
4187  for(int l=0;l<controlledJoints;l++)
4188  {
4189  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4190  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4191 
4192  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4193 
4194  if (!p)
4195  {
4196  return false;
4197  }
4198 
4199  if (p->iPwm)
4200  {
4201  bool ok = p->iPwm->getRefDutyCycle(off, refs+l);
4202  ret = ret && ok;
4203  }
4204  else
4205  {
4206  ret=false;
4207  }
4208  }
4209 
4210  return ret;
4211 }
4212 
4213 bool ControlBoardRemapper::getDutyCycle(int m, double* val)
4214 {
4215  bool ret = false;
4216 
4217  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4218 
4219  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4220 
4221  if (p && p->iPwm)
4222  {
4223  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4224  ret = p->iPwm->getDutyCycle(off, val);
4225  }
4226 
4227  return ret;
4228 }
4229 
4231 {
4232  bool ret=true;
4233 
4234  for(int l=0;l<controlledJoints;l++)
4235  {
4236  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4237  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4238 
4239  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4240 
4241  if (!p)
4242  {
4243  return false;
4244  }
4245 
4246  if (p->iPwm)
4247  {
4248  bool ok = p->iPwm->getDutyCycle(off, vals+l);
4249  ret = ret && ok;
4250  }
4251  else
4252  {
4253  ret=false;
4254  }
4255  }
4256 
4257  return ret;
4258 }
4259 
4260 bool ControlBoardRemapper::getCurrent(int j, double *val)
4261 {
4262  bool ret = false;
4263 
4264  size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4265 
4266  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4267 
4268  if (p && p->iCurr)
4269  {
4270  int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4271  ret = p->iCurr->getCurrent(off, val);
4272  }
4273 
4274  return ret;
4275 }
4276 
4278 {
4279  bool ret=true;
4280 
4281  for(int l=0;l<controlledJoints;l++)
4282  {
4283  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4284  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4285 
4286  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4287 
4288  if (!p)
4289  {
4290  return false;
4291  }
4292 
4293  if (p->iCurr)
4294  {
4295  bool ok = p->iCurr->getCurrent(off, vals+l);
4296  ret = ret && ok;
4297  }
4298  else
4299  {
4300  ret=false;
4301  }
4302  }
4303 
4304  return ret;
4305 }
4306 
4307 bool ControlBoardRemapper::getCurrentRange(int m, double* min, double* max)
4308 {
4309  bool ret = false;
4310 
4311  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4312 
4313  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4314 
4315  if (p && p->iCurr)
4316  {
4317  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4318  ret = p->iCurr->getCurrentRange(off, min, max);
4319  }
4320 
4321  return ret;
4322 }
4323 
4324 bool ControlBoardRemapper::getCurrentRanges(double* min, double* max)
4325 {
4326  bool ret=true;
4327 
4328  for(int l=0;l<controlledJoints;l++)
4329  {
4330  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4331  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4332 
4333  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4334 
4335  if (!p)
4336  {
4337  return false;
4338  }
4339 
4340  if (p->iCurr)
4341  {
4342  bool ok = p->iCurr->getCurrentRange(off, min+l, max+l);
4343  ret = ret && ok;
4344  }
4345  else
4346  {
4347  ret=false;
4348  }
4349  }
4350 
4351  return ret;
4352 }
4353 
4354 bool ControlBoardRemapper::setRefCurrent(int m, double curr)
4355 {
4356  bool ret = false;
4357 
4358  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4359 
4360  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4361 
4362  if (p && p->iCurr)
4363  {
4364  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4365  ret = p->iCurr->setRefCurrent(off, curr);
4366  }
4367 
4368  return ret;
4369 }
4370 
4371 bool ControlBoardRemapper::setRefCurrents(const int n_motor, const int* motors, const double* currs)
4372 {
4373  bool ret=true;
4374  std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4375 
4376  selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(currs,n_motor,motors,remappedControlBoards);
4377 
4378  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4379  {
4380  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4381 
4382  if (!(p && p->iCurr))
4383  {
4384  ret = false;
4385  break;
4386  }
4387 
4388  bool ok = p->iCurr->setRefCurrents(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4389  selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4390  selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4391  ret = ret && ok;
4392  }
4393 
4394  return ret;
4395 }
4396 
4397 bool ControlBoardRemapper::setRefCurrents(const double* currs)
4398 {
4399  bool ret=true;
4400  std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4401 
4402  allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(currs,remappedControlBoards);
4403 
4404  for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4405  {
4406  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4407 
4408  bool ok = p->iCurr->setRefCurrents(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4409  allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4410  allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4411  ret = ret && ok;
4412  }
4413 
4414  return ret;
4415 }
4416 
4417 bool ControlBoardRemapper::getRefCurrent(int m, double* curr)
4418 {
4419  bool ret = false;
4420 
4421  size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4422 
4423  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4424 
4425  if (p && p->iCurr)
4426  {
4427  int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4428  ret = p->iCurr->getRefCurrent(off, curr);
4429  }
4430 
4431  return ret;
4432 }
4433 
4435 {
4436  bool ret=true;
4437 
4438  for(int l=0;l<controlledJoints;l++)
4439  {
4440  int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4441  size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4442 
4443  RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4444 
4445  if (!p)
4446  {
4447  return false;
4448  }
4449 
4450  if (p->iCurr)
4451  {
4452  bool ok = p->iCurr->getRefCurrent(off, currs+l);
4453  ret = ret && ok;
4454  }
4455  else
4456  {
4457  ret=false;
4458  }
4459  }
4460 
4461  return ret;
4462 }
const yarp::os::LogComponent & CONTROLBOARDREMAPPER()
float t
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
Definition: IControlMode.h:123
bool ret
bool parkWholePart() override
parkWholePart: start the parking procedure for the whole part
bool setImpedance(int j, double stiff, double damp) override
Set current impedance gains (stiffness,damping) for a specific joint.
bool getPidErrorLimit(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *limit) override
Get the error limit for the controller on a specific joint.
bool setRefAccelerations(const double *accs) override
Set reference acceleration on all joints.
bool resetMotorEncoder(int m) override
Reset motor encoder, single motor.
bool getTorqueRange(int j, double *min, double *max) override
Get the full scale of the torque sensor of a given joint.
bool getTargetPosition(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets number of counts per revolution for motor encoder m.
bool getAmpStatus(int *st) override
bool setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
bool setPid(const yarp::dev::PidControlTypeEnum &pidtype, int j, const yarp::dev::Pid &p) override
ControlBoard methods.
bool setRefCurrent(int m, double curr) override
Set the reference value of the current for a single motor.
bool getEncoderSpeeds(double *spds) override
Read the instantaneous speed of all axes.
bool getControlMode(int j, int *mode) override
Get the current control mode.
bool getRefPositions(double *refs) override
Get the last position reference for all axes.
bool setRefSpeed(int j, double sp) override
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
bool setNominalCurrent(int m, const double val) override
bool getMotorEncoderTimed(int m, double *v, double *t) override
Read the instantaneous position of a motor encoder.
bool getRefCurrents(double *currs) override
Get the reference value of the currents for all motors.
bool close() override
Close the device driver by deallocating all resources and closing ports.
bool getTorques(double *t) override
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
bool getRemoteVariable(std::string key, yarp::os::Bottle &val) override
bool checkMotionDone(int j, bool *flag) override
Check if the current trajectory is terminated.
bool calibrationDone(int j) override
Check if the calibration is terminated, on a particular joint.
bool getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp) override
Get the current impedandance limits for a specific joint.
bool setPWMLimit(int m, const double val) override
bool getTemperatureLimit(int m, double *val) override
Retreives the current temperature limit for a specific motor.
bool getAxes(int *ax) override
Get the number of controlled axes.
bool setPidOffset(const yarp::dev::PidControlTypeEnum &pidtype, int j, double v) override
Set offset value for a given controller.
bool setEncoder(int j, double val) override
Set the value of the encoder for a given joint.
bool setRefAcceleration(int j, double acc) override
Set reference acceleration for a joint.
bool getPid(const yarp::dev::PidControlTypeEnum &pidtype, int j, yarp::dev::Pid *p) override
Get current pid value for a specific joint.
bool getImpedanceOffset(int j, double *offset) override
Get current force Offset for a specific joint.
bool getEncoderSpeed(int j, double *sp) override
Read the istantaneous speed of an axis.
bool getRefSpeed(int j, double *ref) override
Get reference speed for a joint.
bool resetEncoder(int j) override
Reset encoder, single joint.
bool getDutyCycles(double *vals) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool getEncoderAcceleration(int j, double *acc) override
Read the instantaneous acceleration of an axis.
bool setControlModes(const int n_joints, const int *joints, int *modes) override
Set the current control mode for a subset of axes.
bool getEncoderTimed(int j, double *v, double *t) override
Read the instantaneous acceleration of all axes.
bool getImpedance(int j, double *stiff, double *damp) override
Get current impedance gains (stiffness,damping,offset) for a specific joint.
bool getEncoders(double *encs) override
Read the position of all axes.
bool getRefPosition(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool setVelLimits(int j, double min, double max) override
Set the software speed limits for a particular axis, the behavior of the control card when these limi...
bool getEncoder(int j, double *v) override
Read the value of an encoder.
bool getMotorEncoder(int m, double *v) override
Read the value of a motor encoder.
bool getTorqueRanges(double *min, double *max) override
Get the full scale of the torque sensors of all joints.
bool getMotorEncodersTimed(double *encs, double *t) override
Read the instantaneous position of all motor encoders.
bool setRefTorque(int j, double t) override
Set the reference value of the torque for a given joint.
bool getNumberOfMotors(int *num) override
Retrieves the number of controlled axes from the current physical interface.
bool disableAmp(int j) override
Disable the amplifier on a specific joint.
bool setInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
bool getPeakCurrent(int m, double *val) override
bool setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
bool quitCalibrate() override
quitCalibrate: interrupt the calibration procedure
bool calibrateAxisWithParams(int j, unsigned int ui, double v1, double v2, double v3) override
Start calibration, this method is very often platform specific.
bool getAxisName(int j, std::string &name) override
bool getControlModes(int *modes) override
Get the current control mode (multiple joints).
bool getRefTorques(double *refs) override
Get the reference value of the torque for all joints.
bool getPidReferences(const yarp::dev::PidControlTypeEnum &pidtype, double *refs) override
Get the current reference of all pid controllers.
bool isPidEnabled(const yarp::dev::PidControlTypeEnum &pidtype, int j, bool *enabled) override
Get the current status (enabled/disabled) of the pid.
bool getRefVelocity(const int joint, double *vel) override
Get the last reference speed set by velocityMove for single joint.
bool setPidErrorLimits(const yarp::dev::PidControlTypeEnum &pidtype, const double *limits) override
Get the error limit for the controller on all joints.
bool setRefCurrents(const double *currs) override
Set the reference value of the currents for all motors.
bool setMotorTorqueParams(int j, const yarp::dev::MotorTorqueParameters params) override
Set a subset of motor parameters (bemf, ktau etc) useful for torque control.
bool open(yarp::os::Searchable &prop) override
Open the device driver.
bool setPidErrorLimit(const yarp::dev::PidControlTypeEnum &pidtype, int j, double limit) override
Set the error limit for the controller on a specifi joint.
bool setMaxCurrent(int j, double v) override
yarp::dev::IRemoteCalibrator * getCalibratorDevice() override
getCalibratorDevice: return the pointer stored with the setCalibratorDevice
bool enablePid(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Enable the pid computation for a joint.
bool calibrateWholePart() override
calibrateWholePart: call the procedure for calibrating the whole device
bool getLimits(int j, double *min, double *max) override
Get the software limits for a particular axis.
bool getRefDutyCycles(double *refs) override
Gets the last reference sent using the setRefDutyCycles function.
bool getPidReference(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *ref) override
Get the current reference of the pid controller for a specific joint.
bool setRefSpeeds(const double *spds) override
Set reference speed on all joints.
bool getNominalCurrent(int m, double *val) override
bool getRefVelocities(double *vels) override
Get the last reference speed set by velocityMove for all joints.
bool setEncoders(const double *vals) override
Set the value of all encoders.
bool getInteractionMode(int j, yarp::dev::InteractionModeEnum *mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
bool setMotorEncoder(int m, const double val) override
Set the value of the motor encoder for a given motor.
bool getPidErrors(const yarp::dev::PidControlTypeEnum &pidtype, double *errs) override
Get the error of all joints.
bool getPidError(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *err) override
Get the current error for a joint.
bool getPidErrorLimits(const yarp::dev::PidControlTypeEnum &pidtype, double *limits) override
Get the error limit for all controllers.
bool getCurrent(int m, double *curr) override
bool detachAll() override
Detach the object (you must have first called attach).
bool setPids(const yarp::dev::PidControlTypeEnum &pidtype, const yarp::dev::Pid *ps) override
Set new pid value on multiple axes.
bool parkSingleJoint(int j, bool _wait=true) override
parkSingleJoint(): start the parking procedure for the single joint
bool calibrateSingleJoint(int j) override
calibrateSingleJoint: call the calibration procedure for the single joint
bool getRefTorque(int j, double *t) override
Get the reference value of the torque for a given joint.
bool quitPark() override
quitPark: interrupt the park procedure
bool velocityMove(int j, double v) override
Start motion at a given speed, single joint.
bool getRefDutyCycle(int m, double *ref) override
Gets the last reference sent using the setRefDutyCycle function.
bool getNumberOfMotorEncoders(int *num) override
Get the number of available motor encoders.
bool getPidOutput(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *out) override
Get the output of the controller (e.g.
bool getMotorEncoderAcceleration(int m, double *acc) override
Read the instantaneous acceleration of a motor encoder.
bool setLimits(int j, double min, double max) override
Set the software limits for a particular axis, the behavior of the control card when these limits are...
bool setMotorEncoders(const double *vals) override
Set the value of all motor encoders.
bool getMotorEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all motor encoders.
bool setPidReferences(const yarp::dev::PidControlTypeEnum &pidtype, const double *refs) override
Set the controller reference, multiple axes.
bool getTargetPositions(double *refs) override
Get the last position reference for all axes.
bool getPWM(int m, double *val) override
bool setRemoteVariable(std::string key, const yarp::os::Bottle &val) override
bool setImpedanceOffset(int j, double offset) override
Set current force Offset for a specific joint.
bool getPidOutputs(const yarp::dev::PidControlTypeEnum &pidtype, double *outs) override
Get the output of the controllers (e.g.
bool getJointType(int j, yarp::dev::JointTypeEnum &type) override
bool resetEncoders() override
Reset encoders.
bool setRefDutyCycles(const double *refs) override
Sets the reference dutycycle for all the motors.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
bool getDutyCycle(int m, double *val) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool getCurrentRanges(double *min, double *max) override
Get the full scale of the current measurements for all motors motor (e.g.
bool attachAll(const yarp::dev::PolyDriverList &l) override
Attach to a list of objects.
bool getMotorTorqueParams(int j, yarp::dev::MotorTorqueParameters *params) override
Get a subset of motor parameters (bemf, ktau etc) useful for torque control.
bool setRefTorques(const double *t) override
Set the reference value of the torque for all joints.
bool resetMotorEncoders() override
Reset motor encoders.
bool getTorque(int j, double *t) override
Get the value of the torque on a given joint (this is the feedback if you have a torque sensor).
bool getRefCurrent(int m, double *curr) override
Get the reference value of the current for a single motor.
bool setInteractionMode(int j, yarp::dev::InteractionModeEnum mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
bool getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
bool getVelLimits(int j, double *min, double *max) override
Get the software speed limits for a particular axis.
bool getRefAccelerations(double *accs) override
Get reference acceleration of all joints.
bool enableAmp(int j) override
Enable the amplifier on a specific joint.
bool positionMove(int j, double ref) override
Set new reference point for a single axis.
bool disablePid(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Disable the pid computation for a joint.
bool getTemperatures(double *vals) override
Get temperature of all the motors.
bool resetPid(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Reset the controller of a given joint, usually sets the current status of the joint as the reference ...
bool getCurrentRange(int m, double *min, double *max) override
Get the full scale of the current measurement for a given motor (e.g.
bool getTemperature(int m, double *val) override
Get temperature of a motor.
bool setControlMode(const int j, const int mode) override
Set the current control mode.
bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
bool isCalibratorDevicePresent(bool *isCalib) override
isCalibratorDevicePresent: check if a calibrator device has been set
bool setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
bool getPowerSupplyVoltage(int m, double *val) override
bool getMotorEncoders(double *encs) override
Read the position of all motor encoders.
bool setPositions(const int n_joints, const int *joints, const double *dpos) override
Set new reference point for all axes.
bool setCalibrationParameters(int j, const yarp::dev::CalibrationParameters &params) override
Start calibration, this method is very often platform specific.
bool stop() override
Stop motion, multiple joints.
bool getCurrents(double *currs) override
bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys) override
bool getPWMLimit(int m, double *val) override
bool getEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all axes.
bool setPeakCurrent(int m, const double val) override
bool homingWholePart() override
homingWholePart: call the homing procedure for a the whole part/device
bool getMotorEncoderSpeed(int m, double *sp) override
Read the istantaneous speed of a motor encoder.
bool homingSingleJoint(int j) override
homingSingleJoint: call the homing procedure for a single joint
bool getRefAcceleration(int j, double *acc) override
Get reference acceleration for a joint.
bool getEncodersTimed(double *encs, double *t) override
Read the instantaneous acceleration of all axes.
bool getRefSpeeds(double *spds) override
Get reference speed of all joints.
bool setRefDutyCycle(int m, double ref) override
Sets the reference dutycycle to a single motor.
bool getMaxCurrent(int j, double *v) override
Returns the maximum electric current allowed for a given motor.
bool setPidReference(const yarp::dev::PidControlTypeEnum &pidtype, int j, double ref) override
Set the controller reference for a given axis.
bool getMotorEncoderSpeeds(double *spds) override
Read the instantaneous speed of all motor encoders.
bool getPids(const yarp::dev::PidControlTypeEnum &pidtype, yarp::dev::Pid *pids) override
Get current pid value for a specific joint.
bool setPosition(int j, double ref) override
Set new position for a single axis.
bool relativeMove(int j, double delta) override
Set relative position.
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::IMotorEncoders * iMotEnc
yarp::dev::IPreciselyTimed * iTimed
virtual bool getPWMLimit(int j, double *val)
virtual bool enableAmp(int j)=0
Enable the amplifier on a specific joint.
virtual bool setNominalCurrent(int m, const double val)
virtual bool getPWM(int j, double *val)
virtual bool getAmpStatus(int *st)=0
virtual bool setPWMLimit(int j, const double val)
virtual bool getMaxCurrent(int j, double *v)=0
Returns the maximum electric current allowed for a given motor.
virtual bool getNominalCurrent(int m, double *val)
virtual bool getPowerSupplyVoltage(int j, double *val)
virtual bool setMaxCurrent(int j, double v)=0
virtual bool setPeakCurrent(int m, const double val)
virtual bool getPeakCurrent(int m, double *val)
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:40
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
Definition: IAxisInfo.h:59
virtual bool setCalibrationParameters(int axis, const CalibrationParameters &params)
Start calibration, this method is very often platform specific.
virtual bool calibrationDone(int j)=0
Check if the calibration is terminated, on a particular joint.
virtual bool calibrateAxisWithParams(int axis, unsigned int type, double p1, double p2, double p3)=0
Start calibration, this method is very often platform specific.
virtual bool getVelLimits(int axis, double *min, double *max)=0
Get the software speed limits for a particular axis.
virtual bool getLimits(int axis, double *min, double *max)=0
Get the software limits for a particular axis.
virtual bool setLimits(int axis, double min, double max)=0
Set the software limits for a particular axis, the behavior of the control card when these limits are...
virtual bool setVelLimits(int axis, double min, double max)=0
Set the software speed limits for a particular axis, the behavior of the control card when these limi...
virtual bool setControlModes(const int n_joint, const int *joints, int *modes)=0
Set the current control mode for a subset of axes.
virtual bool getControlModes(int *modes)=0
Get the current control mode (multiple joints).
virtual bool getControlMode(int j, int *mode)=0
Get the current control mode.
virtual bool setRefCurrent(int m, double curr)=0
Set the reference value of the current for a single motor.
virtual bool setRefCurrents(const double *currs)=0
Set the reference value of the currents for all motors.
virtual bool getCurrent(int m, double *curr)=0
Get the instantaneous current measurement for a single motor.
virtual bool getCurrentRange(int m, double *min, double *max)=0
Get the full scale of the current measurement for a given motor (e.g.
virtual bool getRefCurrent(int m, double *curr)=0
Get the reference value of the current for a single motor.
virtual bool getEncoderTimed(int j, double *encs, double *time)=0
Read the instantaneous acceleration of all axes.
Control board, encoder interface.
Definition: IEncoders.h:118
virtual bool getEncoderSpeed(int j, double *sp)=0
Read the istantaneous speed of an axis.
virtual bool setEncoder(int j, double val)=0
Set the value of the encoder for a given joint.
virtual bool getEncoder(int j, double *v)=0
Read the value of an encoder.
virtual bool resetEncoder(int j)=0
Reset encoder, single joint.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getEncoderAcceleration(int j, double *spds)=0
Read the instantaneous acceleration of an axis.
virtual bool setImpedance(int j, double stiffness, double damping)=0
Set current impedance gains (stiffness,damping) for a specific joint.
virtual bool getImpedanceOffset(int j, double *offset)=0
Get current force Offset for a specific joint.
virtual bool setImpedanceOffset(int j, double offset)=0
Set current force Offset for a specific joint.
virtual bool getImpedance(int j, double *stiffness, double *damping)=0
Get current impedance gains (stiffness,damping,offset) for a specific joint.
virtual bool getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)=0
Get the current impedandance limits for a specific joint.
virtual bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum *mode)=0
Get the current interaction mode of the robot, values can be stiff or compliant.
virtual bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool setInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
virtual bool getMotorEncoderCountsPerRevolution(int m, double *cpr)=0
Gets number of counts per revolution for motor encoder m.
virtual bool setMotorEncoderCountsPerRevolution(int m, const double cpr)=0
Sets number of counts per revolution for motor encoder m.
virtual bool resetMotorEncoder(int m)=0
Reset motor encoder, single motor.
virtual bool getMotorEncoderSpeed(int m, double *sp)=0
Read the istantaneous speed of a motor encoder.
virtual bool getMotorEncoderTimed(int m, double *encs, double *time)=0
Read the instantaneous position of a motor encoder.
virtual bool getMotorEncoderAcceleration(int m, double *acc)=0
Read the instantaneous acceleration of a motor encoder.
virtual bool setMotorEncoder(int m, const double val)=0
Set the value of the motor encoder for a given motor.
virtual bool getMotorEncoder(int m, double *v)=0
Read the value of a motor encoder.
virtual bool getTemperature(int m, double *val)=0
Get temperature of a motor.
virtual bool getTemperatureLimit(int m, double *temp)=0
Retreives the current temperature limit for a specific motor.
virtual bool getGearboxRatio(int m, double *val)
Get the gearbox ratio for a specific motor.
Definition: IMotor.h:149
virtual bool setTemperatureLimit(int m, const double temp)=0
Set the temperature limit for a specific motor.
virtual bool setGearboxRatio(int m, const double val)
Set the gearbox ratio for a specific motor.
Definition: IMotor.h:157
virtual bool getDutyCycle(int m, double *val)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual bool setRefDutyCycle(int m, double ref)=0
Sets the reference dutycycle to a single motor.
virtual bool getRefDutyCycle(int m, double *ref)=0
Gets the last reference sent using the setRefDutyCycle function.
virtual bool setPid(const PidControlTypeEnum &pidtype, int j, const Pid &pid)=0
Set new pid value for a joint axis.
virtual bool getPidReference(const PidControlTypeEnum &pidtype, int j, double *ref)=0
Get the current reference of the pid controller for a specific joint.
virtual bool getPidOutput(const PidControlTypeEnum &pidtype, int j, double *out)=0
Get the output of the controller (e.g.
virtual bool resetPid(const PidControlTypeEnum &pidtype, int j)=0
Reset the controller of a given joint, usually sets the current status of the joint as the reference ...
virtual bool setPidOffset(const PidControlTypeEnum &pidtype, int j, double v)=0
Set offset value for a given controller.
virtual bool getPidError(const PidControlTypeEnum &pidtype, int j, double *err)=0
Get the current error for a joint.
virtual bool getPidErrorLimit(const PidControlTypeEnum &pidtype, int j, double *limit)=0
Get the error limit for the controller on a specific joint.
virtual bool setPidErrorLimit(const PidControlTypeEnum &pidtype, int j, double limit)=0
Set the error limit for the controller on a specifi joint.
virtual bool disablePid(const PidControlTypeEnum &pidtype, int j)=0
Disable the pid computation for a joint.
virtual bool setPidReference(const PidControlTypeEnum &pidtype, int j, double ref)=0
Set the controller reference for a given axis.
virtual bool enablePid(const PidControlTypeEnum &pidtype, int j)=0
Enable the pid computation for a joint.
virtual bool isPidEnabled(const PidControlTypeEnum &pidtype, int j, bool *enabled)=0
Get the current status (enabled/disabled) of the pid.
virtual bool getPid(const PidControlTypeEnum &pidtype, int j, Pid *pid)=0
Get current pid value for a specific joint.
virtual bool getRefAcceleration(int j, double *acc)=0
Get reference acceleration for a joint.
virtual bool setRefSpeed(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual bool setRefAcceleration(int j, double acc)=0
Set reference acceleration for a joint.
virtual bool relativeMove(int j, double delta)=0
Set relative position.
virtual bool setRefSpeeds(const double *spds)=0
Set reference speed on all joints.
virtual bool checkMotionDone(int j, bool *flag)=0
Check if the current trajectory is terminated.
virtual bool getRefSpeeds(double *spds)=0
Get reference speed of all joints.
virtual bool stop(int j)=0
Stop motion, single joint.
virtual bool setRefAccelerations(const double *accs)=0
Set reference acceleration on all joints.
virtual bool getRefAccelerations(double *accs)=0
Get reference acceleration of all joints.
virtual bool getRefSpeed(int j, double *ref)=0
Get reference speed for a joint.
virtual bool positionMove(int j, double ref)=0
Set new reference point for a single axis.
virtual bool getTargetPositions(double *refs)
Get the last position reference for all axes.
virtual bool getRefPositions(double *refs)
Get the last position reference for all axes.
virtual bool setPositions(const int n_joint, const int *joints, const double *refs)=0
Set new reference point for all axes.
virtual bool setPosition(int j, double ref)=0
Set new position for a single axis.
virtual yarp::os::Stamp getLastInputStamp()=0
Return the time stamp relative to the last acquisition.
IRemoteCalibrator interface is meant to remotize the access of the calibration device in order to all...
virtual bool homingSingleJoint(int j)=0
homingSingleJoint: call the homing procedure for a single joint
virtual bool isCalibratorDevicePresent(bool *isCalib)
isCalibratorDevicePresent: check if a calibrator device has been set
virtual bool quitPark()=0
quitPark: interrupt the park procedure
virtual bool parkSingleJoint(int j, bool _wait=true)=0
parkSingleJoint(): start the parking procedure for the single joint
virtual bool calibrateSingleJoint(int j)=0
calibrateSingleJoint: call the calibration procedure for the single joint
virtual bool calibrateWholePart()=0
calibrateWholePart: call the procedure for calibrating the whole device
virtual bool quitCalibrate()=0
quitCalibrate: interrupt the calibration procedure
virtual yarp::dev::IRemoteCalibrator * getCalibratorDevice()
getCalibratorDevice: return the pointer stored with the setCalibratorDevice
virtual bool setRemoteVariable(std::string key, const yarp::os::Bottle &val)=0
virtual bool getRemoteVariable(std::string key, yarp::os::Bottle &val)=0
virtual bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys)=0
virtual bool setRefTorque(int j, double t)=0
Set the reference value of the torque for a given joint.
virtual bool setRefTorques(const double *t)=0
Set the reference value of the torque for all joints.
virtual bool setMotorTorqueParams(int j, const yarp::dev::MotorTorqueParameters params)
Set a subset of motor parameters (bemf, ktau etc) useful for torque control.
virtual bool getMotorTorqueParams(int j, yarp::dev::MotorTorqueParameters *params)
Get a subset of motor parameters (bemf, ktau etc) useful for torque control.
virtual bool getTorqueRange(int j, double *min, double *max)=0
Get the full scale of the torque sensor of a given joint.
virtual bool getRefTorque(int j, double *t)=0
Get the reference value of the torque for a given joint.
virtual bool getTorque(int j, double *t)=0
Get the value of the torque on a given joint (this is the feedback if you have a torque sensor).
virtual bool velocityMove(int j, double sp)=0
Start motion at a given speed, single joint.
virtual bool getRefVelocities(double *vels)
Get the last reference speed set by velocityMove for all joints.
Contains the parameters for a PID.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:204
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition: Bottle.cpp:380
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
A class for storing options and configuration information.
Definition: Property.h:34
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1051
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1063
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1041
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition: Property.cpp:1142
A base class for nested structures that can be searched.
Definition: Searchable.h:66
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22
double getTime() const
Get the time stamp.
Definition: Stamp.cpp:34
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:240
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
#define yCInfo(component,...)
Definition: LogComponent.h:132
#define yCError(component,...)
Definition: LogComponent.h:154
#define yCWarning(component,...)
Definition: LogComponent.h:143
An interface for the device drivers.
PidControlTypeEnum
Definition: PidEnums.h:18
An interface to the operating system, including Port based communication.
Signal processing.
Definition: Image.h:22
size_t indexOfSubDeviceInPolyDriverList
std::string subDeviceKey