YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Robot.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
7
11
12#include <yarp/os/LogStream.h>
13
14#include <yarp/dev/PolyDriver.h>
16
18
19#include <algorithm>
20#include <iostream>
21#include <string>
22#include <unordered_set>
23
25
26namespace {
27YARP_LOG_COMPONENT(YRI_ROBOT, "yarp.yri.Robot")
28}
29
31{
32 dbg << "(name = \"" << t.name() << "\"";
33 if (!t.params().empty()) {
34 dbg << ", params = [";
35 dbg << t.params();
36 dbg << "]";
37 }
38 if (!t.devices().empty()) {
39 dbg << ", devices = [";
40 dbg << t.devices();
41 dbg << "]";
42 }
43 dbg << ")";
44 return dbg;
45}
46
47
49{
50public:
51 Private(Robot* /*parent*/)
52 {
53 }
54
55 // return true if a device with the given name exists
56 bool hasDevice(const std::string& name) const;
57
58 // return the device with the given name or <fatal error> if not found
59 Device* findDevice(const std::string& name);
60
61 //Print a debug message with a list of devices
63
64 // return true if a device with the given name exists
65 // considering also the provided external devices
66 bool hasDeviceIncludingExternal(const std::string& name) const;
67
68 // return the device with the given name or nullptr if not found,
69 // considering also the provided external devices
71
72 // check if there is no external devices that has the same name of an internal device
73 // return true if there is a conflict, false otherwise
75
76 // open all the devices and return true if all the open calls were successful
77 bool openDevices();
78
79 // close all the devices and return true if all the close calls were successful
80 bool closeDevices();
81
82 // return a vector of levels that have actions in the requested phase
83 std::vector<unsigned int> getLevels(ActionPhase phase) const;
84
85 // return a vector of actions for that phase and that level
86 std::vector<std::pair<Device, Action>> getActions(ActionPhase phase, unsigned int level) const;
87
88
89 // run configure action on one device
90 bool configure(const Device& device, const ParamList& params);
91
92 // run calibrate action on one device
93 bool calibrate(const Device& device, const ParamList& params);
94
95 // run attach action on one device
96 bool attach(const Device& device, const ParamList& params);
97
98 // run abort action on one device
99 bool abort(const Device& device, const ParamList& params);
100
101 // run detach action on one device
102 bool detach(const Device& device, const ParamList& params);
103
104 // run park action on one device
105 bool park(const Device& device, const ParamList& params);
106
107 // run custom action on one device
108 bool custom(const Device& device, const ParamList& params);
109
110 std::string name;
111 unsigned int build {0};
112 std::string portprefix;
117 unsigned int currentLevel {0};
119 bool dryrun {false};
122 std::string yriDescriptionStorageName = "yriDescriptionStorage";
124
125}; // class yarp::robotinterface::Robot::Private
126
127bool yarp::robotinterface::Robot::Private::hasDevice(const std::string& name) const
128{
129 for (const auto& device : devices) {
130 if (name == device.name()) {
131 return true;
132 }
133 }
134 return false;
135}
136
138{
139 for (auto& device : devices) {
140 if (name == device.name()) {
141 return &device;
142 }
143 }
144 return nullptr;
145}
146
148{
149 for (int i = 0; i < externalDevices.size(); i++) {
150 const yarp::dev::PolyDriverDescriptor* externalDevice = externalDevices[i];
151 yCInfo(YRI_ROBOT) << "- " << externalDevice->key;
152 }
153}
154
156{
157 if (hasDevice(name)) {
158 return true;
159 } else {
160 for (int i = 0; i < externalDevices.size(); i++) {
161 const yarp::dev::PolyDriverDescriptor* externalDevice = externalDevices[i];
162 if (name == externalDevice->key) {
163 return true;
164 }
165 }
166 }
167 return false;
168}
169
172{
174 deviceFound.poly = nullptr;
175 deviceFound.key = "";
176
177 for (auto& device : devices) {
178 if (name == device.name()) {
179 deviceFound.poly = device.driver();
180 deviceFound.key = device.name();
181 return deviceFound;
182 }
183 }
184
185 for (int i = 0; i < externalDevices.size(); i++) {
186 const yarp::dev::PolyDriverDescriptor* externalDevice = externalDevices[i];
187 if (name == externalDevice->key) {
188 deviceFound = *externalDevice;
189 }
190 }
191
192 return deviceFound;
193}
194
196{
197 std::unordered_set<std::string> externalDevicesNames;
198
199 for (int i = 0; i < externalDevicesList.size(); i++) {
200 const yarp::dev::PolyDriverDescriptor* externalDevice = externalDevicesList[i];
201 externalDevicesNames.insert(externalDevice->key);
202 }
203
204 for (auto& device : devices) {
205 if (externalDevicesNames.find(device.name()) != externalDevicesNames.end()) {
206 yCError(YRI_ROBOT) << "Device name " << device.name() << " is used for both an internal and external device.";
207 return true;
208 }
209 }
210
211 return false;
212}
213
214
216{
218 pcfg.put("device", "robotDescriptionStorage");
219 pcfg.put("name", "yriDescriptionStorage");
220 m_ddstorage.open(pcfg);
221 m_ddstorage.view(m_istorage);
222
223 bool ret = true;
224 for (auto& device : devices)
225 {
226 if (showDeviceParameters)
227 {
228 yCInfo(YRI_ROBOT) << "Opening device" << device.name() << "with parameters" << device.params();
229 }
230 else
231 {
232 yCInfo(YRI_ROBOT) << "Opening device" << device.name() << ". Use option `show-device-parameters` for additional info.";
233 }
234
235 if (dryrun) {
236 continue;
237 }
238
239 if (!device.open()) {
240 yCWarning(YRI_ROBOT) << "Cannot open device" << device.name();
241 ret = false;
242 }
243 else
244 {
245 if (m_istorage)
246 {
247 std::vector<std::string> stp;
248 std::string scfg;
250 yarp::dev::IDeviceDriverParams* dparams = nullptr;
251 if (pddrv)
252 {
253 pddrv->view(dparams);
254 if (dparams)
255 {
256 stp = dparams->getListOfParams();
257 scfg = dparams->getConfiguration();
258 }
259 else
260 {
261 yCWarning(YRI_ROBOT) << "Device" << device.name() << "does not derive from IDeviceDriverParams.";
262 }
263 }
264 if (!pddrv || scfg.empty())
265 {
266 yCWarning(YRI_ROBOT) << "Unable to get device" << device.name() << "configuration. yarprobotinterface will continue, but some features for inspecting the device parameters will be disabled.";
267 yCDebug(YRI_ROBOT) << "It is recommended that devices used by yarprobinterface implement the `yarp::dev::IDeviceDriverParams` interface.";
268 yCDebug(YRI_ROBOT) << "See yarprobotinterface documentation page.";
269 }
271 devdesc.device_name = device.name();
272 devdesc.device_type = device.type();
273 devdesc.device_configuration = scfg;
274 yarp::dev::ReturnValue ret = m_istorage->registerDevice(devdesc);
275 if (!ret)
276 {
277 yCError(YRI_ROBOT) << "Unable to register device" << device.name() << "in robotDescriptionStorage";
278 }
279 }
280 }
281 }
282 if (ret)
283 {
284 if (m_istorage)
285 {
286 std::vector<yarp::dev::DeviceDescription> ll;
287 m_istorage->getAllDevices(ll);
288 std::ostringstream oss;
289 for (auto& it_device : ll)
290 {
291 oss << "- name:" << it_device.device_name << ", type:" << it_device.device_type << "\n";
292 }
293 yCInfo(YRI_ROBOT) << "List of opened devices:\n"
294 << oss.str() << "End of list";
295 ;
296 }
297 }
298 else
299 {
300 yCWarning(YRI_ROBOT) << "There was some problem opening one or more devices. Please check the log and your configuration";
301 }
302
303 return ret;
304}
305
307{
308 bool ret = true;
309 for (auto it = devices.rbegin(); it != devices.rend(); ++it) {
311
312 yCInfo(YRI_ROBOT) << "Closing device" << device.name();
313
314 if (dryrun) {
315 continue;
316 }
317
318 // yCDebug(YRI_ROBOT) << device;
319
320 if (!device.close()) {
321 yCWarning(YRI_ROBOT) << "Cannot close device" << device.name();
322 ret = false;
323 }
324 }
325 if (ret) {
326 yCInfo(YRI_ROBOT) << "All devices closed.";
327 } else {
328 yCWarning(YRI_ROBOT) << "There was some problem closing one or more devices. Please check the log and your configuration";
329 }
330
331 if (m_ddstorage.isValid())
332 {
333 m_ddstorage.close();
334 }
335
336 return ret;
337}
338
340{
341 std::vector<unsigned int> levels;
342 for (const auto& device : devices) {
343 if (device.actions().empty()) {
344 continue;
345 }
346
347 for (const auto& action : device.actions()) {
348 if (action.phase() == phase) {
349 levels.push_back(action.level());
350 }
351 }
352 }
353
354 std::sort(levels.begin(), levels.end());
355 auto it = std::unique(levels.begin(), levels.end());
356 levels.resize(it - levels.begin());
357
358 return levels;
359}
360
361
362std::vector<std::pair<yarp::robotinterface::Device, yarp::robotinterface::Action>> yarp::robotinterface::Robot::Private::getActions(yarp::robotinterface::ActionPhase phase, unsigned int level) const
363{
364 std::vector<std::pair<yarp::robotinterface::Device, yarp::robotinterface::Action>> actions;
365 for (const auto& device : devices) {
366 if (device.actions().empty()) {
367 continue;
368 }
369
370 for (const auto& action : device.actions()) {
371 if (action.phase() == phase && action.level() == level) {
372 actions.emplace_back(device, action);
373 }
374 }
375 }
376 return actions;
377}
378
379
385
388{
389 if (!yarp::robotinterface::hasParam(params, "target")) {
390 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeCalibrate) << R"(" requires "target" parameter)";
391 return false;
392 }
393 std::string targetDeviceName = yarp::robotinterface::findParam(params, "target");
394
395 if (!hasDeviceIncludingExternal(targetDeviceName)) {
396 yCError(YRI_ROBOT) << "Target device" << targetDeviceName << "does not exist.";
397 yCError(YRI_ROBOT) << "Available target devices are:";
398 PrintDevicesIncludingExternal();
399 return false;
400 }
401
402 if (dryrun) {
403 return true;
404 }
405
406 yarp::dev::PolyDriverDescriptor targetDevice = findDeviceIncludingExternal(targetDeviceName);
407
408 return device.calibrate(targetDevice);
409}
410
413{
414 if (device.type() == "robotDescription_nws_yarp")
415 {
416 std::string storageName = yarp::robotinterface::findParam(params, "device");
418 drv_list.push(&m_ddstorage, yriDescriptionStorageName.c_str());
419 bool b= device.attach(drv_list);
420 if (!b)
421 {
422 yCError(YRI_ROBOT) << "cannot attach robotDescription_nws_yarp to yriDescriptionStorage";
423 }
424 return true;
425 }
426
427 int check = 0;
428 if (yarp::robotinterface::hasParam(params, "network")) {
429 check++;
430 }
431 if (yarp::robotinterface::hasParam(params, "networks")) {
432 check++;
433 }
435 check++;
436 }
437
438 if (check > 1) {
439 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeAttach) << R"(" : you can have only one option: "network" , "networks" or "all" )";
440 return false;
441 }
442
444
445 if (yarp::robotinterface::hasParam(params, "device")) {
446 std::string targetDeviceName = yarp::robotinterface::findParam(params, "device");
447
448 std::string targetNetwork = "...";
449 if (yarp::robotinterface::hasParam(params, "network")) {
450 targetNetwork = yarp::robotinterface::findParam(params, "network");
451 }
452
453 if (!hasDeviceIncludingExternal(targetDeviceName)) {
454 yCError(YRI_ROBOT) << "Target device" << targetDeviceName << "(network =" << targetNetwork << ") does not exist.";
455 yCError(YRI_ROBOT) << "Available target devices are:";
456 PrintDevicesIncludingExternal();
457 return false;
458 }
459
460 if (!dryrun) {
461 yarp::dev::PolyDriverDescriptor targetDevice = findDeviceIncludingExternal(targetDeviceName);
462
463 // yCDebug() << "Attach device" << device.name() << "to" << targetDevice.name() << "as" << targetNetwork;
464 drivers.push(targetDevice.poly, targetNetwork.c_str());
465 }
466
467 } else if (yarp::robotinterface::hasParam(params, "all")) {
468 if (!dryrun) {
469 for (auto& device : devices) {
470 drivers.push(device.driver(), "all");
471 }
472
473 for (int i = 0; i < externalDevices.size(); i++) {
474 const yarp::dev::PolyDriverDescriptor* externalDevice = externalDevices[i];
475 drivers.push(externalDevice->poly, "all");
476 }
477 }
478 } else if (yarp::robotinterface::hasParam(params, "networks")) {
480 v.fromString(yarp::robotinterface::findParam(params, "networks").c_str());
481 yarp::os::Bottle& targetNetworks = *(v.asList());
482
483 for (size_t i = 0; i < targetNetworks.size(); ++i) {
484 std::string targetNetwork = targetNetworks.get(i).toString();
485
486 if (!yarp::robotinterface::hasParam(params, targetNetwork)) {
487 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeAttach) << "\" requires one parameter per network. \"" << targetNetwork << "\" parameter is missing.";
488 return false;
489 }
490 std::string targetDeviceName = yarp::robotinterface::findParam(params, targetNetwork);
491 if (!hasDeviceIncludingExternal(targetDeviceName)) {
492 yCError(YRI_ROBOT) << "Target device" << targetDeviceName << "(network =" << targetNetwork << ") does not exist.";
493 yCError(YRI_ROBOT) << "Available target devices are:";
494 PrintDevicesIncludingExternal();
495 return false;
496 }
497
498 if (!dryrun) {
499 yarp::dev::PolyDriverDescriptor targetDevice = findDeviceIncludingExternal(targetDeviceName);
500
501 // yCDebug() << "Attach device" << device.name() << "to" << targetDevice.name() << "as" << targetNetwork;
502 drivers.push(targetDevice.poly, targetNetwork.c_str());
503 }
504 }
505 } else {
506 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeAttach) << R"(" requires either "network" or "networks" parameter)";
507 return false;
508 }
509
510 if (dryrun) {
511 return true;
512 }
513
514 if (!drivers.size()) {
515 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeAttach) << "\" couldn't find any device.";
516 return false;
517 }
518
519 return device.attach(drivers);
520}
521
527
528
530{
531 if (!params.empty()) {
532 yCWarning(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypeDetach) << "\" cannot have any parameter. Ignoring them.";
533 }
534
535 if (dryrun) {
536 return true;
537 }
538
539 return device.detach();
540}
541
544{
545 if (!yarp::robotinterface::hasParam(params, "target")) {
546 yCError(YRI_ROBOT) << "Action \"" << ActionTypeToString(ActionTypePark) << R"(" requires "target" parameter)";
547 return false;
548 }
549 std::string targetDeviceName = yarp::robotinterface::findParam(params, "target");
550
551 if (!hasDeviceIncludingExternal(targetDeviceName)) {
552 yCError(YRI_ROBOT) << "Target device" << targetDeviceName << "does not exist.";
553 yCError(YRI_ROBOT) << "Available target devices are:";
554 PrintDevicesIncludingExternal();
555 return false;
556 }
557
558 if (dryrun) {
559 return true;
560 }
561
562 yarp::dev::PolyDriverDescriptor targetDevice = findDeviceIncludingExternal(targetDeviceName);
563
564 return device.park(targetDevice);
565}
566
572
574 mPriv(new Private(this))
575{
576}
577
579 mPriv(new Private(this))
580{
581 mPriv->name = name;
582 mPriv->devices = devices;
583}
584
586 mPriv(new Private(this))
587{
588 mPriv->name = other.mPriv->name;
589 mPriv->build = other.mPriv->build;
590 mPriv->portprefix = other.mPriv->portprefix;
591 mPriv->currentPhase = other.mPriv->currentPhase;
592 mPriv->currentLevel = other.mPriv->currentLevel;
593 mPriv->dryrun = other.mPriv->dryrun;
594 mPriv->showDeviceParameters = other.mPriv->showDeviceParameters;
596 mPriv->devices = other.mPriv->devices;
597 mPriv->params = other.mPriv->params;
598}
599
601{
602 if (&other != this) {
603 mPriv->name = other.mPriv->name;
604 mPriv->build = other.mPriv->build;
605 mPriv->portprefix = other.mPriv->portprefix;
606 mPriv->currentPhase = other.mPriv->currentPhase;
607 mPriv->currentLevel = other.mPriv->currentLevel;
608 mPriv->dryrun = other.mPriv->dryrun;
609 mPriv->showDeviceParameters = other.mPriv->showDeviceParameters;
610 mPriv->reverseShutdownActionOrder = other.mPriv->reverseShutdownActionOrder;
611
612 mPriv->devices.clear();
613 mPriv->devices = other.mPriv->devices;
614
615 mPriv->params.clear();
616 mPriv->params = other.mPriv->params;
617 }
618
619 return *this;
620}
621
623{
624 delete mPriv;
625}
626
628{
629 return mPriv->name;
630}
631
633{
634 return mPriv->build;
635}
636
638{
639 return mPriv->portprefix;
640}
641
643{
644 for (auto& device : devices()) {
645 ParamList& params = device.params();
646 // Do not override "verbose" param if explicitly set in the xml
647 if (verbose && !yarp::robotinterface::hasParam(params, "verbose")) {
648 device.params().push_back(Param("verbose", "1"));
649 }
650 }
651}
652
654{
655 for (auto& device : devices()) {
656 ParamList& params = device.params();
657 // Do not override "allow-deprecated-devices" param if explicitly set in the xml
658 if (allowDeprecatedDevices && !yarp::robotinterface::hasParam(params, "allow-deprecated-devices")) {
659 device.params().push_back(Param("allow-deprecated-devices", "1"));
660 }
661 }
662}
663
665{
666 mPriv->showDeviceParameters = show;
667}
668
670{
671 mPriv->dryrun = dryrun;
672}
673
675{
676 mPriv->reverseShutdownActionOrder = reverseShutdownActionOrder;
677}
678
683
688
690{
691 return *mPriv->findDevice(name);
692}
693
694const std::string& yarp::robotinterface::Robot::name() const
695{
696 return mPriv->name;
697}
698
699const unsigned int& yarp::robotinterface::Robot::build() const
700{
701 return mPriv->build;
702}
703
705{
706 return mPriv->portprefix;
707}
708
710{
711 return mPriv->params;
712}
713
715{
716 return mPriv->devices;
717}
718
719bool yarp::robotinterface::Robot::hasDevice(const std::string& name) const
720{
721 return mPriv->hasDevice(name);
722}
723
725{
726 return *mPriv->findDevice(name);
727}
728
730{
731 yCInfo(YRI_ROBOT) << "Interrupt received. Stopping all running threads.";
732
733 // If we received an interrupt we send a stop signal to all threads
734 // from previous phases
735 for (auto& device : devices()) {
736 device.stopThreads();
737 }
738}
739
741{
742 bool nameConflict = mPriv->checkForNamingConflictsInExternalDevices(list);
743 if (nameConflict) {
744 return false;
745 }
746
747 mPriv->externalDevices = list;
748 return true;
749}
750
752{
753 yCInfo(YRI_ROBOT) << ActionPhaseToString(phase) << "phase starting...";
754
755 mPriv->currentPhase = phase;
756 mPriv->currentLevel = 0;
757
758 // Open all devices
759 if (phase == ActionPhaseStartup) {
760 if (!mPriv->openDevices()) {
761 yCError(YRI_ROBOT) << "One or more devices failed opening... see previous log messages for more info";
762 if (!mPriv->closeDevices()) {
763 yCError(YRI_ROBOT) << "One or more devices failed closing";
764 }
765 return false;
766 }
767 }
768
769 // run phase does not accept actions
770 if (phase == ActionPhaseRun) {
771 if (mPriv->getLevels(phase).size() != 0) {
772 yCWarning(YRI_ROBOT) << "Phase" << ActionPhaseToString(phase) << "does not accept actions. Skipping all actions for this phase";
773 }
774 return true;
775 }
776
777 // Before starting any action we ensure that there are no other
778 // threads running from previous phases.
779 // In interrupt 2 and 3 and this is called by the interrupt callback,
780 // and therefore main thread will be blocked and join will never
781 // return. Therefore, since we want to start the abort actions we
782 // skip this check.
783 if (phase != ActionPhaseInterrupt2 && phase != ActionPhaseInterrupt3) {
784 for (auto& device : devices()) {
785 device.joinThreads();
786 }
787 }
788
789 std::vector<unsigned int> levels = mPriv->getLevels(phase);
790 if (mPriv->reverseShutdownActionOrder && (phase == ActionPhaseShutdown ||
791 phase == ActionPhaseInterrupt1 ||
792 phase == ActionPhaseInterrupt2 ||
793 phase == ActionPhaseInterrupt3)) {
794 std::reverse(levels.begin(), levels.end());
795 }
796
797 bool ret = true;
798 for (unsigned int level : levels) {
799 // for each level
800 yCInfo(YRI_ROBOT) << "Entering action level" << level << "of phase" << ActionPhaseToString(phase);
801 mPriv->currentLevel = level;
802
803 // If current phase was changed by some other thread, we should
804 // exit the loop and avoid starting further actions.
805 if (mPriv->currentPhase != phase) {
806 ret = false;
807 break;
808 }
809
810 std::vector<std::pair<Device, Action>> actions = mPriv->getActions(phase, level);
811
812 for (auto& ait : actions) {
813 // for each action in that level
814 Device& device = ait.first;
815 Action& action = ait.second;
816
817 // If current phase was changed by some other thread, we should
818 // exit the loop and avoid starting further actions.
819 if (mPriv->currentPhase != phase) {
820 ret = false;
821 break;
822 }
823
824 yCInfo(YRI_ROBOT) << "Executing" << ActionTypeToString(action.type()) << "action, level" << action.level() << "on device" << device.name() << "with parameters" << action.params();
825
826 switch (action.type()) {
828 if (!mPriv->configure(device, action.params())) {
829 yCError(YRI_ROBOT) << "Cannot run configure action on device" << device.name();
830 ret = false;
831 }
832 break;
834 if (!mPriv->calibrate(device, action.params())) {
835 yCError(YRI_ROBOT) << "Cannot run calibrate action on device" << device.name();
836 ret = false;
837 }
838 break;
839 case ActionTypeAttach:
840 if (!mPriv->attach(device, action.params())) {
841 yCError(YRI_ROBOT) << "Cannot run attach action on device" << device.name();
842 ret = false;
843 }
844 break;
845 case ActionTypeAbort:
846 if (!mPriv->abort(device, action.params())) {
847 yCError(YRI_ROBOT) << "Cannot run abort action on device" << device.name();
848 ret = false;
849 }
850 break;
851 case ActionTypeDetach:
852 if (!mPriv->detach(device, action.params())) {
853 yCError(YRI_ROBOT) << "Cannot run detach action on device" << device.name();
854 ret = false;
855 }
856 break;
857 case ActionTypePark:
858 if (!mPriv->park(device, action.params())) {
859 yCError(YRI_ROBOT) << "Cannot run park action on device" << device.name();
860 ret = false;
861 }
862 break;
863 case ActionTypeCustom:
864 if (!mPriv->custom(device, action.params())) {
865 yCError(YRI_ROBOT) << "Cannot run custom action on device" << device.name();
866 ret = false;
867 }
868 break;
869 default:
870 yCWarning(YRI_ROBOT) << "Unhandled action" << ActionTypeToString(action.type());
871 ret = false;
872 break;
873 }
874 }
875
876 yCInfo(YRI_ROBOT) << "All actions for action level" << level << "of" << ActionPhaseToString(phase) << "phase started. Waiting for unfinished actions.";
877
878 // Join parallel threads
879 for (auto& device : devices()) {
880 device.joinThreads();
881 // yCDebug() << "All actions for device" << device.name() << "at level()" << level << "finished";
882 }
883
884 yCInfo(YRI_ROBOT) << "All actions for action level" << level << "of" << ActionPhaseToString(phase) << "phase finished.";
885 }
886
887 if (!ret) {
888 yCWarning(YRI_ROBOT) << "There was some problem running actions for" << ActionPhaseToString(phase) << "phase . Please check the log and your configuration";
889 }
890
891 if (phase == ActionPhaseShutdown) {
892 if (!mPriv->closeDevices()) {
893 yCError(YRI_ROBOT) << "One or more devices failed closing";
894 return false;
895 }
896 }
897
898 yCInfo(YRI_ROBOT) << ActionPhaseToString(phase) << "phase finished.";
899
900 return ret;
901}
902
904{
905 return mPriv->currentPhase;
906}
907
909{
910 return mPriv->currentLevel;
911}
912
913bool yarp::robotinterface::Robot::hasParam(const std::string& name) const
914{
915 return yarp::robotinterface::hasParam(mPriv->params, name);
916}
917
918std::string yarp::robotinterface::Robot::findParam(const std::string& name) const
919{
920 return yarp::robotinterface::findParam(mPriv->params, name);
921}
#define YARP_FIXME_NOTIMPLEMENTED(what)
Definition Log.h:411
yarp::os::LogStream operator<<(yarp::os::LogStream dbg, const yarp::robotinterface::Robot &t)
Definition Robot.cpp:30
std::string device_configuration
configuration parameters of the device
std::string device_type
type of the device
std::string device_name
name of the device
bool view(T *&x)
Get an interface to the device driver.
An interface for the management of the parameters of a DeviceDriver.
virtual std::vector< std::string > getListOfParams() const =0
Return a list of all params used by the device.
virtual std::string getConfiguration() const =0
Return the configuration of the device.
This interface allows users to retrieve a list which contains the names and the types of the currentl...
void push(PolyDriver *p, const char *k)
A container for a device driver.
Definition PolyDriver.h:23
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Definition Property.h:33
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
A single value (typically within a Bottle).
Definition Value.h:44
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:252
std::string toString() const override
Return a standard text representation of the content of the object.
Definition Value.cpp:368
void fromString(const char *str)
Set value to correspond to a textual representation.
Definition Value.cpp:363
unsigned int & level()
Definition Action.cpp:105
bool attach(const yarp::dev::PolyDriverList &drivers) const
Definition Device.cpp:419
bool park(const yarp::dev::PolyDriverDescriptor &target) const
Definition Device.cpp:493
yarp::dev::PolyDriver * driver() const
Definition Device.cpp:339
bool calibrate(const yarp::dev::PolyDriverDescriptor &target) const
Definition Device.cpp:359
bool detach(const Device &device, const ParamList &params)
Definition Robot.cpp:529
std::vector< unsigned int > getLevels(ActionPhase phase) const
Definition Robot.cpp:339
yarp::dev::IRobotDescription * m_istorage
Definition Robot.cpp:123
Device * findDevice(const std::string &name)
Definition Robot.cpp:137
bool park(const Device &device, const ParamList &params)
Definition Robot.cpp:542
bool custom(const Device &device, const ParamList &params)
Definition Robot.cpp:567
bool hasDevice(const std::string &name) const
Definition Robot.cpp:127
bool calibrate(const Device &device, const ParamList &params)
Definition Robot.cpp:386
bool hasDeviceIncludingExternal(const std::string &name) const
Definition Robot.cpp:155
bool attach(const Device &device, const ParamList &params)
Definition Robot.cpp:411
bool checkForNamingConflictsInExternalDevices(const yarp::dev::PolyDriverList &newExternalDevicesList)
Definition Robot.cpp:195
yarp::dev::PolyDriver m_ddstorage
Definition Robot.cpp:121
yarp::robotinterface::ActionPhase currentPhase
Definition Robot.cpp:116
yarp::dev::PolyDriverDescriptor findDeviceIncludingExternal(const std::string &name)
Definition Robot.cpp:171
bool configure(const Device &device, const ParamList &params)
Definition Robot.cpp:380
std::vector< std::pair< Device, Action > > getActions(ActionPhase phase, unsigned int level) const
Definition Robot.cpp:362
yarp::dev::PolyDriverList externalDevices
Definition Robot.cpp:115
bool abort(const Device &device, const ParamList &params)
Definition Robot.cpp:522
bool hasParam(const std::string &name) const
Definition Robot.cpp:913
void setAllowDeprecatedDevices(bool allowDeprecatedDevices)
Definition Robot.cpp:653
bool hasDevice(const std::string &name) const
Definition Robot.cpp:719
void setShowDeviceParameters(bool show)
Definition Robot.cpp:664
yarp::robotinterface::ActionPhase currentPhase() const
Definition Robot.cpp:903
std::string & portprefix()
Definition Robot.cpp:637
DeviceList & devices()
Definition Robot.cpp:684
void setVerbose(bool verbose)
Definition Robot.cpp:642
bool enterPhase(yarp::robotinterface::ActionPhase phase)
Definition Robot.cpp:751
bool setExternalDevices(const yarp::dev::PolyDriverList &list)
Definition Robot.cpp:740
void setReverseShutdownActionOrder(bool reverseShutdownActionOrder)
Definition Robot.cpp:674
std::string & name()
Definition Robot.cpp:627
Robot & operator=(const Robot &other)
Definition Robot.cpp:600
unsigned int & build()
Definition Robot.cpp:632
std::string findParam(const std::string &name) const
Definition Robot.cpp:918
Device & device(const std::string &name)
Definition Robot.cpp:689
void setDryRun(bool dryrun)
Definition Robot.cpp:669
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
std::string ActionTypeToString(robotinterface::ActionType actiontype)
Definition Types.cpp:151
bool hasParam(const robotinterface::ParamList &list, const std::string &name)
Definition Types.cpp:20
std::vector< robotinterface::Param > ParamList
Definition Types.h:30
std::string findParam(const robotinterface::ParamList &list, const std::string &name)
Definition Types.cpp:30
std::vector< robotinterface::Device > DeviceList
Definition Types.h:32
std::string ActionPhaseToString(robotinterface::ActionPhase actionphase)
Definition Types.cpp:103