YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
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
19using namespace yarp::os;
20using namespace yarp::dev;
21using 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
47bool 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
82bool 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
102bool 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();
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
204void 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
212bool 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
280
281
282bool 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
296 polylist[p]->poly->view(calibrator);
297
299 continue;
300 }
301
302 // find if one of the desired axis is in this device
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) << "sub-device" << deviceKey << "does not implemented the required IAxisInfo or IEncoders interfaces";
312 return false;
313 }
314
316 bool ok = iencs->getAxes(&nrOfSubdeviceAxes);
317
318 if( !ok )
319 {
320 yCError(CONTROLBOARDREMAPPER) << "sub-device" << deviceKey << "does not implemented the required getAxes method";
321 return false;
322 }
323
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) << "sub-device" << 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
348 newLocation.subDeviceKey = polylist[p]->key;
349 newLocation.indexInSubDevice = axInSubDevice;
350 newLocation.indexOfSubDeviceInPolyDriverList = p;
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 */
381 subControlBoardsKeys.push_back(key);
383 }
384 }
385
386 assert(controlledJoints == (int) axesNames.size());
387
388 // We have now the number of controlboards to attach to
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 {
398 tmpDevice->setVerbose(_verb);
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
420bool 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
430 polylist[p]->poly->view(calibrator);
431
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
471 return true;
472}
473
474void ControlBoardRemapper::configureBuffers()
475{
476 allJointsBuffers.configure(remappedControlBoards);
477 selectedJointsBuffers.configure(remappedControlBoards);
478}
479
480
481bool 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//
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 = true;
1018 if (p->pos) {
1019 ok = p->pos->positionMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1020 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1021 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1022 }
1023 else {
1024 ok = false;
1025 }
1026 ret = ret && ok;
1027 }
1028
1029 return ret;
1030}
1031
1032bool ControlBoardRemapper::positionMove(const int n_joints, const int *joints, const double *refs)
1033{
1034 bool ret=true;
1035 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1036
1037 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(refs,n_joints,joints,remappedControlBoards);
1038
1039 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1040 {
1041 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1042
1043 bool ok = true;
1044 if (p->pos) {
1045 ok = p->pos->positionMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1046 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1047 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1048 }
1049 else {
1050 ok = false;
1051 }
1052 ret = ret && ok;
1053 }
1054
1055 return ret;
1056}
1057
1058bool ControlBoardRemapper::getTargetPosition(const int j, double* ref)
1059{
1060 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1061 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1062
1063 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1064
1065 if (!p)
1066 {
1067 return false;
1068 }
1069
1070 if (p->pos)
1071 {
1072 bool ret = p->pos->getTargetPosition(off, ref);
1073 return ret;
1074 }
1075
1076 return false;
1077}
1078
1080{
1081 bool ret=true;
1082 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1083
1084 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1085 {
1086 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1087
1088 bool ok = true;
1089
1090 if( p->pos )
1091 {
1092 ok = p->pos->getTargetPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1093 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1094 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1095 }
1096 else
1097 {
1098 ok = false;
1099 }
1100
1101 ret = ret && ok;
1102 }
1103
1104 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
1105
1106 return ret;
1107}
1108
1109
1110bool ControlBoardRemapper::getTargetPositions(const int n_joints, const int *joints, double *targets)
1111{
1112 bool ret=true;
1113 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1114
1115 // Resize the input buffers
1116 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1117
1118 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1119 {
1120 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1121
1122 bool ok = true;
1123
1124 if( p->pos )
1125 {
1126 ok = p->pos->getTargetPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1127 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1128 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1129 }
1130 else
1131 {
1132 ok = false;
1133 }
1134
1135 ret = ret && ok;
1136 }
1137
1138 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(targets,n_joints,joints,remappedControlBoards);
1139
1140 return ret;
1141}
1142
1144{
1145 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1146 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1147
1148 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1149
1150 if (!p)
1151 {
1152 return false;
1153 }
1154
1155 if (p->pos)
1156 {
1157 return p->pos->relativeMove(off, delta);
1158 }
1159
1160 return false;
1161}
1162
1164{
1165 bool ret=true;
1166 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1167
1168 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(deltas,remappedControlBoards);
1169
1170 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1171 {
1172 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1173 bool ok = true;
1174 if (p->pos) {
1175 ok = p->pos->relativeMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1176 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1177 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1178 }
1179 else {
1180 ok = false;
1181 }
1182 ret = ret && ok;
1183 }
1184
1185 return ret;
1186}
1187
1188bool ControlBoardRemapper::relativeMove(const int n_joints, const int *joints, const double *deltas)
1189{
1190 bool ret=true;
1191 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1192
1193 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(deltas,n_joints,joints,remappedControlBoards);
1194
1195 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1196 {
1197 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1198 bool ok = true;
1199 if (p->pos) {
1200 ok = p->pos->relativeMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1201 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1202 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1203 }
1204 else {
1205 ok = false;
1206 }
1207 ret = ret && ok;
1208 }
1209
1210 return ret;
1211}
1212
1214{
1215 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1216 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1217
1218 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1219
1220 if (!p)
1221 {
1222 return false;
1223 }
1224
1225 if (p->pos)
1226 {
1227 return p->pos->checkMotionDone(off, flag);
1228 }
1229
1230 return false;
1231}
1232
1234{
1235 bool ret=true;
1236 *flag=true;
1237
1238 for(int l=0;l<controlledJoints;l++)
1239 {
1240 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1241 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1242
1243 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1244
1245 if (!p)
1246 {
1247 return false;
1248 }
1249
1250 if (p->pos)
1251 {
1252 bool singleJointMotionDone =false;
1254 ret = ret && ok;
1256 }
1257 else
1258 {
1259 ret = false;
1260 }
1261 }
1262 return ret;
1263}
1264
1265bool ControlBoardRemapper::checkMotionDone(const int n_joints, const int *joints, bool *flag)
1266{
1267 bool ret=true;
1268 *flag=true;
1269
1270 for(int j=0;j<n_joints;j++)
1271 {
1272 int l = joints[j];
1273
1274 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1275 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1276
1277 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1278
1279 if (!p)
1280 {
1281 return false;
1282 }
1283
1284 if (p->pos)
1285 {
1286 bool singleJointMotionDone =false;
1288 ret = ret && ok;
1290 }
1291 else
1292 {
1293 ret = false;
1294 }
1295 }
1296
1297 return ret;
1298}
1299
1301{
1302 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1303 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1304
1305 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1306
1307 if (!p)
1308 {
1309 return false;
1310 }
1311
1312 if (p->pos)
1313 {
1314 return p->pos->setRefSpeed(off, sp);
1315 }
1316
1317 return false;
1318}
1319
1321{
1322 bool ret=true;
1323 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1324
1325 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(spds,remappedControlBoards);
1326
1327 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1328 {
1329 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1330
1331 bool ok = true;
1332 if (p->pos) {
1333 ok = p->pos->setRefSpeeds(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1334 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1335 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1336 }
1337 else {
1338 ok = false;
1339 }
1340 ret = ret && ok;
1341 }
1342
1343 return ret;
1344}
1345
1346bool ControlBoardRemapper::setRefSpeeds(const int n_joints, const int *joints, const double *spds)
1347{
1348 bool ret=true;
1349 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1350
1351 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(spds,n_joints,joints,remappedControlBoards);
1352
1353 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1354 {
1355 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1356
1357 bool ok = true;
1358 if (p->pos) {
1359 ok = p->pos->setRefSpeeds(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1360 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1361 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1362 }
1363 else {
1364 ok = false;
1365 }
1366 ret = ret && ok;
1367 }
1368
1369 return ret;
1370}
1371
1373{
1374 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1375 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1376
1377 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1378
1379 if (!p)
1380 {
1381 return false;
1382 }
1383
1384 if (p->pos)
1385 {
1386 return p->pos->setRefAcceleration(off, acc);
1387 }
1388
1389 return false;
1390}
1391
1393{
1394 bool ret=true;
1395 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1396
1397 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(accs,remappedControlBoards);
1398
1399 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1400 {
1401 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1402
1403 bool ok = true;
1404 if (p->pos) {
1405 ok = p->pos->setRefAccelerations(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1406 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1407 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1408 }
1409 else {
1410 ok = false;
1411 }
1412 ret = ret && ok;
1413 }
1414
1415 return ret;
1416}
1417
1418bool ControlBoardRemapper::setRefAccelerations(const int n_joints, const int *joints, const double *accs)
1419{
1420 bool ret=true;
1421 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1422
1423 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(accs,n_joints,joints,remappedControlBoards);
1424
1425 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1426 {
1427 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1428
1429 bool ok = true;
1430 if (p->pos) {
1431 ok = p->pos->setRefAccelerations(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1432 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1433 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1434 }
1435 else {
1436 ok = false;
1437 }
1438 ret = ret && ok;
1439 }
1440
1441 return ret;
1442}
1443
1445{
1446 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1447 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1448
1449 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1450
1451 if (!p)
1452 {
1453 return false;
1454 }
1455
1456 if (p->pos)
1457 {
1458 return p->pos->getRefSpeed(off, ref);
1459 }
1460
1461 return false;
1462}
1463
1465{
1466 bool ret=true;
1467 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1468
1469 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1470 {
1471 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1472
1473 bool ok = true;
1474 if( p->pos )
1475 {
1476 ok = p->pos->getRefSpeeds(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1477 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1478 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1479 }
1480 else
1481 {
1482 ok = false;
1483 }
1484
1485 ret = ret && ok;
1486 }
1487
1488 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
1489
1490 return ret;
1491}
1492
1493
1494bool ControlBoardRemapper::getRefSpeeds(const int n_joints, const int *joints, double *spds)
1495{
1496 bool ret=true;
1497 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1498
1499 // Resize the input buffers
1500 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1501
1502 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1503 {
1504 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1505
1506 bool ok = true;
1507
1508 if( p->pos )
1509 {
1510 ok = p->pos->getRefSpeeds(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1511 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1512 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1513 }
1514 else
1515 {
1516 ok = false;
1517 }
1518
1519 ret = ret && ok;
1520 }
1521
1522 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(spds,n_joints,joints,remappedControlBoards);
1523
1524 return ret;
1525}
1526
1528{
1529 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1530 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1531
1532 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1533
1534 if (!p)
1535 {
1536 return false;
1537 }
1538
1539 if (p->pos)
1540 {
1541 return p->pos->getRefAcceleration(off, acc);
1542 }
1543
1544 return false;
1545}
1546
1548{
1549 bool ret=true;
1550 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1551
1552 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1553 {
1554 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1555
1556 bool ok = true;
1557
1558 if( p->pos )
1559 {
1560 ok = p->pos->getRefAccelerations(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1561 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1562 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1563 }
1564 else
1565 {
1566 ok = false;
1567 }
1568
1569 ret = ret && ok;
1570 }
1571
1572 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(accs,remappedControlBoards);
1573
1574 return ret;
1575}
1576
1577bool ControlBoardRemapper::getRefAccelerations(const int n_joints, const int *joints, double *accs)
1578{
1579 bool ret=true;
1580 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1581
1582 // Resize the input buffers
1583 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
1584
1585 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1586 {
1587 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1588
1589 bool ok = true;
1590 if( p->pos )
1591 {
1592 ok = p->pos->getRefAccelerations(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1593 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1594 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1595 }
1596 else
1597 {
1598 ok = false;
1599 }
1600
1601 ret = ret && ok;
1602 }
1603
1604 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(accs,n_joints,joints,remappedControlBoards);
1605
1606 return ret;
1607}
1608
1610{
1611 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1612 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1613
1614 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1615
1616 if (!p)
1617 {
1618 return false;
1619 }
1620
1621 if (p->pos)
1622 {
1623 return p->pos->stop(off);
1624 }
1625
1626 return false;
1627}
1628
1630{
1631 bool ret=true;
1632 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1633
1634 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1635 {
1636 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1637
1638 bool ok = true;
1639
1640 ok = p->pos ? p->pos->stop(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1641 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data()) : false;
1642
1643 ret = ret && ok;
1644 }
1645
1646 return ret;
1647}
1648
1649bool ControlBoardRemapper::stop(const int n_joints, const int *joints)
1650{
1651 bool ret=true;
1652 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
1653 std::lock_guard<std::mutex> lock2(buffers.mutex);
1654
1655
1656 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(buffers.dummyBuffer.data(),n_joints,joints,remappedControlBoards);
1657
1658 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1659 {
1660 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1661 bool ok = true;
1662 if (p->pos) {
1663 ok = p->pos->stop(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1664 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data());
1665 }
1666 else
1667 {
1668 ok = false;
1669 }
1670 ret = ret && ok;
1671 }
1672
1673 return ret;
1674}
1675
1676/* IJointFaultControl */
1677bool ControlBoardRemapper::getLastJointFault(int j, int& fault, std::string& message)
1678{
1679 int off = (int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1680 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
1681
1682 RemappedSubControlBoard* p = remappedControlBoards.getSubControlBoard(subIndex);
1683
1684 if (!p)
1685 {
1686 return false;
1687 }
1688
1689 if (p->iFault)
1690 {
1691 return p->iFault->getLastJointFault(off, fault, message);
1692 }
1693
1694 return false;
1695}
1696
1697/* IVelocityControl */
1698
1700{
1701 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1702 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1703
1704 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1705
1706 if (!p)
1707 {
1708 return false;
1709 }
1710
1711 if (p->vel)
1712 {
1713 return p->vel->velocityMove(off, v);
1714 }
1715
1716 return false;
1717}
1718
1720{
1721 bool ret=true;
1722 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
1723
1724 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(v,remappedControlBoards);
1725
1726 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
1727 {
1728 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
1729
1730 bool ok = true;
1731 if (p->vel) {
1732 ok = p->vel->velocityMove(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
1733 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
1734 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
1735 }
1736 else {
1737 ok = false;
1738 }
1739 ret = ret && ok;
1740 }
1741
1742 return ret;
1743}
1744
1745/* IEncoders */
1747{
1748 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1749 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1750
1751 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1752 if (!p)
1753 {
1754 return false;
1755 }
1756
1757 if (p->iJntEnc)
1758 {
1759 return p->iJntEnc->resetEncoder(off);
1760 }
1761
1762 return false;
1763}
1764
1766{
1767 bool ret=true;
1768
1769 for(int l=0;l<controlledJoints;l++)
1770 {
1771 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1772 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1773
1774 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1775 if (!p)
1776 {
1777 return false;
1778 }
1779
1780 if (p->iJntEnc)
1781 {
1782 bool ok = p->iJntEnc->resetEncoder(off);
1783 ret = ret && ok;
1784 }
1785 else
1786 {
1787 ret=false;
1788 }
1789 }
1790 return ret;
1791}
1792
1794{
1795 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1796 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1797
1798 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1799
1800 if (!p)
1801 {
1802 return false;
1803 }
1804
1805 if (p->iJntEnc)
1806 {
1807 return p->iJntEnc->setEncoder(off,val);
1808 }
1809
1810 return false;
1811}
1812
1814{
1815 bool ret=true;
1816
1817 for(int l=0;l<controlledJoints;l++)
1818 {
1819 int off = (int) remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1820 size_t subIndex = remappedControlBoards.lut[l].subControlBoardIndex;
1821
1822 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
1823
1824 if (!p)
1825 {
1826 return false;
1827 }
1828
1829 if (p->iJntEnc)
1830 {
1831 bool ok = p->iJntEnc->setEncoder(off, vals[l]);
1832 ret = ret && ok;
1833 }
1834 else
1835 {
1836 ret = false;
1837 }
1838 }
1839 return ret;
1840}
1841
1843{
1844 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1845 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1846
1847 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1848
1849 if (!p)
1850 {
1851 return false;
1852 }
1853
1854 if (p->iJntEnc)
1855 {
1856 return p->iJntEnc->getEncoder(off, v);
1857 }
1858
1859 return false;
1860}
1861
1863{
1864 bool ret=true;
1865
1866 for(int l=0;l<controlledJoints;l++)
1867 {
1868 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1869 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1870
1871 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1872
1873 if (!p)
1874 {
1875 return false;
1876 }
1877
1878 if (p->iJntEnc)
1879 {
1880 bool ok = p->iJntEnc->getEncoder(off, encs+l);
1881 ret = ret && ok;
1882 }
1883 else
1884 {
1885 ret = false;
1886 }
1887 }
1888 return ret;
1889}
1890
1891bool ControlBoardRemapper::getEncodersTimed(double *encs, double *t)
1892{
1893 bool ret=true;
1894
1895 for(int l=0;l<controlledJoints;l++)
1896 {
1897 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1898 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1899
1900 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1901
1902 if (!p)
1903 {
1904 return false;
1905 }
1906
1907 if (p->iJntEnc)
1908 {
1909 bool ok = p->iJntEnc->getEncoderTimed(off, encs+l, t+l);
1910 ret = ret && ok;
1911 }
1912 else
1913 {
1914 ret = false;
1915 }
1916 }
1917 return ret;
1918}
1919
1920bool ControlBoardRemapper::getEncoderTimed(int j, double *v, double *t)
1921{
1922 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1923 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1924
1925 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1926
1927 if (!p)
1928 {
1929 return false;
1930 }
1931
1932 if (p->iJntEnc)
1933 {
1934 return p->iJntEnc->getEncoderTimed(off, v, t);
1935 }
1936
1937 return false;
1938}
1939
1941{
1942 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1943 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1944
1945 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1946
1947 if (!p)
1948 {
1949 return false;
1950 }
1951
1952 if (p->iJntEnc)
1953 {
1954 return p->iJntEnc->getEncoderSpeed(off, sp);
1955 }
1956
1957 return false;
1958}
1959
1961{
1962 bool ret=true;
1963
1964 for(int l=0;l<controlledJoints;l++)
1965 {
1966 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
1967 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
1968
1969 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1970
1971 if (!p)
1972 {
1973 return false;
1974 }
1975
1976 if (p->iJntEnc)
1977 {
1978 bool ok = p->iJntEnc->getEncoderSpeed(off, spds+l);
1979 ret = ret && ok;
1980 }
1981 else
1982 {
1983 ret = false;
1984 }
1985 }
1986 return ret;
1987}
1988
1990{
1991 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
1992 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
1993
1994 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
1995
1996 if (!p)
1997 {
1998 return false;
1999 }
2000
2001 if (p->iJntEnc)
2002 {
2003 return p->iJntEnc->getEncoderAcceleration(off,acc);
2004 }
2005
2006 return false;
2007}
2008
2010{
2011 bool ret=true;
2012
2013 for(int l=0;l<controlledJoints;l++)
2014 {
2015 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2016 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2017
2018 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2019
2020 if (!p)
2021 {
2022 return false;
2023 }
2024
2025 if (p->iJntEnc)
2026 {
2027 bool ok = p->iJntEnc->getEncoderAcceleration(off, accs+l);
2028 ret = ret && ok;
2029 }
2030 else
2031 {
2032 ret = false;
2033 }
2034 }
2035 return ret;
2036}
2037
2038/* IMotor */
2040{
2041 *num=controlledJoints;
2042 return true;
2043}
2044
2046{
2047 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2048 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2049
2050 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2051
2052 if (!p)
2053 {
2054 return false;
2055 }
2056
2057 if (p->imotor)
2058 {
2059 return p->imotor->getTemperature(off, val);
2060 }
2061
2062 return false;
2063}
2064
2066{
2067 bool ret=true;
2068 for(int l=0;l<controlledJoints;l++)
2069 {
2070 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2071 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2072
2073 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2074 if (!p)
2075 {
2076 return false;
2077 }
2078
2079 if (p->imotor)
2080 {
2082 }
2083 else
2084 {
2085 ret=false;
2086 }
2087 }
2088 return ret;
2089}
2090
2092{
2093 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2094 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2095
2096 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2097
2098 if (!p)
2099 {
2100 return false;
2101 }
2102
2103 if (p->imotor)
2104 {
2105 return p->imotor->getTemperatureLimit(off, val);
2106 }
2107
2108 return false;
2109}
2110
2112{
2113 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2114 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2115
2116 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2117
2118 if (!p)
2119 {
2120 return false;
2121 }
2122
2123 if (p->imotor)
2124 {
2125 return p->imotor->setTemperatureLimit(off,val);
2126 }
2127
2128 return false;
2129}
2130
2132{
2133 int off = (int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2134 size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2135
2136 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2137
2138 if (!p)
2139 {
2140 return false;
2141 }
2142
2143 if (p->imotor)
2144 {
2145 return p->imotor->getGearboxRatio(off, val);
2146 }
2147
2148 return false;
2149}
2150
2151bool ControlBoardRemapper::setGearboxRatio(int m, const double val)
2152{
2153 int off = (int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2154 size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2155
2156 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2157
2158 if (!p)
2159 {
2160 return false;
2161 }
2162
2163 if (p->imotor)
2164 {
2165 return p->imotor->setGearboxRatio(off, val);
2166 }
2167
2168 return false;
2169}
2170
2171/* IRemoteVariables */
2173{
2174 yCWarning(CONTROLBOARDREMAPPER, "getRemoteVariable is not properly implemented, use at your own risk.");
2175
2176 bool b = true;
2177
2178 for (unsigned int i = 0; i < remappedControlBoards.getNrOfSubControlBoards(); i++)
2179 {
2180 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(i);
2181
2182 if (!p)
2183 {
2184 return false;
2185 }
2186
2187 if (!p->iVar)
2188 {
2189 return false;
2190 }
2191
2193 bool ok = p->iVar->getRemoteVariable(key, tmpval);
2194
2195 if (ok)
2196 {
2197 val.append(tmpval);
2198 }
2199
2200 b = b && ok;
2201 }
2202
2203 return b;
2204}
2205
2207{
2208 yCWarning(CONTROLBOARDREMAPPER, "setRemoteVariable is not properly implemented, use at your own risk.");
2209
2210 size_t bottle_size = val.size();
2211 size_t device_size = remappedControlBoards.getNrOfSubControlBoards();
2212 if (bottle_size != device_size)
2213 {
2214 yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable bottle_size != device_size failure");
2215 return false;
2216 }
2217
2218 bool b = true;
2219 for (unsigned int i = 0; i < device_size; i++)
2220 {
2221 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(i);
2222 if (!p) { yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable !p failure"); return false; }
2223 if (!p->iVar) { yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable !p->iVar failure"); return false; }
2224 Bottle* partial_val = val.get(i).asList();
2225 if (partial_val)
2226 {
2227 b &= p->iVar->setRemoteVariable(key, *partial_val);
2228 }
2229 else
2230 {
2231 yCError(CONTROLBOARDREMAPPER, "ControlBoardRemapper::setRemoteVariable general failure");
2232 return false;
2233 }
2234 }
2235
2236 return b;
2237}
2238
2240{
2241 yCWarning(CONTROLBOARDREMAPPER, "getRemoteVariablesList is not properly implemented, use at your own risk.");
2242
2243 size_t subIndex = remappedControlBoards.lut[0].subControlBoardIndex;
2244 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2245
2246 if (!p)
2247 {
2248 return false;
2249 }
2250
2251 if (p->iVar)
2252 {
2254 }
2255
2256 return false;
2257}
2258
2259/* IMotorEncoders */
2260
2262{
2263 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2264 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2265
2266 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2267
2268 if (!p)
2269 {
2270 return false;
2271 }
2272
2273 if (p->iMotEnc)
2274 {
2275 return p->iMotEnc->resetMotorEncoder(off);
2276 }
2277
2278 return false;
2279}
2280
2282{
2283 bool ret=true;
2284
2285 for(int l=0;l<controlledJoints;l++)
2286 {
2287 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2288 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2289
2290 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2291 if (!p)
2292 {
2293 return false;
2294 }
2295
2296 if (p->iMotEnc)
2297 {
2298 bool ok = p->iMotEnc->resetMotorEncoder(off);
2299 ret= ret && ok;
2300 }
2301 else
2302 {
2303 ret=false;
2304 }
2305 }
2306
2307 return ret;
2308}
2309
2310bool ControlBoardRemapper::setMotorEncoder(int m, const double val)
2311{
2312 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2313 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2314
2315 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2316
2317 if (!p)
2318 {
2319 return false;
2320 }
2321
2322 if (p->iMotEnc)
2323 {
2324 return p->iMotEnc->setMotorEncoder(off,val);
2325 }
2326
2327 return false;
2328}
2329
2331{
2332 bool ret=true;
2333
2334 for(int l=0;l<controlledJoints;l++)
2335 {
2336 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2337 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2338
2339 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2340
2341 if (!p)
2342 {
2343 return false;
2344 }
2345
2346 if (p->iMotEnc)
2347 {
2348 bool ok = p->iMotEnc->setMotorEncoder(off, vals[l]);
2349 ret = ret && ok;
2350 }
2351 else
2352 {
2353 ret=false;
2354 }
2355 }
2356
2357 return ret;
2358}
2359
2361{
2362 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2363 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2364
2365 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2366
2367 if (!p)
2368 {
2369 return false;
2370 }
2371
2372 if (p->iMotEnc)
2373 {
2375 }
2376
2377 return false;
2378}
2379
2381{
2382 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2383 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2384
2385 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2386
2387 if (!p)
2388 {
2389 return false;
2390 }
2391
2392 if (p->iMotEnc)
2393 {
2395 }
2396
2397 return false;
2398}
2399
2401{
2402 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2403 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2404
2405 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2406
2407 if (!p)
2408 {
2409 return false;
2410 }
2411
2412 if (p->iMotEnc)
2413 {
2414 return p->iMotEnc->getMotorEncoder(off, v);
2415 }
2416
2417 return false;
2418}
2419
2421{
2422 bool ret=true;
2423
2424 for(int l=0;l<controlledJoints;l++)
2425 {
2426 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2427 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2428
2429 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2430 if (!p) {
2431 return false;
2432 }
2433
2434 if (p->iMotEnc)
2435 {
2436 ret=ret&&p->iMotEnc->getMotorEncoder(off, encs+l);
2437 } else {
2438 ret = false;
2439 }
2440 }
2441 return ret;
2442}
2443
2445{
2446 bool ret=true;
2447
2448 for(int l=0;l<controlledJoints;l++)
2449 {
2450 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2451 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2452
2453 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2454
2455 if (!p)
2456 {
2457 return false;
2458 }
2459
2460 if (p->iMotEnc)
2461 {
2462 bool ok = p->iMotEnc->getMotorEncoderTimed(off, encs, t);
2463 ret = ret && ok;
2464 }
2465 else
2466 {
2467 ret = false;
2468 }
2469 }
2470 return ret;
2471}
2472
2473bool ControlBoardRemapper::getMotorEncoderTimed(int m, double *v, double *t)
2474{
2475 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2476 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2477
2478 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2479
2480 if (!p)
2481 {
2482 return false;
2483 }
2484
2485 if (p->iMotEnc)
2486 {
2487 return p->iMotEnc->getMotorEncoderTimed(off, v, t);
2488 }
2489
2490 return false;
2491}
2492
2494{
2495 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2496 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2497
2498 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2499
2500 if (!p)
2501 {
2502 return false;
2503 }
2504
2505 if (p->iMotEnc)
2506 {
2507 return p->iMotEnc->getMotorEncoderSpeed(off, sp);
2508 }
2509
2510 return false;
2511}
2512
2514{
2515 bool ret=true;
2516
2517 for(int l=0;l<controlledJoints;l++)
2518 {
2519 int off = (int) remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2520 size_t subIndex = remappedControlBoards.lut[l].subControlBoardIndex;
2521
2522 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2523
2524 if (!p)
2525 {
2526 return false;
2527 }
2528
2529 if (p->iMotEnc)
2530 {
2531 bool ok = p->iMotEnc->getMotorEncoderSpeed(off, spds + l);
2532 ret = ret && ok;
2533 }
2534 else
2535 {
2536 ret = false;
2537 }
2538 }
2539 return ret;
2540}
2541
2543{
2544 int off = (int) remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2545 size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2546
2547 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2548
2549 if (!p)
2550 {
2551 return false;
2552 }
2553
2554 if (p->iMotEnc)
2555 {
2556 return p->iMotEnc->getMotorEncoderAcceleration(off,acc);
2557 }
2558 *acc=0.0;
2559 return false;
2560}
2561
2563{
2564 bool ret=true;
2565
2566 for(int l=0;l<controlledJoints;l++)
2567 {
2568 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2569 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2570
2571 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2572
2573 if (!p)
2574 {
2575 return false;
2576 }
2577
2578 if (p->iMotEnc)
2579 {
2581 ret=ret && ok;
2582 }
2583 else
2584 {
2585 ret=false;
2586 }
2587 }
2588
2589 return ret;
2590}
2591
2592
2594{
2595 *num=controlledJoints;
2596 return true;
2597}
2598
2599/* IAmplifierControl */
2601{
2602 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2603 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2604
2605 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2606
2607 if (!p)
2608 {
2609 return false;
2610 }
2611
2612 if (p->amp)
2613 {
2614 return p->amp->enableAmp(off);
2615 }
2616
2617 return false;
2618}
2619
2621{
2622 return this->setControlMode(j, VOCAB_CM_IDLE);
2623}
2624
2626{
2627 bool ret=true;
2628
2629 for(int l=0;l<controlledJoints;l++)
2630 {
2631 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
2632 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
2633
2634 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2635
2636 if (!p)
2637 {
2638 return false;
2639 }
2640
2641 if (p->amp)
2642 {
2643 bool ok = p->amp->getAmpStatus(off, st+l);
2644 ret = ret && ok;
2645 }
2646 else
2647 {
2648 ret=false;
2649 }
2650 }
2651
2652 return ret;
2653}
2654
2656{
2657 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2658 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2659
2660 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2661
2662 if (!p)
2663 {
2664 return false;
2665 }
2666
2667 if (p->amp)
2668 {
2669 return p->amp->getAmpStatus(off,v);
2670 }
2671
2672 return false;
2673}
2674
2676{
2677 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2678 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2679
2680 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2681
2682 if (!p)
2683 {
2684 return false;
2685 }
2686
2687 if (p->amp)
2688 {
2689 return p->amp->setMaxCurrent(off,v);
2690 }
2691
2692 return false;
2693}
2694
2696{
2697 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2698 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2699
2700 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2701
2702 if (!p)
2703 {
2704 return false;
2705 }
2706
2707 if (p->amp)
2708 {
2709 return p->amp->getMaxCurrent(off,v);
2710 }
2711
2712 return false;
2713}
2714
2716{
2717 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2718 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2719
2720 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2721
2722 if(!p)
2723 {
2724 return false;
2725 }
2726
2727 if(!p->amp)
2728 {
2729 return false;
2730 }
2731
2732 return p->amp->getNominalCurrent(off, val);
2733}
2734
2736{
2737 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2738 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2739
2740 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2741
2742 if(!p)
2743 {
2744 return false;
2745 }
2746
2747 if(!p->amp)
2748 {
2749 return false;
2750 }
2751
2752 return p->amp->getPeakCurrent(off, val);
2753}
2754
2755bool ControlBoardRemapper::setPeakCurrent(int m, const double val)
2756{
2757 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2758 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2759
2760 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2761
2762 if (!p)
2763 {
2764 return false;
2765 }
2766
2767 if (!p->amp)
2768 {
2769 return false;
2770 }
2771
2772 return p->amp->setPeakCurrent(off, val);
2773}
2774
2776{
2777 int off = (int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2778 size_t subIndex = remappedControlBoards.lut[m].subControlBoardIndex;
2779
2780 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
2781
2782 if (!p)
2783 {
2784 return false;
2785 }
2786
2787 if (!p->amp)
2788 {
2789 return false;
2790 }
2791
2792 return p->amp->setNominalCurrent(off, val);
2793}
2794
2795bool ControlBoardRemapper::getPWM(int m, double* val)
2796{
2797 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2798 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2799
2800 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2801
2802 if(!p)
2803 {
2804 return false;
2805 }
2806
2807 if(!p->amp)
2808 {
2809 return false;
2810 }
2811
2812 return p->amp->getPWM(off, val);
2813}
2815{
2816 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2817 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2818
2819 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2820
2821 if(!p)
2822 {
2823 return false;
2824 }
2825
2826 if(!p->amp)
2827 {
2828 return false;
2829 }
2830
2831 return p->amp->getPWMLimit(off, val);
2832}
2833
2834bool ControlBoardRemapper::setPWMLimit(int m, const double val)
2835{
2836 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2837 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2838
2839 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2840
2841 if (!p)
2842 {
2843 return false;
2844 }
2845
2846 if (!p->amp)
2847 {
2848 return false;
2849 }
2850
2851 return p->amp->setPWMLimit(off, val);
2852}
2853
2855{
2856 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
2857 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
2858
2859 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2860
2861 if(!p)
2862 {
2863 return false;
2864 }
2865
2866 if(!p->amp)
2867 {
2868 return false;
2869 }
2870
2871 return p->amp->getPowerSupplyVoltage(off, val);
2872}
2873
2874
2875/* IControlLimits */
2876
2877bool ControlBoardRemapper::setLimits(int j, double min, double max)
2878{
2879 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2880 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2881
2882 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2883
2884 if (!p)
2885 {
2886 return false;
2887 }
2888
2889 if (p->lim)
2890 {
2891 return p->lim->setLimits(off,min, max);
2892 }
2893
2894 return false;
2895}
2896
2897bool ControlBoardRemapper::getLimits(int j, double *min, double *max)
2898{
2899 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2900 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2901
2902 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2903
2904 if (!p)
2905 {
2906 return false;
2907 }
2908
2909 if (p->lim)
2910 {
2911 return p->lim->getLimits(off,min, max);
2912 }
2913
2914 return false;
2915}
2916
2917bool ControlBoardRemapper::setVelLimits(int j, double min, double max)
2918{
2919 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2920 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2921
2922 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2923
2924 if (!p)
2925 {
2926 return false;
2927 }
2928
2929 if (!p->lim)
2930 {
2931 return false;
2932 }
2933
2934 return p->lim->setVelLimits(off,min, max);
2935}
2936
2937bool ControlBoardRemapper::getVelLimits(int j, double *min, double *max)
2938{
2939 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2940 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
2941
2942 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
2943
2944 if (!p)
2945 {
2946 return false;
2947 }
2948
2949 if(!p->lim)
2950 {
2951 return false;
2952 }
2953
2954 return p->lim->getVelLimits(off,min, max);
2955}
2956
2957/* IRemoteCalibrator */
2962
2967
2969{
2970 if(!getCalibratorDevice())
2971 {
2972 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
2973 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
2974
2975 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
2976 if (!s)
2977 {
2978 return false;
2979 }
2980
2981 if (s->remcalib)
2982 {
2983 return s->remcalib->calibrateSingleJoint(off);
2984 }
2985
2986 return false;
2987 }
2988 else
2989 {
2990 return IRemoteCalibrator::getCalibratorDevice()->calibrateSingleJoint(j);
2991 }
2992}
2993
2995{
2996 if(!getCalibratorDevice())
2997 {
2998 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
2999 {
3000 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
3001 if (!s)
3002 {
3003 return false;
3004 }
3005
3006 if (s->remcalib)
3007 {
3008 return s->remcalib->calibrateWholePart();
3009 }
3010 }
3011
3012 return false;
3013 }
3014 else
3015 {
3016 return IRemoteCalibrator::getCalibratorDevice()->calibrateWholePart();
3017 }
3018}
3019
3021{
3022 if(!getCalibratorDevice())
3023 {
3024 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3025 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3026
3027 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
3028 if (!s)
3029 {
3030 return false;
3031 }
3032
3033 if (s->remcalib)
3034 {
3035 return s->remcalib->homingSingleJoint(off);
3036 }
3037
3038 return false;
3039 }
3040 else
3041 {
3042 return IRemoteCalibrator::getCalibratorDevice()->homingSingleJoint(j);
3043 }
3044}
3045
3047{
3048 if(!getCalibratorDevice())
3049 {
3050 bool ret = true;
3051 for(int l=0;l<controlledJoints;l++)
3052 {
3053 bool ok = this->homingSingleJoint(l);
3054 ret = ret && ok;
3055 }
3056
3057 return ret;
3058 }
3059 else
3060 {
3061 return IRemoteCalibrator::getCalibratorDevice()->homingWholePart();
3062 }
3063}
3064
3066{
3067 if(!getCalibratorDevice())
3068 {
3069 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3070 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3071
3072 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(subIndex);
3073 if (!s)
3074 {
3075 return false;
3076 }
3077
3078 if (s->remcalib)
3079 {
3080 return s->remcalib->parkSingleJoint(off,_wait);
3081 }
3082
3083 return false;
3084 }
3085 else
3086 {
3088 }
3089}
3090
3092{
3093 if(!getCalibratorDevice())
3094 {
3095 bool ret = true;
3096
3097 for(int l=0; l<controlledJoints; l++)
3098 {
3099 bool _wait = false;
3100 bool ok = this->parkSingleJoint(l,_wait);
3101 ret = ret && ok;
3102 }
3103
3104 return ret;
3105 }
3106 else
3107 {
3109 }
3110}
3111
3113{
3114 if(!getCalibratorDevice())
3115 {
3116 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3117 {
3118 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
3119 if (!s)
3120 {
3121 return false;
3122 }
3123
3124 if (s->remcalib)
3125 {
3126 return s->remcalib->quitCalibrate();
3127 }
3128 }
3129
3130 return false;
3131 }
3132 else
3133 {
3134 return IRemoteCalibrator::getCalibratorDevice()->quitCalibrate();
3135 }
3136}
3137
3139{
3140 if(!getCalibratorDevice())
3141 {
3142 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3143 {
3144 RemappedSubControlBoard *s = remappedControlBoards.getSubControlBoard(ctrlBrd);
3145 if (!s)
3146 {
3147 return false;
3148 }
3149
3150 if (s->remcalib)
3151 {
3152 return s->remcalib->quitPark();
3153 }
3154 }
3155
3156 return false;
3157 }
3158 else
3159 {
3160 return IRemoteCalibrator::getCalibratorDevice()->quitPark();
3161 }
3162}
3163
3164
3165/* IControlCalibration */
3166bool ControlBoardRemapper::calibrateAxisWithParams(int j, unsigned int ui, double v1, double v2, double v3)
3167{
3168 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3169 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3170
3171 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3172
3173 if (p && p->calib)
3174 {
3175 return p->calib->calibrateAxisWithParams(off, ui,v1,v2,v3);
3176 }
3177 return false;
3178}
3179
3181{
3182 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3183 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3184
3185 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3186
3187 if (p && p->calib)
3188 {
3189 return p->calib->setCalibrationParameters(off, params);
3190 }
3191
3192 return false;
3193}
3194
3196{
3197 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3198 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3199
3200 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3201
3202 if (!p)
3203 {
3204 return false;
3205 }
3206
3207 if (p->calib)
3208 {
3209 return p->calib->calibrationDone(off);
3210 }
3211
3212 return false;
3213}
3214
3216{
3217 yCError(CONTROLBOARDREMAPPER, "Calling abortPark -- not implemented");
3218 return false;
3219}
3220
3222{
3223 yCError(CONTROLBOARDREMAPPER, "Calling abortCalibration -- not implemented");
3224 return false;
3225}
3226
3227/* IAxisInfo */
3228
3229bool ControlBoardRemapper::getAxisName(int j, std::string& name)
3230{
3231 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3232 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3233
3234 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3235
3236 if (!p)
3237 {
3238 return false;
3239 }
3240
3241 if (p->info)
3242 {
3243 return p->info->getAxisName(off, name);
3244 }
3245
3246 return false;
3247}
3248
3250{
3251 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3252 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3253
3254 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3255
3256 if (!p)
3257 {
3258 return false;
3259 }
3260
3261 if (p->info)
3262 {
3263 return p->info->getJointType(off, type);
3264 }
3265
3266 return false;
3267}
3268
3270{
3271 bool ret=true;
3272
3273 for(int l=0;l<controlledJoints;l++)
3274 {
3275 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3276 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3277
3278 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3279
3280 if (!p)
3281 {
3282 return false;
3283 }
3284
3285 if (p->iTorque)
3286 {
3287 bool ok = p->iTorque->getRefTorque(off, refs+l);
3288 ret = ret && ok;
3289 }
3290 else
3291 {
3292 ret = false;
3293 }
3294 }
3295 return ret;
3296}
3297
3299{
3300 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3301 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3302
3303 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3304
3305 if (!p)
3306 {
3307 return false;
3308 }
3309
3310 if (p->iTorque)
3311 {
3312 return p->iTorque->getRefTorque(off, t);
3313 }
3314 return false;
3315}
3316
3318{
3319 bool ret=true;
3320 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3321
3322 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(t,remappedControlBoards);
3323
3324 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3325 {
3326 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3327
3328 bool ok;
3329
3330 if( p->iTorque )
3331 {
3332 ok = p->iTorque->setRefTorques(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3333 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3334 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3335 }
3336 else
3337 {
3338 ok = false;
3339 }
3340
3341 ret = ret && ok;
3342 }
3343
3344 return ret;
3345}
3346
3348{
3349 int off = (int) remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3350 size_t subIndex = remappedControlBoards.lut[j].subControlBoardIndex;
3351
3352 RemappedSubControlBoard *p = remappedControlBoards.getSubControlBoard(subIndex);
3353 if (!p)
3354 {
3355 return false;
3356 }
3357
3358 if (p->iTorque)
3359 {
3360 return p->iTorque->setRefTorque(off, t);
3361 }
3362 return false;
3363}
3364
3365bool ControlBoardRemapper::setRefTorques(const int n_joints, const int *joints, const double *t)
3366{
3367 bool ret=true;
3368 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3369
3370 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(t,n_joints,joints,remappedControlBoards);
3371
3372 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3373 {
3374 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3375
3376 bool ok = p->iTorque->setRefTorques(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3377 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3378 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3379 ret = ret && ok;
3380 }
3381
3382 return ret;
3383}
3384
3386{
3387 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3388 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3389
3390 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3391
3392 if (!p)
3393 {
3394 return false;
3395 }
3396
3397 if (p->iTorque)
3398 {
3399 return p->iTorque->getMotorTorqueParams(off, params);
3400 }
3401
3402 return false;
3403}
3404
3406{
3407 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3408 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3409
3410 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3411
3412 if (!p)
3413 {
3414 return false;
3415 }
3416
3417 if (p->iTorque)
3418 {
3419 return p->iTorque->setMotorTorqueParams(off, params);
3420 }
3421
3422 return false;
3423}
3424
3426{
3427 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3428 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3429
3430 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3431
3432 if (!p)
3433 {
3434 return false;
3435 }
3436
3437 if (p->iImpedance)
3438 {
3439 return p->iImpedance->setImpedance(off, stiff, damp);
3440 }
3441
3442 return false;
3443}
3444
3446{
3447 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3448 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3449
3450 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3451
3452 if (!p)
3453 {
3454 return false;
3455 }
3456
3457 if (p->iImpedance)
3458 {
3459 return p->iImpedance->setImpedanceOffset(off, offset);
3460 }
3461
3462 return false;
3463}
3464
3466{
3467 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3468 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3469
3470 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3471
3472 if (!p)
3473 {
3474 return false;
3475 }
3476
3477 if (p->iTorque)
3478 {
3479 return p->iTorque->getTorque(off, t);
3480 }
3481
3482 return false;
3483}
3484
3486{
3487 bool ret=true;
3488
3489 for(int l=0;l<controlledJoints;l++)
3490 {
3491 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3492 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3493
3494 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3495
3496 if (!p)
3497 {
3498 return false;
3499 }
3500
3501 if (p->iTorque)
3502 {
3503 bool ok = p->iTorque->getTorque(off, t+l);
3504 ret = ret && ok;
3505 }
3506 else
3507 {
3508 ret=false;
3509 }
3510 }
3511
3512 return ret;
3513 }
3514
3515bool ControlBoardRemapper::getTorqueRange(int j, double *min, double *max)
3516{
3517 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3518 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3519
3520 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3521
3522 if (!p)
3523 {
3524 return false;
3525 }
3526
3527 if (p->iTorque)
3528 {
3529 return p->iTorque->getTorqueRange(off, min, max);
3530 }
3531
3532 return false;
3533}
3534
3535bool ControlBoardRemapper::getTorqueRanges(double *min, double *max)
3536{
3537 bool ret=true;
3538
3539 for(int l=0;l<controlledJoints;l++)
3540 {
3541 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
3542 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3543
3544 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3545
3546 if (!p)
3547 {
3548 return false;
3549 }
3550
3551 if (p->iTorque)
3552 {
3553 bool ok = p->iTorque->getTorqueRange(off, min+l, max+l);
3554 ret = ret && ok;
3555 }
3556 else
3557 {
3558 ret=false;
3559 }
3560 }
3561 return ret;
3562 }
3563
3565{
3566 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3567 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3568
3569 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3570
3571 if (!p)
3572 {
3573 return false;
3574 }
3575
3576 if (p->iImpedance)
3577 {
3578 return p->iImpedance->getImpedance(off, stiff, damp);
3579 }
3580
3581 return false;
3582}
3583
3585{
3586 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3587 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3588
3589 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3590
3591 if (!p)
3592 {
3593 return false;
3594 }
3595
3596 if (p->iImpedance)
3597 {
3598 return p->iImpedance->getImpedanceOffset(off, offset);
3599 }
3600
3601 return false;
3602}
3603
3604bool ControlBoardRemapper::getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)
3605{
3606 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3607 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3608
3609 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3610
3611 if (!p)
3612 {
3613 return false;
3614 }
3615
3616 if (p->iImpedance)
3617 {
3618 return p->iImpedance->getCurrentImpedanceLimit(off, min_stiff, max_stiff, min_damp, max_damp);
3619 }
3620
3621 return false;
3622}
3623
3625{
3626 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3627 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3628
3629 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3630 if (!p) {
3631 return false;
3632 }
3633
3634 bool ok = true;
3635
3636 if (p->iMode) {
3637 ok = p->iMode->getControlMode(off, mode);
3638 }
3639 else {
3640 ok = false;
3641 }
3642
3643 return ok;
3644
3645}
3646
3648{
3649 bool ret=true;
3650 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3651
3652 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3653 {
3654 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3655
3656 bool ok;
3657
3658 if( p->iMode )
3659 {
3660 ok = p->iMode->getControlModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3661 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3662 allJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3663 }
3664 else
3665 {
3666 ok = false;
3667 }
3668
3669 ret = ret && ok;
3670 }
3671
3672 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(modes,remappedControlBoards);
3673
3674 return ret;
3675}
3676
3677// IControlMode interface
3678bool ControlBoardRemapper::getControlModes(const int n_joints, const int *joints, int *modes)
3679{
3680 bool ret=true;
3681 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3682
3683 // Resize the input buffers
3684 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
3685
3686 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3687 {
3688 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3689
3690 bool ok;
3691
3692 if( p->iMode )
3693 {
3694 ok = p->iMode->getControlModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3695 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3696 selectedJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3697 }
3698 else
3699 {
3700 ok = false;
3701 }
3702
3703 ret = ret && ok;
3704 }
3705
3706 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(modes,n_joints,joints,remappedControlBoards);
3707
3708 return ret;
3709}
3710
3711bool ControlBoardRemapper::setControlMode(const int j, const int mode)
3712{
3713 bool ret = true;
3714
3715 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3716 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3717
3718 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3719
3720 if (!p)
3721 {
3722 return false;
3723 }
3724
3725 if (p->iMode)
3726 {
3727 ret = p->iMode->setControlMode(off, mode);
3728 }
3729 else
3730 {
3731 ret = false;
3732 }
3733
3734 return ret;
3735}
3736
3737bool ControlBoardRemapper::setControlModes(const int n_joints, const int *joints, int *modes)
3738{
3739 bool ret=true;
3740 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3741
3742 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(modes,n_joints,joints,remappedControlBoards);
3743
3744 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3745 {
3746 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3747
3748 bool ok = true;
3749 if (p->iMode) {
3750 ok = p->iMode->setControlModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3751 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3752 selectedJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3753 }
3754 else {
3755 ok = false;
3756 }
3757 ret = ret && ok;
3758 }
3759
3760 return ret;
3761}
3762
3764{
3765 bool ret=true;
3766 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3767
3768 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(modes,remappedControlBoards);
3769
3770 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3771 {
3772 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3773
3774 bool ok = true;
3775 if (p->iMode) {
3776 ok = p->iMode->setControlModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3777 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3778 allJointsBuffers.m_bufferForSubControlBoardControlModes[ctrlBrd].data());
3779 }
3780 else {
3781 ok = false;
3782 }
3783 ret = ret && ok;
3784 }
3785
3786 return ret;
3787}
3788
3790{
3791 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3792 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3793
3794 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3795
3796 if (!p)
3797 {
3798 return false;
3799 }
3800
3801 if (p->posDir)
3802 {
3803 return p->posDir->setPosition(off, ref);
3804 }
3805
3806 return false;
3807}
3808
3809bool ControlBoardRemapper::setPositions(const int n_joints, const int *joints, const double *dpos)
3810{
3811 bool ret=true;
3812 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3813
3814 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(dpos,n_joints,joints,remappedControlBoards);
3815
3816 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3817 {
3818 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3819
3820 bool ok = true;
3821 if (p->posDir) {
3822 ok = p->posDir->setPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3823 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3824 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3825 }
3826 else {
3827 ok = false;
3828 }
3829 ret = ret && ok;
3830 }
3831
3832 return ret;
3833}
3834
3836{
3837 bool ret=true;
3838 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3839
3840 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(refs,remappedControlBoards);
3841
3842 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3843 {
3844 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3845
3846 bool ok = true;
3847 if (p->posDir) {
3848 ok = p->posDir->setPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3849 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3850 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3851 }
3852 else {
3853 ok = false;
3854 }
3855 ret = ret && ok;
3856 }
3857
3858 return ret;
3859}
3860
3862{
3863 double averageTimestamp = 0.0;
3864 int collectedTimestamps = 0;
3865
3866 for(int l=0;l<controlledJoints;l++)
3867 {
3868 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
3869
3870 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3871
3872 if (!p)
3873 {
3874 return Stamp();
3875 }
3876
3877 if(p->iTimed)
3878 {
3881 }
3882 }
3883
3884
3885 std::lock_guard<std::mutex> lock(buffers.mutex);
3886
3887 if( collectedTimestamps > 0 )
3888 {
3890 }
3891 else
3892 {
3893 buffers.stamp.update();
3894 }
3895
3896 return buffers.stamp;
3897}
3898
3899bool ControlBoardRemapper::getRefPosition(const int j, double* ref)
3900{
3901 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
3902 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
3903
3904 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
3905
3906 if (!p)
3907 {
3908 return false;
3909 }
3910
3911 if (p->posDir)
3912 {
3913 bool ret = p->posDir->getRefPosition(off, ref);
3914 return ret;
3915 }
3916
3917 return false;
3918}
3919
3921{
3922 bool ret=true;
3923 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
3924
3925 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3926 {
3927 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3928
3929 bool ok = true;
3930
3931 if( p->posDir )
3932 {
3933 ok = p->posDir->getRefPositions(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3934 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3935 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3936 }
3937 else
3938 {
3939 ok = false;
3940 }
3941
3942 ret = ret && ok;
3943 }
3944
3945 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(spds,remappedControlBoards);
3946
3947 return ret;
3948}
3949
3950
3951bool ControlBoardRemapper::getRefPositions(const int n_joints, const int *joints, double *targets)
3952{
3953 bool ret=true;
3954 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3955
3956 // Resize the input buffers
3957 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
3958
3959 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3960 {
3961 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3962
3963 bool ok = true;
3964
3965 if( p->posDir )
3966 {
3967 ok = p->posDir->getRefPositions(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
3968 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
3969 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
3970 }
3971 else
3972 {
3973 ok = false;
3974 }
3975
3976 ret = ret && ok;
3977 }
3978
3979 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(targets,n_joints,joints,remappedControlBoards);
3980
3981 return ret;
3982}
3983
3984
3985
3986// IVelocityControl interface
3987bool ControlBoardRemapper::velocityMove(const int n_joints, const int *joints, const double *spds)
3988{
3989 bool ret=true;
3990 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
3991
3992 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(spds,n_joints,joints,remappedControlBoards);
3993
3994 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
3995 {
3996 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
3997
3998 bool ok = true;
3999 if (p->vel) {
4000 ok = p->vel->velocityMove(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4001 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4002 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4003 }
4004 else
4005 {
4006 ok = false;
4007 }
4008 ret = ret && ok;
4009 }
4010
4011 return ret;
4012}
4013
4014bool ControlBoardRemapper::getRefVelocity(const int j, double* vel)
4015{
4016 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4017 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4018
4019 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4020
4021 if (!p)
4022 {
4023 return false;
4024 }
4025
4026 if (p->vel)
4027 {
4028 bool ret = p->vel->getRefVelocity(off, vel);
4029 return ret;
4030 }
4031
4032 return false;
4033}
4034
4035
4037{
4038 bool ret=true;
4039 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4040
4041 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4042 {
4043 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4044
4045 bool ok = true;
4046
4047 if( p->vel )
4048 {
4049 ok = p->vel->getRefVelocities(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4050 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4051 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4052 }
4053 else
4054 {
4055 ok = false;
4056 }
4057
4058 ret = ret && ok;
4059 }
4060
4061 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(vels,remappedControlBoards);
4062
4063 return ret;
4064}
4065
4066bool ControlBoardRemapper::getRefVelocities(const int n_joints, const int* joints, double* vels)
4067{
4068 bool ret=true;
4069 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4070
4071 // Resize the input buffers
4072 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
4073
4074 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4075 {
4076 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4077
4078 bool ok = true;
4079
4080 if( p->vel )
4081 {
4082 ok = p->vel->getRefVelocities(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4083 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4084 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4085 }
4086 else
4087 {
4088 ok = false;
4089 }
4090
4091 ret = ret && ok;
4092 }
4093
4094 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(vels,n_joints,joints,remappedControlBoards);
4095
4096 return ret;
4097}
4098
4100{
4101 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4102 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4103
4104 RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
4105
4106 if (!s)
4107 {
4108 return false;
4109 }
4110
4111 if (s->iInteract)
4112 {
4113 return s->iInteract->getInteractionMode(off, mode);
4114 }
4115
4116 return false;
4117}
4118
4120{
4121 bool ret=true;
4122 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4123
4124 // Resize the input buffers
4125 selectedJointsBuffers.resizeSubControlBoardBuffers(n_joints,joints,remappedControlBoards);
4126
4127 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4128 {
4129 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4130
4131 bool ok = true;
4132
4133 if( p->iMode )
4134 {
4135 ok = p->iInteract->getInteractionModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4136 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4137 selectedJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4138 }
4139 else
4140 {
4141 ok = false;
4142 }
4143
4144 ret = ret && ok;
4145 }
4146
4147 selectedJointsBuffers.fillArbitraryJointVectorFromSubControlBoardBuffers(modes,n_joints,joints,remappedControlBoards);
4148
4149 return ret;
4150}
4151
4153{
4154 bool ret=true;
4155 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4156
4157 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4158 {
4159 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4160
4161 bool ok = true;
4162
4163 if( p->iMode )
4164 {
4166 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4167 allJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4168 }
4169 else
4170 {
4171 ok = false;
4172 }
4173
4174 ret = ret && ok;
4175 }
4176
4177 allJointsBuffers.fillCompleteJointVectorFromSubControlBoardBuffers(modes,remappedControlBoards);
4178
4179 return ret;
4180}
4181
4183{
4184 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4185 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4186
4187 RemappedSubControlBoard *s=remappedControlBoards.getSubControlBoard(subIndex);
4188
4189 if (!s)
4190 {
4191 return false;
4192 }
4193
4194 if (s->iInteract)
4195 {
4196 return s->iInteract->setInteractionMode(off, mode);
4197 }
4198
4199 return false;
4200}
4201
4203{
4204 bool ret=true;
4205 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4206
4207 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(modes,n_joints,joints,remappedControlBoards);
4208
4209 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4210 {
4211 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4212
4213 bool ok = p->iInteract->setInteractionModes(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4214 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4215 selectedJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4216 ret = ret && ok;
4217 }
4218
4219 return ret;
4220}
4221
4223{
4224 bool ret=true;
4225 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4226
4227 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(modes,remappedControlBoards);
4228
4229 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4230 {
4231 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4232
4233 bool ok = p->iInteract->setInteractionModes(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4234 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4235 allJointsBuffers.m_bufferForSubControlBoardInteractionModes[ctrlBrd].data());
4236 ret = ret && ok;
4237 }
4238
4239 return ret;
4240}
4241
4243{
4244 bool ret = false;
4245
4246 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4247
4248 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4249
4250 if (p && p->iPwm)
4251 {
4252 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4253 ret = p->iPwm->setRefDutyCycle(off, ref);
4254 }
4255
4256 return ret;
4257}
4258
4260{
4261 bool ret=true;
4262
4263 for(int l=0;l<controlledJoints;l++)
4264 {
4265 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4266 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4267
4268 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4269
4270 if (!p)
4271 {
4272 return false;
4273 }
4274
4275 if (p->iPwm)
4276 {
4277 bool ok = p->iPwm->setRefDutyCycle(off, refs[l]);
4278 ret = ret && ok;
4279 }
4280 else
4281 {
4282 ret=false;
4283 }
4284 }
4285
4286 return ret;
4287}
4288
4290{
4291 bool ret = false;
4292
4293 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4294
4295 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4296
4297 if (p && p->iPwm)
4298 {
4299 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4300 ret = p->iPwm->getRefDutyCycle(off, ref);
4301 }
4302
4303 return ret;
4304}
4305
4307{
4308 bool ret=true;
4309
4310 for(int l=0;l<controlledJoints;l++)
4311 {
4312 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4313 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4314
4315 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4316
4317 if (!p)
4318 {
4319 return false;
4320 }
4321
4322 if (p->iPwm)
4323 {
4324 bool ok = p->iPwm->getRefDutyCycle(off, refs+l);
4325 ret = ret && ok;
4326 }
4327 else
4328 {
4329 ret=false;
4330 }
4331 }
4332
4333 return ret;
4334}
4335
4337{
4338 bool ret = false;
4339
4340 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4341
4342 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4343
4344 if (p && p->iPwm)
4345 {
4346 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4347 ret = p->iPwm->getDutyCycle(off, val);
4348 }
4349
4350 return ret;
4351}
4352
4354{
4355 bool ret=true;
4356
4357 for(int l=0;l<controlledJoints;l++)
4358 {
4359 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4360 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4361
4362 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4363
4364 if (!p)
4365 {
4366 return false;
4367 }
4368
4369 if (p->iPwm)
4370 {
4371 bool ok = p->iPwm->getDutyCycle(off, vals+l);
4372 ret = ret && ok;
4373 }
4374 else
4375 {
4376 ret=false;
4377 }
4378 }
4379
4380 return ret;
4381}
4382
4384{
4385 bool ret = false;
4386
4387 size_t subIndex=remappedControlBoards.lut[j].subControlBoardIndex;
4388
4389 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4390
4391 if (p && p->iCurr)
4392 {
4393 int off=(int)remappedControlBoards.lut[j].axisIndexInSubControlBoard;
4394 ret = p->iCurr->getCurrent(off, val);
4395 }
4396
4397 return ret;
4398}
4399
4401{
4402 bool ret=true;
4403
4404 for(int l=0;l<controlledJoints;l++)
4405 {
4406 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4407 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4408
4409 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4410
4411 if (!p)
4412 {
4413 return false;
4414 }
4415
4416 if (p->iCurr)
4417 {
4418 bool ok = p->iCurr->getCurrent(off, vals+l);
4419 ret = ret && ok;
4420 }
4421 else
4422 {
4423 ret=false;
4424 }
4425 }
4426
4427 return ret;
4428}
4429
4430bool ControlBoardRemapper::getCurrentRange(int m, double* min, double* max)
4431{
4432 bool ret = false;
4433
4434 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4435
4436 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4437
4438 if (p && p->iCurr)
4439 {
4440 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4441 ret = p->iCurr->getCurrentRange(off, min, max);
4442 }
4443
4444 return ret;
4445}
4446
4447bool ControlBoardRemapper::getCurrentRanges(double* min, double* max)
4448{
4449 bool ret=true;
4450
4451 for(int l=0;l<controlledJoints;l++)
4452 {
4453 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4454 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4455
4456 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4457
4458 if (!p)
4459 {
4460 return false;
4461 }
4462
4463 if (p->iCurr)
4464 {
4465 bool ok = p->iCurr->getCurrentRange(off, min+l, max+l);
4466 ret = ret && ok;
4467 }
4468 else
4469 {
4470 ret=false;
4471 }
4472 }
4473
4474 return ret;
4475}
4476
4478{
4479 bool ret = false;
4480
4481 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4482
4483 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4484
4485 if (p && p->iCurr)
4486 {
4487 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4488 ret = p->iCurr->setRefCurrent(off, curr);
4489 }
4490
4491 return ret;
4492}
4493
4494bool ControlBoardRemapper::setRefCurrents(const int n_motor, const int* motors, const double* currs)
4495{
4496 bool ret=true;
4497 std::lock_guard<std::mutex> lock(selectedJointsBuffers.mutex);
4498
4499 selectedJointsBuffers.fillSubControlBoardBuffersFromArbitraryJointVector(currs,n_motor,motors,remappedControlBoards);
4500
4501 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4502 {
4503 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4504
4505 if (!(p && p->iCurr))
4506 {
4507 ret = false;
4508 break;
4509 }
4510
4511 bool ok = p->iCurr->setRefCurrents(selectedJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4512 selectedJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4513 selectedJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4514 ret = ret && ok;
4515 }
4516
4517 return ret;
4518}
4519
4521{
4522 bool ret=true;
4523 std::lock_guard<std::mutex> lock(allJointsBuffers.mutex);
4524
4525 allJointsBuffers.fillSubControlBoardBuffersFromCompleteJointVector(currs,remappedControlBoards);
4526
4527 for(size_t ctrlBrd=0; ctrlBrd < remappedControlBoards.getNrOfSubControlBoards(); ctrlBrd++)
4528 {
4529 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(ctrlBrd);
4530
4531 bool ok = p->iCurr->setRefCurrents(allJointsBuffers.m_nJointsInSubControlBoard[ctrlBrd],
4532 allJointsBuffers.m_jointsInSubControlBoard[ctrlBrd].data(),
4533 allJointsBuffers.m_bufferForSubControlBoard[ctrlBrd].data());
4534 ret = ret && ok;
4535 }
4536
4537 return ret;
4538}
4539
4541{
4542 bool ret = false;
4543
4544 size_t subIndex=remappedControlBoards.lut[m].subControlBoardIndex;
4545
4546 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4547
4548 if (p && p->iCurr)
4549 {
4550 int off=(int)remappedControlBoards.lut[m].axisIndexInSubControlBoard;
4551 ret = p->iCurr->getRefCurrent(off, curr);
4552 }
4553
4554 return ret;
4555}
4556
4558{
4559 bool ret=true;
4560
4561 for(int l=0;l<controlledJoints;l++)
4562 {
4563 int off=(int)remappedControlBoards.lut[l].axisIndexInSubControlBoard;
4564 size_t subIndex=remappedControlBoards.lut[l].subControlBoardIndex;
4565
4566 RemappedSubControlBoard *p=remappedControlBoards.getSubControlBoard(subIndex);
4567
4568 if (!p)
4569 {
4570 return false;
4571 }
4572
4573 if (p->iCurr)
4574 {
4575 bool ok = p->iCurr->getRefCurrent(off, currs+l);
4576 ret = ret && ok;
4577 }
4578 else
4579 {
4580 ret=false;
4581 }
4582 }
4583
4584 return ret;
4585}
const yarp::os::LogComponent & CONTROLBOARDREMAPPER()
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
bool ret
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
std::vector< std::vector< double > > m_bufferForSubControlBoard
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
void fillSubControlBoardBuffersFromArbitraryJointVector(const double *arbitraryVec, const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Fill buffers for the SubControlBoard from a vector of joints of the RemappedControlBoards.
std::vector< std::vector< int > > m_jointsInSubControlBoard
void resizeSubControlBoardBuffers(const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Resize buffers to have the dimension of specified by the method (used for multi joint methods that re...
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
void fillArbitraryJointVectorFromSubControlBoardBuffers(double *arbitraryVec, const int n_joints, const int *joints, const RemappedControlBoards &remappedControlBoards)
Fill a vector of joints of the ControlBoardRemapper from the buffers of the SubControlBoard .
std::mutex mutex
Mutex to grab to use this class.
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 motors 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
Get the instantaneous current measurement for a single motor.
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 getLastJointFault(int j, int &fault, std::string &message) override
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
Get the instantaneous current measurement for all motors.
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.
bool configure(const RemappedControlBoards &remappedControlBoards)
Resize the buffers using the information in the RemappedControlBoards.
std::mutex mutex
Mutex to grab to use this class.
std::vector< std::vector< int > > m_jointsInSubControlBoard
void fillCompleteJointVectorFromSubControlBoardBuffers(double *full, const RemappedControlBoards &remappedControlBoards)
Fill a vector of joints of the ControlBoardRemapper from the buffers of the SubControlBoard .
void fillSubControlBoardBuffersFromCompleteJointVector(const double *full, const RemappedControlBoards &remappedControlBoards)
Fill buffers for the SubControlBoard from a vector of joints of the RemappedControlBoards.
std::vector< std::vector< double > > m_bufferForSubControlBoard
std::vector< std::vector< int > > m_bufferForSubControlBoardControlModes
std::vector< std::vector< yarp::dev::InteractionModeEnum > > m_bufferForSubControlBoardInteractionModes
std::vector< RemappedSubControlBoard > subdevices
Vector of dimension getNrOfSubControlBoards .
std::vector< RemappedAxis > lut
Vector of dimension getNrOfRemappedAxes .
RemappedSubControlBoard * getSubControlBoard(size_t i)
Given a controlboard index between 0 and getNrOfSubControlBoards()-1, return the relative SubControlB...
yarp::dev::IPositionControl * pos
yarp::dev::IImpedanceControl * iImpedance
yarp::dev::IAmplifierControl * amp
yarp::dev::IEncodersTimed * iJntEnc
yarp::dev::IInteractionMode * iInteract
yarp::dev::IRemoteVariables * iVar
yarp::dev::ICurrentControl * iCurr
yarp::dev::ITorqueControl * iTorque
yarp::dev::IVelocityControl * vel
yarp::dev::IControlMode * iMode
yarp::dev::IJointFault * iFault
yarp::dev::IPositionDirect * posDir
yarp::dev::IRemoteCalibrator * remcalib
yarp::dev::IControlLimits * lim
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:36
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
Definition IAxisInfo.h:63
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 setControlMode(const int j, const int mode)=0
Set the current control mode.
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:116
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 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 getLastJointFault(int j, int &fault, std::string &message)=0
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:147
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:155
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 getTargetPosition(const int joint, double *ref)
Get the last position reference for the specified axis.
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 bool getRefPosition(const int joint, double *ref)
Get the last position reference for the specified 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 parkWholePart()=0
parkWholePart: start the parking procedure for the whole part
virtual bool homingSingleJoint(int j)=0
homingSingleJoint: call the homing procedure for a single joint
virtual bool setCalibratorDevice(yarp::dev::IRemoteCalibrator *dev)
setCalibratorDevice: store the pointer to the calibrator device.
virtual void releaseCalibratorDevice()
releaseCalibratorDevice: reset the internal pointer to NULL when stop using the calibrator
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 getRefVelocity(const int joint, double *vel)
Get the last reference speed set by velocityMove for single joint.
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:64
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition Bottle.cpp:353
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 mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
A base class for nested structures that can be searched.
Definition Searchable.h:31
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:21
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
Definition Stamp.cpp:124
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,...)
#define yCError(component,...)
#define yCWarning(component,...)
For streams capable of holding different kinds of content, check what they actually have.
PidControlTypeEnum
Definition PidEnums.h:15
An interface to the operating system, including Port based communication.
size_t indexOfSubDeviceInPolyDriverList