56 SetEmergencyStopStateNoReportToTopic(
ControlThread* controlThreadModule,
57 EmergencyStopState state)
59 controlThreadModule->setEmergencyStopStateNoReportToTopic(state);
68 virtual public EmergencyStopMasterInterface
81 const Ice::Current& = Ice::emptyCurrent)
final override
87 if (currentState == state)
94 if (currentState == EmergencyStopState::eEmergencyStopActive)
99 ControlThreadAttorneyForRobotUnitEmergencyStopMaster::
106 const ::Ice::Current&)
final override
113 if (targetState == EmergencyStopState::eEmergencyStopInactive and
147 return "EmergencyStopMaster";
165 std::vector<ManagedIceObjectPtr> unitsCopy;
171 Ice::ObjectProxySeq r;
172 r.reserve(unitsCopy.size());
175 r.emplace_back(unit->getProxy(-1,
true));
188 return unit->getProxy(-1,
true);
193 const EmergencyStopMasterInterfacePtr&
197 return emergencyStopMaster;
223 if (_module<RobotData>().arePlatformAndLocalizationUnitsEnabled())
231 if (_module<RobotData>().arePlatformAndLocalizationUnitsEnabled())
256 ARMARX_INFO <<
"initializing default units...done! "
265 using IfaceT = DiagnosticsUnitInterface;
270 if (
getUnit(IfaceT::ice_staticId()))
276 std::map<std::string, std::size_t> batteryDevs;
277 for (
auto i :
getIndices(_module<Devices>().getSensorDevices().keys()))
279 const SensorDevicePtr& sensorDevice = _module<Devices>().getSensorDevices().at(i);
282 batteryDevs[sensorDevice->getDeviceName()] = i;
286 const std::string configName = getProperty<std::string>(
"DiagnosticsUnitName");
287 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
293 unit->setBatteryManagementDevices(batteryDevs);
301 using IfaceT = KinematicUnitInterface;
306 if (
getUnit(IfaceT::ice_staticId()))
320 const std::string& positionControlMode,
321 const std::string& velocityControlMode,
322 const std::string& torqueControlMode,
323 const std::string& pwmControlMode)
332 std::map<std::string, UnitT::ActuatorData> devs;
333 for (
const ControlDevicePtr& controlDevice :
334 _module<Devices>().getControlDevices().
values())
337 const auto& controlDeviceName = controlDevice->getDeviceName();
338 ARMARX_DEBUG <<
"looking at device " << controlDeviceName
339 << controlDevice->getJointControllerToTargetTypeNameMap();
340 if (!controlDevice->hasTag(ControlDeviceTags::CreateNoDefaultController))
342 UnitT::ActuatorData ad;
343 ad.name = controlDeviceName;
345 << _module<Devices>().getSensorDevices().has(controlDeviceName);
346 ad.sensorDeviceIndex =
347 _module<Devices>().getSensorDevices().has(controlDeviceName)
348 ? _module<Devices>().getSensorDevices().index(controlDeviceName)
351 const auto init_controller =
352 [&](
const std::string& requestedControlMode,
auto& ctrl,
const auto* tpptr)
354 auto controlMode = requestedControlMode;
355 using CtargT = std::remove_const_t<std::remove_reference_t<decltype(*tpptr)>>;
356 NJointKinematicUnitPassThroughControllerPtr& pt = ctrl;
358 auto testMode = [&](
const auto& m)
364 if (!testMode(controlMode))
370 auto jointControllers = controlDevice->getJointControllers();
371 for (
const auto* jointController : jointControllers)
373 if (jointController->getControlTarget()->isA<CtargT>())
377 selected_ctrl =
nullptr;
378 ARMARX_INFO <<
"Autodetected two controllers supporting "
379 << requestedControlMode <<
"! autoselection failed";
382 selected_ctrl = jointController;
387 controlMode = selected_ctrl->getControlMode();
388 ARMARX_INFO <<
"Autodetected controller with mode " << controlMode
389 <<
"(the requested mode was " << requestedControlMode
394 if (!controlMode.empty())
396 NJointKinematicUnitPassThroughControllerConfigPtr config =
399 config->deviceName = controlDeviceName;
400 auto ctrl_name =
getName() +
"_" +
"NJointKU_PTCtrl_" + controlDeviceName +
402 std::replace(ctrl_name.begin(), ctrl_name.end(),
'.',
'_');
403 std::replace(ctrl_name.begin(), ctrl_name.end(),
'-',
'_');
404 std::replace(ctrl_name.begin(), ctrl_name.end(),
':',
'_');
405 const NJointControllerBasePtr& nJointCtrl =
406 _module<ControllerManagement>().createNJointController(
407 "NJointKinematicUnitPassThroughController",
412 pt = NJointKinematicUnitPassThroughControllerPtr::dynamicCast(nJointCtrl);
417 positionControlMode, ad.ctrlPos, (ControlTarget1DoFActuatorPosition*)0);
419 velocityControlMode, ad.ctrlVel, (ControlTarget1DoFActuatorVelocity*)0);
420 init_controller(torqueControlMode, ad.ctrlTor, (ControlTarget1DoFActuatorTorque*)0);
426 if (ad.ctrlPos || ad.ctrlTor || ad.ctrlVel)
428 ARMARX_DEBUG <<
"created controllers for " << controlDeviceName
429 <<
" pos/tor/vel " << ad.ctrlPos.get() <<
" / " << ad.ctrlTor.get()
430 <<
" / " << ad.ctrlVel.get();
431 devs[controlDeviceName] = std::move(ad);
437 ARMARX_IMPORTANT <<
"No joint devices found - skipping adding of KinematicUnit";
440 ARMARX_IMPORTANT <<
"Found " << devs.size() <<
" joint devices - adding KinematicUnit";
442 <<
"no 1DoF ControlDevice found with matching SensorDevice";
444 const std::string configName = getProperty<std::string>(
"KinematicUnitName");
445 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
448 properties->setProperty(confPre +
"RobotNodeSetName",
449 _module<RobotData>().getRobotNodetSeName());
450 properties->setProperty(confPre +
"RobotFileName", _module<RobotData>().getRobotFileName());
451 properties->setProperty(confPre +
"RobotFileNameProject",
452 _module<RobotData>().getRobotProjectName());
453 properties->setProperty(confPre +
"TopicPrefix",
454 getProperty<std::string>(
"KinematicUnitNameTopicPrefix"));
457 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
462 unit->setupData(getProperty<std::string>(
"RobotFileName").getValue(),
463 _module<RobotData>().cloneRobot(),
465 _module<Devices>().getControlModeGroups().groups,
466 _module<Devices>().getControlModeGroups().groupsMerged,
476 using IfaceT = PlatformUnitInterface;
483 if (
getUnit(IfaceT::ice_staticId()))
489 if (_module<RobotData>().getRobotPlatformName().
empty())
491 ARMARX_INFO <<
"no platform unit created since no platform name was given";
495 if (!_module<Devices>().getControlDevices().has(
496 _module<RobotData>().getRobotPlatformName()))
499 <<
"no platform unit created since the platform control device with name '"
500 << _module<RobotData>().getRobotPlatformName() <<
"' was not found";
504 const ControlDevicePtr& controlDevice =
505 _module<Devices>().getControlDevices().at(_module<RobotData>().getRobotPlatformName());
506 const SensorDevicePtr& sensorDevice =
507 _module<Devices>().getSensorDevices().at(_module<RobotData>().getRobotPlatformName());
509 controlDevice->getJointController(ControlModes::HolonomicPlatformVelocity);
516 const std::string configName = getProperty<std::string>(
"PlatformUnitName");
517 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
521 properties->setProperty(confPre +
"PlatformName",
522 _module<RobotData>().getRobotPlatformInstanceName());
524 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
531 getProperty<NJointHolonomicPlatformVelocityControllerTypes>(
532 "PlatformUnitVelocityControllerType");
533 if (platformControllerType ==
536 NJointHolonomicPlatformUnitVelocityPassThroughControllerConfigPtr config =
539 config->initialVelocityY = 0;
540 config->initialVelocityRotation = 0;
541 config->platformName = _module<RobotData>().getRobotPlatformName();
543 auto ctrl = NJointHolonomicPlatformUnitVelocityPassThroughControllerPtr::dynamicCast(
544 _module<ControllerManagement>().createNJointController(
545 "NJointHolonomicPlatformUnitVelocityPassThroughController",
546 getName() +
"_" + configName +
"_VelPTContoller",
555 else if (platformControllerType ==
558 NJointHolonomicPlatformVelocityControllerWithRampConfigPtr config =
560 config->
platformName = _module<RobotData>().getRobotPlatformName();
562 config->maxPositionAcceleration =
563 getProperty<float>(
"PlatformUnitMaximumPositionAcceleration");
564 config->maxOrientationAcceleration =
565 getProperty<float>(
"PlatformUnitMaximumOrientationAcceleration");
567 auto ctrl = NJointHolonomicPlatformVelocityControllerWithRampPtr::dynamicCast(
568 _module<ControllerManagement>().createNJointController(
569 "NJointHolonomicPlatformVelocityControllerWithRamp",
570 getName() +
"_" + configName +
"_VelPTContoller",
581 ARMARX_ERROR <<
"Invalid Platform velocity controller specified '"
583 platformControllerType)
587 NJointHolonomicPlatformRelativePositionControllerConfigPtr configRelativePositionCtrlCfg =
589 configRelativePositionCtrlCfg->
platformName = _module<RobotData>().getRobotPlatformName();
590 auto ctrlRelativePosition =
591 NJointHolonomicPlatformRelativePositionControllerPtr::dynamicCast(
592 _module<ControllerManagement>().createNJointController(
593 "NJointHolonomicPlatformRelativePositionController",
594 getName() +
"_" + configName +
"_RelativePositionContoller",
595 configRelativePositionCtrlCfg,
599 unit->relativePosCtrl = ctrlRelativePosition;
603 NJointHolonomicPlatformGlobalPositionControllerConfigPtr configGlobalPositionCtrlCfg =
605 configGlobalPositionCtrlCfg->
platformName = _module<RobotData>().getRobotPlatformName();
606 auto ctrlGlobalPosition = NJointHolonomicPlatformGlobalPositionControllerPtr::dynamicCast(
607 _module<ControllerManagement>().createNJointController(
608 "NJointHolonomicPlatformGlobalPositionController",
609 getName() +
"_" + configName +
"_GlobalPositionContoller",
610 configGlobalPositionCtrlCfg,
615 unit->globalPosCtrl = ctrlGlobalPosition;
618 unit->platformSensorIndex = _module<Devices>().getSensorDevices().index(
619 _module<RobotData>().getRobotPlatformName());
632 using IfaceT = LocalizationUnitInterface;
638 if (
getUnit(IfaceT::ice_staticId()))
644 ARMARX_DEBUG <<
"Getting device SensorValueHolonomicPlatformRelativePosition";
646 _module<Devices>().getSensorDevices().has(_module<RobotData>().getRobotPlatformName()))
647 << _module<RobotData>().getRobotPlatformName();
648 const SensorDevicePtr& sensorDeviceRelativePosition =
649 _module<Devices>().getSensorDevices().at(_module<RobotData>().getRobotPlatformName());
659 const std::string configName =
"LocalizationUnit";
660 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
666 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
671 ARMARX_DEBUG <<
"Setting device GlobalRobotPoseCorrectionSensorDevice";
672 unit->globalPositionCorrectionSensorDevice =
673 dynamic_cast<decltype(unit-
>globalPositionCorrectionSensorDevice)>(
680 const SensorDevicePtr& sensorDeviceGlobalRobotLocalization =
681 _module<Devices>().getSensorDevices().at(
691 unit->globalPositionCorrectionSensorDevice->getSensorValue()
703 using IfaceT = ForceTorqueUnitInterface;
708 if (
getUnit(IfaceT::ice_staticId()))
713 std::vector<ForceTorqueSubUnit::DeviceData> ftdevs;
714 for (
const SensorDevicePtr& ftSensorDevice : _module<Devices>().getSensorDevices().
values())
720 _module<Devices>().getSensorDevices().index(ftSensorDevice->getDeviceName());
721 ftSensorData.
deviceName = ftSensorDevice->getDeviceName();
722 ftSensorData.
frame = ftSensorDevice->getReportingFrame();
724 <<
"The sensor device '" << ftSensorData.
deviceName
726 <<
") reports force torque values but returns an empty string as reporting "
729 <<
"The sensor device '" << ftSensorData.
deviceName
731 <<
") reports force torque values but returns a reporting frame '"
732 << ftSensorData.
frame <<
"' which is not present in the robot '"
733 << _module<RobotData>().getRobotName() <<
"'";
734 ftdevs.emplace_back(std::move(ftSensorData));
740 <<
"no force torque unit created since there are no force torque sensor devices";
744 const std::string configName = getProperty<std::string>(
"ForceTorqueUnitName");
745 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
749 properties->setProperty(confPre +
"AgentName", _module<RobotData>().getRobotName());
750 properties->setProperty(confPre +
"ForceTorqueTopicName",
751 getProperty<std::string>(
"ForceTorqueTopicName").getValue());
753 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
766 using IfaceT = InertialMeasurementUnitInterface;
771 if (
getUnit(IfaceT::ice_staticId()))
776 std::map<std::string, std::size_t> imudevs;
777 for (
auto i :
getIndices(_module<Devices>().getSensorDevices().keys()))
779 const SensorDevicePtr& sensorDevice = _module<Devices>().getSensorDevices().at(i);
782 imudevs[sensorDevice->getDeviceName()] = i;
788 <<
"no inertial measurement unit created since there are no imu sensor devices";
792 const std::string configName = getProperty<std::string>(
"InertialMeasurementUnitName");
793 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
797 properties->setProperty(confPre +
"IMUTopicName",
798 getProperty<std::string>(
"IMUTopicName").getValue());
801 unit->devs = imudevs;
813 if (!getProperty<bool>(
"CreateTrajectoryPlayer").getValue())
819 if (
getUnit(UnitT::ice_staticId()) || !trajectoryControllerSubUnit)
823 (TrajectoryControllerSubUnitPtr::dynamicCast(trajectoryControllerSubUnit))
824 ->setup(_modulePtr<RobotUnit>());
825 addUnit(trajectoryControllerSubUnit);
826 trajectoryControllerSubUnit =
nullptr;
836 if (!getProperty<bool>(
"CreateTCPControlUnit").getValue())
843 if (
getUnit(UnitT::ice_staticId()))
847 (TCPControllerSubUnitPtr::dynamicCast(tcpControllerSubUnit))
848 ->setup(_modulePtr<RobotUnit>(), _module<RobotData>().cloneRobot());
850 tcpControllerSubUnit =
nullptr;
862 RobotUnitSubUnitPtr rsu = RobotUnitSubUnitPtr::dynamicCast(unit);
865 subUnits.emplace_back(std::move(rsu));
867 units.emplace_back(std::move(unit));
871 Units::_icePropertiesInitialized()
875 const std::string& configDomain =
"ArmarX";
879 const std::string configNameTCPControlUnit =
880 getProperty<std::string>(
"TCPControlUnitName");
881 tcpControllerSubUnit = Component::create<TCPControllerSubUnit, TCPControllerSubUnitPtr>(
882 properties, configNameTCPControlUnit, configDomain);
889 const std::string configNameTrajectoryControllerUnit =
890 getProperty<std::string>(
"TrajectoryControllerUnitName");
891 const std::string confPre =
892 configDomain +
"." + configNameTrajectoryControllerUnit +
".";
893 properties->setProperty(confPre +
"KinematicUnitName",
894 getProperty<std::string>(
"KinematicUnitName").getValue());
895 trajectoryControllerSubUnit =
896 Component::create<TrajectoryControllerSubUnit, TrajectoryControllerSubUnitPtr>(
897 properties, configNameTrajectoryControllerUnit, configDomain);
898 addPropertyUser(PropertyUserPtr::dynamicCast(trajectoryControllerSubUnit));
903 Units::_preFinishRunning()
916 Units::_preOnInitRobotUnit()
919 unitCreateRobot = _module<RobotData>().cloneRobot();
922 emergencyStopMaster =
new RobotUnitEmergencyStopMaster{
923 &_module<ControlThread>(),
924 getProperty<std::string>(
"EmergencyStopTopic").getValue()};
928 obj, getProperty<std::string>(
"EmergencyStopMasterName").
getValue(),
true);
929 auto prx = obj->getProxy(-1);
932 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->addObject(
935 catch (
const IceGrid::ObjectExistsException&)
937 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->updateObject(
940 catch (std::exception& e)
942 ARMARX_WARNING <<
"add the robot unit as emergency stop master to the ice grid "
943 "admin!\nThere was an exception:\n"
951 Units::_postOnExitRobotUnit()
958 ManagedIceObjectPtr::dynamicCast(emergencyStopMaster));
960 getProperty<std::string>(
"EmergencyStopMasterName").
getValue());
975 if (unit->ice_isA(staticIceId))