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