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)
153 return "EmergencyStopMaster";
171 std::vector<ManagedIceObjectPtr> unitsCopy;
177 Ice::ObjectProxySeq r;
178 r.reserve(unitsCopy.size());
181 r.emplace_back(unit->getProxy(-1,
true));
194 return unit->getProxy(-1,
true);
199 const EmergencyStopMasterInterfacePtr&
203 return emergencyStopMaster;
262 ARMARX_INFO <<
"initializing default units...done! "
271 using IfaceT = DiagnosticsUnitInterface;
276 if (
getUnit(IfaceT::ice_staticId()))
282 std::map<std::string, std::size_t> batteryDevs;
285 const SensorDevicePtr& sensorDevice =
_module<Devices>().getSensorDevices().at(i);
288 batteryDevs[sensorDevice->getDeviceName()] = i;
293 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
299 unit->setBatteryManagementDevices(batteryDevs);
307 using IfaceT = KinematicUnitInterface;
312 if (
getUnit(IfaceT::ice_staticId()))
326 const std::string& positionControlMode,
327 const std::string& velocityControlMode,
328 const std::string& torqueControlMode,
329 const std::string& pwmControlMode)
338 std::map<std::string, UnitT::ActuatorData> devs;
339 for (
const ControlDevicePtr& controlDevice :
343 const auto& controlDeviceName = controlDevice->getDeviceName();
344 ARMARX_DEBUG <<
"looking at device " << controlDeviceName
345 << controlDevice->getJointControllerToTargetTypeNameMap();
346 if (!controlDevice->hasTag(ControlDeviceTags::CreateNoDefaultController))
348 UnitT::ActuatorData ad;
349 ad.name = controlDeviceName;
352 ad.sensorDeviceIndex =
355 : std::numeric_limits<std::size_t>::max();
357 const auto init_controller =
358 [&](
const std::string& requestedControlMode,
auto& ctrl,
const auto* tpptr)
360 auto controlMode = requestedControlMode;
361 using CtargT = std::remove_const_t<std::remove_reference_t<
decltype(*tpptr)>>;
362 NJointKinematicUnitPassThroughControllerPtr& pt = ctrl;
364 auto testMode = [&](
const auto& m)
370 if (!testMode(controlMode))
376 auto jointControllers = controlDevice->getJointControllers();
377 for (
const auto* jointController : jointControllers)
379 if (jointController->getControlTarget()->isA<CtargT>())
383 selected_ctrl =
nullptr;
384 ARMARX_INFO <<
"Autodetected two controllers supporting "
385 << requestedControlMode <<
"! autoselection failed";
388 selected_ctrl = jointController;
393 controlMode = selected_ctrl->getControlMode();
394 ARMARX_INFO <<
"Autodetected controller with mode " << controlMode
395 <<
"(the requested mode was " << requestedControlMode
400 if (!controlMode.empty())
402 NJointKinematicUnitPassThroughControllerConfigPtr config =
405 config->deviceName = controlDeviceName;
406 auto ctrl_name =
getName() +
"_" +
"NJointKU_PTCtrl_" + controlDeviceName +
408 std::replace(ctrl_name.begin(), ctrl_name.end(),
'.',
'_');
409 std::replace(ctrl_name.begin(), ctrl_name.end(),
'-',
'_');
410 std::replace(ctrl_name.begin(), ctrl_name.end(),
':',
'_');
411 const NJointControllerBasePtr& nJointCtrl =
413 "NJointKinematicUnitPassThroughController",
418 pt = NJointKinematicUnitPassThroughControllerPtr::dynamicCast(nJointCtrl);
423 positionControlMode, ad.ctrlPos, (ControlTarget1DoFActuatorPosition*)0);
425 velocityControlMode, ad.ctrlVel, (ControlTarget1DoFActuatorVelocity*)0);
426 init_controller(torqueControlMode, ad.ctrlTor, (ControlTarget1DoFActuatorTorque*)0);
432 if (ad.ctrlPos || ad.ctrlTor || ad.ctrlVel)
434 ARMARX_DEBUG <<
"created controllers for " << controlDeviceName
435 <<
" pos/tor/vel " << ad.ctrlPos.get() <<
" / " << ad.ctrlTor.get()
436 <<
" / " << ad.ctrlVel.get();
437 devs[controlDeviceName] = std::move(ad);
443 ARMARX_IMPORTANT <<
"No joint devices found - skipping adding of KinematicUnit";
446 ARMARX_IMPORTANT <<
"Found " << devs.size() <<
" joint devices - adding KinematicUnit";
448 <<
"no 1DoF ControlDevice found with matching SensorDevice";
451 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
454 properties->setProperty(confPre +
"RobotNodeSetName",
456 properties->setProperty(confPre +
"RobotFileName",
_module<RobotData>().getRobotFileName());
457 properties->setProperty(confPre +
"RobotFileNameProject",
459 properties->setProperty(confPre +
"TopicPrefix",
463 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
482 using IfaceT = PlatformUnitInterface;
489 if (
getUnit(IfaceT::ice_staticId()))
497 ARMARX_INFO <<
"no platform unit created since no platform name was given";
505 <<
"no platform unit created since the platform control device with name '"
510 const ControlDevicePtr& controlDevice =
512 const SensorDevicePtr& sensorDevice =
515 controlDevice->getJointController(ControlModes::HolonomicPlatformVelocity);
523 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
527 properties->setProperty(confPre +
"PlatformName",
530 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
538 "PlatformUnitVelocityControllerType");
539 if (platformControllerType ==
542 NJointHolonomicPlatformUnitVelocityPassThroughControllerConfigPtr config =
545 config->initialVelocityY = 0;
546 config->initialVelocityRotation = 0;
549 auto ctrl = NJointHolonomicPlatformUnitVelocityPassThroughControllerPtr::dynamicCast(
551 "NJointHolonomicPlatformUnitVelocityPassThroughController",
552 getName() +
"_" + configName +
"_VelPTContoller",
561 else if (platformControllerType ==
564 NJointHolonomicPlatformVelocityControllerWithRampConfigPtr config =
568 config->maxPositionAcceleration =
570 config->maxOrientationAcceleration =
573 auto ctrl = NJointHolonomicPlatformVelocityControllerWithRampPtr::dynamicCast(
575 "NJointHolonomicPlatformVelocityControllerWithRamp",
576 getName() +
"_" + configName +
"_VelPTContoller",
587 ARMARX_ERROR <<
"Invalid Platform velocity controller specified '"
589 platformControllerType)
593 NJointHolonomicPlatformRelativePositionControllerConfigPtr configRelativePositionCtrlCfg =
596 auto ctrlRelativePosition =
597 NJointHolonomicPlatformRelativePositionControllerPtr::dynamicCast(
599 "NJointHolonomicPlatformRelativePositionController",
600 getName() +
"_" + configName +
"_RelativePositionContoller",
601 configRelativePositionCtrlCfg,
605 unit->relativePosCtrl = ctrlRelativePosition;
609 NJointHolonomicPlatformGlobalPositionControllerConfigPtr configGlobalPositionCtrlCfg =
612 auto ctrlGlobalPosition = NJointHolonomicPlatformGlobalPositionControllerPtr::dynamicCast(
614 "NJointHolonomicPlatformGlobalPositionController",
615 getName() +
"_" + configName +
"_GlobalPositionContoller",
616 configGlobalPositionCtrlCfg,
621 unit->globalPosCtrl = ctrlGlobalPosition;
638 using IfaceT = LocalizationUnitInterface;
644 if (
getUnit(IfaceT::ice_staticId()))
658 ARMARX_DEBUG <<
"Getting device SensorValueHolonomicPlatformRelativePosition";
662 const SensorDevicePtr& sensorDeviceRelativePosition =
673 const std::string configName =
"LocalizationUnit";
674 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
680 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
685 ARMARX_DEBUG <<
"Setting device GlobalRobotPoseCorrectionSensorDevice";
686 unit->globalPositionCorrectionSensorDevice =
687 dynamic_cast<decltype(unit-
>globalPositionCorrectionSensorDevice)>(
694 const SensorDevicePtr& sensorDeviceGlobalRobotLocalization =
705 unit->globalPositionCorrectionSensorDevice->getSensorValue()
717 using IfaceT = ForceTorqueUnitInterface;
722 if (
getUnit(IfaceT::ice_staticId()))
727 std::vector<ForceTorqueSubUnit::DeviceData> ftdevs;
728 for (
const SensorDevicePtr& ftSensorDevice :
_module<Devices>().getSensorDevices().values())
734 _module<Devices>().getSensorDevices().index(ftSensorDevice->getDeviceName());
735 ftSensorData.
deviceName = ftSensorDevice->getDeviceName();
736 ftSensorData.
frame = ftSensorDevice->getReportingFrame();
738 <<
"The sensor device '" << ftSensorData.
deviceName
740 <<
") reports force torque values but returns an empty string as reporting "
743 <<
"The sensor device '" << ftSensorData.
deviceName
745 <<
") reports force torque values but returns a reporting frame '"
746 << ftSensorData.
frame <<
"' which is not present in the robot '"
748 ftdevs.emplace_back(std::move(ftSensorData));
754 <<
"no force torque unit created since there are no force torque sensor devices";
759 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
764 properties->setProperty(confPre +
"ForceTorqueTopicName",
767 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
780 using IfaceT = InertialMeasurementUnitInterface;
785 if (
getUnit(IfaceT::ice_staticId()))
790 std::map<std::string, std::size_t> imudevs;
793 const SensorDevicePtr& sensorDevice =
_module<Devices>().getSensorDevices().at(i);
796 imudevs[sensorDevice->getDeviceName()] = i;
802 <<
"no inertial measurement unit created since there are no imu sensor devices";
807 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
811 properties->setProperty(confPre +
"IMUTopicName",
815 unit->devs = imudevs;
833 if (
getUnit(UnitT::ice_staticId()) || !trajectoryControllerSubUnit)
837 (TrajectoryControllerSubUnitPtr::dynamicCast(trajectoryControllerSubUnit))
839 addUnit(trajectoryControllerSubUnit);
840 trajectoryControllerSubUnit =
nullptr;
857 if (
getUnit(UnitT::ice_staticId()))
861 (TCPControllerSubUnitPtr::dynamicCast(tcpControllerSubUnit))
864 tcpControllerSubUnit =
nullptr;
876 RobotUnitSubUnitPtr rsu = RobotUnitSubUnitPtr::dynamicCast(unit);
879 subUnits.emplace_back(std::move(rsu));
881 units.emplace_back(std::move(unit));
885 Units::_icePropertiesInitialized()
889 const std::string& configDomain =
"ArmarX";
893 const std::string configNameTCPControlUnit =
896 properties, configNameTCPControlUnit, configDomain);
903 const std::string configNameTrajectoryControllerUnit =
905 const std::string confPre =
906 configDomain +
"." + configNameTrajectoryControllerUnit +
".";
907 properties->setProperty(confPre +
"KinematicUnitName",
909 trajectoryControllerSubUnit =
911 properties, configNameTrajectoryControllerUnit, configDomain);
912 addPropertyUser(PropertyUserPtr::dynamicCast(trajectoryControllerSubUnit));
917 Units::_preFinishRunning()
930 Units::_preOnInitRobotUnit()
936 emergencyStopMaster =
new RobotUnitEmergencyStopMaster{
943 auto prx = obj->getProxy(-1);
946 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->addObject(
949 catch (
const IceGrid::ObjectExistsException&)
951 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->updateObject(
954 catch (std::exception& e)
956 ARMARX_WARNING <<
"add the robot unit as emergency stop master to the ice grid "
957 "admin!\nThere was an exception:\n"
965 Units::_postOnExitRobotUnit()
972 ManagedIceObjectPtr::dynamicCast(emergencyStopMaster));
989 if (unit->ice_isA(staticIceId))
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
std::string getConfigDomain()
Retrieve config domain for this component as set in constructor.
void addPropertyUser(const PropertyUserPtr &subPropertyUser)
Add additional property users here that should show up in the application help text.
Property< PropertyType > getProperty(const std::string &name)
static std::string DeviceName()
const SensorValueGlobalPoseCorrection * sensorGlobalPositionCorrection
const SensorValueHolonomicPlatformRelativePosition * sensorRelativePosition
static std::string DeviceName()
SensorValueGlobalRobotPose SensorValueType
The JointController class represents one joint in one control mode.
virtual ControlTargetBase * getControlTarget()=0
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
static const ManagedIceObjectPtr NullPtr
A nullptr to be used when a const ref to a nullptr is required.
ManagedIceObject(ManagedIceObject const &other)
std::string getName() const
Retrieve name of object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
This class allows minimal access to private members of ControlThread in a sane fashion for RobotUnitE...
friend class RobotUnitEmergencyStopMaster
This Module manages the ControlThread.
T & _module()
Returns this as ref to the given type.
GuardType getGuard() const
Returns a guard to the RobotUnits mutex.
void throwIfInControlThread(const std::string &fnc) const
Throws if the current thread is the ControlThread.
void throwIfStateIsNot(const std::set< RobotUnitState > &stateSet, const std::string &fnc, bool onlyWarn=false) const
Throws an exception if the current state is not in.
T * _modulePtr()
Returns this as ptr to the given type.
void onConnectComponent() final override
Pure virtual hook for the subclass.
std::string getDefaultName() const final override
Retrieve default name of component.
EmergencyStopState getEmergencyStopState(const Ice::Current &=Ice::emptyCurrent) const final override
armarx::core::time::DateTime lastSS2Activation
RobotUnitEmergencyStopMaster(ControlThread *controlThreadModule, std::string emergencyStopTopicName)
void setEmergencyStopState(EmergencyStopState state, const Ice::Current &=Ice::emptyCurrent) final override
std::shared_mutex ss2StateMutex
void onInitComponent() final override
Pure virtual hook for the subclass.
EmergencyStopListenerPrx emergencyStopTopic
const std::string emergencyStopTopicName
EmergencyStopState trySetEmergencyStopState(EmergencyStopState targetState, const ::Ice::Current &) final override
ControlThread *const controlThreadModule
virtual void initializeForceTorqueUnit()
Initializes the ForceTorqueUnit.
T::PointerType getUnit() const
Returns a pointer to the Unit for the given type (or null if there is none)
virtual void initializeTrajectoryControllerUnit()
Initializes the TrajectoryControllerUnit.
void addUnit(ManagedIceObjectPtr unit)
Registers a unit for management (the Unit is added and removed to the ArmarXManager and updated with ...
virtual void initializeDiagnosticsUnit()
Initialize the diagnostics unit.
virtual void initializeTcpControllerUnit()
Initializes the TcpControllerUnit.
virtual void initializeInertialMeasurementUnit()
Initializes the InertialMeasurementUnit.
virtual void initializePlatformUnit()
Initializes the PlatformUnit.
virtual void initializeLocalizationUnit()
Initializes the TcpControllerUnit.
virtual void initializeDefaultUnits()
Calls all init hooks for all managed Units.
ManagedIceObjectPtr createKinematicSubUnit(const Ice::PropertiesPtr &properties, const std::string &positionControlMode=ControlModes::Position1DoF, const std::string &velocityControlMode=ControlModes::Velocity1DoF, const std::string &torqueControlMode=ControlModes::Torque1DoF, const std::string &pwmControlMode=ControlModes::PWM1DoF)
Create the KinematicUnit (this function should be called in initializeKinematicUnit)
Ice::ObjectProxySeq getUnits(const Ice::Current &) const override
Returns proxies to all units.
virtual void initializeKinematicUnit()
Initializes the KinematicUnit.
const EmergencyStopMasterInterfacePtr & getEmergencyStopMaster() const
Returns a pointer to the EmergencyStopMaster.
The RobotUnit class manages a robot and its controllers.
The pose correction to obtain the robot's global pose.
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Represents a point in time.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
::IceInternal::Handle<::Ice::Properties > PropertiesPtr
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
std::vector< KeyT > getIndices(const std::map< KeyT, ValT > &c)
const simox::meta::EnumNames< NJointHolonomicPlatformVelocityControllerTypes > NJointHolonomicPlatformVelocityControllerTypesNames
NJointHolonomicPlatformVelocityControllerTypes
IceInternal::Handle< ManagedIceObject > ManagedIceObjectPtr