YARP
Yet Another Robot Platform
RPCMessagesParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "RPCMessagesParser.h"
8
9#include <yarp/os/LogStream.h>
10
13#include <iostream>
14
15using namespace yarp::os;
16using namespace yarp::dev;
17using namespace yarp::dev::impl;
18using namespace yarp::sig;
19
20
21inline void appendTimeStamp(Bottle& bot, Stamp& st)
22{
23 int count = st.getCount();
24 double time = st.getTime();
26 bot.addInt32(count);
27 bot.addFloat64(time);
28}
29
31 yarp::os::Bottle& response,
32 bool* rec,
33 bool* ok)
34{
35 if (cmd.get(0).asVocab32() != VOCAB_GET) {
36 *rec = false;
37 *ok = false;
38 return;
39 }
40
45
46 *rec = true;
47 *ok = true;
48}
49
51 yarp::os::Bottle& response,
52 bool* rec,
53 bool* ok)
54{
55 yCTrace(CONTROLBOARD, "Handling IImpedance message");
56 if (!rpc_IImpedance) {
57 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid interface");
58 *ok = false;
59 return;
60 }
61
62 int code = cmd.get(0).asVocab32();
63 *ok = false;
64 switch (code) {
65 case VOCAB_SET: {
66 yCTrace(CONTROLBOARD, "handleImpedanceMsg::VOCAB_SET command");
67 switch (cmd.get(2).asVocab32()) {
68 case VOCAB_IMP_PARAM: {
69 Bottle* b = cmd.get(4).asList();
70 if (b != nullptr) {
71 double stiff = b->get(0).asFloat64();
72 double damp = b->get(1).asFloat64();
73 *ok = rpc_IImpedance->setImpedance(cmd.get(3).asInt32(), stiff, damp);
74 *rec = true;
75 }
76 } break;
77 case VOCAB_IMP_OFFSET: {
78 Bottle* b = cmd.get(4).asList();
79 if (b != nullptr) {
80 double offs = b->get(0).asFloat64();
81 *ok = rpc_IImpedance->setImpedanceOffset(cmd.get(3).asInt32(), offs);
82 *rec = true;
83 }
84 } break;
85 }
86 } break;
87 case VOCAB_GET: {
88 double stiff = 0;
89 double damp = 0;
90 double offs = 0;
91 yCTrace(CONTROLBOARD, "handleImpedanceMsg::VOCAB_GET command");
92
93 response.addVocab32(VOCAB_IS);
94 response.add(cmd.get(1));
95 switch (cmd.get(2).asVocab32()) {
96 case VOCAB_IMP_PARAM: {
97 *ok = rpc_IImpedance->getImpedance(cmd.get(3).asInt32(), &stiff, &damp);
98 Bottle& b = response.addList();
99 b.addFloat64(stiff);
100 b.addFloat64(damp);
101 *rec = true;
102 } break;
103 case VOCAB_IMP_OFFSET: {
104 *ok = rpc_IImpedance->getImpedanceOffset(cmd.get(3).asInt32(), &offs);
105 Bottle& b = response.addList();
106 b.addFloat64(offs);
107 *rec = true;
108 } break;
109 case VOCAB_LIMITS: {
110 double min_stiff = 0;
111 double max_stiff = 0;
112 double min_damp = 0;
113 double max_damp = 0;
114 *ok = rpc_IImpedance->getCurrentImpedanceLimit(cmd.get(3).asInt32(), &min_stiff, &max_stiff, &min_damp, &max_damp);
115 Bottle& b = response.addList();
116 b.addFloat64(min_stiff);
117 b.addFloat64(max_stiff);
118 b.addFloat64(min_damp);
119 b.addFloat64(max_damp);
120 *rec = true;
121 } break;
122 }
123 }
125 appendTimeStamp(response, lastRpcStamp);
126 break; // case VOCAB_GET
127 default:
128 {
129 *rec = false;
130 } break;
131 }
132}
133
135 yarp::os::Bottle& response,
136 bool* rec,
137 bool* ok)
138{
139 //handle here messages about IControlMode interface
140 int code = cmd.get(0).asVocab32();
141 *ok = true;
142 *rec = true; //or false
143
144 switch (code)
145 {
146 case VOCAB_GET:
147 yCTrace(CONTROLBOARD, "GET command");
148
149 int method = cmd.get(2).asVocab32();
150
151 switch (method)
152 {
154 yCTrace(CONTROLBOARD, "getJointFault");
155 int axis = cmd.get(3).asInt32();
156 int faultcode=0;
157 std::string faultmessage;
158 if (rpc_IJointFault)
159 {
160 *ok = rpc_IJointFault->getLastJointFault(axis, faultcode, faultmessage);
161 *rec = true;
162 }
163 response.addVocab32(VOCAB_IS);
164 response.addInt32(faultcode);
165 response.addString(faultmessage);
166
167 yCTrace(CONTROLBOARD, "Returning %d %s", faultcode, faultmessage.c_str());
168 *rec = true;
169 break;
170 }
171
172 break;
173 }
174}
175
177 yarp::os::Bottle& response,
178 bool* rec,
179 bool* ok)
180{
181 yCTrace(CONTROLBOARD, "Handling IControlMode message");
182 if (!(rpc_iCtrlMode)) {
183 yCError(CONTROLBOARD, "ControlBoardWrapper: I do not have a valid iControlMode interface");
184 *ok = false;
185 return;
186 }
187
188 //handle here messages about IControlMode interface
189 int code = cmd.get(0).asVocab32();
190 *ok = true;
191 *rec = true; //or false
192
193 switch (code) {
194 case VOCAB_SET: {
195 yCTrace(CONTROLBOARD, "handleControlModeMsg::VOCAB_SET command");
196
197 int method = cmd.get(2).asVocab32();
198
199 switch (method) {
201 int axis = cmd.get(3).asInt32();
202 yCTrace(CONTROLBOARD) << "got VOCAB_CM_CONTROL_MODE";
203 if (rpc_iCtrlMode) {
204 *ok = rpc_iCtrlMode->setControlMode(axis, cmd.get(4).asVocab32());
205 } else {
206 yCError(CONTROLBOARD) << "ControlBoardWrapper: Unable to handle setControlMode request! This should not happen!";
207 *rec = false;
208 }
209 } break;
210
212 int n_joints = cmd.get(3).asInt32();
213 Bottle& jList = *(cmd.get(4).asList());
214 Bottle& modeList = *(cmd.get(5).asList());
215
216 int* js = new int[n_joints];
217 int* modes = new int[n_joints];
218
219 for (int i = 0; i < n_joints; i++) {
220 js[i] = jList.get(i).asInt32();
221 }
222
223 for (int i = 0; i < n_joints; i++) {
224 modes[i] = modeList.get(i).asVocab32();
225 }
226 if (rpc_iCtrlMode) {
227 *ok = rpc_iCtrlMode->setControlModes(n_joints, js, modes);
228 } else {
229 *rec = false;
230 *ok = false;
231 }
232 delete[] js;
233 delete[] modes;
234 } break;
235
237 yarp::os::Bottle* modeList;
238 modeList = cmd.get(3).asList();
239
240 if (modeList->size() != controlledJoints) {
241 yCError(CONTROLBOARD, "received an invalid setControlMode message. Size of vector doesn´t match the number of controlled joints");
242 *ok = false;
243 break;
244 }
245 int* modes = new int[controlledJoints];
246 for (size_t i = 0; i < controlledJoints; i++) {
247 modes[i] = modeList->get(i).asVocab32();
248 }
249 if (rpc_iCtrlMode) {
250 *ok = rpc_iCtrlMode->setControlModes(modes);
251 } else {
252 *rec = false;
253 *ok = false;
254 }
255 delete[] modes;
256 } break;
257
258 default:
259 {
260 // if I´m here, someone is probably sending command using the old interface.
261 // try to be compatible as much as I can
262
263 yCError(CONTROLBOARD) << " Error, received a set control mode message using a legacy version, trying to be handle the message anyway "
264 << " but please update your client to be compatible with the IControlMode interface";
265
266 yCTrace(CONTROLBOARD) << " cmd.get(4).asVocab32() is " << Vocab32::decode(cmd.get(4).asVocab32());
267 int axis = cmd.get(3).asInt32();
268
269 switch (cmd.get(4).asVocab32()) {
271 if (rpc_iCtrlMode) {
273 }
274 break;
275
277 if (rpc_iCtrlMode) {
279 } else {
280 *rec = false;
281 *ok = false;
282 }
283 break;
284
285
287 if (rpc_iCtrlMode) {
289 }
290 break;
291
292 case VOCAB_CM_TORQUE:
293 if (rpc_iCtrlMode) {
295 }
296 break;
297
299 yCError(CONTROLBOARD) << "The 'impedancePosition' control mode is deprecated. \nUse setInteractionMode(axis, VOCAB_IM_COMPLIANT) + setControlMode(axis, VOCAB_CM_POSITION) instead";
300 break;
301
303 yCError(CONTROLBOARD) << "The 'impedanceVelocity' control mode is deprecated. \nUse setInteractionMode(axis, VOCAB_IM_COMPLIANT) + setControlMode(axis, VOCAB_CM_VELOCITY) instead";
304 break;
305
306 case VOCAB_CM_PWM:
307 if (rpc_iCtrlMode) {
309 } else {
310 *rec = false;
311 *ok = false;
312 }
313 break;
314
315 case VOCAB_CM_CURRENT:
316 if (rpc_iCtrlMode) {
318 } else {
319 *rec = false;
320 *ok = false;
321 }
322 break;
323
324 case VOCAB_CM_MIXED:
325 if (rpc_iCtrlMode) {
327 } else {
328 *rec = false;
329 *ok = false;
330 }
331 break;
332
334 if (rpc_iCtrlMode) {
336 } else {
337 *rec = false;
338 *ok = false;
339 }
340 break;
341
342 default:
343 yCError(CONTROLBOARD, "SET unknown controlMode : %s ", cmd.toString().c_str());
344 *ok = false;
345 *rec = false;
346 break;
347 }
348 } break; // close default case
349 }
350 } break; // close SET case
351
352 case VOCAB_GET: {
353 yCTrace(CONTROLBOARD, "GET command");
354
355 int method = cmd.get(2).asVocab32();
356
357 switch (method) {
358
360 yCTrace(CONTROLBOARD, "getControlModes");
361 int* p = new int[controlledJoints];
362 for (size_t i = 0; i < controlledJoints; ++i) {
363 p[i] = -1;
364 }
365 if (rpc_iCtrlMode) {
367 }
368
369 response.addVocab32(VOCAB_IS);
371
372 Bottle& b = response.addList();
373 for (size_t i = 0; i < controlledJoints; i++) {
374 b.addVocab32(p[i]);
375 }
376 delete[] p;
377
378 *rec = true;
379 } break;
380
382 yCTrace(CONTROLBOARD, "getControlMode");
383
384 int p = -1;
385 int axis = cmd.get(3).asInt32();
386 if (rpc_iCtrlMode) {
387 *ok = rpc_iCtrlMode->getControlMode(axis, &p);
388 }
389
390 response.addVocab32(VOCAB_IS);
391 response.addInt32(axis);
392 response.addVocab32(p);
393
394 yCTrace(CONTROLBOARD, "Returning %d", p);
395 *rec = true;
396 } break;
397
399 yCTrace(CONTROLBOARD, "getControlMode group");
400
401 int n_joints = cmd.get(3).asInt32();
402 Bottle& lIn = *(cmd.get(4).asList());
403
404 int* js = new int[n_joints];
405 int* modes = new int[n_joints];
406 for (int i = 0; i < n_joints; i++) {
407 js[i] = lIn.get(i).asInt32();
408 modes[i] = -1;
409 }
410 if (rpc_iCtrlMode) {
411 *ok = rpc_iCtrlMode->getControlModes(n_joints, js, modes);
412 } else {
413 *rec = false;
414 *ok = false;
415 }
416
417 response.addVocab32(VOCAB_IS);
419 Bottle& b = response.addList();
420 for (int i = 0; i < n_joints; i++) {
421 b.addVocab32(modes[i]);
422 }
423
424 delete[] js;
425 delete[] modes;
426
427 *rec = true;
428 } break;
429
430 default:
431 yCError(CONTROLBOARD, "received a GET ICONTROLMODE command not understood");
432 break;
433 }
434 }
435
437 appendTimeStamp(response, lastRpcStamp);
438 break; // case VOCAB_GET
439
440 default:
441 {
442 *rec = false;
443 } break;
444 }
445}
446
447
449 yarp::os::Bottle& response,
450 bool* rec,
451 bool* ok)
452{
453 yCTrace(CONTROLBOARD, "Handling ITorqueControl message");
454
455 if (!rpc_ITorque) {
456 yCError(CONTROLBOARD, "Error, I do not have a valid ITorque interface");
457 *ok = false;
458 return;
459 }
460
461 int code = cmd.get(0).asVocab32();
462 switch (code) {
463 case VOCAB_SET: {
464 *rec = true;
465 yCTrace(CONTROLBOARD, "set command received");
466
467 switch (cmd.get(2).asVocab32()) {
468 case VOCAB_REF: {
469 *ok = rpc_ITorque->setRefTorque(cmd.get(3).asInt32(), cmd.get(4).asFloat64());
470 } break;
471
472 case VOCAB_MOTOR_PARAMS: {
474 int joint = cmd.get(3).asInt32();
475 Bottle* b = cmd.get(4).asList();
476
477 if (b == nullptr) {
478 break;
479 }
480
481 if (b->size() != 8) {
482 yCError(CONTROLBOARD, "received a SET VOCAB_MOTOR_PARAMS command not understood, size != 8");
483 break;
484 }
485
486 params.bemf = b->get(0).asFloat64();
487 params.bemf_scale = b->get(1).asFloat64();
488 params.ktau = b->get(2).asFloat64();
489 params.ktau_scale = b->get(3).asFloat64();
490 params.viscousPos = b->get(4).asFloat64();
491 params.viscousNeg = b->get(5).asFloat64();
492 params.coulombPos = b->get(6).asFloat64();
493 params.coulombNeg = b->get(7).asFloat64();
494
495 *ok = rpc_ITorque->setMotorTorqueParams(joint, params);
496 } break;
497
498 case VOCAB_REFS: {
499 Bottle* b = cmd.get(3).asList();
500 if (b == nullptr) {
501 break;
502 }
503
504 const size_t njs = b->size();
505 if (njs == controlledJoints) {
506 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
507 for (size_t i = 0; i < njs; i++) {
508 p[i] = b->get(i).asFloat64();
509 }
510 *ok = rpc_ITorque->setRefTorques(p);
511 delete[] p;
512 }
513 } break;
514
515 case VOCAB_TORQUE_MODE: {
516 if (rpc_iCtrlMode) {
517 int* modes = new int[controlledJoints];
518 for (size_t i = 0; i < controlledJoints; i++) {
519 modes[i] = VOCAB_CM_TORQUE;
520 }
521 *ok = rpc_iCtrlMode->setControlModes(modes);
522 delete[] modes;
523 } else {
524 *ok = false;
525 }
526 } break;
527 }
528 } break;
529
530 case VOCAB_GET: {
531 *rec = true;
532 yCTrace(CONTROLBOARD, "get command received");
533 double dtmp = 0.0;
534 double dtmp2 = 0.0;
535 response.addVocab32(VOCAB_IS);
536 response.add(cmd.get(1));
537
538 switch (cmd.get(2).asVocab32()) {
539 case VOCAB_AXES: {
540 int tmp;
541 *ok = rpc_ITorque->getAxes(&tmp);
542 response.addInt32(tmp);
543 } break;
544
545 case VOCAB_TRQ: {
546 *ok = rpc_ITorque->getTorque(cmd.get(3).asInt32(), &dtmp);
547 response.addFloat64(dtmp);
548 } break;
549
550 case VOCAB_MOTOR_PARAMS: {
552 int joint = cmd.get(3).asInt32();
553
554 // get the data
555 *ok = rpc_ITorque->getMotorTorqueParams(joint, &params);
556
557 // convert it back to yarp message
558 Bottle& b = response.addList();
559
560 b.addFloat64(params.bemf);
561 b.addFloat64(params.bemf_scale);
562 b.addFloat64(params.ktau);
563 b.addFloat64(params.ktau_scale);
564 b.addFloat64(params.viscousPos);
565 b.addFloat64(params.viscousNeg);
566 b.addFloat64(params.coulombPos);
567 b.addFloat64(params.coulombNeg);
568 } break;
569 case VOCAB_RANGE: {
570 *ok = rpc_ITorque->getTorqueRange(cmd.get(3).asInt32(), &dtmp, &dtmp2);
571 response.addFloat64(dtmp);
572 response.addFloat64(dtmp2);
573 } break;
574
575 case VOCAB_TRQS: {
576 auto* p = new double[controlledJoints];
577 *ok = rpc_ITorque->getTorques(p);
578 Bottle& b = response.addList();
579 for (size_t i = 0; i < controlledJoints; i++) {
580 b.addFloat64(p[i]);
581 }
582 delete[] p;
583 } break;
584
585 case VOCAB_RANGES: {
586 auto* p1 = new double[controlledJoints];
587 auto* p2 = new double[controlledJoints];
588 *ok = rpc_ITorque->getTorqueRanges(p1, p2);
589 Bottle& b1 = response.addList();
590 for (size_t i = 0; i < controlledJoints; i++) {
591 b1.addFloat64(p1[i]);
592 }
593 Bottle& b2 = response.addList();
594 for (size_t i = 0; i < controlledJoints; i++) {
595 b2.addFloat64(p2[i]);
596 }
597 delete[] p1;
598 delete[] p2;
599 } break;
600
601 case VOCAB_REFERENCE: {
602 *ok = rpc_ITorque->getRefTorque(cmd.get(3).asInt32(), &dtmp);
603 response.addFloat64(dtmp);
604 } break;
605
606 case VOCAB_REFERENCES: {
607 auto* p = new double[controlledJoints];
608 *ok = rpc_ITorque->getRefTorques(p);
609 Bottle& b = response.addList();
610 for (size_t i = 0; i < controlledJoints; i++) {
611 b.addFloat64(p[i]);
612 }
613 delete[] p;
614 } break;
615 }
616 }
618 appendTimeStamp(response, lastRpcStamp);
619 break; // case VOCAB_GET
620 }
621}
622
624 yarp::os::Bottle& response,
625 bool* rec,
626 bool* ok)
627{
628 yCTrace(CONTROLBOARD, "\nHandling IInteractionMode message");
629 if (!rpc_IInteract) {
630 yCError(CONTROLBOARD, "Error I do not have a valid IInteractionMode interface");
631 *ok = false;
632 return;
633 }
634
635 yCTrace(CONTROLBOARD) << "received command: " << cmd.toString();
636
637 int action = cmd.get(0).asVocab32();
638
639 switch (action) {
640 case VOCAB_SET: {
641 switch (cmd.get(2).asVocab32()) {
642 yarp::os::Bottle* jointList;
643 yarp::os::Bottle* modeList;
645
648 } break;
649
651 yCTrace(CONTROLBOARD) << "CBW.h set interactionMode GROUP";
652
653 auto n_joints = static_cast<size_t>(cmd.get(3).asInt32());
654 jointList = cmd.get(4).asList();
655 modeList = cmd.get(5).asList();
656 if ((jointList->size() != n_joints) || (modeList->size() != n_joints)) {
657 yCWarning(CONTROLBOARD, "Received an invalid setInteractionMode message. Size of vectors doesn´t match");
658 *ok = false;
659 break;
660 }
661 int* joints = new int[n_joints];
662 modes = new yarp::dev::InteractionModeEnum[n_joints];
663 for (size_t i = 0; i < n_joints; i++) {
664 joints[i] = jointList->get(i).asInt32();
665 modes[i] = static_cast<yarp::dev::InteractionModeEnum>(modeList->get(i).asVocab32());
666 yCTrace(CONTROLBOARD) << "CBW.cpp received vocab " << yarp::os::Vocab32::decode(modes[i]);
667 }
668 *ok = rpc_IInteract->setInteractionModes(n_joints, joints, modes);
669 delete[] joints;
670 delete[] modes;
671
672 } break;
673
675 yCTrace(CONTROLBOARD) << "CBW.c set interactionMode ALL";
676
677 modeList = cmd.get(3).asList();
678 if (modeList->size() != controlledJoints) {
679 yCWarning(CONTROLBOARD, "Received an invalid setInteractionMode message. Size of vector doesn´t match the number of controlled joints");
680 *ok = false;
681 break;
682 }
684 for (size_t i = 0; i < controlledJoints; i++) {
685 modes[i] = static_cast<yarp::dev::InteractionModeEnum>(modeList->get(i).asVocab32());
686 }
688 delete[] modes;
689 } break;
690
691 default:
692 {
693 yCWarning(CONTROLBOARD, "Error while Handling IInteractionMode message, SET command not understood %s", cmd.get(2).asString().c_str());
694 *ok = false;
695 } break;
696 }
697 *rec = true; //or false
698 } break;
699
700 case VOCAB_GET: {
701 yarp::os::Bottle* jointList;
702
703 switch (cmd.get(2).asVocab32()) {
706 *ok = rpc_IInteract->getInteractionMode(cmd.get(3).asInt32(), &mode);
707 response.addVocab32(mode);
708 yCTrace(CONTROLBOARD) << " resp is " << response.toString();
709 } break;
710
713
714 int n_joints = cmd.get(3).asInt32();
715 jointList = cmd.get(4).asList();
716 if (jointList->size() != static_cast<size_t>(n_joints)) {
717 yCError(CONTROLBOARD, "Received an invalid getInteractionMode message. Size of vectors doesn´t match");
718 *ok = false;
719 break;
720 }
721 int* joints = new int[n_joints];
722 modes = new yarp::dev::InteractionModeEnum[n_joints];
723 for (int i = 0; i < n_joints; i++) {
724 joints[i] = jointList->get(i).asInt32();
725 }
726 *ok = rpc_IInteract->getInteractionModes(n_joints, joints, modes);
727
728 Bottle& c = response.addList();
729 for (int i = 0; i < n_joints; i++) {
730 c.addVocab32(modes[i]);
731 }
732
733 yCTrace(CONTROLBOARD, "got response bottle: %s", response.toString().c_str());
734
735 delete[] joints;
736 delete[] modes;
737 } break;
738
742
744
745 Bottle& b = response.addList();
746 for (size_t i = 0; i < controlledJoints; i++) {
747 b.addVocab32(modes[i]);
748 }
749
750 yCTrace(CONTROLBOARD, "got response bottle: %s", response.toString().c_str());
751
752 delete[] modes;
753 } break;
754 }
756 appendTimeStamp(response, lastRpcStamp);
757 } break; // case VOCAB_GET
758
759 default:
760 yCError(CONTROLBOARD, "Error while Handling IInteractionMode message, command was not SET nor GET");
761 *ok = false;
762 break;
763 }
764}
765
766void RPCMessagesParser::handleCurrentMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok)
767{
768 yCTrace(CONTROLBOARD, "Handling ICurrentControl message");
769
770 if (!rpc_ICurrent) {
771 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid ICurrentControl interface");
772 *ok = false;
773 return;
774 }
775
776 int code = cmd.get(0).asVocab32();
777 int action = cmd.get(2).asVocab32();
778
779 *ok = false;
780 *rec = true;
781 switch (code) {
782 case VOCAB_SET: {
783 switch (action) {
784 case VOCAB_CURRENT_REF: {
785 yCError(CONTROLBOARD, "VOCAB_CURRENT_REF methods is implemented as streaming");
786 *ok = false;
787 } break;
788
789 case VOCAB_CURRENT_REFS: {
790 yCError(CONTROLBOARD, "VOCAB_CURRENT_REFS methods is implemented as streaming");
791 *ok = false;
792 } break;
793
795 yCError(CONTROLBOARD, "VOCAB_CURRENT_REF_GROUP methods is implemented as streaming");
796 *ok = false;
797 } break;
798
799 default:
800 {
801 yCError(CONTROLBOARD) << "Unknown handleCurrentMsg message received";
802 *rec = false;
803 *ok = false;
804 } break;
805 }
806 } break;
807
808 case VOCAB_GET: {
809 *rec = true;
810 yCTrace(CONTROLBOARD, "get command received");
811 double dtmp = 0.0;
812 double dtmp2 = 0.0;
813 response.addVocab32(VOCAB_IS);
814 response.add(cmd.get(1));
815
816 switch (action) {
817 case VOCAB_CURRENT_REF: {
818 *ok = rpc_ICurrent->getRefCurrent(cmd.get(3).asInt32(), &dtmp);
819 response.addFloat64(dtmp);
820 } break;
821
822 case VOCAB_CURRENT_REFS: {
823 auto* p = new double[controlledJoints];
825 Bottle& b = response.addList();
826 for (size_t i = 0; i < controlledJoints; i++) {
827 b.addFloat64(p[i]);
828 }
829 delete[] p;
830 } break;
831
832 case VOCAB_CURRENT_RANGE: {
833
834 *ok = rpc_ICurrent->getCurrentRange(cmd.get(3).asInt32(), &dtmp, &dtmp2);
835 response.addFloat64(dtmp);
836 response.addFloat64(dtmp2);
837 } break;
838
840 auto* p1 = new double[controlledJoints];
841 auto* p2 = new double[controlledJoints];
842 *ok = rpc_ICurrent->getCurrentRanges(p1, p2);
843 Bottle& b1 = response.addList();
844 Bottle& b2 = response.addList();
845 for (size_t i = 0; i < controlledJoints; i++) {
846 b1.addFloat64(p1[i]);
847 }
848 for (size_t i = 0; i < controlledJoints; i++) {
849 b2.addFloat64(p2[i]);
850 }
851 delete[] p1;
852 delete[] p2;
853 } break;
854
855 default:
856 {
857 yCError(CONTROLBOARD) << "Unknown handleCurrentMsg message received";
858 *rec = false;
859 *ok = false;
860 } break;
861 }
862 } break;
863
864 default:
865 {
866 yCError(CONTROLBOARD) << "Unknown handleCurrentMsg message received";
867 *rec = false;
868 *ok = false;
869 } break;
870 }
871}
872
873void RPCMessagesParser::handlePidMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok)
874{
875 yCTrace(CONTROLBOARD, "Handling IPidControl message");
876
877 if (!rpc_IPid) {
878 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid IPidControl interface");
879 *ok = false;
880 return;
881 }
882
883 int code = cmd.get(0).asVocab32();
884 int action = cmd.get(2).asVocab32();
885 auto pidtype = static_cast<yarp::dev::PidControlTypeEnum>(cmd.get(3).asVocab32());
886
887 *ok = false;
888 *rec = true;
889 switch (code) {
890 case VOCAB_SET: {
891 *rec = true;
892 yCTrace(CONTROLBOARD, "set command received");
893
894 switch (action) {
895 case VOCAB_OFFSET: {
896 double v;
897 int j = cmd.get(4).asInt32();
898 v = cmd.get(5).asFloat64();
899 *ok = rpc_IPid->setPidOffset(pidtype, j, v);
900 } break;
901
902 case VOCAB_PID: {
903 Pid p;
904 int j = cmd.get(4).asInt32();
905 Bottle* b = cmd.get(5).asList();
906
907 if (b == nullptr) {
908 break;
909 }
910
911 p.kp = b->get(0).asFloat64();
912 p.kd = b->get(1).asFloat64();
913 p.ki = b->get(2).asFloat64();
914 p.max_int = b->get(3).asFloat64();
915 p.max_output = b->get(4).asFloat64();
916 p.offset = b->get(5).asFloat64();
917 p.scale = b->get(6).asFloat64();
918 p.stiction_up_val = b->get(7).asFloat64();
919 p.stiction_down_val = b->get(8).asFloat64();
920 p.kff = b->get(9).asFloat64();
921 *ok = rpc_IPid->setPid(pidtype, j, p);
922 } break;
923
924 case VOCAB_PIDS: {
925 Bottle* b = cmd.get(4).asList();
926
927 if (b == nullptr) {
928 break;
929 }
930
931 const size_t njs = b->size();
932 if (njs == controlledJoints) {
933 Pid* p = new Pid[njs];
934
935 bool allOK = true;
936
937 for (size_t i = 0; i < njs; i++) {
938 Bottle* c = b->get(i).asList();
939 if (c != nullptr) {
940 p[i].kp = c->get(0).asFloat64();
941 p[i].kd = c->get(1).asFloat64();
942 p[i].ki = c->get(2).asFloat64();
943 p[i].max_int = c->get(3).asFloat64();
944 p[i].max_output = c->get(4).asFloat64();
945 p[i].offset = c->get(5).asFloat64();
946 p[i].scale = c->get(6).asFloat64();
947 p[i].stiction_up_val = c->get(7).asFloat64();
948 p[i].stiction_down_val = c->get(8).asFloat64();
949 p[i].kff = c->get(9).asFloat64();
950 } else {
951 allOK = false;
952 }
953 }
954 if (allOK) {
955 *ok = rpc_IPid->setPids(pidtype, p);
956 } else {
957 *ok = false;
958 }
959
960 delete[] p;
961 }
962 } break;
963
964 case VOCAB_REF: {
965 *ok = rpc_IPid->setPidReference(pidtype, cmd.get(4).asInt32(), cmd.get(5).asFloat64());
966 } break;
967
968 case VOCAB_REFS: {
969 Bottle* b = cmd.get(4).asList();
970
971 if (b == nullptr) {
972 break;
973 }
974
975 const size_t njs = b->size();
976 if (njs == controlledJoints) {
977 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
978 for (size_t i = 0; i < njs; i++) {
979 p[i] = b->get(i).asFloat64();
980 }
981 *ok = rpc_IPid->setPidReferences(pidtype, p);
982 delete[] p;
983 }
984 } break;
985
986 case VOCAB_LIM: {
987 *ok = rpc_IPid->setPidErrorLimit(pidtype, cmd.get(4).asInt32(), cmd.get(5).asFloat64());
988 } break;
989
990 case VOCAB_LIMS: {
991 Bottle* b = cmd.get(4).asList();
992
993 if (b == nullptr) {
994 break;
995 }
996
997 const size_t njs = b->size();
998 if (njs == controlledJoints) {
999 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1000 for (size_t i = 0; i < njs; i++) {
1001 p[i] = b->get(i).asFloat64();
1002 }
1003 *ok = rpc_IPid->setPidErrorLimits(pidtype, p);
1004 delete[] p;
1005 }
1006 } break;
1007
1008 case VOCAB_RESET: {
1009 *ok = rpc_IPid->resetPid(pidtype, cmd.get(4).asInt32());
1010 } break;
1011
1012 case VOCAB_DISABLE: {
1013 *ok = rpc_IPid->disablePid(pidtype, cmd.get(4).asInt32());
1014 } break;
1015
1016 case VOCAB_ENABLE: {
1017 *ok = rpc_IPid->enablePid(pidtype, cmd.get(4).asInt32());
1018 } break;
1019 }
1020 } break;
1021
1022 case VOCAB_GET: {
1023 *rec = true;
1024 yCTrace(CONTROLBOARD, "get command received");
1025 double dtmp = 0.0;
1026 response.addVocab32(VOCAB_IS);
1027 response.add(cmd.get(1));
1028
1029 switch (action) {
1030 case VOCAB_LIMS: {
1031 auto* p = new double[controlledJoints];
1032 *ok = rpc_IPid->getPidErrorLimits(pidtype, p);
1033 Bottle& b = response.addList();
1034 for (size_t i = 0; i < controlledJoints; i++) {
1035 b.addFloat64(p[i]);
1036 }
1037 delete[] p;
1038 } break;
1039
1040 case VOCAB_ENABLE: {
1041 bool booltmp = false;
1042 *ok = rpc_IPid->isPidEnabled(pidtype, cmd.get(4).asInt32(), &booltmp);
1043 response.addInt32(booltmp);
1044 } break;
1045
1046 case VOCAB_ERR: {
1047 *ok = rpc_IPid->getPidError(pidtype, cmd.get(4).asInt32(), &dtmp);
1048 response.addFloat64(dtmp);
1049 } break;
1050
1051 case VOCAB_ERRS: {
1052 auto* p = new double[controlledJoints];
1053 *ok = rpc_IPid->getPidErrors(pidtype, p);
1054 Bottle& b = response.addList();
1055 for (size_t i = 0; i < controlledJoints; i++) {
1056 b.addFloat64(p[i]);
1057 }
1058 delete[] p;
1059 } break;
1060
1061 case VOCAB_OUTPUT: {
1062 *ok = rpc_IPid->getPidOutput(pidtype, cmd.get(4).asInt32(), &dtmp);
1063 response.addFloat64(dtmp);
1064 } break;
1065
1066 case VOCAB_OUTPUTS: {
1067 auto* p = new double[controlledJoints];
1068 *ok = rpc_IPid->getPidOutputs(pidtype, p);
1069 Bottle& b = response.addList();
1070 for (size_t i = 0; i < controlledJoints; i++) {
1071 b.addFloat64(p[i]);
1072 }
1073 delete[] p;
1074 } break;
1075
1076 case VOCAB_PID: {
1077 Pid p;
1078 *ok = rpc_IPid->getPid(pidtype, cmd.get(4).asInt32(), &p);
1079 Bottle& b = response.addList();
1080 b.addFloat64(p.kp);
1081 b.addFloat64(p.kd);
1082 b.addFloat64(p.ki);
1083 b.addFloat64(p.max_int);
1085 b.addFloat64(p.offset);
1086 b.addFloat64(p.scale);
1089 b.addFloat64(p.kff);
1090 } break;
1091
1092 case VOCAB_PIDS: {
1093 Pid* p = new Pid[controlledJoints];
1094 *ok = rpc_IPid->getPids(pidtype, p);
1095 Bottle& b = response.addList();
1096 for (size_t i = 0; i < controlledJoints; i++) {
1097 Bottle& c = b.addList();
1098 c.addFloat64(p[i].kp);
1099 c.addFloat64(p[i].kd);
1100 c.addFloat64(p[i].ki);
1101 c.addFloat64(p[i].max_int);
1102 c.addFloat64(p[i].max_output);
1103 c.addFloat64(p[i].offset);
1104 c.addFloat64(p[i].scale);
1105 c.addFloat64(p[i].stiction_up_val);
1106 c.addFloat64(p[i].stiction_down_val);
1107 c.addFloat64(p[i].kff);
1108 }
1109 delete[] p;
1110 } break;
1111
1112 case VOCAB_REFERENCE: {
1113 *ok = rpc_IPid->getPidReference(pidtype, cmd.get(4).asInt32(), &dtmp);
1114 response.addFloat64(dtmp);
1115 } break;
1116
1117 case VOCAB_REFERENCES: {
1118 auto* p = new double[controlledJoints];
1119 *ok = rpc_IPid->getPidReferences(pidtype, p);
1120 Bottle& b = response.addList();
1121 for (size_t i = 0; i < controlledJoints; i++) {
1122 b.addFloat64(p[i]);
1123 }
1124 delete[] p;
1125 } break;
1126
1127 case VOCAB_LIM: {
1128 *ok = rpc_IPid->getPidErrorLimit(pidtype, cmd.get(4).asInt32(), &dtmp);
1129 response.addFloat64(dtmp);
1130 } break;
1131 }
1132 } break;
1133
1134 default:
1135 {
1136 yCError(CONTROLBOARD) << "Unknown handlePWMMsg message received";
1137 *rec = false;
1138 *ok = false;
1139 } break;
1140 }
1141}
1142
1143void RPCMessagesParser::handlePWMMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok)
1144{
1145 yCTrace(CONTROLBOARD, "Handling IPWMControl message");
1146
1147 if (!rpc_IPWM) {
1148 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid IPWMControl interface");
1149 *ok = false;
1150 return;
1151 }
1152
1153 int code = cmd.get(0).asVocab32();
1154 int action = cmd.get(2).asVocab32();
1155
1156 *ok = false;
1157 *rec = true;
1158 switch (code) {
1159 case VOCAB_SET: {
1160 *rec = true;
1161 yCTrace(CONTROLBOARD, "set command received");
1162
1163 switch (action) {
1165 //handled as streaming!
1166 yCError(CONTROLBOARD) << "VOCAB_PWMCONTROL_REF_PWM handled as straming";
1167 *ok = false;
1168 } break;
1169
1170 default:
1171 {
1172 yCError(CONTROLBOARD) << "Unknown handlePWMMsg message received";
1173 *ok = false;
1174 } break;
1175 }
1176 } break;
1177
1178 case VOCAB_GET: {
1179 yCTrace(CONTROLBOARD, "get command received");
1180 *rec = true;
1181 double dtmp = 0.0;
1182 response.addVocab32(VOCAB_IS);
1183 response.add(cmd.get(1));
1184
1185 switch (action) {
1187 *ok = rpc_IPWM->getRefDutyCycle(cmd.get(3).asInt32(), &dtmp);
1188 response.addFloat64(dtmp);
1189 } break;
1190
1192 auto* p = new double[controlledJoints];
1193 *ok = rpc_IPWM->getRefDutyCycles(p);
1194 Bottle& b = response.addList();
1195 for (size_t i = 0; i < controlledJoints; i++) {
1196 b.addFloat64(p[i]);
1197 }
1198 delete[] p;
1199 } break;
1200
1202 *ok = rpc_IPWM->getDutyCycle(cmd.get(3).asInt32(), &dtmp);
1203 response.addFloat64(dtmp);
1204 } break;
1205
1207 auto* p = new double[controlledJoints];
1208 *ok = rpc_IPWM->getRefDutyCycles(p);
1209 Bottle& b = response.addList();
1210 for (size_t i = 0; i < controlledJoints; i++) {
1211 b.addFloat64(p[i]);
1212 }
1213 delete[] p;
1214 } break;
1215
1216 default:
1217 {
1218 yCError(CONTROLBOARD) << "Unknown handlePWMMsg message received";
1219 *ok = false;
1220 } break;
1221 }
1222 } break;
1223
1224 default:
1225 {
1226 yCError(CONTROLBOARD) << "Unknown handlePWMMsg message received";
1227 *rec = false;
1228 *ok = false;
1229 } break;
1230 }
1231}
1232
1234{
1235 yCTrace(CONTROLBOARD, "Handling IRemoteCalibrator message");
1236
1237 if (!rpc_IRemoteCalibrator) {
1238 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid IRemoteCalibrator interface");
1239 *ok = false;
1240 return;
1241 }
1242
1243 int code = cmd.get(0).asVocab32();
1244 int action = cmd.get(2).asVocab32();
1245
1246 *ok = false;
1247 *rec = true;
1248 switch (code) {
1249 case VOCAB_SET: {
1250 switch (action) {
1251 case VOCAB_VARIABLE: {
1252 Bottle btail = cmd.tail().tail().tail().tail(); // remove the first four elements
1253 std::string s = btail.toString();
1254 *ok = rpc_IVar->setRemoteVariable(cmd.get(3).asString(), btail);
1255 } break;
1256
1257 default:
1258 {
1259 *rec = false;
1260 *ok = false;
1261 } break;
1262 }
1263 } break;
1264
1265 case VOCAB_GET: {
1266 yCTrace(CONTROLBOARD, "get command received");
1267
1268 response.clear();
1269 response.addVocab32(VOCAB_IS);
1270 response.add(cmd.get(1));
1271 Bottle btmp;
1272
1273 switch (action) {
1274 case VOCAB_VARIABLE: {
1275 *ok = rpc_IVar->getRemoteVariable(cmd.get(3).asString(), btmp);
1276 Bottle& b = response.addList();
1277 b = btmp;
1278 } break;
1279
1280 case VOCAB_LIST_VARIABLES: {
1281 *ok = rpc_IVar->getRemoteVariablesList(&btmp);
1282 Bottle& b = response.addList();
1283 b = btmp;
1284 } break;
1285 }
1286 }
1287 } //end get/set switch
1288}
1289
1291{
1292 yCTrace(CONTROLBOARD, "Handling IRemoteCalibrator message");
1293
1294 if (!rpc_IRemoteCalibrator) {
1295 yCError(CONTROLBOARD, "controlBoardWrapper: I do not have a valid IRemoteCalibrator interface");
1296 *ok = false;
1297 return;
1298 }
1299
1300 int code = cmd.get(0).asVocab32();
1301 int action = cmd.get(2).asVocab32();
1302
1303 *ok = false;
1304 *rec = true;
1305 switch (code) {
1306 case VOCAB_SET: {
1307 switch (action) {
1309 yCDebug(CONTROLBOARD) << "cmd is " << cmd.toString() << " joint is " << cmd.get(3).asInt32();
1310 yCTrace(CONTROLBOARD, "Calling calibrate joint with no parameter");
1312 } break;
1313
1315 yCTrace(CONTROLBOARD, "Calling calibrate whole part");
1317 } break;
1318
1320 yCTrace(CONTROLBOARD, "Calling calibrate joint with no parameter");
1322 } break;
1323
1325 yCDebug(CONTROLBOARD) << "Received homing whole part";
1326 yCTrace(CONTROLBOARD, "Calling calibrate whole part");
1328 } break;
1329
1331 yCTrace(CONTROLBOARD, "Calling calibrate joint with no parameter");
1333 } break;
1334
1335 case VOCAB_PARK_WHOLE_PART: {
1336 yCTrace(CONTROLBOARD, "Calling calibrate whole part");
1338 } break;
1339
1340 case VOCAB_QUIT_CALIBRATE: {
1341 yCTrace(CONTROLBOARD, "Calling quit calibrate");
1343 } break;
1344
1345 case VOCAB_QUIT_PARK: {
1346 yCTrace(CONTROLBOARD, "Calling quit park");
1348 } break;
1349
1350 default:
1351 {
1352 *rec = false;
1353 *ok = false;
1354 } break;
1355 }
1356 } break;
1357
1358 case VOCAB_GET: {
1359 response.clear();
1360 response.addVocab32(VOCAB_IS);
1361 response.add(cmd.get(1));
1362
1363 switch (action) {
1365 bool tmp;
1366 yCTrace(CONTROLBOARD, "Calling VOCAB_IS_CALIBRATOR_PRESENT");
1368 response.addInt32(tmp);
1369 } break;
1370 }
1371 }
1372 } //end get/set switch
1373}
1374
1375
1376// rpc callback
1378{
1379 bool ok = false;
1380 bool rec = false; // Tells if the command is recognized!
1381
1382 yCTrace(CONTROLBOARD, "command received: %s", cmd.toString().c_str());
1383
1384 int code = cmd.get(0).asVocab32();
1385
1386 if (cmd.size() < 2) {
1387 ok = false;
1388 } else {
1389 switch (cmd.get(1).asVocab32()) {
1390 case VOCAB_PID:
1391 handlePidMsg(cmd, response, &rec, &ok);
1392 break;
1393
1394 case VOCAB_TORQUE:
1395 handleTorqueMsg(cmd, response, &rec, &ok);
1396 break;
1397
1398 case VOCAB_IJOINTFAULT:
1399 handleJointFaultMsg(cmd, response, &rec, &ok);
1400 break;
1401
1402 case VOCAB_ICONTROLMODE:
1403 handleControlModeMsg(cmd, response, &rec, &ok);
1404 break;
1405
1406 case VOCAB_IMPEDANCE:
1407 handleImpedanceMsg(cmd, response, &rec, &ok);
1408 break;
1409
1411 handleInteractionModeMsg(cmd, response, &rec, &ok);
1412 break;
1413
1415 handleProtocolVersionRequest(cmd, response, &rec, &ok);
1416 break;
1417
1419 handleRemoteCalibratorMsg(cmd, response, &rec, &ok);
1420 break;
1421
1423 handleRemoteVariablesMsg(cmd, response, &rec, &ok);
1424 break;
1425
1427 handleCurrentMsg(cmd, response, &rec, &ok);
1428 break;
1429
1431 handlePWMMsg(cmd, response, &rec, &ok);
1432 break;
1433
1434 default:
1435 // fallback for old interfaces with no specific name
1436 switch (code) {
1437 case VOCAB_CALIBRATE_JOINT: {
1438 rec = true;
1439 yCTrace(CONTROLBOARD, "Calling calibrate joint");
1440
1441 int j = cmd.get(1).asInt32();
1442 int ui = cmd.get(2).asInt32();
1443 double v1 = cmd.get(3).asFloat64();
1444 double v2 = cmd.get(4).asFloat64();
1445 double v3 = cmd.get(5).asFloat64();
1446 if (rpc_Icalib == nullptr) {
1447 yCError(CONTROLBOARD, "Sorry I don't have a IControlCalibration2 interface");
1448 } else {
1449 ok = rpc_Icalib->calibrateAxisWithParams(j, ui, v1, v2, v3);
1450 }
1451 } break;
1452
1454 rec = true;
1455 yCTrace(CONTROLBOARD, "Calling calibrate joint");
1456
1457 int j = cmd.get(1).asInt32();
1458 CalibrationParameters params;
1459 params.type = cmd.get(2).asInt32();
1460 params.param1 = cmd.get(3).asFloat64();
1461 params.param2 = cmd.get(4).asFloat64();
1462 params.param3 = cmd.get(5).asFloat64();
1463 params.param4 = cmd.get(6).asFloat64();
1464 if (rpc_Icalib == nullptr) {
1465 yCError(CONTROLBOARD, "Sorry I don't have a IControlCalibration2 interface");
1466 } else {
1467 ok = rpc_Icalib->setCalibrationParameters(j, params);
1468 }
1469 } break;
1470
1471 case VOCAB_CALIBRATE: {
1472 rec = true;
1473 yCTrace(CONTROLBOARD, "Calling calibrate");
1474 ok = rpc_Icalib->calibrateRobot();
1475 } break;
1476
1477 case VOCAB_CALIBRATE_DONE: {
1478 rec = true;
1479 yCTrace(CONTROLBOARD, "Calling calibrate done");
1480 int j = cmd.get(1).asInt32();
1481 ok = rpc_Icalib->calibrationDone(j);
1482 } break;
1483
1484 case VOCAB_PARK: {
1485 rec = true;
1486 yCTrace(CONTROLBOARD, "Calling park function");
1487 int flag = cmd.get(1).asInt32();
1488 ok = rpc_Icalib->park(flag ? true : false);
1489 ok = true; //client would get stuck if returning false
1490 } break;
1491
1492 case VOCAB_SET: {
1493 rec = true;
1494 yCTrace(CONTROLBOARD, "set command received");
1495
1496 switch (cmd.get(1).asVocab32()) {
1497 case VOCAB_POSITION_MOVE: {
1498 ok = rpc_IPosCtrl->positionMove(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1499 } break;
1500
1501 // this operation is also available on "command" port
1502 case VOCAB_POSITION_MOVES: {
1503 Bottle* b = cmd.get(2).asList();
1504 if (b == nullptr) {
1505 break;
1506 }
1507 const size_t njs = b->size();
1508 if (njs != controlledJoints) {
1509 break;
1510 }
1511 tmpVect.resize(njs);
1512 for (size_t i = 0; i < njs; i++) {
1513 tmpVect[i] = b->get(i).asFloat64();
1514 }
1515
1516 if (rpc_IPosCtrl != nullptr) {
1518 }
1519 } break;
1520
1522 auto len = static_cast<size_t>(cmd.get(2).asInt32());
1523 Bottle* jlut = cmd.get(3).asList();
1524 Bottle* pos_val = cmd.get(4).asList();
1525
1526 if (rpc_IPosCtrl == nullptr) {
1527 break;
1528 }
1529
1530 if (jlut == nullptr || pos_val == nullptr) {
1531 break;
1532 }
1533 if (len != jlut->size() || len != pos_val->size()) {
1534 break;
1535 }
1536
1537 auto* j_tmp = new int[len];
1538 auto* pos_tmp = new double[len];
1539 for (size_t i = 0; i < len; i++) {
1540 j_tmp[i] = jlut->get(i).asInt32();
1541 pos_tmp[i] = pos_val->get(i).asFloat64();
1542 }
1543
1544 ok = rpc_IPosCtrl->positionMove(len, j_tmp, pos_tmp);
1545
1546 delete[] j_tmp;
1547 delete[] pos_tmp;
1548 } break;
1549
1550 // this operation is also available on "command" port
1551 case VOCAB_VELOCITY_MOVES: {
1552 Bottle* b = cmd.get(2).asList();
1553 if (b == nullptr) {
1554 break;
1555 }
1556 const size_t njs = b->size();
1557 if (njs != controlledJoints) {
1558 break;
1559 }
1560 tmpVect.resize(njs);
1561 for (size_t i = 0; i < njs; i++) {
1562 tmpVect[i] = b->get(i).asFloat64();
1563 }
1564 if (rpc_IVelCtrl != nullptr) {
1566 }
1567
1568 } break;
1569
1570 case VOCAB_RELATIVE_MOVE: {
1571 ok = rpc_IPosCtrl->relativeMove(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1572 } break;
1573
1575 auto len = static_cast<size_t>(cmd.get(2).asInt32());
1576 Bottle* jBottle_p = cmd.get(3).asList();
1577 Bottle* posBottle_p = cmd.get(4).asList();
1578
1579 if (rpc_IPosCtrl == nullptr) {
1580 break;
1581 }
1582
1583 if (jBottle_p == nullptr || posBottle_p == nullptr) {
1584 break;
1585 }
1586 if (len != jBottle_p->size() || len != posBottle_p->size()) {
1587 break;
1588 }
1589
1590 int* j_tmp = new int[len];
1591 auto* pos_tmp = new double[len];
1592
1593 for (size_t i = 0; i < len; i++) {
1594 j_tmp[i] = jBottle_p->get(i).asInt32();
1595 }
1596
1597 for (size_t i = 0; i < len; i++) {
1598 pos_tmp[i] = posBottle_p->get(i).asFloat64();
1599 }
1600
1601 ok = rpc_IPosCtrl->relativeMove(len, j_tmp, pos_tmp);
1602
1603 delete[] j_tmp;
1604 delete[] pos_tmp;
1605 } break;
1606
1607 case VOCAB_RELATIVE_MOVES: {
1608 Bottle* b = cmd.get(2).asList();
1609
1610 if (b == nullptr) {
1611 break;
1612 }
1613
1614 const size_t njs = b->size();
1615 if (njs != controlledJoints) {
1616 break;
1617 }
1618 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1619 for (size_t i = 0; i < njs; i++) {
1620 p[i] = b->get(i).asFloat64();
1621 }
1622 ok = rpc_IPosCtrl->relativeMove(p);
1623 delete[] p;
1624 } break;
1625
1626 case VOCAB_REF_SPEED: {
1627 ok = rpc_IPosCtrl->setRefSpeed(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1628 } break;
1629
1630 case VOCAB_REF_SPEED_GROUP: {
1631 auto len = static_cast<size_t>(cmd.get(2).asInt32());
1632 Bottle* jBottle_p = cmd.get(3).asList();
1633 Bottle* velBottle_p = cmd.get(4).asList();
1634
1635 if (rpc_IPosCtrl == nullptr) {
1636 break;
1637 }
1638
1639 if (jBottle_p == nullptr || velBottle_p == nullptr) {
1640 break;
1641 }
1642 if (len != jBottle_p->size() || len != velBottle_p->size()) {
1643 break;
1644 }
1645
1646 int* j_tmp = new int[len];
1647 auto* spds_tmp = new double[len];
1648
1649 for (size_t i = 0; i < len; i++) {
1650 j_tmp[i] = jBottle_p->get(i).asInt32();
1651 }
1652
1653 for (size_t i = 0; i < len; i++) {
1654 spds_tmp[i] = velBottle_p->get(i).asFloat64();
1655 }
1656
1657 ok = rpc_IPosCtrl->setRefSpeeds(len, j_tmp, spds_tmp);
1658 delete[] j_tmp;
1659 delete[] spds_tmp;
1660 } break;
1661
1662 case VOCAB_REF_SPEEDS: {
1663 Bottle* b = cmd.get(2).asList();
1664
1665 if (b == nullptr) {
1666 break;
1667 }
1668
1669 const size_t njs = b->size();
1670 if (njs != controlledJoints) {
1671 break;
1672 }
1673 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1674 for (size_t i = 0; i < njs; i++) {
1675 p[i] = b->get(i).asFloat64();
1676 }
1677 ok = rpc_IPosCtrl->setRefSpeeds(p);
1678 delete[] p;
1679 } break;
1680
1682 ok = rpc_IPosCtrl->setRefAcceleration(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1683 } break;
1684
1686 auto len = static_cast<size_t>(cmd.get(2).asInt32());
1687 Bottle* jBottle_p = cmd.get(3).asList();
1688 Bottle* accBottle_p = cmd.get(4).asList();
1689
1690 if (rpc_IPosCtrl == nullptr) {
1691 break;
1692 }
1693
1694 if (jBottle_p == nullptr || accBottle_p == nullptr) {
1695 break;
1696 }
1697 if (len != jBottle_p->size() || len != accBottle_p->size()) {
1698 break;
1699 }
1700
1701 int* j_tmp = new int[len];
1702 auto* accs_tmp = new double[len];
1703
1704 for (size_t i = 0; i < len; i++) {
1705 j_tmp[i] = jBottle_p->get(i).asInt32();
1706 }
1707
1708 for (size_t i = 0; i < len; i++) {
1709 accs_tmp[i] = accBottle_p->get(i).asFloat64();
1710 }
1711
1712 ok = rpc_IPosCtrl->setRefAccelerations(len, j_tmp, accs_tmp);
1713 delete[] j_tmp;
1714 delete[] accs_tmp;
1715 } break;
1716
1718 Bottle* b = cmd.get(2).asList();
1719
1720 if (b == nullptr) {
1721 break;
1722 }
1723
1724 const size_t njs = b->size();
1725 if (njs != controlledJoints) {
1726 break;
1727 }
1728 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1729 for (size_t i = 0; i < njs; i++) {
1730 p[i] = b->get(i).asFloat64();
1731 }
1733 delete[] p;
1734 } break;
1735
1736 case VOCAB_STOP: {
1737 ok = rpc_IPosCtrl->stop(cmd.get(2).asInt32());
1738 } break;
1739
1740 case VOCAB_STOP_GROUP: {
1741 auto len = static_cast<size_t>(cmd.get(2).asInt32());
1742 Bottle* jBottle_p = cmd.get(3).asList();
1743
1744 if (rpc_IPosCtrl == nullptr) {
1745 break;
1746 }
1747
1748 if (jBottle_p == nullptr) {
1749 break;
1750 }
1751 if (len != jBottle_p->size()) {
1752 break;
1753 }
1754
1755 int* j_tmp = new int[len];
1756
1757 for (size_t i = 0; i < len; i++) {
1758 j_tmp[i] = jBottle_p->get(i).asInt32();
1759 }
1760
1761 ok = rpc_IPosCtrl->stop(len, j_tmp);
1762 delete[] j_tmp;
1763 } break;
1764
1765 case VOCAB_STOPS: {
1766 ok = rpc_IPosCtrl->stop();
1767 } break;
1768
1769 case VOCAB_E_RESET: {
1770 ok = rpc_IEncTimed->resetEncoder(cmd.get(2).asInt32());
1771 } break;
1772
1773 case VOCAB_E_RESETS: {
1775 } break;
1776
1777 case VOCAB_ENCODER: {
1778 ok = rpc_IEncTimed->setEncoder(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1779 } break;
1780
1781 case VOCAB_ENCODERS: {
1782 Bottle* b = cmd.get(2).asList();
1783
1784 if (b == nullptr) {
1785 break;
1786 }
1787
1788 const size_t njs = b->size();
1789 if (njs != controlledJoints) {
1790 break;
1791 }
1792 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1793 for (size_t i = 0; i < njs; i++) {
1794 p[i] = b->get(i).asFloat64();
1795 }
1796 ok = rpc_IEncTimed->setEncoders(p);
1797 delete[] p;
1798 } break;
1799
1800 case VOCAB_MOTOR_CPR: {
1802 } break;
1803
1804 case VOCAB_MOTOR_E_RESET: {
1805 ok = rpc_IMotEnc->resetMotorEncoder(cmd.get(2).asInt32());
1806 } break;
1807
1808 case VOCAB_MOTOR_E_RESETS: {
1810 } break;
1811
1812 case VOCAB_MOTOR_ENCODER: {
1813 ok = rpc_IMotEnc->setMotorEncoder(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1814 } break;
1815
1816 case VOCAB_MOTOR_ENCODERS: {
1817 Bottle* b = cmd.get(2).asList();
1818
1819 if (b == nullptr) {
1820 break;
1821 }
1822
1823 const size_t njs = b->size();
1824 if (njs != controlledJoints) {
1825 break;
1826 }
1827 auto* p = new double[njs]; // LATER: optimize to avoid allocation.
1828 for (size_t i = 0; i < njs; i++) {
1829 p[i] = b->get(i).asFloat64();
1830 }
1832 delete[] p;
1833 } break;
1834
1835 case VOCAB_AMP_ENABLE: {
1836 ok = rcp_IAmp->enableAmp(cmd.get(2).asInt32());
1837 } break;
1838
1839 case VOCAB_AMP_DISABLE: {
1840 ok = rcp_IAmp->disableAmp(cmd.get(2).asInt32());
1841 } break;
1842
1843 case VOCAB_AMP_MAXCURRENT: {
1844 ok = rcp_IAmp->setMaxCurrent(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1845 } break;
1846
1848 ok = rcp_IAmp->setPeakCurrent(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1849 } break;
1850
1852 ok = rcp_IAmp->setNominalCurrent(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1853 } break;
1854
1855 case VOCAB_AMP_PWM_LIMIT: {
1856 ok = rcp_IAmp->setPWMLimit(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1857 } break;
1858
1859 case VOCAB_LIMITS: {
1860 ok = rcp_Ilim->setLimits(cmd.get(2).asInt32(), cmd.get(3).asFloat64(), cmd.get(4).asFloat64());
1861 } break;
1862
1863
1865 ok = rpc_IMotor->setTemperatureLimit(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1866 } break;
1867
1868 case VOCAB_GEARBOX_RATIO: {
1869 ok = rpc_IMotor->setGearboxRatio(cmd.get(2).asInt32(), cmd.get(3).asFloat64());
1870 } break;
1871
1872 case VOCAB_VEL_LIMITS: {
1873 ok = rcp_Ilim->setVelLimits(cmd.get(2).asInt32(), cmd.get(3).asFloat64(), cmd.get(4).asFloat64());
1874 } break;
1875
1876 default:
1877 {
1878 yCError(CONTROLBOARD, "received an unknown command after a VOCAB_SET (%s)", cmd.toString().c_str());
1879 } break;
1880 } //switch(cmd.get(1).asVocab32()
1881 break;
1882 }
1883
1884 case VOCAB_GET: {
1885 rec = true;
1886 yCTrace(CONTROLBOARD, "get command received");
1887
1888 double dtmp = 0.0;
1889 Bottle btmp;
1890 response.addVocab32(VOCAB_IS);
1891 response.add(cmd.get(1));
1892
1893 switch (cmd.get(1).asVocab32()) {
1894
1896 ok = rpc_IMotor->getTemperatureLimit(cmd.get(2).asInt32(), &dtmp);
1897 response.addFloat64(dtmp);
1898 } break;
1899
1900 case VOCAB_TEMPERATURE: {
1901 ok = rpc_IMotor->getTemperature(cmd.get(2).asInt32(), &dtmp);
1902 response.addFloat64(dtmp);
1903 } break;
1904
1905 case VOCAB_GEARBOX_RATIO: {
1906 ok = rpc_IMotor->getGearboxRatio(cmd.get(2).asInt32(), &dtmp);
1907 response.addFloat64(dtmp);
1908 } break;
1909
1910 case VOCAB_TEMPERATURES: {
1911 auto* p = new double[controlledJoints];
1912 ok = rpc_IMotor->getTemperatures(p);
1913 Bottle& b = response.addList();
1914 for (size_t i = 0; i < controlledJoints; i++) {
1915 b.addFloat64(p[i]);
1916 }
1917 delete[] p;
1918 } break;
1919
1920 case VOCAB_AMP_MAXCURRENT: {
1921 ok = rcp_IAmp->getMaxCurrent(cmd.get(2).asInt32(), &dtmp);
1922 response.addFloat64(dtmp);
1923 } break;
1924
1925 case VOCAB_POSITION_MOVE: {
1926 yCTrace(CONTROLBOARD, "getTargetPosition");
1927 ok = rpc_IPosCtrl->getTargetPosition(cmd.get(2).asInt32(), &dtmp);
1928
1929 response.addFloat64(dtmp);
1930 rec = true;
1931 } break;
1932
1934 int len = cmd.get(2).asInt32();
1935 Bottle& in = *(cmd.get(3).asList());
1936 int* jointList = new int[len];
1937 auto* refs = new double[len];
1938
1939 for (int j = 0; j < len; j++) {
1940 jointList[j] = in.get(j).asInt32();
1941 }
1942 ok = rpc_IPosCtrl->getTargetPositions(len, jointList, refs);
1943
1944 Bottle& b = response.addList();
1945 for (int i = 0; i < len; i++) {
1946 b.addFloat64(refs[i]);
1947 }
1948
1949 delete[] jointList;
1950 delete[] refs;
1951 } break;
1952
1953 case VOCAB_POSITION_MOVES: {
1954 auto* refs = new double[controlledJoints];
1955 ok = rpc_IPosCtrl->getTargetPositions(refs);
1956 Bottle& b = response.addList();
1957 for (size_t i = 0; i < controlledJoints; i++) {
1958 b.addFloat64(refs[i]);
1959 }
1960 delete[] refs;
1961 } break;
1962
1963 case VOCAB_POSITION_DIRECT: {
1964 yCTrace(CONTROLBOARD, "getRefPosition");
1965 ok = rpc_IPosDirect->getRefPosition(cmd.get(2).asInt32(), &dtmp);
1966
1967 response.addFloat64(dtmp);
1968 rec = true;
1969 } break;
1970
1972 int len = cmd.get(2).asInt32();
1973 Bottle& in = *(cmd.get(3).asList());
1974 int* jointList = new int[len];
1975 auto* refs = new double[len];
1976
1977 for (int j = 0; j < len; j++) {
1978 jointList[j] = in.get(j).asInt32();
1979 }
1980 ok = rpc_IPosDirect->getRefPositions(len, jointList, refs);
1981
1982 Bottle& b = response.addList();
1983 for (int i = 0; i < len; i++) {
1984 b.addFloat64(refs[i]);
1985 }
1986
1987 delete[] jointList;
1988 delete[] refs;
1989 } break;
1990
1992 auto* refs = new double[controlledJoints];
1993 ok = rpc_IPosDirect->getRefPositions(refs);
1994 Bottle& b = response.addList();
1995 for (size_t i = 0; i < controlledJoints; i++) {
1996 b.addFloat64(refs[i]);
1997 }
1998 delete[] refs;
1999 } break;
2000
2001 case VOCAB_VELOCITY_MOVE: {
2002 yCTrace(CONTROLBOARD, "getVelocityMove - cmd: %s", cmd.toString().c_str());
2003 ok = rpc_IVelCtrl->getRefVelocity(cmd.get(2).asInt32(), &dtmp);
2004
2005 response.addFloat64(dtmp);
2006 rec = true;
2007 } break;
2008
2010 yCTrace(CONTROLBOARD, "getVelocityMove_group - cmd: %s", cmd.toString().c_str());
2011
2012 int len = cmd.get(2).asInt32();
2013 Bottle& in = *(cmd.get(3).asList());
2014 int* jointList = new int[len];
2015 auto* refs = new double[len];
2016
2017 for (int j = 0; j < len; j++) {
2018 jointList[j] = in.get(j).asInt32();
2019 }
2020 ok = rpc_IVelCtrl->getRefVelocities(len, jointList, refs);
2021
2022 Bottle& b = response.addList();
2023 for (int i = 0; i < len; i++) {
2024 b.addFloat64(refs[i]);
2025 }
2026
2027 delete[] jointList;
2028 delete[] refs;
2029 } break;
2030
2031 case VOCAB_VELOCITY_MOVES: {
2032 yCTrace(CONTROLBOARD, "getVelocityMoves - cmd: %s", cmd.toString().c_str());
2033
2034 auto* refs = new double[controlledJoints];
2035 ok = rpc_IVelCtrl->getRefVelocities(refs);
2036 Bottle& b = response.addList();
2037 for (size_t i = 0; i < controlledJoints; i++) {
2038 b.addFloat64(refs[i]);
2039 }
2040 delete[] refs;
2041 } break;
2042
2043 case VOCAB_MOTORS_NUMBER: {
2044 int tmp;
2045 ok = rpc_IMotor->getNumberOfMotors(&tmp);
2046 response.addInt32(tmp);
2047 } break;
2048
2049 case VOCAB_AXES: {
2050 int tmp;
2051 ok = rpc_IPosCtrl->getAxes(&tmp);
2052 response.addInt32(tmp);
2053 } break;
2054
2055 case VOCAB_MOTION_DONE: {
2056 bool x = false;
2057 ;
2058 ok = rpc_IPosCtrl->checkMotionDone(cmd.get(2).asInt32(), &x);
2059 response.addInt32(x);
2060 } break;
2061
2063 bool x = false;
2064 int len = cmd.get(2).asInt32();
2065 Bottle& in = *(cmd.get(3).asList());
2066 int* jointList = new int[len];
2067 for (int j = 0; j < len; j++) {
2068 jointList[j] = in.get(j).asInt32();
2069 }
2070 if (rpc_IPosCtrl != nullptr) {
2071 ok = rpc_IPosCtrl->checkMotionDone(len, jointList, &x);
2072 }
2073 response.addInt32(x);
2074
2075 delete[] jointList;
2076 } break;
2077
2078 case VOCAB_MOTION_DONES: {
2079 bool x = false;
2080 ok = rpc_IPosCtrl->checkMotionDone(&x);
2081 response.addInt32(x);
2082 } break;
2083
2084 case VOCAB_REF_SPEED: {
2085 ok = rpc_IPosCtrl->getRefSpeed(cmd.get(2).asInt32(), &dtmp);
2086 response.addFloat64(dtmp);
2087 } break;
2088
2089 case VOCAB_REF_SPEED_GROUP: {
2090 int len = cmd.get(2).asInt32();
2091 Bottle& in = *(cmd.get(3).asList());
2092 int* jointList = new int[len];
2093 auto* speeds = new double[len];
2094
2095 for (int j = 0; j < len; j++) {
2096 jointList[j] = in.get(j).asInt32();
2097 }
2098 ok = rpc_IPosCtrl->getRefSpeeds(len, jointList, speeds);
2099
2100 Bottle& b = response.addList();
2101 for (int i = 0; i < len; i++) {
2102 b.addFloat64(speeds[i]);
2103 }
2104
2105 delete[] jointList;
2106 delete[] speeds;
2107 } break;
2108
2109 case VOCAB_REF_SPEEDS: {
2110 auto* p = new double[controlledJoints];
2111 ok = rpc_IPosCtrl->getRefSpeeds(p);
2112 Bottle& b = response.addList();
2113 for (size_t i = 0; i < controlledJoints; i++) {
2114 b.addFloat64(p[i]);
2115 }
2116 delete[] p;
2117 } break;
2118
2120 ok = rpc_IPosCtrl->getRefAcceleration(cmd.get(2).asInt32(), &dtmp);
2121 response.addFloat64(dtmp);
2122 } break;
2123
2125 int len = cmd.get(2).asInt32();
2126 Bottle& in = *(cmd.get(3).asList());
2127 int* jointList = new int[len];
2128 auto* accs = new double[len];
2129
2130 for (int j = 0; j < len; j++) {
2131 jointList[j] = in.get(j).asInt32();
2132 }
2133 ok = rpc_IPosCtrl->getRefAccelerations(len, jointList, accs);
2134
2135 Bottle& b = response.addList();
2136 for (int i = 0; i < len; i++) {
2137 b.addFloat64(accs[i]);
2138 }
2139
2140 delete[] jointList;
2141 delete[] accs;
2142 } break;
2143
2145 auto* p = new double[controlledJoints];
2147 Bottle& b = response.addList();
2148 for (size_t i = 0; i < controlledJoints; i++) {
2149 b.addFloat64(p[i]);
2150 }
2151 delete[] p;
2152 } break;
2153
2154 case VOCAB_ENCODER: {
2155 ok = rpc_IEncTimed->getEncoder(cmd.get(2).asInt32(), &dtmp);
2156 response.addFloat64(dtmp);
2157 } break;
2158
2159 case VOCAB_ENCODERS: {
2160 auto* p = new double[controlledJoints];
2161 ok = rpc_IEncTimed->getEncoders(p);
2162 Bottle& b = response.addList();
2163 for (size_t i = 0; i < controlledJoints; i++) {
2164 b.addFloat64(p[i]);
2165 }
2166 delete[] p;
2167 } break;
2168
2169 case VOCAB_ENCODER_SPEED: {
2170 ok = rpc_IEncTimed->getEncoderSpeed(cmd.get(2).asInt32(), &dtmp);
2171 response.addFloat64(dtmp);
2172 } break;
2173
2174 case VOCAB_ENCODER_SPEEDS: {
2175 auto* p = new double[controlledJoints];
2177 Bottle& b = response.addList();
2178 for (size_t i = 0; i < controlledJoints; i++) {
2179 b.addFloat64(p[i]);
2180 }
2181 delete[] p;
2182 } break;
2183
2185 ok = rpc_IEncTimed->getEncoderAcceleration(cmd.get(2).asInt32(), &dtmp);
2186 response.addFloat64(dtmp);
2187 } break;
2188
2190 auto* p = new double[controlledJoints];
2192 Bottle& b = response.addList();
2193 for (size_t i = 0; i < controlledJoints; i++) {
2194 b.addFloat64(p[i]);
2195 }
2196 delete[] p;
2197 } break;
2198
2199 case VOCAB_MOTOR_CPR: {
2201 response.addFloat64(dtmp);
2202 } break;
2203
2204 case VOCAB_MOTOR_ENCODER: {
2205 ok = rpc_IMotEnc->getMotorEncoder(cmd.get(2).asInt32(), &dtmp);
2206 response.addFloat64(dtmp);
2207 } break;
2208
2209 case VOCAB_MOTOR_ENCODERS: {
2210 auto* p = new double[controlledJoints];
2212 Bottle& b = response.addList();
2213 for (size_t i = 0; i < controlledJoints; i++) {
2214 b.addFloat64(p[i]);
2215 }
2216 delete[] p;
2217 } break;
2218
2220 ok = rpc_IMotEnc->getMotorEncoderSpeed(cmd.get(2).asInt32(), &dtmp);
2221 response.addFloat64(dtmp);
2222 } break;
2223
2225 auto* p = new double[controlledJoints];
2227 Bottle& b = response.addList();
2228 for (size_t i = 0; i < controlledJoints; i++) {
2229 b.addFloat64(p[i]);
2230 }
2231 delete[] p;
2232 } break;
2233
2235 ok = rpc_IMotEnc->getMotorEncoderAcceleration(cmd.get(2).asInt32(), &dtmp);
2236 response.addFloat64(dtmp);
2237 } break;
2238
2240 auto* p = new double[controlledJoints];
2242 Bottle& b = response.addList();
2243 for (size_t i = 0; i < controlledJoints; i++) {
2244 b.addFloat64(p[i]);
2245 }
2246 delete[] p;
2247 } break;
2248
2250 int num = 0;
2252 response.addInt32(num);
2253 } break;
2254
2255 case VOCAB_AMP_CURRENT: {
2256 ok = rcp_IAmp->getCurrent(cmd.get(2).asInt32(), &dtmp);
2257 response.addFloat64(dtmp);
2258 } break;
2259
2260 case VOCAB_AMP_CURRENTS: {
2261 auto* p = new double[controlledJoints];
2262 ok = rcp_IAmp->getCurrents(p);
2263 Bottle& b = response.addList();
2264 for (size_t i = 0; i < controlledJoints; i++) {
2265 b.addFloat64(p[i]);
2266 }
2267 delete[] p;
2268 } break;
2269
2270 case VOCAB_AMP_STATUS: {
2271 int* p = new int[controlledJoints];
2272 ok = rcp_IAmp->getAmpStatus(p);
2273 Bottle& b = response.addList();
2274 for (size_t i = 0; i < controlledJoints; i++) {
2275 b.addInt32(p[i]);
2276 }
2277 delete[] p;
2278 } break;
2279
2281 int j = cmd.get(2).asInt32();
2282 int itmp;
2283 ok = rcp_IAmp->getAmpStatus(j, &itmp);
2284 response.addInt32(itmp);
2285 } break;
2286
2288 int m = cmd.get(2).asInt32();
2289 ok = rcp_IAmp->getNominalCurrent(m, &dtmp);
2290 response.addFloat64(dtmp);
2291 } break;
2292
2294 int m = cmd.get(2).asInt32();
2295 ok = rcp_IAmp->getPeakCurrent(m, &dtmp);
2296 response.addFloat64(dtmp);
2297 } break;
2298
2299 case VOCAB_AMP_PWM: {
2300 int m = cmd.get(2).asInt32();
2301 ok = rcp_IAmp->getPWM(m, &dtmp);
2302 yCTrace(CONTROLBOARD) << "RPC parser::getPWM: j" << m << " val " << dtmp;
2303 response.addFloat64(dtmp);
2304 } break;
2305
2306 case VOCAB_AMP_PWM_LIMIT: {
2307 int m = cmd.get(2).asInt32();
2308 ok = rcp_IAmp->getPWMLimit(m, &dtmp);
2309 response.addFloat64(dtmp);
2310 } break;
2311
2313 int m = cmd.get(2).asInt32();
2314 ok = rcp_IAmp->getPowerSupplyVoltage(m, &dtmp);
2315 response.addFloat64(dtmp);
2316 } break;
2317
2318 case VOCAB_LIMITS: {
2319 double min = 0.0;
2320 double max = 0.0;
2321 ok = rcp_Ilim->getLimits(cmd.get(2).asInt32(), &min, &max);
2322 response.addFloat64(min);
2323 response.addFloat64(max);
2324 } break;
2325
2326 case VOCAB_VEL_LIMITS: {
2327 double min = 0.0;
2328 double max = 0.0;
2329 ok = rcp_Ilim->getVelLimits(cmd.get(2).asInt32(), &min, &max);
2330 response.addFloat64(min);
2331 response.addFloat64(max);
2332 } break;
2333
2334 case VOCAB_INFO_NAME: {
2335 std::string name = "undocumented";
2336 ok = rpc_AxisInfo->getAxisName(cmd.get(2).asInt32(), name);
2337 response.addString(name.c_str());
2338 } break;
2339
2340 case VOCAB_INFO_TYPE: {
2342 ok = rpc_AxisInfo->getJointType(cmd.get(2).asInt32(), type);
2343 response.addInt32(type);
2344 } break;
2345
2346 default:
2347 {
2348 yCError(CONTROLBOARD, "received an unknown request after a VOCAB_GET: %s", yarp::os::Vocab32::decode(cmd.get(1).asVocab32()).c_str());
2349 } break;
2350 } //switch cmd.get(1).asVocab32())
2351
2353 appendTimeStamp(response, lastRpcStamp);
2354 } // case VOCAB_GET
2355 default:
2356 break;
2357 } //switch code
2358
2359 if (!rec) {
2360 ok = DeviceResponder::respond(cmd, response);
2361 }
2362 }
2363
2364 if (!ok) {
2365 // failed thus send only a VOCAB back.
2366 response.clear();
2367 response.addVocab32(VOCAB_FAILED);
2368 } else {
2369 response.addVocab32(VOCAB_OK);
2370 }
2371 }
2372 std::string ss = response.toString();
2373
2374 return ok;
2375}
2376
2378{
2379 bool ok = false;
2380 if (rpc_IPosCtrl) {
2381 int tmp_axes;
2382 ok = rpc_IPosCtrl->getAxes(&tmp_axes);
2383 controlledJoints = static_cast<size_t>(tmp_axes);
2384 }
2385
2386 DeviceResponder::makeUsage();
2387 addUsage("[get] [axes]", "get the number of axes");
2388 addUsage("[get] [name] $iAxisNumber", "get a human-readable name for an axis, if available");
2389 addUsage("[set] [pos] $iAxisNumber $fPosition", "command the position of an axis");
2390 addUsage("[set] [rel] $iAxisNumber $fPosition", "command the relative position of an axis");
2391 addUsage("[set] [vmo] $iAxisNumber $fVelocity", "command the velocity of an axis");
2392 addUsage("[get] [enc] $iAxisNumber", "get the encoder value for an axis");
2393
2394 std::string args;
2395 for (size_t i = 0; i < controlledJoints; i++) {
2396 if (i > 0) {
2397 args += " ";
2398 }
2399 // removed dependency from yarp internals
2400 //args = args + "$f" + yarp::yarp::conf::numeric::to_string(i);
2401 }
2402 addUsage((std::string("[set] [poss] (") + args + ")").c_str(),
2403 "command the position of all axes");
2404 addUsage((std::string("[set] [rels] (") + args + ")").c_str(),
2405 "command the relative position of all axes");
2406 addUsage((std::string("[set] [vmos] (") + args + ")").c_str(),
2407 "command the velocity of all axes");
2408
2409 addUsage("[set] [aen] $iAxisNumber", "enable (amplifier for) the given axis");
2410 addUsage("[set] [adi] $iAxisNumber", "disable (amplifier for) the given axis");
2411 addUsage("[get] [acu] $iAxisNumber", "get current for the given axis");
2412 addUsage("[get] [acus]", "get current for all axes");
2413
2414 return ok;
2415}
2416
2418{
2419 x->view(rpc_IPid);
2420 x->view(rpc_IPosCtrl);
2421 x->view(rpc_IPosDirect);
2422 x->view(rpc_IVelCtrl);
2423 x->view(rpc_IEncTimed);
2424 x->view(rpc_IMotEnc);
2425 x->view(rpc_IMotor);
2426 x->view(rpc_IVar);
2427 x->view(rcp_IAmp);
2428 x->view(rcp_Ilim);
2429 x->view(rpc_AxisInfo);
2431 x->view(rpc_Icalib);
2432 x->view(rpc_IImpedance);
2433 x->view(rpc_ITorque);
2434 x->view(rpc_iCtrlMode);
2435 x->view(rpc_IInteract);
2436 x->view(rpc_ICurrent);
2437 x->view(rpc_IPWM);
2439 controlledJoints = 0;
2440}
2441
2443{
2444 rpc_IPid = nullptr;
2445 rpc_IPosCtrl = nullptr;
2446 rpc_IPosDirect = nullptr;
2447 rpc_IVelCtrl = nullptr;
2448 rpc_IEncTimed = nullptr;
2449 rpc_IMotEnc = nullptr;
2450 rpc_IMotor = nullptr;
2451 rpc_IVar = nullptr;
2452 rcp_IAmp = nullptr;
2453 rcp_Ilim = nullptr;
2454 rpc_AxisInfo = nullptr;
2455 rpc_IRemoteCalibrator = nullptr;
2456 rpc_Icalib = nullptr;
2457 rpc_IImpedance = nullptr;
2458 rpc_ITorque = nullptr;
2459 rpc_iCtrlMode = nullptr;
2460 rpc_IInteract = nullptr;
2461 rpc_ICurrent = nullptr;
2462 rpc_IPWM = nullptr;
2463 rpc_IJointFault = nullptr;
2464 controlledJoints = 0;
2465}
constexpr yarp::conf::vocab32_t VOCAB_PARK_SINGLE_JOINT
constexpr yarp::conf::vocab32_t VOCAB_REMOTE_CALIBRATOR_INTERFACE
constexpr yarp::conf::vocab32_t VOCAB_HOMING_WHOLE_PART
constexpr yarp::conf::vocab32_t VOCAB_PARK_WHOLE_PART
constexpr yarp::conf::vocab32_t VOCAB_QUIT_PARK
constexpr yarp::conf::vocab32_t VOCAB_IS_CALIBRATOR_PRESENT
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_SINGLE_JOINT
constexpr yarp::conf::vocab32_t VOCAB_HOMING_SINGLE_JOINT
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_WHOLE_PART
constexpr yarp::conf::vocab32_t VOCAB_QUIT_CALIBRATE
const yarp::os::LogComponent & CONTROLBOARD()
constexpr yarp::conf::vocab32_t VOCAB_TIMESTAMP
constexpr yarp::conf::vocab32_t VOCAB_VELOCITY_MOVE
constexpr yarp::conf::vocab32_t VOCAB_REF_SPEED
constexpr yarp::conf::vocab32_t VOCAB_STOPS
constexpr yarp::conf::vocab32_t VOCAB_MOTION_DONE
constexpr yarp::conf::vocab32_t VOCAB_STOP
constexpr yarp::conf::vocab32_t VOCAB_REF_ACCELERATIONS
constexpr yarp::conf::vocab32_t VOCAB_MOTION_DONES
constexpr yarp::conf::vocab32_t VOCAB_PROTOCOL_VERSION
constexpr yarp::conf::vocab32_t VOCAB_POSITION_MOVE
constexpr yarp::conf::vocab32_t VOCAB_REF_ACCELERATION
constexpr yarp::conf::vocab32_t VOCAB_VELOCITY_MOVES
constexpr yarp::conf::vocab32_t VOCAB_RELATIVE_MOVE
constexpr yarp::conf::vocab32_t VOCAB_REF_SPEEDS
constexpr yarp::conf::vocab32_t VOCAB_RELATIVE_MOVES
constexpr yarp::conf::vocab32_t VOCAB_POSITION_MOVES
constexpr int PROTOCOL_VERSION_TWEAK
constexpr int PROTOCOL_VERSION_MINOR
constexpr int PROTOCOL_VERSION_MAJOR
constexpr yarp::conf::vocab32_t VOCAB_LIM
Definition: GenericVocabs.h:27
constexpr yarp::conf::vocab32_t VOCAB_OUTPUTS
Definition: GenericVocabs.h:33
constexpr yarp::conf::vocab32_t VOCAB_ENABLE
Definition: GenericVocabs.h:31
constexpr yarp::conf::vocab32_t VOCAB_DISABLE
Definition: GenericVocabs.h:30
constexpr yarp::conf::vocab32_t VOCAB_OK
Definition: GenericVocabs.h:15
constexpr yarp::conf::vocab32_t VOCAB_REF
Definition: GenericVocabs.h:24
constexpr yarp::conf::vocab32_t VOCAB_IS
Definition: GenericVocabs.h:14
constexpr yarp::conf::vocab32_t VOCAB_ERRS
Definition: GenericVocabs.h:18
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:13
constexpr yarp::conf::vocab32_t VOCAB_OUTPUT
Definition: GenericVocabs.h:32
constexpr yarp::conf::vocab32_t VOCAB_REFERENCE
Definition: GenericVocabs.h:34
constexpr yarp::conf::vocab32_t VOCAB_FAILED
Definition: GenericVocabs.h:16
constexpr yarp::conf::vocab32_t VOCAB_ERR
Definition: GenericVocabs.h:17
constexpr yarp::conf::vocab32_t VOCAB_REFS
Definition: GenericVocabs.h:25
constexpr yarp::conf::vocab32_t VOCAB_REFERENCES
Definition: GenericVocabs.h:35
constexpr yarp::conf::vocab32_t VOCAB_RESET
Definition: GenericVocabs.h:29
constexpr yarp::conf::vocab32_t VOCAB_AXES
Definition: GenericVocabs.h:36
constexpr yarp::conf::vocab32_t VOCAB_SET
Definition: GenericVocabs.h:12
constexpr yarp::conf::vocab32_t VOCAB_OFFSET
Definition: GenericVocabs.h:23
constexpr yarp::conf::vocab32_t VOCAB_LIMS
Definition: GenericVocabs.h:28
constexpr yarp::conf::vocab32_t VOCAB_AMP_DISABLE
constexpr yarp::conf::vocab32_t VOCAB_AMP_PEAK_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_AMP_ENABLE
constexpr yarp::conf::vocab32_t VOCAB_AMP_VOLTAGE_SUPPLY
constexpr yarp::conf::vocab32_t VOCAB_AMP_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_AMP_MAXCURRENT
constexpr yarp::conf::vocab32_t VOCAB_AMP_STATUS_SINGLE
constexpr yarp::conf::vocab32_t VOCAB_AMP_STATUS
constexpr yarp::conf::vocab32_t VOCAB_AMP_NOMINAL_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_AMP_PWM
constexpr yarp::conf::vocab32_t VOCAB_AMP_CURRENTS
constexpr yarp::conf::vocab32_t VOCAB_AMP_PWM_LIMIT
constexpr yarp::conf::vocab32_t VOCAB_INFO_TYPE
Definition: IAxisInfo.h:86
constexpr yarp::conf::vocab32_t VOCAB_INFO_NAME
Definition: IAxisInfo.h:85
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_JOINT_PARAMS
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_DONE
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_JOINT
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE
constexpr yarp::conf::vocab32_t VOCAB_PARK
constexpr yarp::conf::vocab32_t VOCAB_LIMITS
constexpr yarp::conf::vocab32_t VOCAB_VEL_LIMITS
constexpr yarp::conf::vocab32_t VOCAB_CM_CONTROL_MODE_GROUP
Definition: IControlMode.h:116
constexpr yarp::conf::vocab32_t VOCAB_CM_MIXED
Definition: IControlMode.h:133
constexpr yarp::conf::vocab32_t VOCAB_CM_TORQUE
Definition: IControlMode.h:122
constexpr yarp::conf::vocab32_t VOCAB_CM_PWM
Definition: IControlMode.h:127
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_VEL
Definition: IControlMode.h:129
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
Definition: IControlMode.h:123
constexpr yarp::conf::vocab32_t VOCAB_CM_CONTROL_MODES
Definition: IControlMode.h:117
constexpr yarp::conf::vocab32_t VOCAB_CM_CURRENT
Definition: IControlMode.h:126
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_POS
Definition: IControlMode.h:128
constexpr yarp::conf::vocab32_t VOCAB_CM_CONTROL_MODE
Definition: IControlMode.h:115
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION_DIRECT
Definition: IControlMode.h:124
constexpr yarp::conf::vocab32_t VOCAB_ICONTROLMODE
Definition: IControlMode.h:113
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY
Definition: IControlMode.h:125
constexpr yarp::conf::vocab32_t VOCAB_CM_FORCE_IDLE
Definition: IControlMode.h:136
constexpr yarp::conf::vocab32_t VOCAB_CURRENT_REF_GROUP
constexpr yarp::conf::vocab32_t VOCAB_CURRENT_REFS
constexpr yarp::conf::vocab32_t VOCAB_CURRENT_RANGE
constexpr yarp::conf::vocab32_t VOCAB_CURRENTCONTROL_INTERFACE
constexpr yarp::conf::vocab32_t VOCAB_CURRENT_REF
constexpr yarp::conf::vocab32_t VOCAB_CURRENT_RANGES
constexpr yarp::conf::vocab32_t VOCAB_E_RESET
Definition: IEncoders.h:204
constexpr yarp::conf::vocab32_t VOCAB_ENCODER_ACCELERATIONS
Definition: IEncoders.h:213
constexpr yarp::conf::vocab32_t VOCAB_ENCODER
Definition: IEncoders.h:206
constexpr yarp::conf::vocab32_t VOCAB_ENCODER_SPEEDS
Definition: IEncoders.h:211
constexpr yarp::conf::vocab32_t VOCAB_E_RESETS
Definition: IEncoders.h:205
constexpr yarp::conf::vocab32_t VOCAB_ENCODER_SPEED
Definition: IEncoders.h:210
constexpr yarp::conf::vocab32_t VOCAB_ENCODER_ACCELERATION
Definition: IEncoders.h:212
constexpr yarp::conf::vocab32_t VOCAB_ENCODERS
Definition: IEncoders.h:207
constexpr yarp::conf::vocab32_t VOCAB_IMPEDANCE
constexpr yarp::conf::vocab32_t VOCAB_INTERACTION_MODES
constexpr yarp::conf::vocab32_t VOCAB_INTERACTION_MODE_GROUP
constexpr yarp::conf::vocab32_t VOCAB_INTERACTION_MODE
constexpr yarp::conf::vocab32_t VOCAB_INTERFACE_INTERACTION_MODE
constexpr yarp::conf::vocab32_t VOCAB_JF_GET_JOINTFAULT
Definition: IJointFault.h:42
constexpr yarp::conf::vocab32_t VOCAB_IJOINTFAULT
Definition: IJointFault.h:41
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER_SPEED
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER_ACCELERATIONS
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER_ACCELERATION
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER_SPEEDS
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODER_NUMBER
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_E_RESETS
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_E_RESET
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_ENCODERS
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_CPR
constexpr yarp::conf::vocab32_t VOCAB_TEMPERATURES
Definition: IMotor.h:162
constexpr yarp::conf::vocab32_t VOCAB_TEMPERATURE_LIMIT
Definition: IMotor.h:163
constexpr yarp::conf::vocab32_t VOCAB_TEMPERATURE
Definition: IMotor.h:160
constexpr yarp::conf::vocab32_t VOCAB_GEARBOX_RATIO
Definition: IMotor.h:161
constexpr yarp::conf::vocab32_t VOCAB_MOTORS_NUMBER
Definition: IMotor.h:159
constexpr yarp::conf::vocab32_t VOCAB_PWMCONTROL_INTERFACE
Definition: IPWMControl.h:139
constexpr yarp::conf::vocab32_t VOCAB_PWMCONTROL_PWM_OUTPUTS
Definition: IPWMControl.h:144
constexpr yarp::conf::vocab32_t VOCAB_PWMCONTROL_REF_PWMS
Definition: IPWMControl.h:142
constexpr yarp::conf::vocab32_t VOCAB_PWMCONTROL_REF_PWM
Definition: IPWMControl.h:141
constexpr yarp::conf::vocab32_t VOCAB_PWMCONTROL_PWM_OUTPUT
Definition: IPWMControl.h:143
constexpr yarp::conf::vocab32_t VOCAB_PIDS
Definition: IPidControl.h:378
constexpr yarp::conf::vocab32_t VOCAB_PID
Definition: IPidControl.h:377
constexpr yarp::conf::vocab32_t VOCAB_REF_ACCELERATION_GROUP
constexpr yarp::conf::vocab32_t VOCAB_STOP_GROUP
constexpr yarp::conf::vocab32_t VOCAB_RELATIVE_MOVE_GROUP
constexpr yarp::conf::vocab32_t VOCAB_POSITION_MOVE_GROUP
constexpr yarp::conf::vocab32_t VOCAB_MOTION_DONE_GROUP
constexpr yarp::conf::vocab32_t VOCAB_REF_SPEED_GROUP
constexpr yarp::conf::vocab32_t VOCAB_POSITION_DIRECTS
constexpr yarp::conf::vocab32_t VOCAB_POSITION_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_POSITION_DIRECT_GROUP
constexpr yarp::conf::vocab32_t VOCAB_LIST_VARIABLES
constexpr yarp::conf::vocab32_t VOCAB_VARIABLE
constexpr yarp::conf::vocab32_t VOCAB_REMOTE_VARIABILE_INTERFACE
constexpr yarp::conf::vocab32_t VOCAB_TORQUE
constexpr yarp::conf::vocab32_t VOCAB_TRQ
constexpr yarp::conf::vocab32_t VOCAB_TRQS
constexpr yarp::conf::vocab32_t VOCAB_RANGE
constexpr yarp::conf::vocab32_t VOCAB_IMP_OFFSET
constexpr yarp::conf::vocab32_t VOCAB_MOTOR_PARAMS
constexpr yarp::conf::vocab32_t VOCAB_IMP_PARAM
constexpr yarp::conf::vocab32_t VOCAB_RANGES
constexpr yarp::conf::vocab32_t VOCAB_TORQUE_MODE
constexpr yarp::conf::vocab32_t VOCAB_VELOCITY_MOVE_GROUP
void appendTimeStamp(Bottle &bot, Stamp &st)
void handleRemoteCalibratorMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IControlCalibration * rpc_Icalib
yarp::dev::IEncodersTimed * rpc_IEncTimed
yarp::dev::IControlMode * rpc_iCtrlMode
yarp::dev::IRemoteCalibrator * rpc_IRemoteCalibrator
yarp::dev::IAxisInfo * rpc_AxisInfo
yarp::dev::ITorqueControl * rpc_ITorque
yarp::dev::IPidControl * rpc_IPid
void handleProtocolVersionRequest(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handlePWMMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IRemoteVariables * rpc_IVar
yarp::dev::IImpedanceControl * rpc_IImpedance
void handleCurrentMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleInteractionModeMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleControlModeMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void init(yarp::dev::DeviceDriver *x)
Initialization.
yarp::dev::IPositionDirect * rpc_IPosDirect
yarp::dev::ICurrentControl * rpc_ICurrent
void handleTorqueMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IMotorEncoders * rpc_IMotEnc
yarp::dev::IInteractionMode * rpc_IInteract
void handleJointFaultMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handlePidMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IJointFault * rpc_IJointFault
virtual bool initialize()
Initialize the internal data.
yarp::dev::IPositionControl * rpc_IPosCtrl
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
yarp::sig::Vector tmpVect
yarp::dev::IVelocityControl * rpc_IVelCtrl
yarp::dev::IPWMControl * rpc_IPWM
yarp::dev::IAmplifierControl * rcp_IAmp
yarp::dev::IMotor * rpc_IMotor
yarp::dev::IControlLimits * rcp_Ilim
yarp::os::Stamp lastRpcStamp
void handleImpedanceMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleRemoteVariablesMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
void addUsage(const char *txt, const char *explain=nullptr)
Add information about a message that the respond() method understands.
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 getCurrents(double *vals)=0
virtual bool disableAmp(int j)=0
Disable the amplifier on a specific joint.
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 getCurrent(int j, double *val)=0
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)
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
Definition: IAxisInfo.h:55
virtual bool setCalibrationParameters(int axis, const CalibrationParameters &params)
Start calibration, this method is very often platform specific.
virtual bool calibrateRobot()
Calibrate robot by using an external calibrator.
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 getRefCurrents(double *currs)=0
Get the reference value of the currents for all motors.
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 getCurrentRanges(double *min, double *max)=0
Get the full scale of the current measurements for all motors motor (e.g.
virtual bool getEncoderSpeed(int j, double *sp)=0
Read the istantaneous speed of an axis.
virtual bool getEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all axes.
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 setEncoders(const double *vals)=0
Set the value of all encoders.
virtual bool getEncoders(double *encs)=0
Read the position of all axes.
virtual bool getEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all axes.
virtual bool getEncoderAcceleration(int j, double *spds)=0
Read the instantaneous acceleration of an axis.
virtual bool resetEncoders()=0
Reset encoders.
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 getMotorEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all motor encoders.
virtual bool getMotorEncoderAcceleration(int m, double *acc)=0
Read the instantaneous acceleration of a motor encoder.
virtual bool getMotorEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
virtual bool getNumberOfMotorEncoders(int *num)=0
Get the number of available motor encoders.
virtual bool setMotorEncoders(const double *vals)=0
Set the value of all motor encoders.
virtual bool getMotorEncoders(double *encs)=0
Read the position of all motor encoders.
virtual bool resetMotorEncoders()=0
Reset motor encoders.
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 getTemperatures(double *vals)=0
Get temperature of all the motors.
virtual bool getNumberOfMotors(int *num)=0
Get the number of available motors.
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 getRefDutyCycles(double *refs)=0
Gets the last reference sent using the setRefDutyCycles function.
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 getPidReferences(const PidControlTypeEnum &pidtype, double *refs)=0
Get the current reference of all pid controllers.
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 getPidErrorLimits(const PidControlTypeEnum &pidtype, double *limits)=0
Get the error limit for all controllers.
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 setPidErrorLimits(const PidControlTypeEnum &pidtype, const double *limits)=0
Get the error limit for the controller on all joints.
virtual bool getPidOutputs(const PidControlTypeEnum &pidtype, double *outs)=0
Get the output of the controllers (e.g.
virtual bool setPidReference(const PidControlTypeEnum &pidtype, int j, double ref)=0
Set the controller reference for a given axis.
virtual bool setPidReferences(const PidControlTypeEnum &pidtype, const double *refs)=0
Set the controller reference, multiple axes.
virtual bool getPidErrors(const PidControlTypeEnum &pidtype, double *errs)=0
Get the error of all joints.
virtual bool setPids(const PidControlTypeEnum &pidtype, const Pid *pids)=0
Set new pid value on multiple axes.
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 getPids(const PidControlTypeEnum &pidtype, Pid *pids)=0
Get current pid value for a specific joint.
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 getAxes(int *ax)=0
Get the number of controlled axes.
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 getRefPosition(const int joint, double *ref)
Get the last position reference for the specified axis.
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 isCalibratorDevicePresent(bool *isCalib)
isCalibratorDevicePresent: check if a calibrator device has been set
virtual bool homingWholePart()=0
homingWholePart: call the homing procedure for a the whole part/device
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 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 getRefTorques(double *t)=0
Get 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 getTorques(double *t)=0
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getTorqueRange(int j, double *min, double *max)=0
Get the full scale of the torque sensor of a given joint.
virtual bool getTorqueRanges(double *min, double *max)=0
Get the full scale of the torque sensors of all joints.
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.
double kd
derivative gain
double scale
scale for the pid output
double offset
pwm offset added to the pid output
double stiction_down_val
down stiction offset added to the pid output
double stiction_up_val
up stiction offset added to the pid output
double max_output
max output
double kff
feedforward gain
double ki
integrative gain
double max_int
saturation threshold for the integrator
double kp
proportional gain
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
Definition: Bottle.cpp:336
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition: Bottle.cpp:182
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:251
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:158
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
Bottle tail() const
Get all but the first element of a bottle.
Definition: Bottle.cpp:388
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:170
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
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
double getTime() const
Get the time stamp.
Definition: Stamp.cpp:34
int getCount() const
Get the sequence number.
Definition: Stamp.cpp:29
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:228
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
void resize(size_t size) override
Resize the vector.
Definition: Vector.h:220
#define yCError(component,...)
Definition: LogComponent.h:213
#define yCTrace(component,...)
Definition: LogComponent.h:84
#define yCWarning(component,...)
Definition: LogComponent.h:192
#define yCDebug(component,...)
Definition: LogComponent.h:128
For streams capable of holding different kinds of content, check what they actually have.
PidControlTypeEnum
Definition: PidEnums.h:15
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition: Vocab.cpp:33
An interface to the operating system, including Port based communication.