YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeMotionControl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "FakeMotionControl.h"
7
9
10#include <yarp/os/Bottle.h>
11#include <yarp/os/Time.h>
13#include <yarp/os/LogStream.h>
14#include <yarp/os/NetType.h>
15#include <yarp/dev/Drivers.h>
16
17#include <sstream>
18#include <cstring>
19
20using namespace yarp::dev;
21using namespace yarp::os;
22using namespace yarp::os::impl;
23
24// macros
25#define NEW_JSTATUS_STRUCT 1
26#define VELOCITY_WATCHDOG 0.1
27#define OPENLOOP_WATCHDOG 0.1
28#define PWM_CONSTANT 0.1
29
30namespace {
31YARP_LOG_COMPONENT(FAKEMOTIONCONTROL, "yarp.device.fakeMotionControl")
32}
33
35{
36 std::lock_guard lock(_mutex);
37
38 _cycleTimestamp = yarp::os::Time::now();
39
40 for (int i=0;i <_njoints ;i++)
41 {
42 if (_controlModes[i] == VOCAB_CM_VELOCITY)
43 {
44 //increment joint position
45 if (this->_command_speeds[i]!=0)
46 {
47 double elapsed = yarp::os::Time::now()-prev_time;
48 double increment = _command_speeds[i]*elapsed;
49 pos[i]+=increment;
50 }
51
52 //velocity watchdog
53 if (velocity_watchdog_enabled && yarp::os::Time::now()-last_velocity_command[i]>=VELOCITY_WATCHDOG)
54 {
55 this->_command_speeds[i]=0.0;
56 }
57 }
58 else if (_controlModes[i] == VOCAB_CM_PWM)
59 {
60 //increment joint position
61 if (this->refpwm[i]!=0)
62 {
63 double elapsed = yarp::os::Time::now()-prev_time;
64 double increment = refpwm[i]*elapsed*PWM_CONSTANT;
65 pos[i]+=increment;
66 }
67
68 //pwm watchdog
69 if (openloop_watchdog_enabled && yarp::os::Time::now()-last_pwm_command[i]>=OPENLOOP_WATCHDOG)
70 {
71 this->refpwm[i]=0.0;
72 }
73 }
74 else if (_controlModes[i] == VOCAB_CM_POSITION_DIRECT)
75 {
76 pos[i] = _posDir_references[i];
77 }
78 else if (_controlModes[i] == VOCAB_CM_POSITION)
79 {
80 pos[i] = _posCtrl_references[i];
81 //do something with _ref_speeds[i];
82 }
83 else if (_controlModes[i] == VOCAB_CM_IDLE)
84 {
85 //do nothing
86 }
87 else if (_controlModes[i] == VOCAB_CM_CURRENT)
88 {
89 //do nothing
90 }
91 else if (_controlModes[i] == VOCAB_CM_VELOCITY_DIRECT)
92 {
93 //not yet implemented
94 }
95 else if (_controlModes[i] == VOCAB_CM_MIXED)
96 {
97 //not yet implemented
98 }
99 else if (_controlModes[i] == VOCAB_CM_TORQUE)
100 {
101 //not yet implemented
102 }
103 else if (_controlModes[i] == VOCAB_CM_HW_FAULT)
104 {
105 //not yet implemented
106 }
107 else
108 {
109 //unsupported control mode
110 yCWarning(FAKEMOTIONCONTROL) << "Unsupported control mode, joint " << i << " " << yarp::os::Vocab32::decode(_controlModes[i]);
111 }
112 }
113 prev_time = yarp::os::Time::now();
114}
115
116static inline bool NOT_YET_IMPLEMENTED(const char *txt)
117{
118 yCDebug(FAKEMOTIONCONTROL) << txt << "is not yet implemented for FakeMotionControl";
119 return true;
120}
121
122static inline bool DEPRECATED(const char *txt)
123{
124 yCError(FAKEMOTIONCONTROL) << txt << "has been deprecated for FakeMotionControl";
125 return true;
126}
127
128
129// replace with to_string as soon as C++11 is required by YARP
134template<typename T>
135std::string toString(const T& value)
136{
137 std::ostringstream oss;
138 oss << value;
139 return oss.str();
140}
141
142//generic function that check is key1 is present in input bottle and that the result has size elements
143// return true/false
144/*
145bool FakeMotionControl::extractGroup(Bottle &input, Bottle &out, const std::string &key1, const std::string &txt, int size)
146{
147 size++;
148 Bottle &tmp=input.findGroup(key1, txt);
149
150 if (tmp.isNull())
151 {
152 yCError(FAKEMOTIONCONTROL) << key1.c_str() << "parameter not found";
153 return false;
154 }
155
156 if(tmp.size()!=(size_t) size)
157 {
158 yCError(FAKEMOTIONCONTROL) << key1.c_str() << "incorrect number of entries";
159 return false;
160 }
161
162 out=tmp;
163 return true;
164}
165*/
166
168{
169 pos.resize(_njoints);
170 dpos.resize(_njoints);
171 vel.resize(_njoints);
172 speed.resize(_njoints);
173 acc.resize(_njoints);
174 loc.resize(_njoints);
175 amp.resize(_njoints);
176
177 current.resize(_njoints);
178 nominalCurrent.resize(_njoints);
179 maxCurrent.resize(_njoints);
180 peakCurrent.resize(_njoints);
181 pwm.resize(_njoints);
182 refpwm.resize(_njoints);
183 pwmLimit.resize(_njoints);
184 supplyVoltage.resize(_njoints);
185 last_velocity_command.resize(_njoints);
186 last_pwm_command.resize(_njoints);
187
188 pos.zero();
189 dpos.zero();
190 vel.zero();
191 speed.zero();
192 acc.zero();
193 loc.zero();
194 amp.zero();
195
196 current.zero();
197 nominalCurrent.zero();
198 maxCurrent.zero();
199 peakCurrent.zero();
200
201 pwm.zero();
202 refpwm.zero();
203 pwmLimit.zero();
204 supplyVoltage.zero();
205}
206
208{
209 _axisMap = allocAndCheck<int>(nj);
210 _controlModes = allocAndCheck<int>(nj);
211 _interactMode = allocAndCheck<int>(nj);
212 _angleToEncoder = allocAndCheck<double>(nj);
213 _dutycycleToPWM = allocAndCheck<double>(nj);
214 _ampsToSensor = allocAndCheck<double>(nj);
215 _encodersStamp = allocAndCheck<double>(nj);
216 _DEPRECATED_encoderconversionoffset = allocAndCheck<float>(nj);
217 _DEPRECATED_encoderconversionfactor = allocAndCheck<float>(nj);
218 _jointEncoderRes = allocAndCheck<int>(nj);
219 _rotorEncoderRes = allocAndCheck<int>(nj);
220 _gearbox = allocAndCheck<double>(nj);
221 _torqueSensorId= allocAndCheck<int>(nj);
222 _torqueSensorChan= allocAndCheck<int>(nj);
223 _maxTorque=allocAndCheck<double>(nj);
224 _torques = allocAndCheck<double>(nj);
225 _maxJntCmdVelocity = allocAndCheck<double>(nj);
226 _maxMotorVelocity = allocAndCheck<double>(nj);
227 _newtonsToSensor=allocAndCheck<double>(nj);
228 _hasHallSensor = allocAndCheck<bool>(nj);
229 _hasTempSensor = allocAndCheck<bool>(nj);
230 _hasRotorEncoder = allocAndCheck<bool>(nj);
231 _hasRotorEncoderIndex = allocAndCheck<bool>(nj);
232 _rotorIndexOffset = allocAndCheck<int>(nj);
233 _motorPoles = allocAndCheck<int>(nj);
234 _rotorlimits_max = allocAndCheck<double>(nj);
235 _rotorlimits_min = allocAndCheck<double>(nj);
236 _hwfault_code = allocAndCheck<int>(nj);
237 _hwfault_message = allocAndCheck<std::string>(nj);
238 _braked = allocAndCheck<bool>(nj);
239 _autobraked = allocAndCheck<bool>(nj);
240
241 _ppids=allocAndCheck<Pid>(nj);
242 _tpids=allocAndCheck<Pid>(nj);
243 _cpids = allocAndCheck<Pid>(nj);
244 _vpids = allocAndCheck<Pid>(nj);
245 _ppids_ena=allocAndCheck<bool>(nj);
246 _tpids_ena=allocAndCheck<bool>(nj);
247 _cpids_ena = allocAndCheck<bool>(nj);
248 _vpids_ena = allocAndCheck<bool>(nj);
249 _ppids_lim=allocAndCheck<double>(nj);
250 _tpids_lim=allocAndCheck<double>(nj);
251 _cpids_lim = allocAndCheck<double>(nj);
252 _vpids_lim = allocAndCheck<double>(nj);
253 _ppids_ref=allocAndCheck<double>(nj);
254 _tpids_ref=allocAndCheck<double>(nj);
255 _cpids_ref = allocAndCheck<double>(nj);
256 _vpids_ref = allocAndCheck<double>(nj);
257
258// _impedance_params=allocAndCheck<ImpedanceParameters>(nj);
259// _impedance_limits=allocAndCheck<ImpedanceLimits>(nj);
260 _axisName = new std::string[nj];
261 _jointType = new JointTypeEnum[nj];
262
263 _limitsMax=allocAndCheck<double>(nj);
264 _limitsMin=allocAndCheck<double>(nj);
265 _kinematic_mj=allocAndCheck<double>(16);
266// _currentLimits=allocAndCheck<MotorCurrentLimits>(nj);
267 _motorPwmLimits=allocAndCheck<double>(nj);
268 checking_motiondone=allocAndCheck<bool>(nj);
269
270 _velocityShifts=allocAndCheck<int>(nj);
271 _velocityTimeout=allocAndCheck<int>(nj);
272 _kbemf=allocAndCheck<double>(nj);
273 _ktau=allocAndCheck<double>(nj);
274 _kbemf_scale = allocAndCheck<int>(nj);
275 _ktau_scale = allocAndCheck<int>(nj);
276 _filterType=allocAndCheck<int>(nj);
277 _last_position_move_time=allocAndCheck<double>(nj);
278 _viscousPos=allocAndCheck<double>(nj);
279 _viscousNeg=allocAndCheck<double>(nj);
280 _coulombPos=allocAndCheck<double>(nj);
281 _coulombNeg=allocAndCheck<double>(nj);
282 _velocityThres=allocAndCheck<double>(nj);
283
284 // Reserve space for data stored locally. values are initialized to 0
285 _posCtrl_references = allocAndCheck<double>(nj);
286 _posDir_references = allocAndCheck<double>(nj);
287 _command_speeds = allocAndCheck<double>(nj);
288 _dir_vel_commands = allocAndCheck<double>(nj);
289 _ref_speeds = allocAndCheck<double>(nj);
290 _ref_accs = allocAndCheck<double>(nj);
291 _ref_torques = allocAndCheck<double>(nj);
292 _ref_currents = allocAndCheck<double>(nj);
293 _enabledAmp = allocAndCheck<bool>(nj);
294 _enabledPid = allocAndCheck<bool>(nj);
295 _calibrated = allocAndCheck<bool>(nj);
296// _cacheImpedance = allocAndCheck<eOmc_impedance_t>(nj);
297
299
300 return true;
301}
302
303bool FakeMotionControl::dealloc()
304{
305 checkAndDestroy(_axisMap);
306 checkAndDestroy(_controlModes);
307 checkAndDestroy(_interactMode);
308 checkAndDestroy(_angleToEncoder);
309 checkAndDestroy(_ampsToSensor);
310 checkAndDestroy(_dutycycleToPWM);
311 checkAndDestroy(_encodersStamp);
312 checkAndDestroy(_DEPRECATED_encoderconversionoffset);
313 checkAndDestroy(_DEPRECATED_encoderconversionfactor);
314 checkAndDestroy(_jointEncoderRes);
315 checkAndDestroy(_rotorEncoderRes);
316// checkAndDestroy(_jointEncoderType);
317// checkAndDestroy(_rotorEncoderType);
318 checkAndDestroy(_gearbox);
319 checkAndDestroy(_torqueSensorId);
320 checkAndDestroy(_torqueSensorChan);
321 checkAndDestroy(_braked);
322 checkAndDestroy(_autobraked);
323 checkAndDestroy(_maxTorque);
324 checkAndDestroy(_maxJntCmdVelocity);
325 checkAndDestroy(_maxMotorVelocity);
326 checkAndDestroy(_newtonsToSensor);
327 checkAndDestroy(_ppids);
328 checkAndDestroy(_tpids);
329 checkAndDestroy(_cpids);
330 checkAndDestroy(_vpids);
331 checkAndDestroy(_ppids_ena);
332 checkAndDestroy(_tpids_ena);
333 checkAndDestroy(_cpids_ena);
334 checkAndDestroy(_vpids_ena);
335 checkAndDestroy(_ppids_lim);
336 checkAndDestroy(_tpids_lim);
337 checkAndDestroy(_cpids_lim);
338 checkAndDestroy(_vpids_lim);
339 checkAndDestroy(_ppids_ref);
340 checkAndDestroy(_tpids_ref);
341 checkAndDestroy(_cpids_ref);
342 checkAndDestroy(_vpids_ref);
343// checkAndDestroy(_impedance_params);
344// checkAndDestroy(_impedance_limits);
345 checkAndDestroy(_limitsMax);
346 checkAndDestroy(_limitsMin);
347 checkAndDestroy(_kinematic_mj);
348// checkAndDestroy(_currentLimits);
349 checkAndDestroy(_motorPwmLimits);
350 checkAndDestroy(checking_motiondone);
351 checkAndDestroy(_velocityShifts);
352 checkAndDestroy(_velocityTimeout);
353 checkAndDestroy(_kbemf);
354 checkAndDestroy(_ktau);
355 checkAndDestroy(_kbemf_scale);
356 checkAndDestroy(_ktau_scale);
357 checkAndDestroy(_filterType);
358 checkAndDestroy(_viscousPos);
359 checkAndDestroy(_viscousNeg);
360 checkAndDestroy(_coulombPos);
361 checkAndDestroy(_coulombNeg);
362 checkAndDestroy(_velocityThres);
363 checkAndDestroy(_posCtrl_references);
364 checkAndDestroy(_posDir_references);
365 checkAndDestroy(_command_speeds);
366 checkAndDestroy(_dir_vel_commands);
367 checkAndDestroy(_ref_speeds);
368 checkAndDestroy(_ref_accs);
369 checkAndDestroy(_ref_torques);
370 checkAndDestroy(_ref_currents);
371 checkAndDestroy(_enabledAmp);
372 checkAndDestroy(_enabledPid);
373 checkAndDestroy(_calibrated);
374 checkAndDestroy(_hasHallSensor);
375 checkAndDestroy(_hasTempSensor);
376 checkAndDestroy(_hasRotorEncoder);
377 checkAndDestroy(_hasRotorEncoderIndex);
378 checkAndDestroy(_rotorIndexOffset);
379 checkAndDestroy(_motorPoles);
380 checkAndDestroy(_axisName);
381 checkAndDestroy(_jointType);
382 checkAndDestroy(_rotorlimits_max);
383 checkAndDestroy(_rotorlimits_min);
384 checkAndDestroy(_last_position_move_time);
385 checkAndDestroy(_torques);
386 checkAndDestroy(_hwfault_code);
387 checkAndDestroy(_hwfault_message);
388
389 return true;
390}
391
393 PeriodicThread(0.01),
415 _mutex(),
416 _njoints (0),
417 _axisMap (nullptr),
418 _angleToEncoder(nullptr),
419 _encodersStamp (nullptr),
420 _ampsToSensor (nullptr),
421 _dutycycleToPWM(nullptr),
422 _DEPRECATED_encoderconversionfactor (nullptr),
423 _DEPRECATED_encoderconversionoffset (nullptr),
424 _jointEncoderRes (nullptr),
425 _rotorEncoderRes (nullptr),
426 _gearbox (nullptr),
427 _hasHallSensor (nullptr),
428 _hasTempSensor (nullptr),
429 _hasRotorEncoder (nullptr),
430 _hasRotorEncoderIndex (nullptr),
431 _rotorIndexOffset (nullptr),
432 _motorPoles (nullptr),
433 _rotorlimits_max (nullptr),
434 _rotorlimits_min (nullptr),
435 _ppids (nullptr),
436 _tpids (nullptr),
437 _cpids (nullptr),
438 _vpids (nullptr),
439 _ppids_ena (nullptr),
440 _tpids_ena (nullptr),
441 _cpids_ena (nullptr),
442 _vpids_ena (nullptr),
443 _ppids_lim (nullptr),
444 _tpids_lim (nullptr),
445 _cpids_lim (nullptr),
446 _vpids_lim (nullptr),
447 _ppids_ref (nullptr),
448 _tpids_ref (nullptr),
449 _cpids_ref (nullptr),
450 _vpids_ref (nullptr),
451 _axisName (nullptr),
452 _jointType (nullptr),
453 _limitsMin (nullptr),
454 _limitsMax (nullptr),
455 _kinematic_mj (nullptr),
456 _maxJntCmdVelocity (nullptr),
457 _maxMotorVelocity (nullptr),
458 _velocityShifts (nullptr),
459 _velocityTimeout (nullptr),
460 _kbemf (nullptr),
461 _ktau (nullptr),
462 _kbemf_scale (nullptr),
463 _ktau_scale (nullptr),
464 _viscousPos (nullptr),
465 _viscousNeg (nullptr),
466 _coulombPos (nullptr),
467 _coulombNeg (nullptr),
468 _velocityThres (nullptr),
469 _filterType (nullptr),
470 _torqueSensorId (nullptr),
471 _torqueSensorChan (nullptr),
472 _maxTorque (nullptr),
473 _newtonsToSensor (nullptr),
474 checking_motiondone (nullptr),
475 _last_position_move_time(nullptr),
476 _motorPwmLimits (nullptr),
477 _torques (nullptr),
478 useRawEncoderData (false),
479 _pwmIsLimited (false),
480 _torqueControlEnabled (false),
481 _torqueControlUnits (T_MACHINE_UNITS),
482 _positionControlUnits (P_MACHINE_UNITS),
483 prev_time (0.0),
484 opened (false),
485 verbose (VERY_VERBOSE)
486{
488 std::string tmp = yarp::conf::environment::get_string("VERBOSE_STICA");
489 verbosewhenok = (tmp != "") ? (bool)yarp::conf::numeric::from_string<int>(tmp) :
490 false;
491}
492
498
500{
501 return opened;
502}
503
505{
507 for(int i=0; i<_njoints; i++)
508 {
509 pwm[i] = 33+i;
510 pwmLimit[i] = (33+i)*10;
511 current[i] = (33+i)*100;
512 maxCurrent[i] = (33+i)*1000;
513 peakCurrent[i] = (33+i)*2;
514 nominalCurrent[i] = (33+i)*20;
515 supplyVoltage[i] = (33+i)*200;
516 last_velocity_command[i] = -1;
517 last_pwm_command[i] = -1;
518 _controlModes[i] = VOCAB_CM_POSITION;
519 _maxJntCmdVelocity[i]=50.0;
520 }
521 prev_time = yarp::os::Time::now();
522 return true;
523}
524
528
530{
531 if (!this->parseParams(config)) {return false;}
532
533 std::string str;
534
535 //
536 // Read Configuration params from file
537 //
538 _njoints = m_GENERAL_Joints;
539
540 if(!alloc(_njoints))
541 {
542 yCError(FAKEMOTIONCONTROL) << "Malloc failed";
543 return false;
544 }
545
546 // Default value
547 for (int i = 0; i < _njoints; i++) {
548 _newtonsToSensor[i] = 1;
549 }
550
551 if(!fromConfig(config))
552 {
553 yCError(FAKEMOTIONCONTROL) << "Missing parameters in config file";
554 return false;
555 }
556
557 // INIT ALL INTERFACES
558 yarp::sig::Vector tmpZeros; tmpZeros.resize (_njoints, 0.0);
559 yarp::sig::Vector tmpOnes; tmpOnes.resize (_njoints, 1.0);
560 yarp::sig::Vector bemfToRaw; bemfToRaw.resize(_njoints, 1.0);
561 yarp::sig::Vector ktauToRaw; ktauToRaw.resize(_njoints, 1.0);
562 for (size_t i = 0; i < _njoints; i++) { bemfToRaw [i] = _newtonsToSensor[i] / _angleToEncoder[i];}
563 for (size_t i = 0; i < _njoints; i++) { ktauToRaw[i] = _dutycycleToPWM[i] / _newtonsToSensor[i]; }
564 ControlBoardHelper cb(_njoints, _axisMap, _angleToEncoder, nullptr, _newtonsToSensor, _ampsToSensor, _dutycycleToPWM);
566 ImplementControlCalibration::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
567 ImplementAmplifierControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
568 ImplementEncodersTimed::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
569 ImplementMotorEncoders::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
570 ImplementPositionControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
571 ImplementPidControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr, _newtonsToSensor, _ampsToSensor, _dutycycleToPWM);
572 ImplementPidControl::setConversionUnits(PidControlTypeEnum::VOCAB_PIDTYPE_POSITION, PidFeedbackUnitsEnum::METRIC, PidOutputUnitsEnum::DUTYCYCLE_PWM_PERCENT);
573 ImplementPidControl::setConversionUnits(PidControlTypeEnum::VOCAB_PIDTYPE_TORQUE, PidFeedbackUnitsEnum::METRIC, PidOutputUnitsEnum::DUTYCYCLE_PWM_PERCENT);
574 ImplementControlMode::initialize(_njoints, _axisMap);
575 ImplementVelocityControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
576 ImplementVelocityDirect::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
577 ImplementControlLimits::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
578 ImplementImpedanceControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr, _newtonsToSensor);
579 ImplementTorqueControl::initialize(_njoints, _axisMap, _angleToEncoder, nullptr, _newtonsToSensor, _ampsToSensor, _dutycycleToPWM, bemfToRaw.data(), ktauToRaw.data());
580 ImplementPositionDirect::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
581 ImplementInteractionMode::initialize(_njoints, _axisMap, _angleToEncoder, nullptr);
582 ImplementMotor::initialize(_njoints, _axisMap);
583 ImplementAxisInfo::initialize(_njoints, _axisMap);
584 ImplementPWMControl::initialize(_njoints, _axisMap, _dutycycleToPWM);
585 ImplementCurrentControl::initialize(_njoints, _axisMap, _ampsToSensor);
586 ImplementVirtualAnalogSensor::initialize(_njoints, _axisMap, _newtonsToSensor);
587 ImplementJointFault::initialize(_njoints, _axisMap);
588 ImplementJointBrake::initialize(_njoints, _axisMap);
589
590 //start the rateThread
591 bool init = this->start();
592 if(!init)
593 {
594 yCError(FAKEMOTIONCONTROL) << "open() has an error in call of FakeMotionControl::init() for board" ;
595 return false;
596 }
597 else
598 {
599 if(verbosewhenok)
600 {
601 yCDebug(FAKEMOTIONCONTROL) << "init() has successfully initted board ";
602 }
603 }
604 opened = true;
605
606 return true;
607}
608
610{
611 size_t i;
612
613 // AxisMap
614 if (!m_GENERAL_AxisMap.empty())
615 {
616 for (i = 0; i < m_GENERAL_AxisMap.size(); i++) {
617 _axisMap[i] = m_GENERAL_AxisMap[i];
618 }
619 }
620 else
621 {
622 for (i = 0; i < _njoints; i++) {
623 _axisMap[i] = i;
624 }
625 }
626 for (i = 0; i < _njoints; i++) {yDebug() << "_axisMap: " << _axisMap[i] << " "; }
627
628 // AxisName
629 if (!m_GENERAL_AxisName.empty())
630 {
631 for (i = 0; i < m_GENERAL_AxisName.size(); i++) {
632 _axisName[_axisMap[i]] = m_GENERAL_AxisName[i];
633 }
634 }
635 else
636 {
637 for (i = 0; i < _njoints; i++) {
638 _axisName[_axisMap[i]] = "joint" + toString(i);
639 }
640 }
641 for (i = 0; i < _njoints; i++) { yDebug() << "_axisName: " << _axisName[_axisMap[i]] << " "; }
642
643 // Axis Type
644 if (!m_GENERAL_AxisType.empty())
645 {
646 //beware: axis type has to be remapped here because they are not set using the toHw() helper function
647 for (i = 0; i < m_GENERAL_AxisType.size(); i++)
648 {
649 std::string typeString = m_GENERAL_AxisType[i];
650 if (typeString == "revolute") {
651 _jointType[_axisMap[i]] = VOCAB_JOINTTYPE_REVOLUTE;
652 }
653 else if (typeString == "prismatic") {
654 _jointType[_axisMap[i]] = VOCAB_JOINTTYPE_PRISMATIC;
655 }
656 else {
657 yCError(FAKEMOTIONCONTROL, "Unknown AxisType value %s!", typeString.c_str());
658 _jointType[_axisMap[i]] = VOCAB_JOINTTYPE_UNKNOWN;
659 return false;
660 }
661 }
662 }
663 else
664 {
665 yCInfo(FAKEMOTIONCONTROL) << "Using default AxisType (revolute)";
666 for (i = 0; i < _njoints; i++) {
667 _jointType[_axisMap[i]] = VOCAB_JOINTTYPE_REVOLUTE;
668 }
669 }
670
671 // current conversions factor
672 if (!m_GENERAL_ampsToSensor.empty())
673 {
674 for (i = 0; i < m_GENERAL_ampsToSensor.size(); i++) {
675 _ampsToSensor[i] = m_GENERAL_ampsToSensor[i];
676 }
677 }
678 else
679 {
680 yCInfo(FAKEMOTIONCONTROL) << "Using default ampsToSensor=1";
681 for (i = 0; i < _njoints; i++) {
682 _ampsToSensor[i] = 1;
683 }
684 }
685
686
687 // pwm conversions factor
688 if (!m_GENERAL_fullscalePWM.empty())
689 {
690 for (i = 0; i < m_GENERAL_fullscalePWM.size(); i++) {
691 _dutycycleToPWM[i] = m_GENERAL_fullscalePWM[i]/100;
692 }
693 }
694 else
695 {
696 yCInfo(FAKEMOTIONCONTROL) << "Using default fullscalePWM=1";
697 for (i = 0; i < _njoints; i++) {
698 _dutycycleToPWM[i] = 1;
699 }
700 }
701
702// double tmp_A2E;
703 // Encoder scales
704 if(!m_GENERAL_Encoder.empty())
705 {
706 for (i = 0; i < m_GENERAL_Encoder.size(); i++) {
707 _angleToEncoder[i] = m_GENERAL_Encoder[i]; }
708 }
709 else
710 {
711 yCInfo(FAKEMOTIONCONTROL) << "Using default Encoder=1";
712 for (i = 0; i < _njoints; i++) {
713 _angleToEncoder[i] = 1; }
714 }
715
717 if (!m_LIMITS_Max.empty())
718 {
719 for (i = 0; i < m_LIMITS_Max.size(); i++) {
720 _limitsMax[i] = m_LIMITS_Max[i];
721 }
722 }
723 else
724 {
725 yCInfo(FAKEMOTIONCONTROL) << "Using default m_LIMITS_Max=100";
726 for (i = 0; i < _njoints; i++) {
727 _limitsMax[i] = 100;
728 }
729 }
730
731 if (!m_LIMITS_Min.empty())
732 {
733 for (i = 0; i < m_LIMITS_Min.size(); i++) {
734 _limitsMin[i] = m_LIMITS_Min[i];
735 }
736 }
737 else
738 {
739 yCInfo(FAKEMOTIONCONTROL) << "Using default m_LIMITS_Min=0";
740 for (i = 0; i < _njoints; i++) {
741 _limitsMin[i] = 0;
742 }
743 }
744
745 return true;
746}
747
748
780
781void FakeMotionControl::cleanup()
782{
783
784}
785
786
787
789
791{
792 yCDebug(FAKEMOTIONCONTROL) << "setPidRaw" << pidtype << j << pid.kp;
793 switch (pidtype)
794 {
796 _ppids[j]=pid;
797 break;
799 _vpids[j]=pid;
800 break;
802 _cpids[j]=pid;
803 break;
805 _tpids[j]=pid;
806 break;
807 default:
808 break;
809 }
810 return true;
811}
812
814{
815 bool ret = true;
816 for(int j=0; j< _njoints; j++)
817 {
818 ret &= setPidRaw(pidtype, j, pids[j]);
819 }
820 return ret;
821}
822
824{
825 switch (pidtype)
826 {
828 _ppids_ref[j]=ref;
829 break;
831 _vpids_ref[j]=ref;
832 break;
834 _cpids_ref[j]=ref;
835 break;
837 _tpids_ref[j]=ref;
838 break;
839 default:
840 break;
841 }
842 return true;
843}
844
846{
847 bool ret = true;
848 for(int j=0, index=0; j< _njoints; j++, index++)
849 {
850 ret &= setPidReferenceRaw(pidtype, j, refs[index]);
851 }
852 return ret;
853}
854
856{
857 switch (pidtype)
858 {
860 _ppids_lim[j]=limit;
861 break;
863 _vpids_lim[j]=limit;
864 break;
866 _cpids_lim[j]=limit;
867 break;
869 _tpids_lim[j]=limit;
870 break;
871 default:
872 break;
873 }
874 return true;
875}
876
878{
879 bool ret = true;
880 for(int j=0, index=0; j< _njoints; j++, index++)
881 {
882 ret &= setPidErrorLimitRaw(pidtype, j, limits[index]);
883 }
884 return ret;
885}
886
888{
889 switch (pidtype)
890 {
892 *err=0.1;
893 break;
895 *err=0.2;
896 break;
898 *err=0.3;
899 break;
901 *err=0.4;
902 break;
903 default:
904 break;
905 }
906 return true;
907}
908
910{
911 bool ret = true;
912 for(int j=0; j< _njoints; j++)
913 {
914 ret &= getPidErrorRaw(pidtype, j, &errs[j]);
915 }
916 return ret;
917}
918
920{
921 switch (pidtype)
922 {
924 *pid=_ppids[j];
925 break;
927 *pid=_vpids[j];
928 break;
930 *pid=_cpids[j];
931 break;
933 *pid=_tpids[j];
934 break;
935 default:
936 break;
937 }
938 yCDebug(FAKEMOTIONCONTROL) << "getPidRaw" << pidtype << j << pid->kp;
939 return true;
940}
941
943{
944 bool ret = true;
945
946 // just one joint at time, wait answer before getting to the next.
947 // This is because otherwise too many msg will be placed into can queue
948 for(int j=0, index=0; j<_njoints; j++, index++)
949 {
950 ret &=getPidRaw(pidtype, j, &pids[j]);
951 }
952 return ret;
953}
954
956{
957 switch (pidtype)
958 {
960 *ref=_ppids_ref[j];
961 break;
963 *ref=_vpids_ref[j];
964 break;
966 *ref=_cpids_ref[j];
967 break;
969 *ref=_tpids_ref[j];
970 break;
971 default:
972 break;
973 }
974 return true;
975}
976
978{
979 bool ret = true;
980
981 // just one joint at time, wait answer before getting to the next.
982 // This is because otherwise too many msg will be placed into can queue
983 for(int j=0; j< _njoints; j++)
984 {
986 }
987 return ret;
988}
989
991{
992 switch (pidtype)
993 {
995 *limit=_ppids_lim[j];
996 break;
998 *limit=_vpids_lim[j];
999 break;
1001 *limit=_cpids_lim[j];
1002 break;
1004 *limit=_tpids_lim[j];
1005 break;
1006 default:
1007 break;
1008 }
1009 return true;
1010}
1011
1013{
1014 bool ret = true;
1015 for(int j=0, index=0; j<_njoints; j++, index++)
1016 {
1017 ret &=getPidErrorLimitRaw(pidtype, j, &limits[j]);
1018 }
1019 return ret;
1020}
1021
1023{
1024 return true;
1025}
1026
1028{
1029 switch (pidtype)
1030 {
1032 _ppids_ena[j]=false;
1033 break;
1035 _vpids_ena[j]=false;
1036 break;
1038 _cpids_ena[j]=false;
1039 break;
1041 _tpids_ena[j]=false;
1042 break;
1043 default:
1044 break;
1045 }
1046 return true;
1047}
1048
1050{
1051 switch (pidtype)
1052 {
1054 _ppids_ena[j]=true;
1055 break;
1057 _vpids_ena[j]=true;
1058 break;
1060 _cpids_ena[j]=true;
1061 break;
1063 _tpids_ena[j]=true;
1064 break;
1065 default:
1066 break;
1067 }
1068 return true;
1069}
1070
1072{
1073 yCDebug(FAKEMOTIONCONTROL) << "setPidOffsetRaw" << pidtype << j << v;
1074 switch (pidtype)
1075 {
1077 _ppids[j].offset=v;
1078 break;
1080 _vpids[j].offset=v;
1081 break;
1083 _cpids[j].offset=v;
1084 break;
1086 _tpids[j].offset=v;
1087 break;
1088 default:
1089 break;
1090 }
1091 return true;
1092}
1093
1095{
1096 switch (pidtype)
1097 {
1099 *enabled=_ppids_ena[j];
1100 break;
1102 *enabled=_vpids_ena[j];
1103 break;
1105 *enabled=_cpids_ena[j];
1106 break;
1108 *enabled=_tpids_ena[j];
1109 break;
1110 default:
1111 break;
1112 }
1113 return true;
1114}
1115
1117{
1118 switch (pidtype)
1119 {
1121 *out=1.1 + j * 10;
1122 break;
1124 *out=1.2 + j * 10;
1125 break;
1127 *out=1.3 + j * 10;
1128 break;
1130 *out=1.4 + j * 10;
1131 break;
1132 default:
1133 break;
1134 }
1135 yCDebug(FAKEMOTIONCONTROL) << "getPidOutputRaw" << pidtype << j << *out;
1136 return true;
1137}
1138
1140{
1141 bool ret = true;
1142 for(int j=0; j< _njoints; j++)
1143 {
1144 ret &= getPidOutputRaw(pidtype, j, &outs[j]);
1145 }
1146 return ret;
1147}
1148
1150// Velocity control interface raw //
1152
1154{
1155 int mode=0;
1157 if( (mode != VOCAB_CM_VELOCITY) &&
1158 (mode != VOCAB_CM_MIXED) &&
1160 (mode != VOCAB_CM_IDLE))
1161 {
1162 yCError(FAKEMOTIONCONTROL) << "velocityMoveRaw: skipping command because board " << " joint " << j << " is not in VOCAB_CM_VELOCITY mode";
1163 }
1164 _command_speeds[j] = sp;
1165 last_velocity_command[j]=yarp::os::Time::now();
1166 return true;
1167}
1168
1170{
1172 bool ret = true;
1173 for (int i = 0; i < _njoints; i++) {
1174 ret &= velocityMoveRaw(i, sp[i]);
1175 }
1176 return ret;
1177}
1178
1179
1181// Calibration control interface //
1183
1185{
1186 yCTrace(FAKEMOTIONCONTROL) << "setCalibrationParametersRaw for joint" << j;
1187 return true;
1188}
1189
1190bool FakeMotionControl::calibrateAxisWithParamsRaw(int j, unsigned int type, double p1, double p2, double p3)
1191{
1192 yCTrace(FAKEMOTIONCONTROL) << "calibrateRaw for joint" << j;
1193 return true;
1194}
1195
1197{
1198 return NOT_YET_IMPLEMENTED("calibrationDoneRaw");
1199}
1200
1202// Position control interface //
1204
1206{
1207 *ax=_njoints;
1208
1209 return true;
1210}
1211
1213{
1214 if (verbose >= VERY_VERBOSE) {
1215 yCTrace(FAKEMOTIONCONTROL) << "j " << j << " ref " << ref;
1216 }
1217
1218// if (yarp::os::Time::now()-_last_position_move_time[j]<MAX_POSITION_MOVE_INTERVAL)
1219// {
1220// yCWarning(FAKEMOTIONCONTROL) << "Performance warning: You are using positionMove commands at high rate (<"<< MAX_POSITION_MOVE_INTERVAL*1000.0 <<" ms). Probably position control mode is not the right control mode to use.";
1221// }
1222// _last_position_move_time[j] = yarp::os::Time::now();
1223
1224 int mode = 0;
1226 if( (mode != VOCAB_CM_POSITION) &&
1227 (mode != VOCAB_CM_MIXED) &&
1229 (mode != VOCAB_CM_IDLE))
1230 {
1231 yCError(FAKEMOTIONCONTROL) << "positionMoveRaw: skipping command because joint " << j << " is not in VOCAB_CM_POSITION mode";
1232 }
1233 _posCtrl_references[j] = ref;
1234 return true;
1235}
1236
1238{
1239 if (verbose >= VERY_VERBOSE) {
1241 }
1242
1243 bool ret = true;
1244 for(int j=0, index=0; j< _njoints; j++, index++)
1245 {
1246 ret &= positionMoveRaw(j, refs[index]);
1247 }
1248 return ret;
1249}
1250
1252{
1253 if (verbose >= VERY_VERBOSE) {
1254 yCTrace(FAKEMOTIONCONTROL) << "j " << j << " ref " << delta;
1255 }
1256// if (yarp::os::Time::now()-_last_position_move_time[j]<MAX_POSITION_MOVE_INTERVAL)
1257// {
1258// yCWarning(FAKEMOTIONCONTROL) << "Performance warning: You are using positionMove commands at high rate (<"<< MAX_POSITION_MOVE_INTERVAL*1000.0 <<" ms). Probably position control mode is not the right control mode to use.";
1259// }
1260// _last_position_move_time[j] = yarp::os::Time::now();
1261
1262 int mode = 0;
1264 if( (mode != VOCAB_CM_POSITION) &&
1265 (mode != VOCAB_CM_MIXED) &&
1267 (mode != VOCAB_CM_IDLE))
1268 {
1269 yCError(FAKEMOTIONCONTROL) << "relativeMoveRaw: skipping command because joint " << j << " is not in VOCAB_CM_POSITION mode";
1270 }
1271 _posCtrl_references[j] += delta;
1272 return true;
1273}
1274
1276{
1277 if (verbose >= VERY_VERBOSE) {
1279 }
1280
1281 bool ret = true;
1282 for(int j=0, index=0; j< _njoints; j++, index++)
1283 {
1284 ret &= relativeMoveRaw(j, deltas[index]);
1285 }
1286 return ret;
1287}
1288
1289
1291{
1292 if (verbose >= VERY_VERBOSE) {
1293 yCTrace(FAKEMOTIONCONTROL) << "j ";
1294 }
1295
1296 *flag = false;
1297 return true;
1298}
1299
1301{
1302 if (verbose >= VERY_VERBOSE) {
1304 }
1305
1306 bool ret = true;
1307 bool val, tot_res = true;
1308
1309 for(int j=0, index=0; j< _njoints; j++, index++)
1310 {
1311 ret &= checkMotionDoneRaw(j, &val);
1312 tot_res &= val;
1313 }
1314 *flag = tot_res;
1315 return ret;
1316}
1317
1319{
1320 // Velocity is expressed in iDegrees/s
1321 // save internally the new value of speed; it'll be used in the positionMove
1322 int index = j ;
1323 _ref_speeds[index] = sp;
1324 return true;
1325}
1326
1328{
1329 // Velocity is expressed in iDegrees/s
1330 // save internally the new value of speed; it'll be used in the positionMove
1331 for(int j=0, index=0; j< _njoints; j++, index++)
1332 {
1333 _ref_speeds[index] = spds[index];
1334 }
1335 return true;
1336}
1337
1339{
1340 // Acceleration is expressed in iDegrees/s^2
1341 // save internally the new value of the acceleration; it'll be used in the velocityMove command
1342
1343 if (acc > 1e6)
1344 {
1345 _ref_accs[j ] = 1e6;
1346 }
1347 else if (acc < -1e6)
1348 {
1349 _ref_accs[j ] = -1e6;
1350 }
1351 else
1352 {
1353 _ref_accs[j ] = acc;
1354 }
1355
1356 return true;
1357}
1358
1360{
1361 // Acceleration is expressed in iDegrees/s^2
1362 // save internally the new value of the acceleration; it'll be used in the velocityMove command
1363 for(int j=0, index=0; j< _njoints; j++, index++)
1364 {
1365 if (accs[j] > 1e6)
1366 {
1367 _ref_accs[index] = 1e6;
1368 }
1369 else if (accs[j] < -1e6)
1370 {
1371 _ref_accs[index] = -1e6;
1372 }
1373 else
1374 {
1375 _ref_accs[index] = accs[j];
1376 }
1377 }
1378 return true;
1379}
1380
1382{
1383 *spd = _ref_speeds[j];
1384 return true;
1385}
1386
1388{
1389 memcpy(spds, _ref_speeds, sizeof(double) * _njoints);
1390 return true;
1391}
1392
1394{
1395 *acc = _ref_accs[j];
1396 return true;
1397}
1398
1400{
1401 memcpy(accs, _ref_accs, sizeof(double) * _njoints);
1402 return true;
1403}
1404
1406{
1407 velocityMoveRaw(j,0);
1408 return true;
1409}
1410
1412{
1413 bool ret = true;
1414 for(int j=0; j< _njoints; j++)
1415 {
1416 ret &= stopRaw(j);
1417 }
1418 return ret;
1419}
1421
1423// Position control2 interface //
1425
1426bool FakeMotionControl::positionMoveRaw(const int n_joint, const int *joints, const double *refs)
1427{
1428 if (verbose >= VERY_VERBOSE) {
1429 yCTrace(FAKEMOTIONCONTROL) << " -> n_joint " << n_joint;
1430 }
1431
1432 for(int j=0; j<n_joint; j++)
1433 {
1434 yCDebug(FAKEMOTIONCONTROL, "j: %d; ref %f;\n", joints[j], refs[j]); fflush(stdout);
1435 }
1436
1437 bool ret = true;
1438 for(int j=0; j<n_joint; j++)
1439 {
1440 ret = ret &&positionMoveRaw(joints[j], refs[j]);
1441 }
1442 return ret;
1443}
1444
1445bool FakeMotionControl::relativeMoveRaw(const int n_joint, const int *joints, const double *deltas)
1446{
1447 if (verbose >= VERY_VERBOSE) {
1448 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1449 }
1450
1451 bool ret = true;
1452 for(int j=0; j<n_joint; j++)
1453 {
1454 ret = ret &&relativeMoveRaw(joints[j], deltas[j]);
1455 }
1456 return ret;
1457}
1458
1460{
1461 if (verbose >= VERY_VERBOSE) {
1462 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1463 }
1464
1465 bool ret = true;
1466 bool val = true;
1467 bool tot_val = true;
1468
1469 for(int j=0; j<n_joint; j++)
1470 {
1471 ret = ret && checkMotionDoneRaw(joints[j], &val);
1472 tot_val &= val;
1473 }
1474 *flag = tot_val;
1475 return ret;
1476}
1477
1478bool FakeMotionControl::setRefSpeedsRaw(const int n_joint, const int *joints, const double *spds)
1479{
1480 if (verbose >= VERY_VERBOSE) {
1481 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1482 }
1483
1484 bool ret = true;
1485 for(int j=0; j<n_joint; j++)
1486 {
1487 ret = ret &&setRefSpeedRaw(joints[j], spds[j]);
1488 }
1489 return ret;
1490}
1491
1492bool FakeMotionControl::setRefAccelerationsRaw(const int n_joint, const int *joints, const double *accs)
1493{
1494 if (verbose >= VERY_VERBOSE) {
1495 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1496 }
1497
1498 bool ret = true;
1499 for(int j=0; j<n_joint; j++)
1500 {
1502 }
1503 return ret;
1504}
1505
1506bool FakeMotionControl::getRefSpeedsRaw(const int n_joint, const int *joints, double *spds)
1507{
1508 if (verbose >= VERY_VERBOSE) {
1509 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1510 }
1511
1512 bool ret = true;
1513 for(int j=0; j<n_joint; j++)
1514 {
1515 ret = ret && getRefSpeedRaw(joints[j], &spds[j]);
1516 }
1517 return ret;
1518}
1519
1521{
1522 if (verbose >= VERY_VERBOSE) {
1523 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1524 }
1525
1526 bool ret = true;
1527 for(int j=0; j<n_joint; j++)
1528 {
1529 ret = ret && getRefAccelerationRaw(joints[j], &accs[j]);
1530 }
1531 return ret;
1532}
1533
1534bool FakeMotionControl::stopRaw(const int n_joint, const int *joints)
1535{
1536 if (verbose >= VERY_VERBOSE) {
1537 yCTrace(FAKEMOTIONCONTROL) << "n_joint " << _njoints;
1538 }
1539
1540 bool ret = true;
1541 for(int j=0; j<n_joint; j++)
1542 {
1543 ret = ret &&stopRaw(joints[j]);
1544 }
1545 return ret;
1546}
1547
1549
1550// ControlMode
1551
1552// puo' essere richiesto con get
1554{
1555 if (verbose > VERY_VERY_VERBOSE) {
1556 yCTrace(FAKEMOTIONCONTROL) << "j: " << j;
1557 }
1558
1559 *v = _controlModes[j];
1560 return true;
1561}
1562
1563// IControl Mode 2
1565{
1566 bool ret = true;
1567 for(int j=0; j< _njoints; j++)
1568 {
1569 ret = ret && getControlModeRaw(j, &v[j]);
1570 }
1571 return ret;
1572}
1573
1575{
1576 bool ret = true;
1577 for(int j=0; j< n_joint; j++)
1578 {
1579 ret = ret && getControlModeRaw(joints[j], &modes[j]);
1580 }
1581 return ret;
1582}
1583
1585{
1586 if (verbose >= VERY_VERBOSE) {
1587 yCTrace(FAKEMOTIONCONTROL) << "j: " << j << " mode: " << yarp::os::Vocab32::decode(_mode);
1588 }
1589
1591 {
1592 _controlModes[j] = VOCAB_CM_IDLE;
1593 }
1594 else
1595 {
1596 _controlModes[j] = _mode;
1597 }
1598 _posCtrl_references[j] = pos[j];
1599 return true;
1600}
1601
1602
1604{
1605 if (verbose >= VERY_VERBOSE) {
1606 yCTrace(FAKEMOTIONCONTROL) << "n_joints: " << n_joint;
1607 }
1608
1609 bool ret = true;
1610 for(int i=0; i<n_joint; i++)
1611 {
1612 ret &= setControlModeRaw(joints[i], modes[i]);
1613 }
1614 return ret;
1615}
1616
1618{
1619 if (verbose >= VERY_VERBOSE) {
1621 }
1622
1623 bool ret = true;
1624 for(int i=0; i<_njoints; i++)
1625 {
1626 ret &= setControlModeRaw(i, modes[i]);
1627 }
1628 return ret;
1629}
1630
1631
1633
1635{
1636 return NOT_YET_IMPLEMENTED("setEncoder");
1637}
1638
1640{
1641 return NOT_YET_IMPLEMENTED("setEncoders");
1642}
1643
1645{
1646 return NOT_YET_IMPLEMENTED("resetEncoder");
1647}
1648
1650{
1651 return NOT_YET_IMPLEMENTED("resetEncoders");
1652}
1653
1654bool FakeMotionControl::getEncoderRaw(int j, double *value)
1655{
1656 bool ret = true;
1657
1658 // To simulate a real controlboard, we assume that the joint
1659 // encoders is exactly the last set by setPosition(s) or positionMove
1660 *value = pos[j];
1661
1662 return ret;
1663}
1664
1666{
1667 bool ret = true;
1668 for(int j=0; j< _njoints; j++)
1669 {
1670 bool ok = getEncoderRaw(j, &encs[j]);
1671 ret = ret && ok;
1672
1673 }
1674 return ret;
1675}
1676
1678{
1679 // To avoid returning uninitialized memory, we set the encoder speed to 0
1680 *sp = 0.0;
1681 return true;
1682}
1683
1685{
1686 bool ret = true;
1687 for(int j=0; j< _njoints; j++)
1688 {
1689 ret &= getEncoderSpeedRaw(j, &spds[j]);
1690 }
1691 return ret;
1692}
1693
1695{
1696 // To avoid returning uninitialized memory, we set the encoder acc to 0
1697 *acc = 0.0;
1698
1699 return true;
1700}
1701
1703{
1704 bool ret = true;
1705 for(int j=0; j< _njoints; j++)
1706 {
1708 }
1709 return ret;
1710}
1711
1713
1715{
1716 bool ret = getEncodersRaw(encs);
1717 _mutex.lock();
1718 for (int i = 0; i < _njoints; i++) {
1719 stamps[i] = _encodersStamp[i] = _cycleTimestamp;
1720 }
1721 _mutex.unlock();
1722 return ret;
1723}
1724
1725bool FakeMotionControl::getEncoderTimedRaw(int j, double *encs, double *stamp)
1726{
1727 bool ret = getEncoderRaw(j, encs);
1728 _mutex.lock();
1729 *stamp = _encodersStamp[j] = _cycleTimestamp;
1730 _mutex.unlock();
1731
1732 return ret;
1733}
1734
1736
1738{
1739 *num=_njoints;
1740 return true;
1741}
1742
1743bool FakeMotionControl::setMotorEncoderRaw(int m, const double val)
1744{
1745 return NOT_YET_IMPLEMENTED("setMotorEncoder");
1746}
1747
1749{
1750 return NOT_YET_IMPLEMENTED("setMotorEncoders");
1751}
1752
1754{
1755 return NOT_YET_IMPLEMENTED("setMotorEncoderCountsPerRevolutionRaw");
1756}
1757
1759{
1760 return NOT_YET_IMPLEMENTED("getMotorEncoderCountsPerRevolutionRaw");
1761}
1762
1764{
1765 return NOT_YET_IMPLEMENTED("resetMotorEncoder");
1766}
1767
1769{
1770 return NOT_YET_IMPLEMENTED("reseMotortEncoders");
1771}
1772
1774{
1775 *value = pos[m]*10;
1776 return true;
1777}
1778
1780{
1781 bool ret = true;
1782 for(int j=0; j< _njoints; j++)
1783 {
1784 ret &= getMotorEncoderRaw(j, &encs[j]);
1785
1786 }
1787 return ret;
1788}
1789
1791{
1792 *sp = 0.0;
1793 return true;
1794}
1795
1797{
1798 bool ret = true;
1799 for(int j=0; j< _njoints; j++)
1800 {
1801 ret &= getMotorEncoderSpeedRaw(j, &spds[j]);
1802 }
1803 return ret;
1804}
1805
1807{
1808 *acc = 0.0;
1809 return true;
1810}
1811
1813{
1814 bool ret = true;
1815 for(int j=0; j< _njoints; j++)
1816 {
1818 }
1819 return ret;
1820}
1821
1823{
1824 bool ret = getMotorEncodersRaw(encs);
1825 _mutex.lock();
1826 for (int i = 0; i < _njoints; i++) {
1827 stamps[i] = _encodersStamp[i] = _cycleTimestamp;
1828 }
1829 _mutex.unlock();
1830
1831 return ret;
1832}
1833
1834bool FakeMotionControl::getMotorEncoderTimedRaw(int m, double *encs, double *stamp)
1835{
1836 bool ret = getMotorEncoderRaw(m, encs);
1837 _mutex.lock();
1838 *stamp = _encodersStamp[m] = _cycleTimestamp;
1839 _mutex.unlock();
1840
1841 return ret;
1842}
1844
1846
1848{
1849 return DEPRECATED("enableAmpRaw");
1850}
1851
1853{
1854 return DEPRECATED("disableAmpRaw");
1855}
1856
1857bool FakeMotionControl::getCurrentRaw(int j, double *value)
1858{
1859 //just for testing purposes, this is not a real implementation
1860 *value = current[j];
1861 return true;
1862}
1863
1865{
1866 //just for testing purposes, this is not a real implementation
1867 bool ret = true;
1868 for(int j=0; j< _njoints; j++)
1869 {
1870 ret &= getCurrentRaw(j, &vals[j]);
1871 }
1872 return ret;
1873}
1874
1876{
1877 maxCurrent[m] = val;
1878 return true;
1879}
1880
1882{
1883 *val = maxCurrent[m];
1884 return true;
1885}
1886
1888{
1889 (_enabledAmp[j ]) ? *st = 1 : *st = 0;
1890 return true;
1891}
1892
1894{
1895 bool ret = true;
1896 for(int j=0; j<_njoints; j++)
1897 {
1898 sts[j] = _enabledAmp[j];
1899 }
1900 return ret;
1901}
1902
1904{
1905 *val = peakCurrent[m];
1906 return true;
1907}
1908
1909bool FakeMotionControl::setPeakCurrentRaw(int m, const double val)
1910{
1911 peakCurrent[m] = val;
1912 return true;
1913}
1914
1916{
1917 *val = nominalCurrent[m];
1918 return true;
1919}
1920
1922{
1923 nominalCurrent[m] = val;
1924 return true;
1925}
1926
1927bool FakeMotionControl::getPWMRaw(int m, double *val)
1928{
1929 *val = pwm[m];
1930 return true;
1931}
1932
1934{
1935 *val = pwmLimit[m];
1936 return true;
1937}
1938
1939bool FakeMotionControl::setPWMLimitRaw(int m, const double val)
1940{
1941 pwmLimit[m] = val;
1942 return true;
1943}
1944
1946{
1947 *val = supplyVoltage[m];
1948 return true;
1949}
1950
1951
1952// Limit interface
1953bool FakeMotionControl::setLimitsRaw(int j, double min, double max)
1954{
1955 bool ret = true;
1956 return ret;
1957}
1958
1959bool FakeMotionControl::getLimitsRaw(int j, double *min, double *max)
1960{
1961 *min = _limitsMin[j];
1962 *max = _limitsMax[j];
1963 return true;
1964}
1965
1967{
1968 return NOT_YET_IMPLEMENTED("getGearboxRatioRaw");
1969}
1970
1971bool FakeMotionControl::setGearboxRatioRaw(int m, const double val)
1972{
1973 return NOT_YET_IMPLEMENTED("setGearboxRatioRaw");
1974}
1975
1977{
1978 return NOT_YET_IMPLEMENTED("getTorqueControlFilterType");
1979}
1980
1982{
1983 return NOT_YET_IMPLEMENTED("getRotorEncoderResolutionRaw");
1984}
1985
1987{
1988 return NOT_YET_IMPLEMENTED("getJointEncoderResolutionRaw");
1989}
1990
1992{
1993 return NOT_YET_IMPLEMENTED("getJointEncoderTypeRaw");
1994}
1995
1997{
1998 return NOT_YET_IMPLEMENTED("getRotorEncoderTypeRaw");
1999}
2000
2002{
2003 return NOT_YET_IMPLEMENTED("getKinematicMJRaw");
2004}
2005
2007{
2008 return NOT_YET_IMPLEMENTED("getHasTempSensorsRaw");
2009}
2010
2012{
2013 return NOT_YET_IMPLEMENTED("getHasHallSensorRaw");
2014}
2015
2017{
2018 return NOT_YET_IMPLEMENTED("getHasRotorEncoderRaw");
2019}
2020
2022{
2023 return NOT_YET_IMPLEMENTED("getHasRotorEncoderIndexRaw");
2024}
2025
2027{
2028 return NOT_YET_IMPLEMENTED("getMotorPolesRaw");
2029}
2030
2032{
2033 return NOT_YET_IMPLEMENTED("getRotorIndexOffsetRaw");
2034}
2035
2036bool FakeMotionControl::getAxisNameRaw(int axis, std::string& name)
2037{
2038 if (axis >= 0 && axis < _njoints)
2039 {
2040 name = _axisName[axis];
2041 return true;
2042 }
2043 else
2044 {
2045 name = "ERROR";
2046 return false;
2047 }
2048}
2049
2051{
2052 if (axis >= 0 && axis < _njoints)
2053 {
2054 type = _jointType[axis];
2055 return true;
2056 }
2057 else
2058 {
2059 return false;
2060 }
2061}
2062
2063// IControlLimits
2064bool FakeMotionControl::setVelLimitsRaw(int axis, double min, double max)
2065{
2066 return NOT_YET_IMPLEMENTED("setVelLimitsRaw");
2067}
2068
2069bool FakeMotionControl::getVelLimitsRaw(int axis, double *min, double *max)
2070{
2071 *min = 0.0;
2072 *max = _maxJntCmdVelocity[axis];
2073 return true;
2074}
2075
2076
2077// Torque control
2079{
2080 *t = _torques[j];
2081 return true;
2082}
2083
2085{
2086 for (int i = 0; i < _njoints; i++)
2087 {
2088 t[i]= _torques[i];
2089 }
2090 return true;
2091}
2092
2093bool FakeMotionControl::getTorqueRangeRaw(int j, double *min, double *max)
2094{
2095 *min = -100;
2096 *max = 100;
2097 return true;
2098}
2099
2100bool FakeMotionControl::getTorqueRangesRaw(double *min, double *max)
2101{
2102 bool ret = true;
2103 for (int j = 0; j < _njoints && ret; j++) {
2104 ret &= getTorqueRangeRaw(j, &min[j], &max[j]);
2105 }
2106 return ret;
2107}
2108
2110{
2111 bool ret = true;
2112 for (int j = 0; j < _njoints && ret; j++) {
2113 ret &= setRefTorqueRaw(j, t[j]);
2114 }
2115 return ret;
2116}
2117
2119{
2120 _mutex.lock();
2121 _ref_torques[j]=t;
2122
2123 if (t>1.0 || t< -1.0)
2124 {
2125 yCError(FAKEMOTIONCONTROL) << "Joint received a high torque command, and was put in hardware fault";
2126 _hwfault_code[j] = 1;
2127 _hwfault_message[j] = "test" + std::to_string(j) + " torque";
2128 _controlModes[j] = VOCAB_CM_HW_FAULT;
2129 }
2130 _mutex.unlock();
2131 return true;
2132}
2133
2134bool FakeMotionControl::setRefTorquesRaw(const int n_joint, const int *joints, const double *t)
2135{
2136 return NOT_YET_IMPLEMENTED("setRefTorquesRaw");
2137}
2138
2140{
2141 bool ret = true;
2142 for (int j = 0; j < _njoints && ret; j++) {
2143 ret &= getRefTorqueRaw(j, &_ref_torques[j]);
2144 }
2145 return true;
2146}
2147
2149{
2150 _mutex.lock();
2151 *t = _ref_torques[j];
2152 _mutex.unlock();
2153 return true;
2154}
2155
2156bool FakeMotionControl::getImpedanceRaw(int j, double *stiffness, double *damping)
2157{
2158 return NOT_YET_IMPLEMENTED("getImpedanceRaw");
2159}
2160
2161bool FakeMotionControl::setImpedanceRaw(int j, double stiffness, double damping)
2162{
2163 return NOT_YET_IMPLEMENTED("setImpedanceRaw");
2164}
2165
2167{
2168 return NOT_YET_IMPLEMENTED("setImpedanceOffsetRaw");
2169}
2170
2172{
2173 return NOT_YET_IMPLEMENTED("getImpedanceOffsetRaw");
2174}
2175
2176bool FakeMotionControl::getCurrentImpedanceLimitRaw(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)
2177{
2178 return NOT_YET_IMPLEMENTED("getCurrentImpedanceLimitRaw");
2179}
2180
2182{
2183 params->bemf = _kbemf[j];
2184 params->bemf_scale = _kbemf_scale[j];
2185 params->ktau = _ktau[j];
2186 params->ktau_scale = _ktau_scale[j];
2187 params->viscousPos = _viscousPos[j];
2188 params->viscousNeg = _viscousNeg[j];
2189 params->coulombPos = _coulombPos[j];
2190 params->coulombNeg = _coulombNeg[j];
2191 params->velocityThres = _velocityThres[j];
2192 yCDebug(FAKEMOTIONCONTROL) << "getMotorTorqueParamsRaw" << params->bemf
2193 << params->bemf_scale
2194 << params->ktau
2195 << params->ktau_scale
2196 << params->viscousPos
2197 << params->viscousNeg
2198 << params->coulombPos
2199 << params->coulombNeg
2200 << params->velocityThres;
2201 return true;
2202}
2203
2205{
2206 _kbemf[j] = params.bemf;
2207 _ktau[j] = params.ktau;
2208 _kbemf_scale[j] = params.bemf_scale;
2209 _ktau_scale[j] = params.ktau_scale;
2210 _viscousPos[j] = params.viscousPos;
2211 _viscousNeg[j] = params.viscousNeg;
2212 _coulombPos[j] = params.coulombPos;
2213 _coulombNeg[j] = params.coulombNeg;
2214 _velocityThres[j] = params.velocityThres;
2215 yCDebug(FAKEMOTIONCONTROL) << "setMotorTorqueParamsRaw" << params.bemf
2216 << params.bemf_scale
2217 << params.ktau
2218 << params.ktau_scale
2219 << params.viscousPos
2220 << params.viscousNeg
2221 << params.coulombPos
2222 << params.coulombNeg
2223 << params.velocityThres;
2224 return true;
2225}
2226
2227// IVelocityControl interface
2228bool FakeMotionControl::velocityMoveRaw(const int n_joint, const int *joints, const double *spds)
2229{
2230 bool ret = true;
2231 for(int i=0; i<n_joint; i++)
2232 {
2233 ret &= velocityMoveRaw(joints[i], spds[i]);
2234 }
2235 return ret;
2236}
2237
2238// PositionDirect Interface
2240{
2241 _posDir_references[j] = ref;
2242 return true;
2243}
2244
2245bool FakeMotionControl::setPositionsRaw(const int n_joint, const int *joints, const double *refs)
2246{
2247 for(int i=0; i< n_joint; i++)
2248 {
2249 _posDir_references[joints[i]] = refs[i];
2250 }
2251 return true;
2252}
2253
2255{
2256 for(int i=0; i< _njoints; i++)
2257 {
2258 _posDir_references[i] = refs[i];
2259 }
2260 return true;
2261}
2262
2263
2265{
2266 if (verbose >= VERY_VERBOSE) {
2267 yCTrace(FAKEMOTIONCONTROL) << "j " << axis << " ref " << _posCtrl_references[axis];
2268 }
2269
2270 int mode = 0;
2272 if( (mode != VOCAB_CM_POSITION) &&
2273 (mode != VOCAB_CM_MIXED) &&
2275 {
2276 yCWarning(FAKEMOTIONCONTROL) << "getTargetPosition: Joint " << axis << " is not in POSITION mode, therefore the value returned by " <<
2277 "this call is for reference only and may not reflect the actual behaviour of the motor/firmware.";
2278 }
2279 *ref = _posCtrl_references[axis];
2280 return true;
2281}
2282
2284{
2285 bool ret = true;
2286 for (int i = 0; i < _njoints; i++) {
2287 ret &= getTargetPositionRaw(i, &refs[i]);
2288 }
2289 return ret;
2290}
2291
2292bool FakeMotionControl::getTargetPositionsRaw(int nj, const int * jnts, double *refs)
2293{
2294 bool ret = true;
2295 for (int i = 0; i<nj; i++)
2296 {
2297 ret &= getTargetPositionRaw(jnts[i], &refs[i]);
2298 }
2299 return ret;
2300}
2301
2303{
2304 *ref = _command_speeds[axis];
2305 return true;
2306}
2307
2309{
2310 bool ret = true;
2311 for (int i = 0; i<_njoints; i++)
2312 {
2313 ret &= getRefVelocityRaw(i, &refs[i]);
2314 }
2315 return ret;
2316}
2317
2318bool FakeMotionControl::getRefVelocitiesRaw(int nj, const int * jnts, double *refs)
2319{
2320 bool ret = true;
2321 for (int i = 0; i<nj; i++)
2322 {
2323 ret &= getRefVelocityRaw(jnts[i], &refs[i]);
2324 }
2325 return ret;
2326}
2327
2329{
2330 int mode = 0;
2332 if( (mode != VOCAB_CM_POSITION) &&
2333 (mode != VOCAB_CM_MIXED) &&
2336 {
2337 yCWarning(FAKEMOTIONCONTROL) << "getRefPosition: Joint " << axis << " is not in POSITION_DIRECT mode, therefore the value returned by \
2338 this call is for reference only and may not reflect the actual behaviour of the motor/firmware.";
2339 }
2340
2341 *ref = _posDir_references[axis];
2342
2343 return true;
2344}
2345
2347{
2348 bool ret = true;
2349 for (int i = 0; i<_njoints; i++)
2350 {
2351 ret &= getRefPositionRaw(i, &refs[i]);
2352 }
2353 return ret;
2354}
2355
2356bool FakeMotionControl::getRefPositionsRaw(int nj, const int * jnts, double *refs)
2357{
2358 bool ret = true;
2359 for (int i = 0; i<nj; i++)
2360 {
2361 ret &= getRefPositionRaw(jnts[i], &refs[i]);
2362 }
2363 return ret;
2364}
2365
2366
2367// InteractionMode
2369{
2370 if (verbose > VERY_VERY_VERBOSE) {
2371 yCTrace(FAKEMOTIONCONTROL) << "j: " << j;
2372 }
2373
2374 *_mode = (yarp::dev::InteractionModeEnum)_interactMode[j];
2375 return true;}
2376
2378{
2379 bool ret = true;
2380 for(int j=0; j< n_joints; j++)
2381 {
2383 }
2384 return ret;
2385
2386}
2387
2389{
2390 bool ret = true;
2391 for (int j = 0; j < _njoints; j++) {
2392 ret = ret && getInteractionModeRaw(j, &modes[j]);
2393 }
2394 return ret;
2395}
2396
2397// marco.accame: con alberto cardellino abbiamo parlato della correttezza di effettuare la verifica di quanto imposto (in setInteractionModeRaw() ed affini)
2398// andando a rileggere il valore nella scheda eth fino a che esso non sia quello atteso. si deve fare oppure no?
2399// con il interaction mode il can ora non lo fa. mentre lo fa per il control mode. perche' diverso?
2401{
2402 if (verbose >= VERY_VERBOSE) {
2403 yCTrace(FAKEMOTIONCONTROL) << "j: " << j << " interaction mode: " << yarp::os::Vocab32::decode(_mode);
2404 }
2405
2406 _interactMode[j] = _mode;
2407
2408 return true;
2409}
2410
2411
2413{
2414 bool ret = true;
2415 for(int i=0; i<n_joints; i++)
2416 {
2418 }
2419 return ret;
2420}
2421
2423{
2424 bool ret = true;
2425 for(int i=0; i<_njoints; i++)
2426 {
2428 }
2429 return ret;
2430
2431}
2432
2434{
2435 *num=_njoints;
2436 return true;
2437}
2438
2440{
2441 *val = 37.5+double(m);
2442 return true;
2443}
2444
2446{
2447 bool ret = true;
2448 for(int j=0; j< _njoints; j++)
2449 {
2450 ret &= getTemperatureRaw(j, &vals[j]);
2451 }
2452 return ret;
2453}
2454
2456{
2457 return NOT_YET_IMPLEMENTED("getTemperatureLimitRaw");
2458}
2459
2461{
2462 return NOT_YET_IMPLEMENTED("setTemperatureLimitRaw");
2463}
2464
2465//PWM interface
2467{
2468 refpwm[j] = v;
2469 pwm[j] = v;
2470 last_pwm_command[j]=yarp::os::Time::now();
2471 return true;
2472}
2473
2475{
2476 for (int i = 0; i < _njoints; i++)
2477 {
2478 setRefDutyCycleRaw(i,v[i]);
2479 }
2480 return true;
2481}
2482
2484{
2485 *v = refpwm[j];
2486 return true;
2487}
2488
2490{
2491 for (int i = 0; i < _njoints; i++)
2492 {
2493 v[i] = refpwm[i];
2494 }
2495 return true;
2496}
2497
2499{
2500 *v = pwm[j];
2501 return true;
2502}
2503
2505{
2506 for (int i = 0; i < _njoints; i++)
2507 {
2508 v[i] = pwm[i];
2509 }
2510 return true;
2511}
2512
2513// Current interface
2514/*bool FakeMotionControl::getCurrentRaw(int j, double *t)
2515{
2516 return NOT_YET_IMPLEMENTED("getCurrentRaw");
2517}
2518
2519bool FakeMotionControl::getCurrentsRaw(double *t)
2520{
2521 return NOT_YET_IMPLEMENTED("getCurrentsRaw");
2522}
2523*/
2524
2525bool FakeMotionControl::getCurrentRangeRaw(int j, double *min, double *max)
2526{
2527 //just for testing purposes, this is not a real implementation
2528 *min = -3.5;
2529 *max = +3.5;
2530 return true;
2531}
2532
2533bool FakeMotionControl::getCurrentRangesRaw(double *min, double *max)
2534{
2535 //just for testing purposes, this is not a real implementation
2536 for (int i = 0; i < _njoints; i++)
2537 {
2538 min[i] = -3.5;
2539 max[i] = +3.5;
2540 }
2541 return true;
2542}
2543
2545{
2546 for (int i = 0; i < _njoints; i++)
2547 {
2548 _ref_currents[i] = t[i];
2549 current[i] = t[i] / 2;
2550 }
2551 return true;
2552}
2553
2555{
2556 _ref_currents[j] = t;
2557 current[j] = t / 2;
2558 return true;
2559}
2560
2561bool FakeMotionControl::setRefCurrentsRaw(const int n_joint, const int *joints, const double *t)
2562{
2563 bool ret = true;
2564 for (int j = 0; j<n_joint; j++)
2565 {
2566 ret = ret &&setRefCurrentRaw(joints[j], t[j]);
2567 }
2568 return ret;
2569}
2570
2572{
2573 for (int i = 0; i < _njoints; i++)
2574 {
2575 t[i] = _ref_currents[i];
2576 }
2577 return true;
2578}
2579
2581{
2582 *t = _ref_currents[j];
2583 return true;
2584}
2585
2590
2592{
2593 return _njoints;
2594}
2595
2597{
2598 for (int i = 0; i < _njoints; i++)
2599 {
2600 measure[i] = _torques[i];
2601 }
2602 return true;
2603}
2604
2606{
2607 _torques[ch] = measure;
2608 return true;
2609}
2610
2611bool FakeMotionControl::getLastJointFaultRaw(int j, int& fault, std::string& message)
2612{
2613 _mutex.lock();
2614 fault = _hwfault_code[j];
2615 message = _hwfault_message[j];
2616 _mutex.unlock();
2617 return true;
2618}
2619
2621{
2622 braked = _braked[j];
2623 return ReturnValue_ok;
2624}
2625
2627{
2628 _braked[j] = active;
2629 return ReturnValue_ok;
2630}
2631
2633{
2634 _autobraked[j] = enabled;
2635 return ReturnValue_ok;
2636}
2637
2639{
2640 enabled = _autobraked[j];
2641 return ReturnValue_ok;
2642}
2643
2645{
2646 axes = _njoints;
2647 return ReturnValue_ok;
2648}
2649
2651{
2653 if (jnt < 0 || jnt >= _njoints) {
2654 yCError(FAKEMOTIONCONTROL) << "setDesiredVelocityRaw: joint index out of bounds";
2655 return ReturnValue::return_code::return_value_error_method_failed;
2656 }
2657 if (vel < -_maxJntCmdVelocity[jnt] || vel > _maxJntCmdVelocity[jnt]) {
2658 yCError(FAKEMOTIONCONTROL) << "setDesiredVelocityRaw: velocity out of bounds for joint" << jnt;
2659 return ReturnValue::return_code::return_value_error_method_failed;
2660 }
2661 _mutex.lock();
2662 _dir_vel_commands[jnt] = vel;
2663 _mutex.unlock();
2664 return ReturnValue_ok;
2665}
2666
2668{
2671 for (int i = 0; i < _njoints; i++) {
2672 ret &= setDesiredVelocityRaw(i, vels[i]);
2673 }
2674 return ret;
2675}
2676
2677ReturnValue FakeMotionControl::setDesiredVelocityRaw(const std::vector<int>& jnts, const std::vector<double>& vels)
2678{
2680 if (jnts.size() != vels.size()) {
2681 yCError(FAKEMOTIONCONTROL) << "setDesiredVelocityRaw: jnts and vels vectors must have the same size";
2682 return ReturnValue::return_code::return_value_error_method_failed;
2683 }
2685 for (int i = 0; i < _njoints; i++) {
2687 }
2688 return ret;
2689}
2690
2692{
2694 if (jnt < 0 || jnt >= _njoints) {
2695 yCError(FAKEMOTIONCONTROL) << "setDesiredVelocityRaw: joint index out of bounds";
2696 return ReturnValue::return_code::return_value_error_method_failed;
2697 }
2698 _mutex.lock();
2699 vel = _dir_vel_commands[jnt];
2700 _mutex.unlock();
2701 return ReturnValue_ok;
2702}
2703
2705{
2708 vels.resize(_njoints);
2709 for (int i = 0; i < _njoints; i++) {
2710 ret &= getDesiredVelocityRaw(i, vels[i]);
2711 }
2712 return ret;
2713}
2714
2715ReturnValue FakeMotionControl::getDesiredVelocityRaw(const std::vector<int>& jnts, std::vector<double>& vels)
2716{
2718 if (jnts.size() != vels.size()) {
2719 yCError(FAKEMOTIONCONTROL) << "getDesiredVelocityRaw: jnts and vels vectors must have the same size";
2720 return ReturnValue::return_code::return_value_error_method_failed;
2721 }
2723 vels.resize(_njoints);
2724 for (int i = 0; i < _njoints; i++) {
2726 }
2727 return ret;
2728}
2729
2730/*
2731bool FakeMotionControl::parseImpedanceGroup_NewFormat(Bottle& pidsGroup, ImpedanceParameters vals[])
2732{
2733 int j=0;
2734 Bottle xtmp;
2735
2736 if (!extractGroup(pidsGroup, xtmp, "stiffness", "stiffness parameter", _njoints)) {
2737 return false;
2738 }
2739 for (j=0; j<_njoints; j++) {
2740 vals[j].stiffness = xtmp.get(j+1).asFloat64();
2741 }
2742
2743 if (!extractGroup(pidsGroup, xtmp, "damping", "damping parameter", _njoints)) {
2744 return false;
2745 }
2746 for (j=0; j<_njoints; j++) {
2747 vals[j].damping = xtmp.get(j+1).asFloat64();
2748 }
2749
2750 return true;
2751}
2752*/
2753
2754/*
2755bool FakeMotionControl::parsePositionPidsGroup(Bottle& pidsGroup, Pid myPid[])
2756{
2757 int j=0;
2758 Bottle xtmp;
2759
2760 if (!extractGroup(pidsGroup, xtmp, "kp", "Pid kp parameter", _njoints)) {
2761 return false;
2762 }
2763 for (j=0; j<_njoints; j++) {
2764 myPid[j].kp = xtmp.get(j+1).asFloat64();
2765 }
2766
2767 if (!extractGroup(pidsGroup, xtmp, "kd", "Pid kd parameter", _njoints)) {
2768 return false;
2769 }
2770 for (j=0; j<_njoints; j++) {
2771 myPid[j].kd = xtmp.get(j+1).asFloat64();
2772 }
2773
2774 if (!extractGroup(pidsGroup, xtmp, "ki", "Pid kp parameter", _njoints)) {
2775 return false;
2776 }
2777 for (j=0; j<_njoints; j++) {
2778 myPid[j].ki = xtmp.get(j+1).asFloat64();
2779 }
2780
2781 if (!extractGroup(pidsGroup, xtmp, "maxInt", "Pid maxInt parameter", _njoints)) {
2782 return false;
2783 }
2784 for (j=0; j<_njoints; j++) {
2785 myPid[j].max_int = xtmp.get(j+1).asFloat64();
2786 }
2787
2788 if (!extractGroup(pidsGroup, xtmp, "maxPwm", "Pid maxPwm parameter", _njoints)) {
2789 return false;
2790 }
2791 for (j=0; j<_njoints; j++) {
2792 myPid[j].max_output = xtmp.get(j+1).asFloat64();
2793 }
2794
2795 if (!extractGroup(pidsGroup, xtmp, "shift", "Pid shift parameter", _njoints)) {
2796 return false;
2797 }
2798 for (j=0; j<_njoints; j++) {
2799 myPid[j].scale = xtmp.get(j+1).asFloat64();
2800 }
2801
2802 if (!extractGroup(pidsGroup, xtmp, "ko", "Pid ko parameter", _njoints)) {
2803 return false;
2804 }
2805 for (j=0; j<_njoints; j++) {
2806 myPid[j].offset = xtmp.get(j+1).asFloat64();
2807 }
2808
2809 if (!extractGroup(pidsGroup, xtmp, "stictionUp", "Pid stictionUp", _njoints)) {
2810 return false;
2811 }
2812 for (j=0; j<_njoints; j++) {
2813 myPid[j].stiction_up_val = xtmp.get(j+1).asFloat64();
2814 }
2815
2816 if (!extractGroup(pidsGroup, xtmp, "stictionDwn", "Pid stictionDwn", _njoints)) {
2817 return false;
2818 }
2819 for (j=0; j<_njoints; j++) {
2820 myPid[j].stiction_down_val = xtmp.get(j+1).asFloat64();
2821 }
2822
2823 if (!extractGroup(pidsGroup, xtmp, "kff", "Pid kff parameter", _njoints)) {
2824 return false;
2825 }
2826 for (j=0; j<_njoints; j++) {
2827 myPid[j].kff = xtmp.get(j+1).asFloat64();
2828 }
2829
2830 //conversion from metric to machine units (if applicable)
2831 if (_positionControlUnits==P_METRIC_UNITS)
2832 {
2833 for (j=0; j<_njoints; j++)
2834 {
2835 myPid[j].kp = myPid[j].kp / _angleToEncoder[j]; //[PWM/deg]
2836 myPid[j].ki = myPid[j].ki / _angleToEncoder[j]; //[PWM/deg]
2837 myPid[j].kd = myPid[j].kd / _angleToEncoder[j]; //[PWM/deg]
2838 }
2839 }
2840 else
2841 {
2842 //do nothing
2843 }
2844
2845 //optional PWM limit
2846 if(_pwmIsLimited)
2847 { // check for value in the file
2848 if (!extractGroup(pidsGroup, xtmp, "limPwm", "Limited PWD", _njoints))
2849 {
2850 yCError(FAKEMOTIONCONTROL) << "The PID parameter limPwm was requested but was not correctly set in the configuration file, please fill it.";
2851 return false;
2852 }
2853
2854 yCInfo(FAKEMOTIONCONTROL) << "Using LIMITED PWM!!";
2855 for (j = 0; j < _njoints; j++) {
2856 myPid[j].max_output = xtmp.get(j + 1).asFloat64();
2857 }
2858 }
2859
2860 return true;
2861}
2862*/
2863
2864/*
2865bool FakeMotionControl::parseTorquePidsGroup(Bottle& pidsGroup, Pid myPid[], double kbemf[], double ktau[], int filterType[], double viscousPos[], double viscousNeg[], double coulombPos[], double coulombNeg[], double velocityThres[])
2866{
2867 int j=0;
2868 Bottle xtmp;
2869 if (!extractGroup(pidsGroup, xtmp, "kp", "Pid kp parameter", _njoints)) {
2870 return false;
2871 }
2872 for (j=0; j<_njoints; j++) {
2873 myPid[j].kp = xtmp.get(j+1).asFloat64();
2874 }
2875
2876 if (!extractGroup(pidsGroup, xtmp, "kd", "Pid kd parameter", _njoints)) {
2877 return false;
2878 }
2879 for (j=0; j<_njoints; j++) {
2880 myPid[j].kd = xtmp.get(j+1).asFloat64();
2881 }
2882
2883 if (!extractGroup(pidsGroup, xtmp, "ki", "Pid kp parameter", _njoints)) {
2884 return false;
2885 }
2886 for (j=0; j<_njoints; j++) {
2887 myPid[j].ki = xtmp.get(j+1).asFloat64();
2888 }
2889
2890 if (!extractGroup(pidsGroup, xtmp, "maxInt", "Pid maxInt parameter", _njoints)) {
2891 return false;
2892 }
2893 for (j=0; j<_njoints; j++) {
2894 myPid[j].max_int = xtmp.get(j+1).asFloat64();
2895 }
2896
2897 if (!extractGroup(pidsGroup, xtmp, "maxPwm", "Pid maxPwm parameter", _njoints)) {
2898 return false;
2899 }
2900 for (j=0; j<_njoints; j++) {
2901 myPid[j].max_output = xtmp.get(j+1).asFloat64();
2902 }
2903
2904 if (!extractGroup(pidsGroup, xtmp, "shift", "Pid shift parameter", _njoints)) {
2905 return false;
2906 }
2907 for (j=0; j<_njoints; j++) {
2908 myPid[j].scale = xtmp.get(j+1).asFloat64();
2909 }
2910
2911 if (!extractGroup(pidsGroup, xtmp, "ko", "Pid ko parameter", _njoints)) {
2912 return false;
2913 }
2914 for (j=0; j<_njoints; j++) {
2915 myPid[j].offset = xtmp.get(j+1).asFloat64();
2916 }
2917
2918 if (!extractGroup(pidsGroup, xtmp, "stictionUp", "Pid stictionUp", _njoints)) {
2919 return false;
2920 }
2921 for (j=0; j<_njoints; j++) {
2922 myPid[j].stiction_up_val = xtmp.get(j+1).asFloat64();
2923 }
2924
2925 if (!extractGroup(pidsGroup, xtmp, "stictionDwn", "Pid stictionDwn", _njoints)) {
2926 return false;
2927 }
2928 for (j=0; j<_njoints; j++) {
2929 myPid[j].stiction_down_val = xtmp.get(j+1).asFloat64();
2930 }
2931
2932 if (!extractGroup(pidsGroup, xtmp, "kff", "Pid kff parameter", _njoints)) {
2933 return false;
2934 }
2935 for (j=0; j<_njoints; j++) {
2936 myPid[j].kff = xtmp.get(j+1).asFloat64();
2937 }
2938
2939 if (!extractGroup(pidsGroup, xtmp, "kbemf", "kbemf parameter", _njoints)) {
2940 return false;
2941 }
2942 for (j=0; j<_njoints; j++) {
2943 kbemf[j] = xtmp.get(j+1).asFloat64();
2944 }
2945
2946 if (!extractGroup(pidsGroup, xtmp, "ktau", "ktau parameter", _njoints)) {
2947 return false;
2948 }
2949 for (j=0; j<_njoints; j++) {
2950 ktau[j] = xtmp.get(j+1).asFloat64();
2951 }
2952
2953 if (!extractGroup(pidsGroup, xtmp, "filterType", "filterType param", _njoints)) {
2954 return false;
2955 }
2956 for (j=0; j<_njoints; j++) {
2957 filterType[j] = xtmp.get(j+1).asInt32();
2958 }
2959
2960 if (!extractGroup(pidsGroup, xtmp, "viscousPos", "viscous pos parameter", _njoints)) {
2961 return false;
2962 }
2963 for (j=0; j<_njoints; j++) {
2964 viscousPos[j] = xtmp.get(j+1).asFloat64();
2965 }
2966
2967 if (!extractGroup(pidsGroup, xtmp, "viscousNeg", "viscous neg parameter", _njoints)) {
2968 return false;
2969 }
2970 for (j=0; j<_njoints; j++) {
2971 viscousNeg[j] = xtmp.get(j+1).asFloat64();
2972 }
2973
2974 if (!extractGroup(pidsGroup, xtmp, "coulombPos", "coulomb pos parameter", _njoints)) {
2975 return false;
2976 }
2977 for (j=0; j<_njoints; j++) {
2978 coulombPos[j] = xtmp.get(j+1).asFloat64();
2979 }
2980
2981 if (!extractGroup(pidsGroup, xtmp, "coulombNeg", "coulomb neg parameter", _njoints)) {
2982 return false;
2983 }
2984 for (j=0; j<_njoints; j++) {
2985 coulombNeg[j] = xtmp.get(j+1).asFloat64();
2986 }
2987
2988 if (!extractGroup(pidsGroup, xtmp, "velocityThres", "velocity threshold parameter", _njoints)) {
2989 return false;
2990 }
2991 for (j=0; j<_njoints; j++) {
2992 velocityThres[j] = xtmp.get(j+1).asFloat64();
2993 }
2994
2995
2996 //conversion from metric to machine units (if applicable)
2997// for (j=0; j<_njoints; j++)
2998// {
2999// myPid[j].kp = myPid[j].kp / _torqueControlHelper->getNewtonsToSensor(j); //[PWM/Nm]
3000// myPid[j].ki = myPid[j].ki / _torqueControlHelper->getNewtonsToSensor(j); //[PWM/Nm]
3001// myPid[j].kd = myPid[j].kd / _torqueControlHelper->getNewtonsToSensor(j); //[PWM/Nm]
3002// myPid[j].stiction_up_val = myPid[j].stiction_up_val * _torqueControlHelper->getNewtonsToSensor(j); //[Nm]
3003// myPid[j].stiction_down_val = myPid[j].stiction_down_val * _torqueControlHelper->getNewtonsToSensor(j); //[Nm]
3004// }
3005
3006 //optional PWM limit
3007 if(_pwmIsLimited)
3008 { // check for value in the file
3009 if (!extractGroup(pidsGroup, xtmp, "limPwm", "Limited PWM", _njoints))
3010 {
3011 yCError(FAKEMOTIONCONTROL) << "The PID parameter limPwm was requested but was not correctly set in the configuration file, please fill it.";
3012 return false;
3013 }
3014
3015 yCInfo(FAKEMOTIONCONTROL) << "Using LIMITED PWM!!";
3016 for (j = 0; j < _njoints; j++) {
3017 myPid[j].max_output = xtmp.get(j + 1).asFloat64();
3018 }
3019 }
3020
3021 return true;
3022}
3023*/
3024
3025// eof
void checkAndDestroy(T *&p)
bool NOT_YET_IMPLEMENTED(const char *txt)
FeatureMode mode
#define OPENLOOP_WATCHDOG
std::string toString(const T &value)
convert an arbitrary type to string.
#define PWM_CONSTANT
static bool NOT_YET_IMPLEMENTED(const char *txt)
static bool DEPRECATED(const char *txt)
#define VELOCITY_WATCHDOG
constexpr yarp::conf::vocab32_t VOCAB_CM_MIXED
constexpr yarp::conf::vocab32_t VOCAB_CM_TORQUE
constexpr yarp::conf::vocab32_t VOCAB_CM_PWM
constexpr yarp::conf::vocab32_t VOCAB_CM_HW_FAULT
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_VEL
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
constexpr yarp::conf::vocab32_t VOCAB_CM_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_CM_IMPEDANCE_POS
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY
constexpr yarp::conf::vocab32_t VOCAB_CM_FORCE_IDLE
bool ret
#define yDebug(...)
Definition Log.h:275
#define ReturnValue_ok
Definition ReturnValue.h:80
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool getPowerSupplyVoltageRaw(int j, double *val) override
bool getRefSpeedRaw(int j, double *ref) override
Get reference speed for a joint.
virtual bool getHasTempSensorsRaw(int j, int &ret)
bool setRefCurrentsRaw(const double *t) override
Set the reference value of the currents for all motors.
bool setRefTorqueRaw(int j, double t) override
Set the reference value of the torque for a given joint.
bool getCurrentsRaw(double *vals) override
bool getImpedanceOffsetRaw(int j, double *offset) override
Get current force Offset for a specific joint.
bool getTargetPositionRaw(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool getTorqueRangeRaw(int j, double *min, double *max) override
Get the full scale of the torque sensor of a given joint.
bool getCurrentImpedanceLimitRaw(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp) override
Get the current impedandance limits for a specific joint.
bool setTemperatureLimitRaw(int m, const double temp) override
Set the temperature limit for a specific motor.
bool getPidErrorRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *err) override
Get the current error for a joint.
bool setPeakCurrentRaw(int m, const double val) override
bool velocityMoveRaw(int j, double sp) override
Start motion at a given speed, single joint.
yarp::dev::ReturnValue setAutoBrakeEnabledRaw(int j, bool enabled) override
bool checkMotionDoneRaw(bool *flag) override
Check if the current trajectory is terminated.
bool getMotorEncoderSpeedRaw(int m, double *sp) override
Read the istantaneous speed of a motor encoder.
virtual bool getJointEncoderTypeRaw(int j, int &type)
bool setRefDutyCycleRaw(int j, double v) override
Sets the reference dutycycle of a single motor.
bool getTemperatureRaw(int m, double *val) override
Get temperature of a motor.
bool getEncoderAccelerationRaw(int j, double *spds) override
Read the instantaneous acceleration of an axis.
bool getRefAccelerationRaw(int j, double *acc) override
Get reference acceleration for a joint.
bool getMotorEncoderSpeedsRaw(double *spds) override
Read the instantaneous speed of all motor encoders.
bool setPidsRaw(const yarp::dev::PidControlTypeEnum &pidtype, const yarp::dev::Pid *pids) override
Set new pid value on multiple axes.
bool setVelLimitsRaw(int axis, double min, double max) override
Set the software speed limits for a particular axis, the behavior of the control card when these limi...
bool getJointTypeRaw(int axis, yarp::dev::JointTypeEnum &type) override
bool setMotorEncoderRaw(int m, const double val) override
Set the value of the motor encoder for a given motor.
bool getPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *limit) override
Get the error limit for the controller on a specific joint.
bool getPidOutputRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *out) override
Get the output of the controller (e.g.
bool setControlModeRaw(const int j, const int mode) override
bool getMotorEncoderAccelerationRaw(int m, double *spds) override
Read the instantaneous acceleration of a motor encoder.
bool open(yarp::os::Searchable &par) override
Open the DeviceDriver.
virtual bool getHasHallSensorRaw(int j, int &ret)
bool getTemperatureLimitRaw(int m, double *temp) override
Retreives the current temperature limit for a specific motor.
bool getNumberOfMotorsRaw(int *num) override
Get the number of available motors.
bool disableAmpRaw(int j) override
Disable the amplifier on a specific joint.
bool setMotorTorqueParamsRaw(int j, const yarp::dev::MotorTorqueParameters params) override
Set the motor parameters.
bool calibrateAxisWithParamsRaw(int axis, unsigned int type, double p1, double p2, double p3) override
Start calibration, this method is very often platform specific.
bool setRefAccelerationRaw(int j, double acc) override
Set reference acceleration for a joint.
virtual bool initialised()
bool setGearboxRatioRaw(int m, const double val) override
Set the gearbox ratio for a specific motor.
bool setEncodersRaw(const double *vals) override
Set the value of all encoders.
bool getPidOutputsRaw(const yarp::dev::PidControlTypeEnum &pidtype, double *outs) override
Get the output of the controllers (e.g.
bool isPidEnabledRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, bool *enabled) override
Get the current status (enabled/disabled) of the pid controller.
bool setRefSpeedsRaw(const double *spds) override
Set reference speed on all joints.
bool getTargetPositionsRaw(double *refs) override
Get the last position reference for all axes.
bool getRefDutyCycleRaw(int j, double *v) override
Gets the last reference sent using the setRefDutyCycleRaw function.
bool setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
bool setPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum &pidtype, const double *limits) override
Get the error limit for the controller on all joints.
bool getPidReferenceRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double *ref) override
Get the current reference of the pid controller for a specific joint.
bool getNominalCurrentRaw(int m, double *val) override
bool getControlModeRaw(int j, int *v) override
bool calibrationDoneRaw(int j) override
Check if the calibration is terminated, on a particular joint.
bool threadInit() override
Initialization method.
bool getRefDutyCyclesRaw(double *v) override
Gets the last reference sent using the setRefDutyCyclesRaw function.
bool getRefVelocityRaw(const int joint, double *ref) override
Get the last reference speed set by velocityMove for single joint.
bool getEncoderTimedRaw(int j, double *encs, double *stamp) override
Read the instantaneous acceleration of all axes.
bool disablePidRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Disable the pid computation for a joint.
yarp::dev::VAS_status getVirtualAnalogSensorStatusRaw(int ch) override
Check the status of a given channel.
bool getMotorEncodersRaw(double *encs) override
Read the position of all motor encoders.
bool getTorqueRangesRaw(double *min, double *max) override
Get the full scale of the torque sensors of all joints.
bool getRefCurrentsRaw(double *t) override
Get the reference value of the currents for all motors.
bool setRefDutyCyclesRaw(const double *v) override
Sets the reference dutycycle for all motors.
bool getEncoderSpeedRaw(int j, double *sp) override
Read the instantaneous speed of an axis.
int getVirtualAnalogSensorChannelsRaw() override
Get the number of channels of the virtual sensor.
bool resetPidRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Reset the controller of a given joint, usually sets the current status of the joint as the reference ...
bool getCurrentRangesRaw(double *min, double *max) override
Get the full scale of the current measurements for all motors motor (e.g.
yarp::dev::ReturnValue getDesiredVelocityRaw(const int jnt, double &vel) override
Get the last reference velocity set by setDesiredVelocity() for a single joint.
bool getEncoderRaw(int j, double *v) override
Read the value of an encoder.
bool getPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum &pidtype, double *limits) override
Get the error limit for all controllers.
bool enableAmpRaw(int j) override
Enable the amplifier on a specific joint.
bool fromConfig(yarp::os::Searchable &config)
yarp::dev::ReturnValue setManualBrakeActiveRaw(int j, bool active) override
bool getPidsRaw(const yarp::dev::PidControlTypeEnum &pidtype, yarp::dev::Pid *pids) override
Get current pid value for a specific joint.
bool getRefPositionsRaw(double *refs) override
Get the last position reference for all axes.
bool getMotorTorqueParamsRaw(int j, yarp::dev::MotorTorqueParameters *params) override
Get the motor parameters.
bool setControlModesRaw(const int n_joint, const int *joints, int *modes) override
bool setRefSpeedRaw(int j, double sp) override
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual bool getHasRotorEncoderIndexRaw(int j, int &ret)
bool updateVirtualAnalogSensorMeasureRaw(yarp::sig::Vector &measure) override
Set a vector of torque values for virtual sensor.
void resizeBuffers()
Resize previously allocated buffers.
yarp::dev::ReturnValue isJointBrakedRaw(int j, bool &braked) const override
void threadRelease() override
Release method.
bool getAmpStatusRaw(int *st) override
bool getLastJointFaultRaw(int j, int &fault, std::string &message) override
bool setImpedanceRaw(int j, double stiffness, double damping) override
Set current impedance parameters (stiffness,damping) for a specific joint.
bool setPWMLimitRaw(int j, const double val) override
bool relativeMoveRaw(int j, double delta) override
Set relative position.
virtual bool getMotorPolesRaw(int j, int &poles)
bool getPidRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, yarp::dev::Pid *pid) override
Get current pid value for a specific joint.
bool getCurrentRaw(int j, double *val) override
bool getPeakCurrentRaw(int m, double *val) override
bool getDutyCyclesRaw(double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool setEncoderRaw(int j, double val) override
Set the value of the encoder for a given joint.
bool getRefPositionRaw(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool getLimitsRaw(int axis, double *min, double *max) override
Get the software limits for a particular axis.
virtual bool getRotorIndexOffsetRaw(int j, double &rotorOffset)
bool getVelLimitsRaw(int axis, double *min, double *max) override
Get the software speed limits for a particular axis.
bool setPositionsRaw(const int n_joint, const int *joints, const double *refs) override
Set new reference point for all axes.
bool setPidReferenceRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double ref) override
Set the controller reference for a given axis.
bool resetEncodersRaw() override
Reset encoders.
bool getPWMRaw(int j, double *val) override
yarp::dev::ReturnValue setDesiredVelocityRaw(int jnt, double vel) override
Set the velocity of single joint.
yarp::dev::ReturnValue getAutoBrakeEnabledRaw(int j, bool &enabled) const override
bool getAxisNameRaw(int axis, std::string &name) override
bool setCalibrationParametersRaw(int axis, const yarp::dev::CalibrationParameters &params) override
Start calibration, this method is very often platform specific.
bool setPidOffsetRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double v) override
Set an offset value on the ourput of pid controller.
bool getInteractionModeRaw(int j, yarp::dev::InteractionModeEnum *_mode) override
Get the current interaction mode of the robot, values can be stiff or compliant.
bool getCurrentRangeRaw(int j, double *min, double *max) override
Get the full scale of the current measurement for a given motor (e.g.
bool stopRaw() override
Stop motion, multiple joints.
virtual bool getKinematicMJRaw(int j, double &rotres)
bool getRefSpeedsRaw(double *spds) override
Get reference speed of all joints.
bool getRefAccelerationsRaw(double *accs) override
Get reference acceleration of all joints.
virtual bool getJointEncoderResolutionRaw(int m, double &jntres)
bool getAxes(int *ax) override
Get the number of controlled axes.
bool setMaxCurrentRaw(int j, double val) override
bool alloc(int njoints)
Allocated buffers.
bool resetMotorEncodersRaw() override
Reset motor encoders.
bool setRefTorquesRaw(const double *t) override
Set the reference value of the torque for all joints.
bool getEncodersRaw(double *encs) override
Read the position of all axes.
bool setRefAccelerationsRaw(const double *accs) override
Set reference acceleration on all joints.
bool getControlModesRaw(int *v) override
bool setPidRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, const yarp::dev::Pid &pid) override
Set new pid value for a joint axis.
bool getPWMLimitRaw(int j, double *val) override
virtual bool getRotorEncoderTypeRaw(int j, int &type)
bool getRefCurrentRaw(int j, double *t) override
Get the reference value of the current for a single motor.
bool getDutyCycleRaw(int j, double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool setPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j, double limit) override
Set the error limit for the controller on a specific joint.
bool getInteractionModesRaw(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
bool positionMoveRaw(int j, double ref) override
Set new reference point for a single axis.
bool getMotorEncoderCountsPerRevolutionRaw(int m, double *v) override
Gets number of counts per revolution for motor encoder m.
bool setImpedanceOffsetRaw(int j, double offset) override
Set current force Offset for a specific joint.
bool setMotorEncodersRaw(const double *vals) override
Set the value of all motor encoders.
bool getPidErrorsRaw(const yarp::dev::PidControlTypeEnum &pidtype, double *errs) override
Get the error of all joints.
bool getGearboxRatioRaw(int m, double *gearbox) override
Get the gearbox ratio for a specific motor.
bool getMaxCurrentRaw(int j, double *val) override
Returns the maximum electric current allowed for a given motor.
bool close() override
Close the DeviceDriver.
bool getRefTorquesRaw(double *t) override
Get the reference value of the torque for all joints.
bool setRefCurrentRaw(int j, double t) override
Set the reference value of the current for a single motor.
bool getNumberOfMotorEncodersRaw(int *num) override
Get the number of available motor encoders.
bool getPidReferencesRaw(const yarp::dev::PidControlTypeEnum &pidtype, double *refs) override
Get the current reference of all pid controllers.
bool getTorqueRaw(int j, double *t) override
Get the value of the torque on a given joint (this is the feedback if you have a torque sensor).
bool getImpedanceRaw(int j, double *stiffness, double *damping) override
Get current impedance parameters (stiffness,damping,offset) for a specific joint.
bool enablePidRaw(const yarp::dev::PidControlTypeEnum &pidtype, int j) override
Enable the pid computation for a joint.
bool getRefVelocitiesRaw(double *refs) override
Get the last reference speed set by velocityMove for all joints.
bool setPositionRaw(int j, double ref) override
Set new position for a single axis.
bool getEncoderAccelerationsRaw(double *accs) override
Read the instantaneous acceleration of all axes.
bool setPidReferencesRaw(const yarp::dev::PidControlTypeEnum &pidtype, const double *refs) override
Set the controller reference, multiple axes.
bool getMotorEncoderRaw(int m, double *v) override
Read the value of a motor encoder.
bool getRefTorqueRaw(int j, double *t) override
Set the reference value of the torque for a given joint.
bool getMotorEncoderAccelerationsRaw(double *accs) override
Read the instantaneous acceleration of all motor encoders.
bool setInteractionModesRaw(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Set the interaction mode of the robot for a set of joints, values can be stiff or compliant.
bool getTemperaturesRaw(double *vals) override
Get temperature of all the motors.
bool resetMotorEncoderRaw(int m) override
Reset motor encoder, single motor.
bool setNominalCurrentRaw(int m, const double val) override
virtual bool getRotorEncoderResolutionRaw(int m, double &rotres)
virtual bool getHasRotorEncoderRaw(int j, int &ret)
bool getMotorEncodersTimedRaw(double *encs, double *stamps) override
Read the instantaneous position of all motor encoders.
bool resetEncoderRaw(int j) override
Reset encoder, single joint.
bool getTorquesRaw(double *t) override
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
bool setLimitsRaw(int axis, double min, double max) override
Set the software limits for a particular axis, the behavior of the control card when these limits are...
bool setInteractionModeRaw(int j, yarp::dev::InteractionModeEnum _mode) override
Set the interaction mode of the robot, values can be stiff or compliant.
void run() override
Loop function.
bool getMotorEncoderTimedRaw(int m, double *encs, double *stamp) override
Read the instantaneous position of a motor encoder.
bool getEncodersTimedRaw(double *encs, double *stamps) override
Read the instantaneous acceleration of all axes.
bool getEncoderSpeedsRaw(double *spds) override
Read the instantaneous acceleration of an axis.
virtual bool getTorqueControlFilterType(int j, int &type)
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *ampereFactor=NULL, const double *voltFactor=NULL)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
class ImplementControlLimits; class StubImplControlLimitsRaw;
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool initialize(int k, const int *amap)
bool initialize(int size, const int *amap, const double *ampsToSens)
Initialize the internal data and alloc memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw)
Initialize the internal data and alloc memory.
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory, smaller version.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool initialize(int size, const int *amap)
Initialize the internal data and alloc memory.
bool initialize(int k, const int *amap, const double *dutyToPWM)
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *newtons, const double *amps, const double *dutys)
Initialize the internal data and alloc memory.
bool setConversionUnits(const PidControlTypeEnum &pidtype, const PidFeedbackUnitsEnum fbk_conv_units, const PidOutputUnitsEnum out_conv_units)
Default implementation of the IPositionControl interface.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
Default implementation of the IPositionDirect interface.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw, const double *amps, const double *dutys, const double *bemfs, const double *ktaus)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool uninitialize()
Clean up internal data and memory.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool initialize(int k, const int *amap, const double *userToRaw)
Contains the parameters for a PID.
double offset
pwm offset added to the pid output
double kp
proportional gain
A mini-server for performing network communication in the background.
An abstraction for a periodic thread.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A base class for nested structures that can be searched.
Definition Searchable.h:31
void resize(size_t size) override
Resize the vector.
Definition Vector.h:211
void zero()
Zero the elements of the vector.
Definition Vector.h:353
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition environment.h:66
For streams capable of holding different kinds of content, check what they actually have.
PidControlTypeEnum
Definition PidEnums.h:15
@ VOCAB_PIDTYPE_TORQUE
Definition PidEnums.h:18
@ VOCAB_PIDTYPE_VELOCITY
Definition PidEnums.h:17
@ VOCAB_PIDTYPE_POSITION
Definition PidEnums.h:16
@ VOCAB_PIDTYPE_CURRENT
Definition PidEnums.h:19
@ VOCAB_JOINTTYPE_REVOLUTE
Definition IAxisInfo.h:24
@ VOCAB_JOINTTYPE_PRISMATIC
Definition IAxisInfo.h:25
@ VOCAB_JOINTTYPE_UNKNOWN
Definition IAxisInfo.h:26
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition Vocab32.cpp:33
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.