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