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;
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;
279 const SensorDevicePtr& sensorDevice =
_module<Devices>().getSensorDevices().at(i);
282 batteryDevs[sensorDevice->getDeviceName()] = i;
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 :
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;
346 ad.sensorDeviceIndex =
349 : std::numeric_limits<std::size_t>::max();
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 =
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";
445 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
448 properties->setProperty(confPre +
"RobotNodeSetName",
450 properties->setProperty(confPre +
"RobotFileName",
_module<RobotData>().getRobotFileName());
451 properties->setProperty(confPre +
"RobotFileNameProject",
453 properties->setProperty(confPre +
"TopicPrefix",
457 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
476 using IfaceT = PlatformUnitInterface;
483 if (
getUnit(IfaceT::ice_staticId()))
491 ARMARX_INFO <<
"no platform unit created since no platform name was given";
499 <<
"no platform unit created since the platform control device with name '"
504 const ControlDevicePtr& controlDevice =
506 const SensorDevicePtr& sensorDevice =
509 controlDevice->getJointController(ControlModes::HolonomicPlatformVelocity);
517 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
521 properties->setProperty(confPre +
"PlatformName",
524 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
532 "PlatformUnitVelocityControllerType");
533 if (platformControllerType ==
536 NJointHolonomicPlatformUnitVelocityPassThroughControllerConfigPtr config =
539 config->initialVelocityY = 0;
540 config->initialVelocityRotation = 0;
543 auto ctrl = NJointHolonomicPlatformUnitVelocityPassThroughControllerPtr::dynamicCast(
545 "NJointHolonomicPlatformUnitVelocityPassThroughController",
546 getName() +
"_" + configName +
"_VelPTContoller",
555 else if (platformControllerType ==
558 NJointHolonomicPlatformVelocityControllerWithRampConfigPtr config =
562 config->maxPositionAcceleration =
564 config->maxOrientationAcceleration =
567 auto ctrl = NJointHolonomicPlatformVelocityControllerWithRampPtr::dynamicCast(
569 "NJointHolonomicPlatformVelocityControllerWithRamp",
570 getName() +
"_" + configName +
"_VelPTContoller",
581 ARMARX_ERROR <<
"Invalid Platform velocity controller specified '"
583 platformControllerType)
587 NJointHolonomicPlatformRelativePositionControllerConfigPtr configRelativePositionCtrlCfg =
590 auto ctrlRelativePosition =
591 NJointHolonomicPlatformRelativePositionControllerPtr::dynamicCast(
593 "NJointHolonomicPlatformRelativePositionController",
594 getName() +
"_" + configName +
"_RelativePositionContoller",
595 configRelativePositionCtrlCfg,
599 unit->relativePosCtrl = ctrlRelativePosition;
603 NJointHolonomicPlatformGlobalPositionControllerConfigPtr configGlobalPositionCtrlCfg =
606 auto ctrlGlobalPosition = NJointHolonomicPlatformGlobalPositionControllerPtr::dynamicCast(
608 "NJointHolonomicPlatformGlobalPositionController",
609 getName() +
"_" + configName +
"_GlobalPositionContoller",
610 configGlobalPositionCtrlCfg,
615 unit->globalPosCtrl = ctrlGlobalPosition;
632 using IfaceT = LocalizationUnitInterface;
638 if (
getUnit(IfaceT::ice_staticId()))
652 ARMARX_DEBUG <<
"Getting device SensorValueHolonomicPlatformRelativePosition";
656 const SensorDevicePtr& sensorDeviceRelativePosition =
667 const std::string configName =
"LocalizationUnit";
668 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
674 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
679 ARMARX_DEBUG <<
"Setting device GlobalRobotPoseCorrectionSensorDevice";
680 unit->globalPositionCorrectionSensorDevice =
681 dynamic_cast<decltype(unit-
>globalPositionCorrectionSensorDevice)>(
688 const SensorDevicePtr& sensorDeviceGlobalRobotLocalization =
699 unit->globalPositionCorrectionSensorDevice->getSensorValue()
711 using IfaceT = ForceTorqueUnitInterface;
716 if (
getUnit(IfaceT::ice_staticId()))
721 std::vector<ForceTorqueSubUnit::DeviceData> ftdevs;
722 for (
const SensorDevicePtr& ftSensorDevice :
_module<Devices>().getSensorDevices().values())
728 _module<Devices>().getSensorDevices().index(ftSensorDevice->getDeviceName());
729 ftSensorData.
deviceName = ftSensorDevice->getDeviceName();
730 ftSensorData.
frame = ftSensorDevice->getReportingFrame();
732 <<
"The sensor device '" << ftSensorData.
deviceName
734 <<
") reports force torque values but returns an empty string as reporting "
737 <<
"The sensor device '" << ftSensorData.
deviceName
739 <<
") reports force torque values but returns a reporting frame '"
740 << ftSensorData.
frame <<
"' which is not present in the robot '"
742 ftdevs.emplace_back(std::move(ftSensorData));
748 <<
"no force torque unit created since there are no force torque sensor devices";
753 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
758 properties->setProperty(confPre +
"ForceTorqueTopicName",
761 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
774 using IfaceT = InertialMeasurementUnitInterface;
779 if (
getUnit(IfaceT::ice_staticId()))
784 std::map<std::string, std::size_t> imudevs;
787 const SensorDevicePtr& sensorDevice =
_module<Devices>().getSensorDevices().at(i);
790 imudevs[sensorDevice->getDeviceName()] = i;
796 <<
"no inertial measurement unit created since there are no imu sensor devices";
801 const std::string confPre =
getConfigDomain() +
"." + configName +
".";
805 properties->setProperty(confPre +
"IMUTopicName",
809 unit->devs = imudevs;
827 if (
getUnit(UnitT::ice_staticId()) || !trajectoryControllerSubUnit)
831 (TrajectoryControllerSubUnitPtr::dynamicCast(trajectoryControllerSubUnit))
833 addUnit(trajectoryControllerSubUnit);
834 trajectoryControllerSubUnit =
nullptr;
851 if (
getUnit(UnitT::ice_staticId()))
855 (TCPControllerSubUnitPtr::dynamicCast(tcpControllerSubUnit))
858 tcpControllerSubUnit =
nullptr;
870 RobotUnitSubUnitPtr rsu = RobotUnitSubUnitPtr::dynamicCast(unit);
873 subUnits.emplace_back(std::move(rsu));
875 units.emplace_back(std::move(unit));
879 Units::_icePropertiesInitialized()
883 const std::string& configDomain =
"ArmarX";
887 const std::string configNameTCPControlUnit =
890 properties, configNameTCPControlUnit, configDomain);
897 const std::string configNameTrajectoryControllerUnit =
899 const std::string confPre =
900 configDomain +
"." + configNameTrajectoryControllerUnit +
".";
901 properties->setProperty(confPre +
"KinematicUnitName",
903 trajectoryControllerSubUnit =
905 properties, configNameTrajectoryControllerUnit, configDomain);
906 addPropertyUser(PropertyUserPtr::dynamicCast(trajectoryControllerSubUnit));
911 Units::_preFinishRunning()
924 Units::_preOnInitRobotUnit()
930 emergencyStopMaster =
new RobotUnitEmergencyStopMaster{
937 auto prx = obj->getProxy(-1);
940 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->addObject(
943 catch (
const IceGrid::ObjectExistsException&)
945 getArmarXManager()->getIceManager()->getIceGridSession()->getAdmin()->updateObject(
948 catch (std::exception& e)
950 ARMARX_WARNING <<
"add the robot unit as emergency stop master to the ice grid "
951 "admin!\nThere was an exception:\n"
959 Units::_postOnExitRobotUnit()
966 ManagedIceObjectPtr::dynamicCast(emergencyStopMaster));
983 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