Go to the documentation of this file.
30 #include <VirtualRobot/VirtualRobot.h>
35 #include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
39 #include <RobotAPI/interface/units/RobotUnit/NJointController.h>
40 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
44 class DebugDrawerInterface;
45 class DebugObserverInterface;
46 class RobotUnitInterface;
51 namespace RobotUnitModule
53 class NJointControllerAttorneyForPublisher;
54 class NJointControllerAttorneyForControlThread;
55 class NJointControllerAttorneyForControllerManagement;
65 namespace WidgetDescription
68 typedef ::IceInternal::Handle<::armarx::WidgetDescription::Widget>
WidgetPtr;
69 typedef ::std::map<::std::string, ::armarx::WidgetDescription::WidgetPtr>
80 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface>
82 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface>
84 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface>
580 virtual public NJointControllerInterface,
590 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
591 const std::map<std::string, ConstSensorDevicePtr>& sensorDevices);
592 template <
class ConfigPrtType>
623 const std::string& controlMode);
638 "The given type does not derive ControlTargetBase");
640 return dynamic_cast<T*
>(ptr);
662 "The given type does not derive SensorValueBase");
664 return dynamic_cast<const T*
>(ptr);
752 template <
typename Task>
754 runTask(
const std::string& taskName, Task&& task)
760 ARMARX_VERBOSE <<
"Adding NJointControllerBase task named '" << taskName
761 <<
"' - current available thread count: "
765 <<
"Could not add task (" << taskName <<
" - " <<
GetTypeString(task)
766 <<
" ) - available threads: " <<
getThreadPool()->getAvailableTaskCount();
790 isDeletable(
const Ice::Current& = Ice::emptyCurrent)
const final override
798 return deactivatedBecauseOfError;
801 std::string
getClassName(
const Ice::Current& = Ice::emptyCurrent)
const override = 0;
806 return instanceName_;
809 NJointControllerDescription
811 NJointControllerStatus
814 const Ice::Current& = Ice::emptyCurrent)
const final override;
819 void deleteController(
const Ice::Current& = Ice::emptyCurrent)
final override;
831 const Ice::Current& = Ice::emptyCurrent)
override
857 const std::vector<VirtualRobot::RobotNodePtr>&
873 return controlDeviceUsedBitmap.at(deviceIndex);
882 const std::vector<std::size_t>&
885 return controlDeviceUsedIndices;
904 return controlDeviceUsedIndices.size();
924 return instanceName_;
952 errorState.store(
true);
964 void rtActivateController();
973 void rtDeactivateController();
985 void rtDeactivateControllerBecauseOfError();
1001 StringStringDictionary
1003 const Ice::Current& = Ice::emptyCurrent)
const final override
1005 return controlDeviceControlModeMap;
1008 const std::vector<char>&
1011 return controlDeviceUsedBitmap;
1014 const std::vector<std::size_t>&
1017 return controlDeviceUsedIndices;
1020 const std::map<std::string, const JointController*>&
1023 return controlDeviceUsedJointController;
1027 std::optional<std::vector<char>>
1033 std::optional<std::vector<char>>
isNotInConflictWith(
const std::vector<char>& used)
const;
1035 template <
class ItT>
1036 static std::optional<std::vector<char>>
1041 return std::vector<char>{};
1043 std::size_t n = (*first)->getControlDeviceUsedBitmap().size();
1044 std::vector<char> inuse(n,
false);
1045 while (first != last)
1047 auto r = (*first)->isNotInConflictWith(inuse);
1052 inuse = std::move(*r);
1093 StringStringDictionary controlDeviceControlModeMap;
1095 std::map<std::string, const JointController*> controlDeviceUsedJointController;
1097 std::vector<char> controlDeviceUsedBitmap;
1099 std::vector<std::size_t> controlDeviceUsedIndices;
1101 std::string rtClassName_;
1102 std::string instanceName_;
1105 std::atomic_bool isActive{
false};
1106 std::atomic_bool isRequested{
false};
1107 std::atomic_bool deactivatedBecauseOfError{
false};
1108 std::atomic_bool errorState{
false};
1109 bool deletable{
false};
1110 bool internal{
false};
1112 std::atomic_bool publishActive{
false};
1114 std::atomic_bool statusReportedActive{
false};
1115 std::atomic_bool statusReportedRequested{
false};
1118 std::vector<VirtualRobot::RobotNodePtr> rtRobotNodes;
1156 rtRun(sensorValuesTimestamp, timeSinceLastIteration);
T * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
virtual void rtRunIterationBegin(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
TODO make protected and use attorneys.
ConstSensorDevicePtr peekSensorDevice(const std::string &deviceName) const
Get a const ptr to the given SensorDevice.
const std::string & rtGetInstanceName() const
Returns the instance name.
~NJointControllerBase() override
std::string getInstanceName(const Ice::Current &=Ice::emptyCurrent) const final override
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
void deactivateController(const Ice::Current &=Ice::emptyCurrent) final override
std::map< std::string, VariantBasePtr > StringVariantBaseMap
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
The SensorValueBase class.
void activateController(const Ice::Current &=Ice::emptyCurrent) final override
void onInitComponent() final
Brief description of class JointControlTargetBase.
std::map< std::string, std::shared_ptr< ThreadPool::Handle > > threadHandles
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
const std::map< std::string, const JointController * > & getControlDevicesUsedJointController()
const std::vector< VirtualRobot::RobotNodePtr > & rtGetRobotNodes()
Returns the nodes of the virtual robot used by this NJointControllerBase in the rtRun.
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override=0
virtual void onDisconnectNJointController()
void onDisconnectComponent() final
std::mutex threadHandlesMutex
int getState() const
Retrieve current state of the ManagedIceObject.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
StringStringDictionary getControlDeviceUsedControlModeMap(const Ice::Current &=Ice::emptyCurrent) const final override
void onExitComponent() final
The JointController class represents one joint in one control mode.
NJointControllerDescription getControllerDescription(const Ice::Current &=Ice::emptyCurrent) const final override
This class allows minimal access to private members of NJointControllerBase in a sane fashion for Con...
virtual void onPublishDeactivation(const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
virtual void onConnectNJointController()
NJointControllerConfigPtr ConfigPtrT
void callDescribedFunction(const std::string &, const StringVariantBaseMap &, const Ice::Current &=Ice::emptyCurrent) override
ConfigPrtType(*)(const StringVariantBaseMap &) GenerateConfigFromVariantsFunctionSignature
std::optional< std::vector< char > > isNotInConflictWith(const NJointControllerBasePtr &other) const
std::size_t rtGetNumberOfUsedControlDevices() const
Returns the number of used ControlDevices.
const std::string & rtGetClassName() const
Returns the class name.
static const NJointControllerBasePtr NullPtr
virtual void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
TODO make protected and use attorneys.
std::shared_ptr< ThreadPool > ThreadPoolPtr
virtual void onPublishActivation(const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
NJointControllerDescriptionWithStatus getControllerDescriptionWithStatus(const Ice::Current &=Ice::emptyCurrent) const final override
void onConnectComponent() final
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
This class allows minimal access to private members of NJointControllerBase in a sane fashion for Con...
std::shared_ptr< Value > value()
void deactivateAndDeleteController(const Ice::Current &=Ice::emptyCurrent) final override
virtual void rtSwapBufferAndRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
virtual void rtPostDeactivateController()
This function is called after the controller is deactivated.
bool rtUsesControlDevice(std::size_t deviceIndex) const
Returns whether this NJointControllerBase calculates a ControlTarget for the given ControlDevice.
This class allows minimal access to private members of NJointControllerBase in a sane fashion for Pub...
bool isControllerActive(const Ice::Current &=Ice::emptyCurrent) const final override
const T * useSensorValue(const std::string &deviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
bool isDeletable(const Ice::Current &=Ice::emptyCurrent) const final override
ThreadPoolPtr getThreadPool() const
void runTask(const std::string &taskName, Task &&task)
Executes a given task in a separate thread from the Application ThreadPool.
WidgetDescription::StringWidgetDictionary getFunctionDescriptions(const Ice::Current &=Ice::emptyCurrent) const override
NJointControllerStatus getControllerStatus(const Ice::Current &=Ice::emptyCurrent) const final override
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
bool rtGetErrorState() const
Sets the error state to true.
virtual void onExitNJointController()
ConstControlDevicePtr peekControlDevice(const std::string &deviceName) const
Get a const ptr to the given ControlDevice.
armarx::core::time::DateTime Time
void deleteController(const Ice::Current &=Ice::emptyCurrent) final override
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
virtual void rtRunIterationEnd(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
WidgetDescription::WidgetPtr(*)(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &controlDevices, const std::map< std::string, ConstSensorDevicePtr > &sensorDevices) GenerateConfigDescriptionFunctionSignature
The ManagedIceObject is the base class for all ArmarX objects.
virtual void rtPreActivateController()
This function is called before the controller is activated.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
SynchronousNJointControllerPtr NJointControllerPtr
A high level controller writing its results into ControlTargets.
The RobotUnit class manages a robot and its controllers.
void rtSetErrorState()
Sets the error state to true.
const std::vector< std::size_t > & rtGetControlDeviceUsedIndices() const
Returns the indices of all ControlDevice's this NJointControllerBase calculates a ControlTarget for.
virtual void onInitNJointController()
std::shared_ptr< const class SensorDevice > ConstSensorDevicePtr
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface > RobotUnitInterfacePrx
bool hasControllerError(const Ice::Current &=Ice::emptyCurrent) const final override
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
static std::optional< std::vector< char > > AreNotInConflict(ItT first, ItT last)
const std::vector< std::size_t > & getControlDeviceUsedIndices() const
std::shared_ptr< const class ControlDevice > ConstControlDevicePtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
std::shared_ptr< class Robot > RobotPtr
std::string getDefaultName() const override
bool isControllerRequested(const Ice::Current &=Ice::emptyCurrent) const final override
const std::vector< char > & getControlDeviceUsedBitmap() const