Go to the documentation of this file.
31 #include <VirtualRobot/VirtualRobot.h>
36 #include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
39 #include <RobotAPI/interface/units/RobotUnit/NJointController.h>
43 class DebugDrawerInterface;
44 class DebugObserverInterface;
45 class RobotUnitInterface;
50 namespace RobotUnitModule
52 class NJointControllerAttorneyForPublisher;
53 class NJointControllerAttorneyForControlThread;
54 class NJointControllerAttorneyForControllerManagement;
64 namespace WidgetDescription
67 typedef ::IceInternal::Handle<::armarx::WidgetDescription::Widget>
WidgetPtr;
68 typedef ::std::map<::std::string, ::armarx::WidgetDescription::WidgetPtr>
79 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface>
81 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface>
83 typedef ::IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface>
579 virtual public NJointControllerInterface,
589 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
590 const std::map<std::string, ConstSensorDevicePtr>& sensorDevices);
591 template <
class ConfigPrtType>
622 const std::string& controlMode);
637 "The given type does not derive ControlTargetBase");
639 return dynamic_cast<T*
>(ptr);
661 "The given type does not derive SensorValueBase");
663 return dynamic_cast<const T*
>(ptr);
751 template <
typename Task>
753 runTask(
const std::string& taskName, Task&& task)
759 ARMARX_VERBOSE <<
"Adding NJointControllerBase task named '" << taskName
760 <<
"' - current available thread count: "
764 <<
"Could not add task (" << taskName <<
" - " <<
GetTypeString(task)
765 <<
" ) - available threads: " <<
getThreadPool()->getAvailableTaskCount();
789 isDeletable(
const Ice::Current& = Ice::emptyCurrent)
const final override
797 return deactivatedBecauseOfError;
800 std::string
getClassName(
const Ice::Current& = Ice::emptyCurrent)
const override = 0;
805 return instanceName_;
808 NJointControllerDescription
810 NJointControllerStatus
813 const Ice::Current& = Ice::emptyCurrent)
const final override;
818 void deleteController(
const Ice::Current& = Ice::emptyCurrent)
final override;
830 const Ice::Current& = Ice::emptyCurrent)
override
856 const std::vector<VirtualRobot::RobotNodePtr>&
872 return controlDeviceUsedBitmap.at(deviceIndex);
881 const std::vector<std::size_t>&
884 return controlDeviceUsedIndices;
903 return controlDeviceUsedIndices.size();
923 return instanceName_;
951 errorState.store(
true);
963 void rtActivateController();
972 void rtDeactivateController();
984 void rtDeactivateControllerBecauseOfError();
1000 StringStringDictionary
1002 const Ice::Current& = Ice::emptyCurrent)
const final override
1004 return controlDeviceControlModeMap;
1007 const std::vector<char>&
1010 return controlDeviceUsedBitmap;
1013 const std::vector<std::size_t>&
1016 return controlDeviceUsedIndices;
1019 const std::map<std::string, const JointController*>&
1022 return controlDeviceUsedJointController;
1026 std::optional<std::vector<char>>
1032 std::optional<std::vector<char>>
isNotInConflictWith(
const std::vector<char>& used)
const;
1034 template <
class ItT>
1035 static std::optional<std::vector<char>>
1040 return std::vector<char>{};
1042 std::size_t n = (*first)->getControlDeviceUsedBitmap().size();
1043 std::vector<char> inuse(n,
false);
1044 while (first != last)
1046 auto r = (*first)->isNotInConflictWith(inuse);
1051 inuse = std::move(*r);
1092 StringStringDictionary controlDeviceControlModeMap;
1094 std::map<std::string, const JointController*> controlDeviceUsedJointController;
1096 std::vector<char> controlDeviceUsedBitmap;
1098 std::vector<std::size_t> controlDeviceUsedIndices;
1100 std::string rtClassName_;
1101 std::string instanceName_;
1104 std::atomic_bool isActive{
false};
1105 std::atomic_bool isRequested{
false};
1106 std::atomic_bool deactivatedBecauseOfError{
false};
1107 std::atomic_bool errorState{
false};
1108 bool deletable{
false};
1109 bool internal{
false};
1111 std::atomic_bool publishActive{
false};
1113 std::atomic_bool statusReportedActive{
false};
1114 std::atomic_bool statusReportedRequested{
false};
1117 std::vector<VirtualRobot::RobotNodePtr> rtRobotNodes;
1155 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