From 1749c7f8c15867db46cc87f9489db6976424890f Mon Sep 17 00:00:00 2001 From: Raphael Grimm <raphael.grimm@kit.edu> Date: Fri, 13 Sep 2019 22:59:28 +0200 Subject: [PATCH] Add AsynchronousNJointController * The old controllers are called SynchronousNJointController * Added the common base class NJointControllerBase * AsynchronousNJointController provides rtRunIterationBegin and rtRunIterationEnd. The former is called before and the second after all SynchronousNJointController are executed --- .../NJointControllers/NJointController.cpp | 58 ++--- .../NJointControllers/NJointController.h | 145 ++++++----- .../NJointControllers/NJointController.ipp | 60 ++--- .../components/units/RobotUnit/RobotUnit.h | 6 +- .../RobotUnitModules/RobotUnitModuleBase.h | 2 +- .../RobotUnitModuleControlThread.cpp | 224 ++++++++++++++--- .../RobotUnitModuleControlThread.h | 52 ++-- ...RobotUnitModuleControlThreadDataBuffer.cpp | 26 +- .../RobotUnitModuleControlThreadDataBuffer.h | 56 ++--- .../RobotUnitModuleControllerManagement.cpp | 106 ++++---- .../RobotUnitModuleControllerManagement.h | 228 +++++++++--------- .../RobotUnitModules/RobotUnitModuleDevices.h | 10 +- .../RobotUnitModulePublisher.cpp | 20 +- .../RobotUnitModulePublisher.h | 16 +- .../RobotUnitModules/RobotUnitModuleUnits.cpp | 10 +- .../units/RobotUnit/SyntaxCheck.cpp | 102 -------- .../RobotUnit/Units/KinematicSubUnit.cpp | 6 +- .../RobotUnit/Units/TCPControllerSubUnit.cpp | 4 +- .../Units/TrajectoryControllerSubUnit.cpp | 2 +- .../util/JointAndNJointControllers.h | 4 +- 20 files changed, 610 insertions(+), 527 deletions(-) diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp index 86911d7e4..dedc38b46 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp @@ -35,12 +35,12 @@ namespace armarx { /** - * \brief This class allows minimal access to private members of \ref armarx::RobotUnitModule::Devices in a sane fashion for \ref armarx::NJointController. + * \brief This class allows minimal access to private members of \ref armarx::RobotUnitModule::Devices in a sane fashion for \ref armarx::NJointControllerBase. * \warning !! DO NOT ADD ANYTHING IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ class DevicesAttorneyForNJointController { - friend class ::armarx::NJointController; + friend class ::armarx::NJointControllerBase; static JointController* GetJointController(Devices& d, const std::string& deviceName, const std::string& controlMode) { if (d.controlDevices.has(deviceName)) @@ -64,12 +64,12 @@ thread_local bool armarx::NJointControllerRegistryEntry::ConstructorIsRunning_ = namespace armarx { - const NJointControllerPtr NJointController::NullPtr + const NJointControllerBasePtr NJointControllerBase::NullPtr { nullptr }; - NJointControllerDescription NJointController::getControllerDescription(const Ice::Current&) const + NJointControllerDescription NJointControllerBase::getControllerDescription(const Ice::Current&) const { NJointControllerDescription d; d.className = getClassName(); @@ -82,7 +82,7 @@ namespace armarx return d; } - boost::optional<std::vector<char> > NJointController::isNotInConflictWith(const std::vector<char>& used) const + boost::optional<std::vector<char> > NJointControllerBase::isNotInConflictWith(const std::vector<char>& used) const { ARMARX_CHECK_EXPRESSION(used.size() == controlDeviceUsedBitmap.size()); auto result = used; @@ -101,7 +101,7 @@ namespace armarx return {true, std::move(result)}; } - NJointControllerStatus NJointController::getControllerStatus(const Ice::Current&) const + NJointControllerStatus NJointControllerBase::getControllerStatus(const Ice::Current&) const { NJointControllerStatus s; s.active = isActive; @@ -112,7 +112,7 @@ namespace armarx return s; } - NJointControllerDescriptionWithStatus NJointController::getControllerDescriptionWithStatus(const Ice::Current&) const + NJointControllerDescriptionWithStatus NJointControllerBase::getControllerDescriptionWithStatus(const Ice::Current&) const { NJointControllerDescriptionWithStatus ds; ds.description = getControllerDescription(); @@ -120,31 +120,31 @@ namespace armarx return ds; } - RobotUnitInterfacePrx NJointController::getRobotUnit(const Ice::Current&) const + RobotUnitInterfacePrx NJointControllerBase::getRobotUnit(const Ice::Current&) const { return RobotUnitInterfacePrx::uncheckedCast(robotUnit.getProxy(-1)); } - void NJointController::activateController(const Ice::Current&) + void NJointControllerBase::activateController(const Ice::Current&) { robotUnit.activateNJointController(this); } - void NJointController::deactivateController(const Ice::Current&) + void NJointControllerBase::deactivateController(const Ice::Current&) { robotUnit.deactivateNJointController(this); } - void NJointController::deleteController(const Ice::Current&) + void NJointControllerBase::deleteController(const Ice::Current&) { robotUnit.deleteNJointController(this); } - void NJointController::deactivateAndDeleteController(const Ice::Current&) + void NJointControllerBase::deactivateAndDeleteController(const Ice::Current&) { robotUnit.deactivateAndDeleteNJointController(this); } - void NJointController::publish(const SensorAndControl& sac, const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) + void NJointControllerBase::publish(const SensorAndControl& sac, const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) { const bool active = isActive; if (publishActive.exchange(active) != active) @@ -199,7 +199,7 @@ namespace armarx } } - void NJointController::deactivatePublish(const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) + void NJointControllerBase::deactivatePublish(const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) { if (publishActive.exchange(false)) { @@ -208,7 +208,7 @@ namespace armarx } } - void NJointController::rtActivateController() + void NJointControllerBase::rtActivateController() { if (!isActive) { @@ -219,7 +219,7 @@ namespace armarx } } - void NJointController::rtDeactivateController() + void NJointControllerBase::rtDeactivateController() { if (isActive) { @@ -228,13 +228,13 @@ namespace armarx } } - void NJointController::rtDeactivateControllerBecauseOfError() + void NJointControllerBase::rtDeactivateControllerBecauseOfError() { deactivatedBecauseOfError = true; rtDeactivateController(); } - armarx::ConstSensorDevicePtr armarx::NJointController::peekSensorDevice(const std::string& deviceName) const + armarx::ConstSensorDevicePtr armarx::NJointControllerBase::peekSensorDevice(const std::string& deviceName) const { ARMARX_CHECK_EXPRESSION_W_HINT( NJointControllerRegistryEntry::ConstructorIsRunning(), @@ -243,7 +243,7 @@ namespace armarx return RobotUnitModule::Devices::Instance().getSensorDevice(deviceName); } - ConstControlDevicePtr NJointController::peekControlDevice(const std::string& deviceName) const + ConstControlDevicePtr NJointControllerBase::peekControlDevice(const std::string& deviceName) const { ARMARX_CHECK_EXPRESSION_W_HINT( NJointControllerRegistryEntry::ConstructorIsRunning(), @@ -252,7 +252,7 @@ namespace armarx return RobotUnitModule::Devices::Instance().getControlDevice(deviceName); } - const VirtualRobot::RobotPtr& NJointController::useSynchronizedRtRobot(bool updateCollisionModel) + const VirtualRobot::RobotPtr& NJointControllerBase::useSynchronizedRtRobot(bool updateCollisionModel) { ARMARX_CHECK_EXPRESSION_W_HINT( NJointControllerRegistryEntry::ConstructorIsRunning(), @@ -264,22 +264,22 @@ namespace armarx return rtRobot; } - void NJointController::onInitComponent() + void NJointControllerBase::onInitComponent() { onInitNJointController(); } - void NJointController::onConnectComponent() + void NJointControllerBase::onConnectComponent() { onConnectNJointController(); } - void NJointController::onDisconnectComponent() + void NJointControllerBase::onDisconnectComponent() { onDisconnectNJointController(); } - void NJointController::onExitComponent() + void NJointControllerBase::onExitComponent() { onExitNJointController(); // make sure the destructor of the handles does not throw an exception and triggers a termination of the process @@ -327,14 +327,14 @@ namespace armarx threadHandles.clear(); } - ThreadPoolPtr NJointController::getThreadPool() const + ThreadPoolPtr NJointControllerBase::getThreadPool() const { ARMARX_CHECK_EXPRESSION(Application::getInstance()); return Application::getInstance()->getThreadPool(); } - const SensorValueBase* NJointController::useSensorValue(const std::string& deviceName) const + const SensorValueBase* NJointControllerBase::useSensorValue(const std::string& deviceName) const { ARMARX_CHECK_EXPRESSION_W_HINT( NJointControllerRegistryEntry::ConstructorIsRunning(), @@ -349,18 +349,18 @@ namespace armarx return dev->getSensorValue(); } - NJointController::NJointController() : + NJointControllerBase::NJointControllerBase() : robotUnit(RobotUnitModule::ModuleBase::Instance< ::armarx::RobotUnit>()), controlDeviceUsedBitmap(robotUnit.getNumberOfControlDevices(), 0) { controlDeviceUsedIndices.reserve(robotUnit.getNumberOfControlDevices()); } - NJointController::~NJointController() + NJointControllerBase::~NJointControllerBase() { } - ControlTargetBase* NJointController::useControlTarget(const std::string& deviceName, const std::string& controlMode) + ControlTargetBase* NJointControllerBase::useControlTarget(const std::string& deviceName, const std::string& controlMode) { ARMARX_CHECK_EXPRESSION_W_HINT( NJointControllerRegistryEntry::ConstructorIsRunning(), diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h index 95ce73190..7bb3d4620 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h @@ -76,7 +76,9 @@ namespace armarx { using ThreadPoolPtr = std::shared_ptr<class ThreadPool>; - TYPEDEF_PTRS_HANDLE(NJointController); + TYPEDEF_PTRS_HANDLE(NJointControllerBase); + TYPEDEF_PTRS_HANDLE(SynchronousNJointController); + TYPEDEF_PTRS_HANDLE(AsynchronousNJointController); TYPEDEF_PTRS_HANDLE(RobotUnit); @@ -91,40 +93,40 @@ namespace armarx * * This is the abstract base class for all NJointControllers. * It implements basic management routines required by the RobotUnit and some basic ice calls. - * \ref NJointController "NJointControllers" are instantiated and managed by the \ref RobotUnit. + * \ref NJointControllerBase "NJointControllers" are instantiated and managed by the \ref RobotUnit. * - * A \ref NJointController calculates \ref ControlTargetBase "ControlTargets" for a set of + * A \ref NJointControllerBase calculates \ref ControlTargetBase "ControlTargets" for a set of * \ref ControlDevice "ControlDevices" in a specific ControlMode. * This ControlMode is defined for each \ref ControlDevice during construction. * * \section nj-state Requested and Active - * A \ref NJointController can is requested / not requested and active / inactive. + * A \ref NJointControllerBase can is requested / not requested and active / inactive. * All four combinations are possible. * * \subsection nj-state-req Requested / Not Requested - * If the user wants this \ref NJointController to be executed it is in a requested state (see \ref isControllerRequested). + * If the user wants this \ref NJointControllerBase to be executed it is in a requested state (see \ref isControllerRequested). * Otherwise the controler is not requested. * * Calling \ref activateController sets the state to requested. * Calling \ref deactivateController sets the state to not requested. - * If the \ref NJointController causes an error or a different \ref NJointController using one or more of the same - * \ref ControlDevice's is requested, this \ref NJointController is deactivated. + * If the \ref NJointControllerBase causes an error or a different \ref NJointControllerBase using one or more of the same + * \ref ControlDevice's is requested, this \ref NJointControllerBase is deactivated. * * * \subsection nj-state-act Active / Inactive - * Is the \ref NJointController executed by the \ref RobotUnitModules::ControlThread "ControlThread" it is active + * Is the \ref NJointControllerBase executed by the \ref RobotUnitModules::ControlThread "ControlThread" it is active * (see \ref isControllerActive). * - * To be executed by the \ref RobotUnitModules::ControlThread "ControlThread", the \ref NJointController has to be + * To be executed by the \ref RobotUnitModules::ControlThread "ControlThread", the \ref NJointControllerBase has to be * requested at some point in the past. * * If a controller is active, it has to write a valid \ref ControlTargetBase "ControlTarget" * for each of its \ref ControlDevice "ControlDevicea" (if it fails, it will be deactivated). * * \section Constructor - * In the Constructor, a \ref NJointController has to declare all \ref ControlDevice "ControlDevices" it uses. + * In the Constructor, a \ref NJointControllerBase has to declare all \ref ControlDevice "ControlDevices" it uses. * - * The constructor takes a pointer to a configuration structure of the type \ref NJointController::ConfigPtrT. + * The constructor takes a pointer to a configuration structure of the type \ref NJointControllerBase::ConfigPtrT. * If an implementation requires a special configuration structure (e.g.: SomeOtherCfg), it has to override this type by calling adding * \code{.cpp} * using ConfigPtrT = SomeOtherCfgPtr; @@ -135,19 +137,19 @@ namespace armarx * There is a way to generate a small gui widget for controller construction (see this \ref nj-ctor-gui "section"). * * \subsection nj-ctor-req-ctrl Using ControlTargets - * A \ref NJointController can use \ref peekControlDevice to examine a \ref ControlDevice before using it + * A \ref NJointControllerBase can use \ref peekControlDevice to examine a \ref ControlDevice before using it * (e.g.: checking the supported \ref ControlTargetBase "ControlTargets"). * - * If a \ref ControlDevice should be used by this \ref NJointController, it has to call \ref useControlDevice. + * If a \ref ControlDevice should be used by this \ref NJointControllerBase, it has to call \ref useControlDevice. * This sets the ControlMode for the \ref ControlDevice and returns a pointer to the \ref ControlTargetBase "ControlTarget". * This pointer has to be used to send commands in each iteration of \ref rtRun. - * The ControlMode can't be changed afterwards (A new \ref NJointController has to be created). + * The ControlMode can't be changed afterwards (A new \ref NJointControllerBase has to be created). * * * \subsection nj-ctor-req-sens Using SensorValues - * A \ref NJointController can use \ref peekSensorDevice to examine a \ref SensorDevice before using it. + * A \ref NJointControllerBase can use \ref peekSensorDevice to examine a \ref SensorDevice before using it. * - * If a \ref SensorDevice should be used by this \ref NJointController, it has to call \ref useSensorDevice. + * If a \ref SensorDevice should be used by this \ref NJointControllerBase, it has to call \ref useSensorDevice. * This returns a pointer to the \ref SensorValueBase "SensorValue". * * \subsection nj-ctor-rob A synchronized Virtualrobot @@ -156,15 +158,15 @@ namespace armarx * This robot is synchronized with the real robots state before calling \ref rtRun * * \section nj-parts Rt and non Rt - * Each \ref NJointController has two parts: + * Each \ref NJointControllerBase has two parts: * \li The RT controll loop * \li The NonRT ice communication * * \subsection rtcontrollloop The Rt controll loop (\ref rtRun) * \warning This part has to satisfy realtime conditions! - * All realtime functions of \ref NJointController have the 'rt' prefix. + * All realtime functions of \ref NJointControllerBase have the 'rt' prefix. * - * Here the \ref NJointController has access to the robot's current state + * Here the \ref NJointControllerBase has access to the robot's current state * and has to write results into \ref ControlTargetBase "ControlTargets". * * It must not: @@ -178,21 +180,21 @@ namespace armarx * * \subsection nonrtpart The NonRT ice communication * This part consits of any ice communication. - * Here the \ref NJointController can get new controll parameters or targets from other components. + * Here the \ref NJointControllerBase can get new controll parameters or targets from other components. * * \section rtnrtcomm Communication between RT and NonRT * All communication between RT and NonRT has to be lockfree. - * The \ref NJointController has to use constructs like atomics or + * The \ref NJointControllerBase has to use constructs like atomics or * \ref TripleBuffer "TripleBuffers" (See \ref armarx::NJointControllerWithTripleBuffer). * - * \image html NJointControllerGeneralDataFlow.svg "General Dataflow in a NJointController" + * \image html NJointControllerGeneralDataFlow.svg "General Dataflow in a NJointControllerBase" * - * \image html NJointControllerAtomicDataFlow.svg "Dataflow in a NJointController using atomics for communication between RT and NonRT" + * \image html NJointControllerAtomicDataFlow.svg "Dataflow in a NJointControllerBase using atomics for communication between RT and NonRT" * - * \image html NJointControllerTripleBufferDataFlow.svg "Dataflow in a NJointController using a triple buffer for communication between RT and NonRT" + * \image html NJointControllerTripleBufferDataFlow.svg "Dataflow in a NJointControllerBase using a triple buffer for communication between RT and NonRT" * * - * \image html NJointControllerDataFlow_Graph.svg "Dataflow in a NJointController as a Graph of the two participating domains" + * \image html NJointControllerDataFlow_Graph.svg "Dataflow in a NJointControllerBase as a Graph of the two participating domains" * The above image shows the two participating domains: one RT thread and multiple ICE threads. * If data has to flow along an arrow, you need some construct for non blocking message passing. * @@ -210,9 +212,9 @@ namespace armarx * * If you do some additional calculation in rtRun, you maybe need to pass config parameters from NonRT to RT using a nonblocking method. * - * \image html NJointControllerWorkerThreadDataFlow.svg "Dataflow in a NJointController using a worker thread" + * \image html NJointControllerWorkerThreadDataFlow.svg "Dataflow in a NJointControllerBase using a worker thread" * - * \image html NJointControllerWorkerThreadDataFlow_Graph.svg "Dataflow in a NJointController using a worker thread as a Graph of the three participating domains" + * \image html NJointControllerWorkerThreadDataFlow_Graph.svg "Dataflow in a NJointControllerBase using a worker thread as a Graph of the three participating domains" * The above image shows the three participating domains: one RT thread, one worker trhead and multiple ICE threads. * If data has to flow along an arrow, you need some construct for non blocking message passing. * @@ -230,7 +232,7 @@ namespace armarx static ConfigPtrT GenerateConfigFromVariants(const StringVariantBaseMap&); // turns the resulting variants into a config * \endcode * - * The \ref RobotUnitGui will provide a widget to configure and construct a \ref NJointController of this type. + * The \ref RobotUnitGui will provide a widget to configure and construct a \ref NJointControllerBase of this type. * * \section Examples * @@ -269,14 +271,14 @@ namespace armarx }; * \endcode * - * The controller class has to inherit \ref NJointController + * The controller class has to inherit \ref NJointControllerBase * \code{.cpp} - class NJointPositionPassThroughController: public NJointController + class NJointPositionPassThroughController: public NJointControllerBase { public: * \endcode * - * The \ref NJointController provides a config widget for the \ref RobotUnitGuiPlugin + * The \ref NJointControllerBase provides a config widget for the \ref RobotUnitGuiPlugin * \code{.cpp} static WidgetDescription::WidgetPtr GenerateConfigDescription ( @@ -312,14 +314,14 @@ namespace armarx void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override; * \endcode * - * Hooks for this \ref NJointController to execute code during publishing. + * Hooks for this \ref NJointControllerBase to execute code during publishing. * \code{.cpp} void onPublishActivation(const DebugDrawerInterfacePrx&, const DebugObserverInterfacePrx&) override; void onPublishDeactivation(const DebugDrawerInterfacePrx& drawer, const DebugObserverInterfacePrx&) override; void onPublish(const SensorAndControl&, const DebugDrawerInterfacePrx& drawer, const DebugObserverInterfacePrx&) override; * \endcode * - * This \ref NJointController uses one position \ref SensorValue1DoFActuatorPosition "SensorValue", calculates one + * This \ref NJointControllerBase uses one position \ref SensorValue1DoFActuatorPosition "SensorValue", calculates one * position \ref ControlTarget1DoFActuatorPosition "ControlTarget" and stores the current position target and position value in atomics. * \code{.cpp} const SensorValue1DoFActuatorPosition* sensor; @@ -387,7 +389,7 @@ namespace armarx } * \endcode * - * This turns a map of variants into the config required by this \ref NJointController. + * This turns a map of variants into the config required by this \ref NJointControllerBase. * The \ref Variant for the key 'name' defines the \ref ControlDevice. * \code{.cpp} NJointControllerConfigPtr NJointPositionPassThroughController::GenerateConfigFromVariants(const StringVariantBaseMap& values) @@ -435,7 +437,7 @@ namespace armarx * \endcode * - * This \ref NJointController provides two widgets for function calls. + * This \ref NJointControllerBase provides two widgets for function calls. * \code{.cpp} WidgetDescription::StringWidgetDictionary NJointPositionPassThroughController::getFunctionDescriptions(const Ice::Current&) const { @@ -547,8 +549,8 @@ namespace armarx } * \endcode * - * This registers a factory for this \ref NJointController. - * This factory is used by the \ref RobotUnit to create the \ref NJointController. + * This registers a factory for this \ref NJointControllerBase. + * This factory is used by the \ref RobotUnit to create the \ref NJointControllerBase. * The passed name has to match the name returned by \ref getClassName. * \code{.cpp} NJointControllerRegistration<NJointPositionPassThroughController> registrationControllerNJointPositionPassThroughController("NJointPositionPassThroughController"); @@ -563,7 +565,7 @@ namespace armarx } * \endcode */ - class NJointController: + class NJointControllerBase: virtual public NJointControllerInterface, virtual public ManagedIceObject { @@ -586,14 +588,14 @@ namespace armarx public: /** * @brief Get a const ptr to the given \ref SensorDevice - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref SensorDevice's name * @return A const ptr to the given \ref SensorDevice */ ConstSensorDevicePtr peekSensorDevice(const std::string& deviceName) const; /** * @brief Get a const ptr to the given \ref ControlDevice - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref ControlDevice's name * @return A const ptr to the given \ref ControlDevice */ @@ -602,7 +604,7 @@ namespace armarx /** * @brief Declares to calculate the \ref ControlTargetBase "ControlTarget" * for the given \ref ControlDevice in the given ControlMode when \ref rtRun is called - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref ControlDevice's name * @param controlMode The \ref ControlTargetBase "ControlTarget's" ControlMode * @return A ptr to the given \ref ControlDevice's \ref ControlTargetBase "ControlTarget"in the given ControlMode @@ -611,7 +613,7 @@ namespace armarx /** * @brief Declares to calculate the \ref ControlTargetBase "ControlTarget" * for the given \ref ControlDevice in the given ControlMode when \ref rtRun is called - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref ControlDevice's name * @param controlMode The \ref ControlTargetBase "ControlTarget's" ControlMode * @return A ptr to the given \ref ControlDevice's \ref ControlTargetBase "ControlTarget"in the given ControlMode @@ -621,14 +623,14 @@ namespace armarx /** * @brief Get a const ptr to the given \ref SensorDevice's \ref SensorValueBase "SensorValue" - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref SensorDevice's name * @return A const ptr to the given \ref SensorDevice's \ref SensorValueBase "SensorValue" */ const SensorValueBase* useSensorValue(const std::string& sensorDeviceName) const; /** * @brief Get a const ptr to the given \ref SensorDevice's \ref SensorValueBase "SensorValue" - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * @param deviceName The \ref SensorDevice's name * @return A const ptr to the given \ref SensorDevice's \ref SensorValueBase "SensorValue" */ @@ -638,7 +640,7 @@ namespace armarx /** * @brief Requests a VirtualRobot for use in \ref rtRun * * - * \warning This function can only be called in a \ref NJointController's ctor (or functions called in it) + * \warning This function can only be called in a \ref NJointControllerBase's ctor (or functions called in it) * * The robot is updated before \ref rtRun is called and can be accessed via \rtGetRobot * @param updateCollisionModel Whether the robot's collision model should be updated @@ -677,7 +679,7 @@ namespace armarx * @brief Executes a given task in a separate thread from the Application ThreadPool. * @param taskName Descriptive name of this task to identify it on errors. * @param task std::function object (or lambda) that is to be executed. - * @note This task will be joined in onExitComponent of the NJointController. So make sure it terminates, when the + * @note This task will be joined in onExitComponent of the NJointControllerBase. So make sure it terminates, when the * controller is deactivated or removed! * * @code{.cpp} @@ -708,7 +710,7 @@ namespace armarx ARMARX_CHECK_EXPRESSION(!taskName.empty()); ARMARX_CHECK_EXPRESSION(!threadHandles.count(taskName)); ARMARX_CHECK_EXPRESSION(getState() < eManagedIceObjectExiting); - ARMARX_VERBOSE << "Adding NJointController task named '" << taskName << "' - current available thread count: " << getThreadPool()->getAvailableTaskCount(); + ARMARX_VERBOSE << "Adding NJointControllerBase task named '" << taskName << "' - current available thread count: " << getThreadPool()->getAvailableTaskCount(); auto handlePtr = std::make_shared<ThreadPool::Handle>(getThreadPool()->runTask(task)); ARMARX_CHECK_EXPRESSION_W_HINT(handlePtr->isValid(), "Could not add task (" << taskName << " - " << GetTypeString(task) << " ) - available threads: " << getThreadPool()->getAvailableTaskCount()); threadHandles[taskName] = handlePtr; @@ -744,12 +746,10 @@ namespace armarx // ///////////////////////////////////// rt interface ///////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////// // public: ///TODO make protected and use attorneys - virtual void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) = 0; - virtual void rtSwapBufferAndRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration); /** - * @brief Returns the virtual robot used by this \ref NJointController in the \ref rtRun - * @return The virtual robot used by this \ref NJointController in the \ref rtRun + * @brief Returns the virtual robot used by this \ref NJointControllerBase in the \ref rtRun + * @return The virtual robot used by this \ref NJointControllerBase in the \ref rtRun * @see useSynchronizedRtRobot * @see rtGetRobotNodes */ @@ -758,8 +758,8 @@ namespace armarx return rtRobot; } /** - * @brief Returns the nodes of the virtual robot used by this \ref NJointController in the \ref rtRun - * @return The nodes of the virtual robot used by this \ref NJointController in the \ref rtRun + * @brief Returns the nodes of the virtual robot used by this \ref NJointControllerBase in the \ref rtRun + * @return The nodes of the virtual robot used by this \ref NJointControllerBase in the \ref rtRun * @see useSynchronizedRtRobot * @see rtGetRobot */ @@ -768,17 +768,17 @@ namespace armarx return rtRobotNodes; } /** - * @brief Returns whether this \ref NJointController calculates a \ref ControlTargetBase "ControlTarget" + * @brief Returns whether this \ref NJointControllerBase calculates a \ref ControlTargetBase "ControlTarget" * for the given \ref ControlDevice * @param deviceIndex The \ref ControlDevice's index - * @return Whether this \ref NJointController calculates a \ref ControlTargetBase "ControlTarget" + * @return Whether this \ref NJointControllerBase calculates a \ref ControlTargetBase "ControlTarget" * for the given \ref ControlDevice */ bool rtUsesControlDevice(std::size_t deviceIndex) const; /** - * @brief Returns the indices of all \ref ControlDevice's this \ref NJointController + * @brief Returns the indices of all \ref ControlDevice's this \ref NJointControllerBase * calculates a \ref ControlTargetBase "ControlTarget" for. - * @return The indices of all \ref ControlDevice's this \ref NJointController + * @return The indices of all \ref ControlDevice's this \ref NJointControllerBase * calculates a \ref ControlTargetBase "ControlTarget" for. */ const std::vector<std::size_t>& rtGetControlDeviceUsedIndices() const; @@ -846,7 +846,7 @@ namespace armarx * and sets the error flag. * * Calls \ref rtPostDeactivateController - * This function is called when this \ref NJointController produces an error + * This function is called when this \ref NJointControllerBase produces an error * (e.g.: calculates an invalid \ref ControlTargetBase "ControlTarget", throws an exception) * @see rtActivateController * @see rtDeactivateController @@ -856,11 +856,11 @@ namespace armarx public: - static const NJointControllerPtr NullPtr; + static const NJointControllerBasePtr NullPtr; - NJointController(); + NJointControllerBase(); - ~NJointController() override; + ~NJointControllerBase() override; //ice interface (must not be called in the rt thread) //c++ interface (local calls) (must be called in the rt thread) @@ -876,7 +876,7 @@ namespace armarx const std::map<std::string, const JointController*>& getControlDevicesUsedJointController(); //check for conflict - boost::optional<std::vector<char>> isNotInConflictWith(const NJointControllerPtr& other) const; + boost::optional<std::vector<char>> isNotInConflictWith(const NJointControllerBasePtr& other) const; boost::optional<std::vector<char>> isNotInConflictWith(const std::vector<char>& used) const; template<class ItT> @@ -930,17 +930,17 @@ namespace armarx // //////////////////////////////////////////////////////////////////////////////////////// // private: /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref RobotUnitModule::ControllerManagement. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref RobotUnitModule::ControllerManagement. * \warning !! DO NOT ADD ADDITIONAL FRIENDS IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ friend class RobotUnitModule::NJointControllerAttorneyForControllerManagement; /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref RobotUnitModule::ControlThread. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref RobotUnitModule::ControlThread. * \warning !! DO NOT ADD ADDITIONAL FRIENDS IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ friend class RobotUnitModule::NJointControllerAttorneyForControlThread; /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref RobotUnitModule::Publisher. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref RobotUnitModule::Publisher. * \warning !! DO NOT ADD ADDITIONAL FRIENDS IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ friend class RobotUnitModule::NJointControllerAttorneyForPublisher; @@ -950,6 +950,21 @@ namespace armarx */ template<class> friend class detail::NJointControllerRegistryEntryHelper; }; + + class SynchronousNJointController : public NJointControllerBase + { + public: ///TODO make protected and use attorneys + virtual void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) = 0; + virtual void rtSwapBufferAndRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration); + }; + class AsynchronousNJointController : public NJointControllerBase + { + public: ///TODO make protected and use attorneys + virtual void rtRunIterationBegin(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) = 0; + virtual void rtRunIterationEnd(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) = 0; + }; + using NJointController = SynchronousNJointController; + using NJointControllerPtr = SynchronousNJointControllerPtr; } #include "NJointController.ipp" diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.ipp b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.ipp index b35039429..bcefd5a83 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.ipp +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.ipp @@ -39,7 +39,7 @@ namespace armarx { private: friend class RobotUnitModule::ControllerManagement; - virtual NJointControllerPtr create( + virtual NJointControllerBasePtr create( RobotUnitModule::ControllerManagement* cmngr, const NJointControllerConfigPtr&, const VirtualRobot::RobotPtr&, @@ -63,7 +63,7 @@ namespace armarx struct NJointControllerRegistration; template <typename ControlDataStruct> - class NJointControllerWithTripleBuffer: virtual public NJointController + class NJointControllerWithTripleBuffer: public SynchronousNJointController { public: using MutexType = std::recursive_mutex; @@ -100,119 +100,119 @@ namespace armarx namespace armarx { template<class T> - inline T* NJointController::useControlTarget(const std::string& deviceName, const std::string& controlMode) + inline T* NJointControllerBase::useControlTarget(const std::string& deviceName, const std::string& controlMode) { static_assert(std::is_base_of<ControlTargetBase, T>::value, "The given type does not derive ControlTargetBase"); ControlTargetBase* const ptr = useControlTarget(deviceName, controlMode); return ptr ? ptr->asA<T>(): nullptr; } template<class T> - inline const T* NJointController::useSensorValue(const std::string& deviceName) const + inline const T* NJointControllerBase::useSensorValue(const std::string& deviceName) const { static_assert(std::is_base_of<SensorValueBase, T>::value, "The given type does not derive SensorValueBase"); const SensorValueBase* const ptr = useSensorValue(deviceName); return ptr ? ptr->asA<T>(): nullptr; } - inline void NJointController::rtSwapBufferAndRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) + inline void SynchronousNJointController::rtSwapBufferAndRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) { rtRun(sensorValuesTimestamp, timeSinceLastIteration); } - inline bool NJointController::rtUsesControlDevice(std::size_t deviceIndex) const + inline bool NJointControllerBase::rtUsesControlDevice(std::size_t deviceIndex) const { return controlDeviceUsedBitmap.at(deviceIndex); } - inline StringStringDictionary NJointController::getControlDeviceUsedControlModeMap(const Ice::Current&) const + inline StringStringDictionary NJointControllerBase::getControlDeviceUsedControlModeMap(const Ice::Current&) const { return controlDeviceControlModeMap; } - inline const std::vector<char>& NJointController::getControlDeviceUsedBitmap() const + inline const std::vector<char>& NJointControllerBase::getControlDeviceUsedBitmap() const { return controlDeviceUsedBitmap; } - inline const std::vector<std::size_t>& NJointController::rtGetControlDeviceUsedIndices() const + inline const std::vector<std::size_t>& NJointControllerBase::rtGetControlDeviceUsedIndices() const { return controlDeviceUsedIndices; } - inline const std::vector<std::size_t>& NJointController::getControlDeviceUsedIndices() const + inline const std::vector<std::size_t>& NJointControllerBase::getControlDeviceUsedIndices() const { return controlDeviceUsedIndices; } - inline const std::map<std::string, const JointController*>& NJointController::getControlDevicesUsedJointController() + inline const std::map<std::string, const JointController*>& NJointControllerBase::getControlDevicesUsedJointController() { return controlDeviceUsedJointController; } - inline boost::optional<std::vector<char> > NJointController::isNotInConflictWith(const NJointControllerPtr& other) const + inline boost::optional<std::vector<char> > NJointControllerBase::isNotInConflictWith(const NJointControllerBasePtr& other) const { return isNotInConflictWith(other->getControlDeviceUsedBitmap()); } - inline std::string NJointController::getDefaultName() const + inline std::string NJointControllerBase::getDefaultName() const { return getClassName(); } - inline bool NJointController::isControllerActive(const Ice::Current&) const + inline bool NJointControllerBase::isControllerActive(const Ice::Current&) const { return isActive; } - inline bool NJointController::isControllerRequested(const Ice::Current&) const + inline bool NJointControllerBase::isControllerRequested(const Ice::Current&) const { return isRequested; } - inline bool NJointController::isDeletable(const Ice::Current&) const + inline bool NJointControllerBase::isDeletable(const Ice::Current&) const { return deletable; } - inline bool NJointController::hasControllerError(const Ice::Current&) const + inline bool NJointControllerBase::hasControllerError(const Ice::Current&) const { return deactivatedBecauseOfError; } - inline std::string NJointController::getInstanceName(const Ice::Current&) const + inline std::string NJointControllerBase::getInstanceName(const Ice::Current&) const { return instanceName_; } - inline WidgetDescription::StringWidgetDictionary NJointController::getFunctionDescriptions(const Ice::Current&) const + inline WidgetDescription::StringWidgetDictionary NJointControllerBase::getFunctionDescriptions(const Ice::Current&) const { return {}; } - inline void NJointController::callDescribedFunction(const std::string&, const StringVariantBaseMap&, const Ice::Current&) + inline void NJointControllerBase::callDescribedFunction(const std::string&, const StringVariantBaseMap&, const Ice::Current&) { } - inline void NJointController::rtSetErrorState() + inline void NJointControllerBase::rtSetErrorState() { errorState.store(true); } - inline bool NJointController::rtGetErrorState() const + inline bool NJointControllerBase::rtGetErrorState() const { return errorState; } - inline std::size_t NJointController::rtGetNumberOfUsedControlDevices() const + inline std::size_t NJointControllerBase::rtGetNumberOfUsedControlDevices() const { return controlDeviceUsedIndices.size(); } - inline const std::string& NJointController::rtGetClassName() const + inline const std::string& NJointControllerBase::rtGetClassName() const { return rtClassName_; } - inline const std::string& NJointController::rtGetInstanceName() const + inline const std::string& NJointControllerBase::rtGetInstanceName() const { return instanceName_; } @@ -273,7 +273,7 @@ namespace armarx namespace armarx { template<class ItT> - inline boost::optional<std::vector<char>> NJointController::AreNotInConflict(ItT first, ItT last) + inline boost::optional<std::vector<char>> NJointControllerBase::AreNotInConflict(ItT first, ItT last) { if (first == last) { @@ -297,9 +297,9 @@ namespace armarx namespace armarx::detail { ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasGenerateConfigDescription, GenerateConfigDescription, - NJointController::GenerateConfigDescriptionFunctionSignature); + NJointControllerBase::GenerateConfigDescriptionFunctionSignature); ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(hasGenerateConfigFromVariants, GenerateConfigFromVariants, - NJointController::GenerateConfigFromVariantsFunctionSignature<typename T::ConfigPtrT>); + NJointControllerBase::GenerateConfigFromVariantsFunctionSignature<typename T::ConfigPtrT>); template<class NJointControllerT> class NJointControllerRegistryEntryHelper : public NJointControllerRegistryEntry @@ -311,7 +311,7 @@ namespace armarx::detail ); static constexpr bool hasRemoteConfiguration_ = hasGenerateConfigDescription<NJointControllerT>::value; - NJointControllerPtr create(RobotUnitModule::ControllerManagement* cmngr, + NJointControllerBasePtr create(RobotUnitModule::ControllerManagement* cmngr, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr& rob, bool deletable, @@ -326,7 +326,7 @@ namespace armarx::detail << GetTypeString<ConfigPtrT>()); ARMARX_CHECK_EXPRESSION_W_HINT(!ConstructorIsRunning(), "Two NJointControllers are created at the same time"); - NJointControllerPtr ptr; + NJointControllerBasePtr ptr; { ConstructorIsRunning_ = true; ARMARX_ON_SCOPE_EXIT{ConstructorIsRunning_ = false;}; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnit.h b/source/RobotAPI/components/units/RobotUnit/RobotUnit.h index 639de7394..dc96e422a 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnit.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnit.h @@ -69,7 +69,7 @@ namespace armarx * @ingroup Library-RobotUnit * @brief The RobotUnit class manages a robot and its controllers. * - * The \ref RobotUnit manages \ref NJointController and \ref JointController for a robot. + * The \ref RobotUnit manages \ref NJointControllerBase and \ref JointController for a robot. * Controllers are executed in a control thread. * * \section Controllers @@ -138,7 +138,7 @@ namespace armarx * Its tasks are: * * - Communication with the Robot - * - Execution of \ref NJointController and \ref JointController + * - Execution of \ref NJointControllerBase and \ref JointController * - Transferring data (\ref SensorValues, \ref ControlTargets) to other threads * (publishing, units, logging) * @@ -157,7 +157,7 @@ namespace armarx * Its tasks are: * * - Update Units - * - Call publishing hooks of \ref NJointController + * - Call publishing hooks of \ref NJointControllerBase * - Publish data to \ref RobotUnitListener * * \subsection logthrd RtLogging Thread diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleBase.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleBase.h index 8c107ae88..01a1faf9c 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleBase.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleBase.h @@ -49,7 +49,7 @@ namespace armarx { TYPEDEF_PTRS_HANDLE(RobotUnit); - TYPEDEF_PTRS_HANDLE(NJointController); + TYPEDEF_PTRS_HANDLE(NJointControllerBase); template<class Targ, class Src> Targ& CheckedCastAndDeref(Src* src) diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp index 97b3b4275..abaa2f96c 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp @@ -38,21 +38,21 @@ namespace armarx namespace RobotUnitModule { /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref ControlThread. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref ControlThread. * \warning !! DO NOT ADD ANYTHING IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ class NJointControllerAttorneyForControlThread { friend class ControlThread; - static void RtDeactivateController(const NJointControllerPtr& nJointCtrl) + static void RtDeactivateController(const NJointControllerBasePtr& nJointCtrl) { nJointCtrl->rtDeactivateController(); } - static void RtActivateController(const NJointControllerPtr& nJointCtrl) + static void RtActivateController(const NJointControllerBasePtr& nJointCtrl) { nJointCtrl->rtActivateController(); } - static void RtDeactivateControllerBecauseOfError(const NJointControllerPtr& nJointCtrl) + static void RtDeactivateControllerBecauseOfError(const NJointControllerBasePtr& nJointCtrl) { nJointCtrl->rtDeactivateControllerBecauseOfError(); } @@ -68,7 +68,7 @@ namespace armarx { return p->_module<ControlThreadDataBuffer>().controllersActivated.getWriteBuffer().jointControllers; } - static std::vector<NJointController*>& GetActivatedNJointControllers(ControlThread* p) + static std::vector<NJointControllerBase*>& GetActivatedNJointControllers(ControlThread* p) { return p->_module<ControlThreadDataBuffer>().controllersActivated.getWriteBuffer().nJointControllers; } @@ -80,7 +80,7 @@ namespace armarx { return p->_module<ControlThreadDataBuffer>().controllersActivated.getWriteBuffer().jointControllers; } - static const std::vector<NJointController*>& GetActivatedNJointControllers(const ControlThread* p) + static const std::vector<NJointControllerBase*>& GetActivatedNJointControllers(const ControlThread* p) { return p->_module<ControlThreadDataBuffer>().controllersActivated.getWriteBuffer().nJointControllers; } @@ -107,7 +107,7 @@ namespace armarx { return p->_module<ControlThreadDataBuffer>().controllersRequested.getReadBuffer().jointControllers; } - static const std::vector<NJointController*>& GetRequestedNJointControllers(const ControlThread* p) + static const std::vector<NJointControllerBase*>& GetRequestedNJointControllers(const ControlThread* p) { return p->_module<ControlThreadDataBuffer>().controllersRequested.getReadBuffer().nJointControllers; } @@ -202,11 +202,47 @@ namespace armarx const auto& actJC = rtGetActivatedJointControllers(); const auto& assig = rtGetActivatedJointToNJointControllerAssignement(); const auto& actNJC = rtGetActivatedNJointControllers(); + + std::size_t numSyncNj = 0; + std::size_t numAsyncNj = 0; + for (std::size_t i = 0; i < actJC.size(); ++i) { postSwitchSetup_ActivatedJointControllers.at(i) = actJC.at(i); postSwitchSetup_ActivatedJointToNJointControllerAssignement.at(i) = assig.at(i); postSwitchSetup_ActivatedNJointControllers.at(i) = actNJC.at(i); + + if (dynamic_cast<SynchronousNJointController*>(actNJC.at(i))) + { + _activatedSynchronousNJointControllersIdx.at(numSyncNj++) = i; + } + else if (dynamic_cast<AsynchronousNJointController*>(actNJC.at(i))) + { + _activatedAsynchronousNJointControllersIdx.at(numAsyncNj++) = i; + } + else + { + throw std::logic_error{"NJoint controller that is neither SynchronousNJointController" + " nor AsynchronousNJointController"}; + } + } + for ( + std::size_t i = numSyncNj; + i < _maxControllerCount && + _activatedSynchronousNJointControllersIdx.at(i) != _maxControllerCount; + ++i + ) + { + _activatedSynchronousNJointControllersIdx.at(i) = _maxControllerCount; + } + for ( + std::size_t i = numAsyncNj; + i < _maxControllerCount && + _activatedAsynchronousNJointControllersIdx.at(i) != _maxControllerCount; + ++i + ) + { + _activatedAsynchronousNJointControllersIdx.at(i) = _maxControllerCount; } }; @@ -285,8 +321,8 @@ namespace armarx { ++idxAct; } - const NJointControllerPtr& req = idxReq < n ? rtGetRequestedNJointControllers().at(idxReq) : nullptr; //may be null - const NJointControllerPtr& act = idxAct < n ? rtGetActivatedNJointControllers().at(idxAct) : nullptr; //may be null if it is the last + const NJointControllerBasePtr& req = idxReq < n ? rtGetRequestedNJointControllers().at(idxReq) : nullptr; //may be null + const NJointControllerBasePtr& act = idxAct < n ? rtGetActivatedNJointControllers().at(idxAct) : nullptr; //may be null if it is the last const auto reqId = reinterpret_cast<std::uintptr_t>(req.get()); const auto actId = reinterpret_cast<std::uintptr_t>(act.get()); @@ -400,9 +436,75 @@ namespace armarx { rtGetThreadTimingsSensorDevice().rtMarkRtRunNJointControllersStart(); // bool activeControllersChanged = false; - for (std::size_t nJointCtrlIndex = 0; nJointCtrlIndex < rtGetActivatedNJointControllers().size(); ++nJointCtrlIndex) + auto activatedNjointCtrls = rtGetActivatedNJointControllers(); + //start async + for (std::size_t nJointCtrlIndex : _activatedAsynchronousNJointControllersIdx) + { + if (nJointCtrlIndex == _maxControllerCount) + { + break; + } + auto nJointCtrl = static_cast<AsynchronousNJointController*>(activatedNjointCtrls.at(nJointCtrlIndex)); + if (!nJointCtrl) + { + continue; + } + try + { + if (nJointCtrl->rtGetErrorState()) + { + ARMARX_RT_LOGF_ERROR( + "NJointControllerBase '%s' requested deactivation while activating it", + nJointCtrl->rtGetInstanceName().c_str() + ); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + auto start = TimeUtil::GetTime(true); + rtSyncNJointControllerRobot(nJointCtrl); + nJointCtrl->rtRunIterationBegin(sensorValuesTimestamp, timeSinceLastIteration); + auto duration = TimeUtil::GetTime(true) - start; + if (nJointCtrl->rtGetErrorState()) + { + ARMARX_RT_LOGF_ERROR( + "NJointControllerBase '%s' requested deactivation while running it", + nJointCtrl->rtGetInstanceName().c_str() + ); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError) + { + ARMARX_RT_LOGF_ERROR( + "The NJointControllerBase '%s' took %ld µs to run!", + nJointCtrl->rtGetInstanceName().c_str(), + duration.toMicroSeconds() + ).deactivateSpam(5); + } + else if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn) + { + ARMARX_RT_LOGF_WARNING( + "The NJointControllerBase '%s' took %ld µs to run!", + nJointCtrl->rtGetInstanceName().c_str(), + duration.toMicroSeconds() + ).deactivateSpam(5); + } + } + catch (...) + { + ARMARX_ERROR << "NJoint Controller " << nJointCtrl->getInstanceName() + << " threw an exception and is now deactivated: " + << GetHandledExceptionString(); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + } + + //start sync + for (std::size_t nJointCtrlIndex : _activatedSynchronousNJointControllersIdx) { - NJointController* nJointCtrl = rtGetActivatedNJointControllers().at(nJointCtrlIndex); + if (nJointCtrlIndex == _maxControllerCount) + { + break; + } + auto nJointCtrl = static_cast<SynchronousNJointController*>(activatedNjointCtrls.at(nJointCtrlIndex)); try { if (nJointCtrl) @@ -410,7 +512,7 @@ namespace armarx if (nJointCtrl->rtGetErrorState()) { ARMARX_RT_LOGF_ERROR( - "NJointController '%s' requested deactivation while activating it", + "NJointControllerBase '%s' requested deactivation while activating it", nJointCtrl->rtGetInstanceName().c_str() ); rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); @@ -424,7 +526,7 @@ namespace armarx if (nJointCtrl->rtGetErrorState()) { ARMARX_RT_LOGF_ERROR( - "NJointController '%s' requested deactivation while running it", + "NJointControllerBase '%s' requested deactivation while running it", nJointCtrl->rtGetInstanceName().c_str() ); rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); @@ -433,7 +535,7 @@ namespace armarx if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError) { ARMARX_RT_LOGF_ERROR( - "The NJointController '%s' took %ld µs to run!", + "The NJointControllerBase '%s' took %ld µs to run!", nJointCtrl->rtGetInstanceName().c_str(), duration.toMicroSeconds() ).deactivateSpam(5); @@ -441,7 +543,7 @@ namespace armarx else if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn) { ARMARX_RT_LOGF_WARNING( - "The NJointController '%s' took %ld µs to run!", + "The NJointControllerBase '%s' took %ld µs to run!", nJointCtrl->rtGetInstanceName().c_str(), duration.toMicroSeconds() ).deactivateSpam(5); @@ -457,13 +559,72 @@ namespace armarx // activeControllersChanged = true; } } + //stop async + for (std::size_t nJointCtrlIndex : _activatedAsynchronousNJointControllersIdx) + { + if (nJointCtrlIndex == _maxControllerCount) + { + break; + } + auto nJointCtrl = static_cast<AsynchronousNJointController*>(activatedNjointCtrls.at(nJointCtrlIndex)); + if (!nJointCtrl) + { + continue; + } + try + { + if (nJointCtrl->rtGetErrorState()) + { + ARMARX_RT_LOGF_ERROR( + "NJointControllerBase '%s' requested deactivation while activating it", + nJointCtrl->rtGetInstanceName().c_str() + ); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + auto start = TimeUtil::GetTime(true); + rtSyncNJointControllerRobot(nJointCtrl); + nJointCtrl->rtRunIterationEnd(sensorValuesTimestamp, timeSinceLastIteration); + auto duration = TimeUtil::GetTime(true) - start; + if (nJointCtrl->rtGetErrorState()) + { + ARMARX_RT_LOGF_ERROR( + "NJointControllerBase '%s' requested deactivation while running it", + nJointCtrl->rtGetInstanceName().c_str() + ); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError) + { + ARMARX_RT_LOGF_ERROR( + "The NJointControllerBase '%s' took %ld µs to run!", + nJointCtrl->rtGetInstanceName().c_str(), + duration.toMicroSeconds() + ).deactivateSpam(5); + } + else if (static_cast<std::size_t>(duration.toMicroSeconds()) > nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn) + { + ARMARX_RT_LOGF_WARNING( + "The NJointControllerBase '%s' took %ld µs to run!", + nJointCtrl->rtGetInstanceName().c_str(), + duration.toMicroSeconds() + ).deactivateSpam(5); + } + } + catch (...) + { + ARMARX_ERROR << "NJoint Controller " << nJointCtrl->getInstanceName() + << " threw an exception and is now deactivated: " + << GetHandledExceptionString(); + rtDeactivateNJointControllerBecauseOfError(nJointCtrlIndex); + } + } // the activated controllers are committed in rtUpdateSensorAndControlBuffer(...) rtGetThreadTimingsSensorDevice().rtMarkRtRunNJointControllersEnd(); } void ControlThread::rtDeactivateNJointControllerBecauseOfError(std::size_t nJointCtrlIndex) { - const NJointControllerPtr& nJointCtrl = rtGetActivatedNJointControllers().at(nJointCtrlIndex); + const NJointControllerBasePtr& nJointCtrl = rtGetActivatedNJointControllers().at(nJointCtrlIndex); NJointControllerAttorneyForControlThread::RtDeactivateControllerBecauseOfError(nJointCtrl); for (auto ctrlDevIdx : nJointCtrl->rtGetControlDeviceUsedIndices()) { @@ -611,17 +772,22 @@ namespace armarx throwIfInControlThread(BOOST_CURRENT_FUNCTION); controlThreadId = std::this_thread::get_id(); - ARMARX_CHECK_EQUAL(rtGetActivatedJointControllers().size(), rtGetActivatedJointToNJointControllerAssignement().size()); - ARMARX_CHECK_EQUAL(rtGetActivatedJointControllers().size(), rtGetActivatedNJointControllers().size()); + _maxControllerCount = rtGetActivatedJointControllers().size(); + + ARMARX_CHECK_EQUAL(_maxControllerCount, rtGetActivatedJointToNJointControllerAssignement().size()); + ARMARX_CHECK_EQUAL(_maxControllerCount, rtGetActivatedNJointControllers().size()); //resize buffers used for error oputput - preSwitchSetup_ActivatedJointControllers.resize(rtGetActivatedJointControllers().size()); - postSwitchSetup_ActivatedJointControllers.resize(rtGetActivatedJointControllers().size()); + preSwitchSetup_ActivatedJointControllers.resize(_maxControllerCount); + postSwitchSetup_ActivatedJointControllers.resize(_maxControllerCount); + + preSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(_maxControllerCount); + postSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(_maxControllerCount); - preSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(rtGetActivatedJointToNJointControllerAssignement().size()); - postSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(rtGetActivatedJointToNJointControllerAssignement().size()); + preSwitchSetup_ActivatedNJointControllers.resize(_maxControllerCount); + postSwitchSetup_ActivatedNJointControllers.resize(_maxControllerCount); - preSwitchSetup_ActivatedNJointControllers.resize(rtGetActivatedNJointControllers().size()); - postSwitchSetup_ActivatedNJointControllers.resize(rtGetActivatedNJointControllers().size()); + _activatedSynchronousNJointControllersIdx.resize(_maxControllerCount, _maxControllerCount); + _activatedAsynchronousNJointControllersIdx.resize(_maxControllerCount, _maxControllerCount); // setup inverse dynamics if (getProperty<bool>("EnableInverseDynamics").getValue()) @@ -717,7 +883,7 @@ namespace armarx return ControlThreadDataBufferAttorneyForControlThread::GetActivatedJointControllers(this); } - const std::vector<NJointController*>& ControlThread::rtGetActivatedNJointControllers() const + const std::vector<NJointControllerBase*>& ControlThread::rtGetActivatedNJointControllers() const { return ControlThreadDataBufferAttorneyForControlThread::GetActivatedNJointControllers(this); } @@ -732,7 +898,7 @@ namespace armarx return ControlThreadDataBufferAttorneyForControlThread::GetActivatedJointControllers(this); } - std::vector<NJointController*>& ControlThread::rtGetActivatedNJointControllers() + std::vector<NJointControllerBase*>& ControlThread::rtGetActivatedNJointControllers() { return ControlThreadDataBufferAttorneyForControlThread::GetActivatedNJointControllers(this); } @@ -747,7 +913,7 @@ namespace armarx return ControlThreadDataBufferAttorneyForControlThread::GetRequestedJointControllers(this); } - const std::vector<NJointController*>& ControlThread::rtGetRequestedNJointControllers() const + const std::vector<NJointControllerBase*>& ControlThread::rtGetRequestedNJointControllers() const { return ControlThreadDataBufferAttorneyForControlThread::GetRequestedNJointControllers(this); } @@ -757,7 +923,7 @@ namespace armarx return ControlThreadDataBufferAttorneyForControlThread::GetRequestedJointToNJointControllerAssignement(this); } - void ControlThread::rtSyncNJointControllerRobot(NJointController* njctrl) + void ControlThread::rtSyncNJointControllerRobot(NJointControllerBase* njctrl) { if (njctrl->rtGetRobot()) { @@ -776,7 +942,7 @@ namespace armarx const std::string& indent, const std::vector<JointController*>& activeJCtrls, const std::vector<std::size_t>& assignement, - const std::vector<NJointController*>& activeNJCtrls) const + const std::vector<NJointControllerBase*>& activeNJCtrls) const { out << indent << "JointControllers:\n"; { diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.h index 59644ac61..6ec7fe3ac 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.h @@ -44,12 +44,12 @@ namespace armarx { defineOptionalProperty<std::size_t>( "NjointController_AllowedExecutionTimePerControlDeviceUntilWarning", 2, - "A Warning will be printed, If the execution time in micro seconds of a NJointController " + "A Warning will be printed, If the execution time in micro seconds of a NJointControllerBase " "exceeds this parameter times the number of ControlDevices." ); defineOptionalProperty<std::size_t>( "NjointController_AllowedExecutionTimePerControlDeviceUntilError", 20, - "An Error will be printed, If the execution time in micro seconds of a NJointController " + "An Error will be printed, If the execution time in micro seconds of a NJointControllerBase " "exceeds this parameter times the number of ControlDevices." ); defineOptionalProperty<bool>("EnableInverseDynamics", false, @@ -166,15 +166,15 @@ namespace armarx bool rtSwitchControllerSetup(); /** - * @brief Searches for the \ref NJointController responsible for the given \ref JointController and deactivates it. + * @brief Searches for the \ref NJointControllerBase responsible for the given \ref JointController and deactivates it. * Does not commit the new set of activated controllers) * @param ctrlDevIndex The control device index causing the problem. */ void rtDeactivateAssignedNJointControllerBecauseOfError(std::size_t ctrlDevIndex); /** - * @brief Deactivates a NJointController and sets all used ControlDevices to EmergencyStop. + * @brief Deactivates a NJointControllerBase and sets all used ControlDevices to EmergencyStop. * Does not commit the new set of activated controllers) - * @param nJointCtrlIndex The NJointController to deactivate (index in controllersActivated) + * @param nJointCtrlIndex The NJointControllerBase to deactivate (index in controllersActivated) */ void rtDeactivateNJointControllerBecauseOfError(std::size_t nJointCtrlIndex); /** @@ -206,7 +206,7 @@ namespace armarx /// @brief Calls \ref JointController::rtResetTarget for all active Joint controllers void rtResetAllTargets(); /** - * @brief Hook for deriving classes (called AFTER a NJointController is deactivated due to an error) + * @brief Hook for deriving classes (called AFTER a NJointControllerBase is deactivated due to an error) * * This is useful when two Control devices can be controlled by different NJointControllers but either both or none * have to be controlled. @@ -214,7 +214,7 @@ namespace armarx * Since this hook is called after the controller with an error was deactivated an other call to * \ref rtDeactivateAssignedNJointControllerBecauseOfError can't lead to a cyclic execution. */ - virtual void rtDeactivatedNJointControllerBecauseOfError(const NJointControllerPtr& /*nJointCtrl*/) {} + virtual void rtDeactivatedNJointControllerBecauseOfError(const NJointControllerBasePtr& /*nJointCtrl*/) {} /** * @brief Updates the current \ref SensorValueBase "SensorValues" and \ref ControlTargetBase "ControlTargets" * for code running outside of the \ref ControlThread @@ -274,16 +274,16 @@ namespace armarx std::vector<JointController*>& rtGetActivatedJointControllers(); const std::vector<JointController*>& rtGetActivatedJointControllers() const; /** - * @brief Returns the activated \ref NJointController "NJointControllers" - * @return The activated \ref NJointController "NJointControllers" + * @brief Returns the activated \ref NJointControllerBase "NJointControllers" + * @return The activated \ref NJointControllerBase "NJointControllers" */ - std::vector<NJointController*>& rtGetActivatedNJointControllers(); - const std::vector<NJointController*>& rtGetActivatedNJointControllers() const; + std::vector<NJointControllerBase*>& rtGetActivatedNJointControllers(); + const std::vector<NJointControllerBase*>& rtGetActivatedNJointControllers() const; /** - * @brief Returns a vector containing the index of the activated \ref NJointController + * @brief Returns a vector containing the index of the activated \ref NJointControllerBase * for each \ref JointController - * @return A vector containing the index of the activated \ref NJointController + * @return A vector containing the index of the activated \ref NJointControllerBase * for each \ref JointController */ std::vector<std::size_t>& rtGetActivatedJointToNJointControllerAssignement(); @@ -296,27 +296,27 @@ namespace armarx */ const std::vector<JointController*>& rtGetRequestedJointControllers() const; /** - * @brief Returns the requested \ref NJointController "NJointControllers" - * @return The requested \ref NJointController "NJointControllers" + * @brief Returns the requested \ref NJointControllerBase "NJointControllers" + * @return The requested \ref NJointControllerBase "NJointControllers" */ - const std::vector<NJointController*>& rtGetRequestedNJointControllers() const; + const std::vector<NJointControllerBase*>& rtGetRequestedNJointControllers() const; /** - * @brief Returns a vector containing the index of the requested \ref NJointController + * @brief Returns a vector containing the index of the requested \ref NJointControllerBase * for each \ref JointController - * @return A vector containing the index of the requested \ref NJointController + * @return A vector containing the index of the requested \ref NJointControllerBase * for each \ref JointController */ const std::vector<std::size_t>& rtGetRequestedJointToNJointControllerAssignement() const; - void rtSyncNJointControllerRobot(NJointController* njctrl); + void rtSyncNJointControllerRobot(NJointControllerBase* njctrl); void dumpRtControllerSetup( std::ostream& out, const std::string& indent, const std::vector<JointController*>& activeCdevs, const std::vector<std::size_t>& activeJCtrls, - const std::vector<NJointController*>& assignement) const; + const std::vector<NJointControllerBase*>& assignement) const; std::string dumpRtState() const; // //////////////////////////////////////////////////////////////////////////////////////// // // ///////////////////////////////////////// Data ///////////////////////////////////////// // @@ -335,9 +335,9 @@ namespace armarx ///@brief The \ref ControlThread's thread id std::atomic<std::thread::id> controlThreadId; - /// @brief A Warning will be printed, if the execution time per ControlDev of a NJointController exceeds this parameter + /// @brief A Warning will be printed, if the execution time per ControlDev of a NJointControllerBase exceeds this parameter std::size_t usPerDevUntilWarn; - /// @brief An Error will be printed, if the execution time per ControlDev of a NJointController exceeds this parameter + /// @brief An Error will be printed, if the execution time per ControlDev of a NJointControllerBase exceeds this parameter std::size_t usPerDevUntilError; bool rtSwitchControllerSetupChangedControllers {false}; @@ -345,16 +345,20 @@ namespace armarx std::vector<JointController*> preSwitchSetup_ActivatedJointControllers; std::vector<std::size_t> preSwitchSetup_ActivatedJointToNJointControllerAssignement; - std::vector<NJointController*> preSwitchSetup_ActivatedNJointControllers; + std::vector<NJointControllerBase*> preSwitchSetup_ActivatedNJointControllers; std::vector<JointController*> postSwitchSetup_ActivatedJointControllers; std::vector<std::size_t> postSwitchSetup_ActivatedJointToNJointControllerAssignement; - std::vector<NJointController*> postSwitchSetup_ActivatedNJointControllers; + std::vector<NJointControllerBase*> postSwitchSetup_ActivatedNJointControllers; + + std::vector<std::size_t> _activatedSynchronousNJointControllersIdx; + std::vector<std::size_t> _activatedAsynchronousNJointControllersIdx; std::atomic<EmergencyStopStateRequest> emergencyStopStateRequest {EmergencyStopStateRequest::RequestNone}; std::shared_ptr<DynamicsHelper> dynamicsHelpers; + std::size_t _maxControllerCount = 0; // //////////////////////////////////////////////////////////////////////////////////////// // // /////////////////////////////////////// Attorneys ////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////// // diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.cpp index 36e7c7a9a..4f020945f 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.cpp @@ -51,7 +51,7 @@ namespace armarx { friend class ControlThreadDataBuffer; - static void UpdateNJointControllerRequestedState(ControlThreadDataBuffer* p, const std::set<NJointControllerPtr>& request) + static void UpdateNJointControllerRequestedState(ControlThreadDataBuffer* p, const std::set<NJointControllerBasePtr>& request) { p->_module<ControllerManagement>().updateNJointControllerRequestedState(request); } @@ -79,7 +79,7 @@ namespace armarx return controllersActivated.getReadBuffer().jointControllers; } - std::vector<NJointController*> ControlThreadDataBuffer::getActivatedNJointControllers() const + std::vector<NJointControllerBase*> ControlThreadDataBuffer::getActivatedNJointControllers() const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); throwIfDevicesNotReady(__FUNCTION__); @@ -110,7 +110,7 @@ namespace armarx return controllersRequested.getWriteBuffer().jointControllers; } - std::vector<NJointController*> ControlThreadDataBuffer::copyRequestedNJointControllers() const + std::vector<NJointControllerBase*> ControlThreadDataBuffer::copyRequestedNJointControllers() const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); throwIfDevicesNotReady(__FUNCTION__); @@ -138,10 +138,10 @@ namespace armarx throwIfDevicesNotReady(__FUNCTION__); //check NJoint const auto& nJointCtrls = setOfControllers.nJointControllers; - std::set<NJointControllerPtr> nJointSet {nJointCtrls.begin(), nJointCtrls.end()}; + std::set<NJointControllerBasePtr> nJointSet {nJointCtrls.begin(), nJointCtrls.end()}; nJointSet.erase(nullptr); //# NJoint - const std::size_t nNJointCtrls = std::count_if(nJointCtrls.begin(), nJointCtrls.end(), [](const NJointControllerPtr & p) + const std::size_t nNJointCtrls = std::count_if(nJointCtrls.begin(), nJointCtrls.end(), [](const NJointControllerBasePtr & p) { return p; }); @@ -149,18 +149,18 @@ namespace armarx ARMARX_CHECK_EXPRESSION(nNJointCtrls == nJointSet.size()); ARMARX_CHECK_EXPRESSION(nJointCtrls.size() == _module<Devices>().getNumberOfControlDevices()); //first nNJointCtrls not null - ARMARX_CHECK_EXPRESSION(std::all_of(nJointCtrls.begin(), nJointCtrls.begin() + nNJointCtrls, [](NJointController * p) + ARMARX_CHECK_EXPRESSION(std::all_of(nJointCtrls.begin(), nJointCtrls.begin() + nNJointCtrls, [](NJointControllerBase * p) { return p; })); //last getNumberOfControlDevices()-nNJointCtrls null - ARMARX_CHECK_EXPRESSION(std::all_of(nJointCtrls.begin() + nNJointCtrls, nJointCtrls.end(), [](NJointController * p) + ARMARX_CHECK_EXPRESSION(std::all_of(nJointCtrls.begin() + nNJointCtrls, nJointCtrls.end(), [](NJointControllerBase * p) { return !p; })); //conflict free and sorted - ARMARX_CHECK_EXPRESSION(std::is_sorted(nJointCtrls.begin(), nJointCtrls.end(), std::greater<NJointController*> {})); - ARMARX_CHECK_EXPRESSION(NJointController::AreNotInConflict(nJointCtrls.begin(), nJointCtrls.begin() + nNJointCtrls)); + ARMARX_CHECK_EXPRESSION(std::is_sorted(nJointCtrls.begin(), nJointCtrls.end(), std::greater<NJointControllerBase*> {})); + ARMARX_CHECK_EXPRESSION(NJointControllerBase::AreNotInConflict(nJointCtrls.begin(), nJointCtrls.begin() + nNJointCtrls)); //check JointCtrl const auto& jointCtrls = setOfControllers.jointControllers; @@ -196,7 +196,7 @@ namespace armarx setOfControllers.resetAssignement(); for (std::size_t nJointCtrlIndex = 0; nJointCtrlIndex < setOfControllers.nJointControllers.size(); ++nJointCtrlIndex) { - const NJointController* nJoint = setOfControllers.nJointControllers.at(nJointCtrlIndex); + const NJointControllerBase* nJoint = setOfControllers.nJointControllers.at(nJointCtrlIndex); if (!nJoint) { break; @@ -229,7 +229,7 @@ namespace armarx ARMARX_DEBUG << "writeRequestedControllers(JointAndNJointControllers&& setOfControllers)...done!"; } - void ControlThreadDataBuffer::setActivateControllersRequest(std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls) + void ControlThreadDataBuffer::setActivateControllersRequest(std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> ctrls) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); std::lock_guard<std::recursive_mutex> guardRequested {controllersRequestedMutex}; @@ -238,7 +238,7 @@ namespace armarx ctrls.erase(nullptr); ARMARX_CHECK_EXPRESSION(ctrls.size() <= _module<Devices>().getNumberOfControlDevices()); - const std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> setOfRequestedCtrls + const std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> setOfRequestedCtrls { controllersRequested.getWriteBuffer().nJointControllers.begin(), controllersRequested.getWriteBuffer().nJointControllers.end() @@ -251,7 +251,7 @@ namespace armarx } JointAndNJointControllers request {_module<Devices>().getNumberOfControlDevices()}; std::size_t idx = 0; - for (const NJointControllerPtr& nJointCtrl : ctrls) + for (const NJointControllerBasePtr& nJointCtrl : ctrls) { request.nJointControllers.at(idx++) = nJointCtrl.get(); //add Joint for this ctrl diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.h index bb05c426c..578acae92 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThreadDataBuffer.h @@ -50,8 +50,8 @@ namespace armarx * \subsection bufferreq Buffer for requested controllers * \note This buffer's direction is ArmarX -> \ref ControlThread * - * This buffer contains all \ref NJointController "NJointControllers" - * requested by the user (e.g.: via \ref NJointController::activate) and + * This buffer contains all \ref NJointControllerBase "NJointControllers" + * requested by the user (e.g.: via \ref NJointControllerBase::activate) and * the set of \ref JointController "JointControllers" implicitly defined by this. * These controllers will be activated by \ref ControlThread::rtSwitchControllerSetup. * @@ -60,7 +60,7 @@ namespace armarx * \note This buffer's direction is \ref ControlThread -> ArmarX * * This buffer contains all \ref JointController "Joint-" and - * \ref NJointController "NJointControllers" executed by the \ref ControlThread. + * \ref NJointControllerBase "NJointControllers" executed by the \ref ControlThread. * * * \subsection bufferout Buffer for iteration data @@ -112,18 +112,18 @@ namespace armarx /** * @brief Returns whether the set of activated \ref JointController "Joint-" and - * \ref NJointController "NJointControllers" changed. + * \ref NJointControllerBase "NJointControllers" changed. * @return Whether the set of activated \ref JointController "Joint-" and - * \ref NJointController "NJointControllers" changed. + * \ref NJointControllerBase "NJointControllers" changed. * @see ControlThread * @see ControlThread::rtSwitchControllerSetup */ bool activatedControllersChanged() const; ///TODO private + attorney for publish /** * @brief Returns the set of activated \ref JointController "Joint-" and - * \ref NJointController "NJointControllers". + * \ref NJointControllerBase "NJointControllers". * @return The set of activated \ref JointController "Joint-" and - * \ref NJointController "NJointControllers". + * \ref NJointControllerBase "NJointControllers". * @see ControlThread * @see ControlThread::rtSwitchControllerSetup */ @@ -136,24 +136,24 @@ namespace armarx */ std::vector<JointController*> getActivatedJointControllers() const; /** - * @brief Returns the set of activated \ref NJointController "NJointControllers". - * @return The set of activated \ref NJointController "NJointControllers". + * @brief Returns the set of activated \ref NJointControllerBase "NJointControllers". + * @return The set of activated \ref NJointControllerBase "NJointControllers". * @see ControlThread * @see ControlThread::rtSwitchControllerSetup */ - std::vector<NJointController*> getActivatedNJointControllers() const; + std::vector<NJointControllerBase*> getActivatedNJointControllers() const; /** * @brief Returns the set of requsted \ref JointController "Joint-" and - * \ref NJointController "NJointControllers". + * \ref NJointControllerBase "NJointControllers". * @return The set of requested \ref JointController "Joint-" and - * \ref NJointController "NJointControllers". + * \ref NJointControllerBase "NJointControllers". * @see ControllerManagement * @see ControllerManagement::activateNJointController * @see ControllerManagement::deactivateNJointController * @see ControllerManagement::switchNJointControllerSetup - * @see NJointController::activateController - * @see NJointController::deactivateController + * @see NJointControllerBase::activateController + * @see NJointControllerBase::deactivateController * @see setActivateControllersRequest */ JointAndNJointControllers copyRequestedControllers() const; @@ -164,23 +164,23 @@ namespace armarx * @see ControllerManagement::activateNJointController * @see ControllerManagement::deactivateNJointController * @see ControllerManagement::switchNJointControllerSetup - * @see NJointController::activateController - * @see NJointController::deactivateController + * @see NJointControllerBase::activateController + * @see NJointControllerBase::deactivateController * @see setActivateControllersRequest */ std::vector<JointController*> copyRequestedJointControllers() const; /** - * @brief Returns the set of requsted \ref NJointController "NJointControllers". - * @return The set of requested \ref NJointController "NJointControllers". + * @brief Returns the set of requsted \ref NJointControllerBase "NJointControllers". + * @return The set of requested \ref NJointControllerBase "NJointControllers". * @see ControllerManagement * @see ControllerManagement::activateNJointController * @see ControllerManagement::deactivateNJointController * @see ControllerManagement::switchNJointControllerSetup - * @see NJointController::activateController - * @see NJointController::deactivateController + * @see NJointControllerBase::activateController + * @see NJointControllerBase::deactivateController * @see setActivateControllersRequest */ - std::vector<NJointController*> copyRequestedNJointControllers() const; + std::vector<NJointControllerBase*> copyRequestedNJointControllers() const; /** * @brief Updates the sensor and control buffer and returns whether the buffer was updated. @@ -220,16 +220,16 @@ namespace armarx } /** - * @brief Sets the set of requested \ref NJointController "NJointControllers" to \param ctrls. - * @param ctrls \ref NJointController "NJointControllers" requested. + * @brief Sets the set of requested \ref NJointControllerBase "NJointControllers" to \param ctrls. + * @param ctrls \ref NJointControllerBase "NJointControllers" requested. * @see ControllerManagement * @see ControllerManagement::activateNJointController * @see ControllerManagement::deactivateNJointController * @see ControllerManagement::switchNJointControllerSetup - * @see NJointController::activateController - * @see NJointController::deactivateController + * @see NJointControllerBase::activateController + * @see NJointControllerBase::deactivateController */ - void setActivateControllersRequest(std::set<NJointControllerPtr, std::greater<NJointControllerPtr> > ctrls); + void setActivateControllersRequest(std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr> > ctrls); // //////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////// implementation //////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////// // @@ -251,14 +251,14 @@ namespace armarx private: /// @brief Controllers the RT thread is supposed to activate (direction nonRT -> RT) (some NJoint controllers may be null) /// data may only be used after State::InitializingDevices - /// all NJointController have to be sorted by id (null controllers are at the end) + /// all NJointControllerBase have to be sorted by id (null controllers are at the end) WriteBufferedTripleBuffer<JointAndNJointControllers> controllersRequested; /// @brief Mutex guarding \ref controllersRequested mutable std::recursive_mutex controllersRequestedMutex; /// @brief Controllers the RT thread is currently running (direction RT -> nonRT) (some NJoint controllers may be null) /// data may only be used after State::InitializingDevices - /// all NJointController are sorted by id (null controllers may be anywhere) + /// all NJointControllerBase are sorted by id (null controllers may be anywhere) WriteBufferedTripleBuffer<JointAndNJointControllers> controllersActivated; /// @brief Mutex guarding \ref controllersActivated mutable std::recursive_mutex controllersActivatedMutex; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp index d528147fd..24536f741 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp @@ -45,13 +45,13 @@ namespace armarx } /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref ControllerManagement. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref ControllerManagement. * \warning !! DO NOT ADD ANYTHING IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ class NJointControllerAttorneyForControllerManagement { friend class ControllerManagement; - static void SetRequested(const NJointControllerPtr& nJointCtrl, bool requested) + static void SetRequested(const NJointControllerBasePtr& nJointCtrl, bool requested) { nJointCtrl->isRequested = requested; } @@ -88,12 +88,12 @@ namespace armarx } } - std::vector<NJointControllerPtr> ControllerManagement::getNJointControllersNotNull(const std::vector<std::string>& names) const + std::vector<NJointControllerBasePtr> ControllerManagement::getNJointControllersNotNull(const std::vector<std::string>& names) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); auto guard = getGuard(); throwIfDevicesNotReady(__FUNCTION__); - std::vector<NJointControllerPtr> ctrl; + std::vector<NJointControllerBasePtr> ctrl; ctrl.reserve(names.size()); for (const auto& name : names) { @@ -102,7 +102,7 @@ namespace armarx return ctrl; } - const NJointControllerPtr& ControllerManagement::getNJointControllerNotNull(const std::string& name) const + const NJointControllerBasePtr& ControllerManagement::getNJointControllerNotNull(const std::string& name) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); auto guard = getGuard(); @@ -111,14 +111,14 @@ namespace armarx if (it == nJointControllers.end()) { std::stringstream ss; - ss << "RobotUnit: there is no NJointController with name '" << name + ss << "RobotUnit: there is no NJointControllerBase with name '" << name << "'. Existing NJointControllers are: " << getNJointControllerNames(); throw InvalidArgumentException {ss.str()}; } if (!it->second) { std::stringstream ss; - ss << "RobotUnit: The NJointController with name '" << name + ss << "RobotUnit: The NJointControllerBase with name '" << name << "'. Is a nullptr! This should never be the case (invariant)! \nMap:\n" << nJointControllers; ARMARX_FATAL << ss.str(); throw InvalidArgumentException {ss.str()}; @@ -126,16 +126,16 @@ namespace armarx return it->second; } - void ControllerManagement::deleteNJointController(const NJointControllerPtr& ctrl) + void ControllerManagement::deleteNJointController(const NJointControllerBasePtr& ctrl) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - deleteNJointControllers(std::vector<NJointControllerPtr> {ctrl}); + deleteNJointControllers(std::vector<NJointControllerBasePtr> {ctrl}); } StringNJointControllerPrxDictionary ControllerManagement::getAllNJointControllers(const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - std::map<std::string, NJointControllerPtr> nJointControllersCopy; + std::map<std::string, NJointControllerBasePtr> nJointControllersCopy; { auto guard = getGuard(); //copy to keep lock retention time low @@ -186,7 +186,7 @@ namespace armarx Ice::emptyCurrent/*to select ice overload*/); } - const NJointControllerPtr& ControllerManagement::createNJointController( + const NJointControllerBasePtr& ControllerManagement::createNJointController( const std::string& className, const std::string& instanceName, const NJointControllerConfigPtr& config, @@ -217,16 +217,16 @@ namespace armarx //create the controller ARMARX_CHECK_EXPRESSION(factory); - NJointControllerPtr nJointCtrl = factory->create( - this, - config, - controllerCreateRobot, - deletable, internal, - instanceName - ); + NJointControllerBasePtr nJointCtrl = factory->create( + this, + config, + controllerCreateRobot, + deletable, internal, + instanceName + ); ARMARX_CHECK_NOT_EQUAL_W_HINT( nJointCtrl->getControlDeviceUsedIndices().size(), 0, - "The NJointController '" << nJointCtrl->getName() << "' uses no ControlDevice! (It has to use at least one)" + "The NJointControllerBase '" << nJointCtrl->getName() << "' uses no ControlDevice! (It has to use at least one)" ); getArmarXManager()->addObject(nJointCtrl, instanceName, false, false); @@ -264,7 +264,7 @@ namespace armarx auto guard = getGuard(); return getMapKeys(nJointControllers); } - std::vector<std::string> ControllerManagement::getNJointControllerNames(const std::vector<NJointControllerPtr>& ctrls) const + std::vector<std::string> ControllerManagement::getNJointControllerNames(const std::vector<NJointControllerBasePtr>& ctrls) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); std::vector<std::string> result; @@ -289,12 +289,12 @@ namespace armarx throwIfInControlThread(BOOST_CURRENT_FUNCTION); activateNJointControllers(getNJointControllersNotNull(names)); } - void ControllerManagement::activateNJointController(const NJointControllerPtr& ctrl) + void ControllerManagement::activateNJointController(const NJointControllerBasePtr& ctrl) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - activateNJointControllers(std::vector<NJointControllerPtr> {ctrl}); + activateNJointControllers(std::vector<NJointControllerBasePtr> {ctrl}); } - void ControllerManagement::activateNJointControllers(const std::vector<NJointControllerPtr>& ctrlsToActVec) + void ControllerManagement::activateNJointControllers(const std::vector<NJointControllerBasePtr>& ctrlsToActVec) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); if (ctrlsToActVec.empty()) @@ -304,13 +304,13 @@ namespace armarx auto guard = getGuard(); throwIfDevicesNotReady(__FUNCTION__); //if not activate them - std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrlsToAct {ctrlsToActVec.begin(), ctrlsToActVec.end()}; + std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> ctrlsToAct {ctrlsToActVec.begin(), ctrlsToActVec.end()}; ARMARX_CHECK_EXPRESSION(!ctrlsToAct.count(nullptr)); //check if all already active if ( std::all_of( ctrlsToActVec.begin(), ctrlsToActVec.end(), - [](const NJointControllerPtr & ctrl) + [](const NJointControllerBasePtr & ctrl) { return ctrl->isControllerActive(); } @@ -321,13 +321,13 @@ namespace armarx } //get already requested const auto ctrlVector = _module<ControlThreadDataBuffer>().copyRequestedNJointControllers(); - std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrlsAlreadyRequested {ctrlVector.begin(), ctrlVector.end()}; + std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> ctrlsAlreadyRequested {ctrlVector.begin(), ctrlVector.end()}; ctrlsAlreadyRequested.erase(nullptr); //check for conflict std::vector<char> inuse; //check requested controllers { - auto r = NJointController::AreNotInConflict(ctrlsToAct.begin(), ctrlsToAct.end()); + auto r = NJointControllerBase::AreNotInConflict(ctrlsToAct.begin(), ctrlsToAct.end()); if (!r) { std::stringstream ss; @@ -353,7 +353,7 @@ namespace armarx { ARMARX_DEBUG << "no already requested NJointControllers"; } - for (const NJointControllerPtr& nJointCtrl : ctrlsAlreadyRequested) + for (const NJointControllerBasePtr& nJointCtrl : ctrlsAlreadyRequested) { if (ctrlsToAct.count(nJointCtrl)) { @@ -362,14 +362,14 @@ namespace armarx auto r = nJointCtrl->isNotInConflictWith(inuse); if (r) { - ARMARX_DEBUG << "keeping already requested NJointController '" + ARMARX_DEBUG << "keeping already requested NJointControllerBase '" << nJointCtrl->getInstanceName() << "' in list of requested controllers"; ctrlsToAct.insert(nJointCtrl); inuse = std::move(r.get()); } else { - ARMARX_INFO << "removing already requested NJointController '" + ARMARX_INFO << "removing already requested NJointControllerBase '" << nJointCtrl->getInstanceName() << "' from list of requested controllers"; } } @@ -388,12 +388,12 @@ namespace armarx throwIfInControlThread(BOOST_CURRENT_FUNCTION); deactivateNJointControllers(getNJointControllersNotNull(names)); } - void ControllerManagement::deactivateNJointController(const NJointControllerPtr& ctrl) + void ControllerManagement::deactivateNJointController(const NJointControllerBasePtr& ctrl) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - deactivateNJointControllers(std::vector<NJointControllerPtr> {ctrl}); + deactivateNJointControllers(std::vector<NJointControllerBasePtr> {ctrl}); } - void ControllerManagement::deactivateNJointControllers(const std::vector<NJointControllerPtr>& ctrlsDeacVec) + void ControllerManagement::deactivateNJointControllers(const std::vector<NJointControllerBasePtr>& ctrlsDeacVec) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); auto guard = getGuard(); @@ -403,7 +403,7 @@ namespace armarx return; } const auto ctrlVector = _module<ControlThreadDataBuffer>().copyRequestedNJointControllers(); - std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls {ctrlVector.begin(), ctrlVector.end()}; + std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> ctrls {ctrlVector.begin(), ctrlVector.end()}; const std::size_t ctrlsNum = ctrls.size(); for (const auto& nJointCtrlToDeactivate : ctrlsDeacVec) { @@ -434,7 +434,7 @@ namespace armarx auto ctrlsToActVec = getNJointControllersNotNull(newSetup); //also checks if these controllers exist _module<ControlThreadDataBuffer>().setActivateControllersRequest({ctrlsToActVec.begin(), ctrlsToActVec.end()}); } - void ControllerManagement::deleteNJointControllers(const std::vector<NJointControllerPtr>& ctrlsToDelVec) + void ControllerManagement::deleteNJointControllers(const std::vector<NJointControllerBasePtr>& ctrlsToDelVec) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); auto guard = getGuard(); @@ -450,16 +450,16 @@ namespace armarx { throw LogicError { - "The NJointController '" + nJointCtrl->getInstanceName() + - "' can't be deleted since this operation is not allowed for this controller! (no NJointController was deleted)" + "The NJointControllerBase '" + nJointCtrl->getInstanceName() + + "' can't be deleted since this operation is not allowed for this controller! (no NJointControllerBase was deleted)" }; } if (nJointCtrl->isControllerActive() || nJointCtrl->isControllerRequested()) { throw LogicError { - "The NJointController '" + nJointCtrl->getInstanceName() + - "' can't be deleted since it is active or requested! (no NJointController was deleted)" + "The NJointControllerBase '" + nJointCtrl->getInstanceName() + + "' can't be deleted since it is active or requested! (no NJointControllerBase was deleted)" }; } } @@ -469,7 +469,7 @@ namespace armarx //deletion is done in a different thread since this call may be done by the controller (protection against use after free) nJointControllersToBeDeleted[name] = std::move(nJointCtrl); nJointControllers.erase(name); - ARMARX_VERBOSE << "added NJointController '" << name << "' to be deleted"; + ARMARX_VERBOSE << "added NJointControllerBase '" << name << "' to be deleted"; } } @@ -483,12 +483,12 @@ namespace armarx throwIfInControlThread(BOOST_CURRENT_FUNCTION); deactivateAndDeleteNJointControllers(getNJointControllersNotNull(names)); } - void ControllerManagement::deactivateAndDeleteNJointController(const NJointControllerPtr& ctrl) + void ControllerManagement::deactivateAndDeleteNJointController(const NJointControllerBasePtr& ctrl) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); deactivateAndDeleteNJointControllers({ctrl}); } - void ControllerManagement::deactivateAndDeleteNJointControllers(const std::vector<NJointControllerPtr>& ctrlsToDelVec) + void ControllerManagement::deactivateAndDeleteNJointControllers(const std::vector<NJointControllerBasePtr>& ctrlsToDelVec) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); auto guard = getGuard(); @@ -502,7 +502,7 @@ namespace armarx std::any_of( ctrlsToDelVec.begin(), ctrlsToDelVec.end(), - [](const NJointControllerPtr & ctrl) + [](const NJointControllerBasePtr & ctrl) { return ctrl->isControllerActive(); } @@ -570,7 +570,7 @@ namespace armarx NJointControllerInterfacePrx ControllerManagement::getNJointController(const std::string& name, const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - NJointControllerPtr ctrl; + NJointControllerBasePtr ctrl; { auto guard = getGuard(); auto it = nJointControllers.find(name); @@ -611,7 +611,7 @@ namespace armarx NJointControllerDescription ControllerManagement::getNJointControllerDescription(const std::string& name, const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - NJointControllerPtr nJointCtrl; + NJointControllerBasePtr nJointCtrl; { auto guard = getGuard(); throwIfDevicesNotReady(__FUNCTION__); @@ -623,7 +623,7 @@ namespace armarx NJointControllerDescriptionSeq ControllerManagement::getNJointControllerDescriptions(const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - std::map<std::string, NJointControllerPtr> nJointControllersCopy; + std::map<std::string, NJointControllerBasePtr> nJointControllersCopy; { auto guard = getGuard(); if (!areDevicesReady()) @@ -645,7 +645,7 @@ namespace armarx const std::string& name, const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - NJointControllerPtr nJointCtrl; + NJointControllerBasePtr nJointCtrl; { auto guard = getGuard(); throwIfDevicesNotReady(__FUNCTION__); @@ -657,7 +657,7 @@ namespace armarx NJointControllerDescriptionWithStatusSeq ControllerManagement::getNJointControllerDescriptionsWithStatuses(const Ice::Current&) const { throwIfInControlThread(BOOST_CURRENT_FUNCTION); - std::map<std::string, NJointControllerPtr> nJointControllersCopy; + std::map<std::string, NJointControllerBasePtr> nJointControllersCopy; { auto guard = getGuard(); if (!areDevicesReady()) @@ -675,20 +675,20 @@ namespace armarx return r; } - void ControllerManagement::removeNJointControllers(std::map<std::string, NJointControllerPtr>& ctrls, bool blocking, RobotUnitListenerPrx l) + void ControllerManagement::removeNJointControllers(std::map<std::string, NJointControllerBasePtr>& ctrls, bool blocking, RobotUnitListenerPrx l) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); for (auto& n2NJointCtrl : ctrls) { - NJointControllerPtr& nJointCtrl = n2NJointCtrl.second; + NJointControllerBasePtr& nJointCtrl = n2NJointCtrl.second; if (blocking) { - ARMARX_VERBOSE << "deleted NJointController " << n2NJointCtrl.first; + ARMARX_VERBOSE << "deleted NJointControllerBase " << n2NJointCtrl.first; getArmarXManager()->removeObjectBlocking(nJointCtrl->getName()); } else { - ARMARX_VERBOSE << "deleted NJointController " << n2NJointCtrl.first; + ARMARX_VERBOSE << "deleted NJointControllerBase " << n2NJointCtrl.first; getArmarXManager()->removeObjectBlocking(nJointCtrl->getName()); } if (l) @@ -730,7 +730,7 @@ namespace armarx controllerCreateRobot = _module<RobotData>().cloneRobot(); } - void ControllerManagement::updateNJointControllerRequestedState(const std::set<NJointControllerPtr>& request) + void ControllerManagement::updateNJointControllerRequestedState(const std::set<NJointControllerBasePtr>& request) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); ARMARX_DEBUG << "set requested state for NJoint controllers"; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h index 421e03796..422af32c7 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h @@ -34,7 +34,7 @@ namespace armarx { /** * @ingroup Library-RobotUnit-Modules - * @brief This \ref ModuleBase "Module" manages \ref NJointController "NJointControllers". + * @brief This \ref ModuleBase "Module" manages \ref NJointControllerBase "NJointControllers". * * @see ModuleBase */ @@ -65,23 +65,23 @@ namespace armarx // //////////////////////////////////////////////////////////////////////////////////////// // public: /** - * @brief Returns a proxy to the \ref NJointController. - * @param name The \ref NJointController's name. - * @return A proxy to the \ref NJointController. + * @brief Returns a proxy to the \ref NJointControllerBase. + * @param name The \ref NJointControllerBase's name. + * @return A proxy to the \ref NJointControllerBase. * @see getAllNJointControllers */ NJointControllerInterfacePrx getNJointController(const std::string& name, const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns proxies to all \ref NJointController "NJointControllers" - * @return Proxies to all \ref NJointController "NJointControllers" + * @brief Returns proxies to all \ref NJointControllerBase "NJointControllers" + * @return Proxies to all \ref NJointControllerBase "NJointControllers" * @see getNJointController */ StringNJointControllerPrxDictionary getAllNJointControllers(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the status of the \ref NJointController. - * @param name The \ref NJointController's name. - * @return The status of the \ref NJointController. + * @brief Returns the status of the \ref NJointControllerBase. + * @param name The \ref NJointControllerBase's name. + * @return The status of the \ref NJointControllerBase. * @see NJointControllerStatus * @see getNJointControllerStatuses * @see getNJointControllerDescriptionWithStatus @@ -89,8 +89,8 @@ namespace armarx */ NJointControllerStatus getNJointControllerStatus(const std::string& name, const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the status of all \ref NJointController "NJointControllers". - * @return The status of all \ref NJointController "NJointControllers". + * @brief Returns the status of all \ref NJointControllerBase "NJointControllers". + * @return The status of all \ref NJointControllerBase "NJointControllers". * @see NJointControllerStatus * @see getNJointControllerStatus * @see getNJointControllerDescriptionWithStatus @@ -99,9 +99,9 @@ namespace armarx NJointControllerStatusSeq getNJointControllerStatuses(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the description of the \ref NJointController. - * @param name The \ref NJointController's name. - * @return The description of the \ref NJointController. + * @brief Returns the description of the \ref NJointControllerBase. + * @param name The \ref NJointControllerBase's name. + * @return The description of the \ref NJointControllerBase. * @see NJointControllerDescription * @see getNJointControllerDescriptions * @see getNJointControllerDescriptionWithStatus @@ -109,8 +109,8 @@ namespace armarx */ NJointControllerDescription getNJointControllerDescription(const std::string& name, const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the description of all \ref NJointController "NJointControllers". - * @return The description of all \ref NJointController "NJointControllers". + * @brief Returns the description of all \ref NJointControllerBase "NJointControllers". + * @return The description of all \ref NJointControllerBase "NJointControllers". * @see NJointControllerDescription * @see getNJointControllerDescription * @see getNJointControllerDescriptionWithStatus @@ -120,9 +120,9 @@ namespace armarx NJointControllerDescriptionSeq getNJointControllerDescriptions(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the status and description of the \ref NJointController. - * @param name The \ref NJointController's name. - * @return The status and description of the \ref NJointController. + * @brief Returns the status and description of the \ref NJointControllerBase. + * @param name The \ref NJointControllerBase's name. + * @return The status and description of the \ref NJointControllerBase. * @see getNJointControllerDescriptionsWithStatuses * @see NJointControllerStatus * @see getNJointControllerStatus @@ -134,8 +134,8 @@ namespace armarx NJointControllerDescriptionWithStatus getNJointControllerDescriptionWithStatus( const std::string& name, const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the status and description of all \ref NJointController "NJointControllers". - * @return The status and description of all \ref NJointController "NJointControllers". + * @brief Returns the status and description of all \ref NJointControllerBase "NJointControllers". + * @return The status and description of all \ref NJointControllerBase "NJointControllers". * @see getNJointControllerDescriptionsWithStatus * @see NJointControllerStatus * @see getNJointControllerStatus @@ -174,45 +174,45 @@ namespace armarx */ bool loadLibFromPackage(const std::string& package, const std::string& lib, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Returns the names of all available classes of \ref NJointController. - * @return The names of all available classes of \ref NJointController. + * @brief Returns the names of all available classes of \ref NJointControllerBase. + * @return The names of all available classes of \ref NJointControllerBase. */ Ice::StringSeq getNJointControllerClassNames(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the names of all \ref NJointController "NJointControllers" - * @return The names of all \ref NJointController "NJointControllers" + * @brief Returns the names of all \ref NJointControllerBase "NJointControllers" + * @return The names of all \ref NJointControllerBase "NJointControllers" */ Ice::StringSeq getNJointControllerNames(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the names of all requested \ref NJointController "NJointControllers" - * @return The names of all requested \ref NJointController "NJointControllers" + * @brief Returns the names of all requested \ref NJointControllerBase "NJointControllers" + * @return The names of all requested \ref NJointControllerBase "NJointControllers" */ Ice::StringSeq getRequestedNJointControllerNames(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Returns the names of all activated \ref NJointController "NJointControllers" - * @return The names of all activated \ref NJointController "NJointControllers" + * @brief Returns the names of all activated \ref NJointControllerBase "NJointControllers" + * @return The names of all activated \ref NJointControllerBase "NJointControllers" */ Ice::StringSeq getActivatedNJointControllerNames(const Ice::Current& = Ice::emptyCurrent) const override; /** - * @brief Queues the given \ref NJointController for deletion. - * @param name The \ref NJointController to delete. + * @brief Queues the given \ref NJointControllerBase for deletion. + * @param name The \ref NJointControllerBase to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointControllers */ void deleteNJointController(const std::string& name, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Queues the given \ref NJointController "NJointControllers" for deletion. - * @param names The \ref NJointController "NJointControllers" to delete. + * @brief Queues the given \ref NJointControllerBase "NJointControllers" for deletion. + * @param names The \ref NJointControllerBase "NJointControllers" to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController */ void deleteNJointControllers(const Ice::StringSeq& names, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Queues the given \ref NJointController for deletion and deactivates it if necessary. - * @param name The \ref NJointController to delete. + * @brief Queues the given \ref NJointControllerBase for deletion and deactivates it if necessary. + * @param name The \ref NJointControllerBase to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController @@ -221,8 +221,8 @@ namespace armarx */ void deactivateAndDeleteNJointController(const std::string& name, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Queues the given \ref NJointController "NJointControllers" for deletion and deactivates them if necessary. - * @param names The \ref NJointController "NJointControllers" to delete. + * @brief Queues the given \ref NJointControllerBase "NJointControllers" for deletion and deactivates them if necessary. + * @param names The \ref NJointControllerBase "NJointControllers" to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController @@ -232,55 +232,55 @@ namespace armarx void deactivateAndDeleteNJointControllers(const Ice::StringSeq& names, const Ice::Current&) override; /** - * @brief Requests activation for the given \ref NJointController. - * @param name The requested \ref NJointController. + * @brief Requests activation for the given \ref NJointControllerBase. + * @param name The requested \ref NJointControllerBase. * @see activateNJointControllers */ void activateNJointController(const std::string& name, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Requests activation for the given \ref NJointController "NJointControllers". - * @param names The requested \ref NJointController "NJointControllers". + * @brief Requests activation for the given \ref NJointControllerBase "NJointControllers". + * @param names The requested \ref NJointControllerBase "NJointControllers". * @see activateNJointController */ void activateNJointControllers(const Ice::StringSeq& names, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Requests deactivation for the given \ref NJointController. - * @param name The \ref NJointController to be deactivated. + * @brief Requests deactivation for the given \ref NJointControllerBase. + * @param name The \ref NJointControllerBase to be deactivated. * @see deactivateNJointControllers */ void deactivateNJointController(const std::string& name, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Requests deactivation for the given \ref NJointController "NJointControllers". - * @param names The \ref NJointController "NJointControllers" to be deactivated. + * @brief Requests deactivation for the given \ref NJointControllerBase "NJointControllers". + * @param names The \ref NJointControllerBase "NJointControllers" to be deactivated. * @see deactivateNJointController */ void deactivateNJointControllers(const Ice::StringSeq& names, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Cretes a \ref NJointController. - * @param className The \ref NJointController's class. - * @param instanceName The \ref NJointController's name. - * @param config A config passed to the \ref NJointController's ctor. - * @return A proxy to the created \ref NJointController. + * @brief Cretes a \ref NJointControllerBase. + * @param className The \ref NJointControllerBase's class. + * @param instanceName The \ref NJointControllerBase's name. + * @param config A config passed to the \ref NJointControllerBase's ctor. + * @return A proxy to the created \ref NJointControllerBase. */ NJointControllerInterfacePrx createNJointController( const std::string& className, const std::string& instanceName, const NJointControllerConfigPtr& config, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Cretes a \ref NJointController. - * @param className The \ref NJointController's class. - * @param instanceName The \ref NJointController's name. - * @param variants A map of \ref Variant "Variants" passed to the \ref NJointController's ctor. - * @return A proxy to the created \ref NJointController. + * @brief Cretes a \ref NJointControllerBase. + * @param className The \ref NJointControllerBase's class. + * @param instanceName The \ref NJointControllerBase's name. + * @param variants A map of \ref Variant "Variants" passed to the \ref NJointControllerBase's ctor. + * @return A proxy to the created \ref NJointControllerBase. */ NJointControllerInterfacePrx createNJointControllerFromVariantConfig( const std::string& className, const std::string& instanceName, const StringVariantBaseMap& variants, const Ice::Current& = Ice::emptyCurrent) override; /** - * @brief Changes the set of requested \ref NJointController "NJointControllers" to the given set. - * @param newSetup The new set of requested \ref NJointController "NJointControllers" + * @brief Changes the set of requested \ref NJointControllerBase "NJointControllers" to the given set. + * @param newSetup The new set of requested \ref NJointControllerBase "NJointControllers" */ void switchNJointControllerSetup(const Ice::StringSeq& newSetup, const Ice::Current& = Ice::emptyCurrent) override; // //////////////////////////////////////////////////////////////////////////////////////// // @@ -288,118 +288,118 @@ namespace armarx // //////////////////////////////////////////////////////////////////////////////////////// // public: /** - * @brief Cretes a \ref NJointController. - * @param className The \ref NJointController's class. - * @param instanceName The \ref NJointController's name. - * @param config A config passed to the \ref NJointController's ctor. - * @param deletable Whether the \ref NJointController can be deleted. - * @param internal Whether the \ref NJointController should be tagged as internal. - * @return A pointer to the created \ref NJointController + * @brief Cretes a \ref NJointControllerBase. + * @param className The \ref NJointControllerBase's class. + * @param instanceName The \ref NJointControllerBase's name. + * @param config A config passed to the \ref NJointControllerBase's ctor. + * @param deletable Whether the \ref NJointControllerBase can be deleted. + * @param internal Whether the \ref NJointControllerBase should be tagged as internal. + * @return A pointer to the created \ref NJointControllerBase */ - const NJointControllerPtr& createNJointController( + const NJointControllerBasePtr& createNJointController( const std::string& className, const std::string& instanceName, const NJointControllerConfigPtr& config, bool deletable, bool internal); /** - * @brief Returns pointers to the \ref NJointController "NJointControllers". (If one does not exist, an exception is thrown.) - * @param names The \ref NJointController "NJointControllers" names. - * @return Pointers to the \ref NJointController "NJointControllers". - * @throw If there is no \ref NJointcontroller for \param name + * @brief Returns pointers to the \ref NJointControllerBase "NJointControllers". (If one does not exist, an exception is thrown.) + * @param names The \ref NJointControllerBase "NJointControllers" names. + * @return Pointers to the \ref NJointControllerBase "NJointControllers". + * @throw If there is no \ref NJointControllerBase for \param name */ - std::vector<armarx::NJointControllerPtr> getNJointControllersNotNull(const std::vector<std::string>& names) const; + std::vector<armarx::NJointControllerBasePtr> getNJointControllersNotNull(const std::vector<std::string>& names) const; /** - * @brief Returns a pointer to the \ref NJointController. (If it does not exist, an exception is thrown.) - * @param name The \ref NJointController - * @return A pointer to the \ref NJointController. - * @throw If there is no \ref NJointcontroller for \param name + * @brief Returns a pointer to the \ref NJointControllerBase. (If it does not exist, an exception is thrown.) + * @param name The \ref NJointControllerBase + * @return A pointer to the \ref NJointControllerBase. + * @throw If there is no \ref NJointControllerBase for \param name */ - const NJointControllerPtr& getNJointControllerNotNull(const std::string& name) const; + const NJointControllerBasePtr& getNJointControllerNotNull(const std::string& name) const; /** - * @brief Returns the names of given \ref NJointController "NJointControllers" - * @param ctrls The \ref NJointController "NJointControllers" - * @return The names of given \ref NJointController "NJointControllers" + * @brief Returns the names of given \ref NJointControllerBase "NJointControllers" + * @param ctrls The \ref NJointControllerBase "NJointControllers" + * @return The names of given \ref NJointControllerBase "NJointControllers" */ - std::vector<std::string> getNJointControllerNames(const std::vector<armarx::NJointControllerPtr>& ctrls) const; + std::vector<std::string> getNJointControllerNames(const std::vector<armarx::NJointControllerBasePtr>& ctrls) const; /** - * @brief Queues the given \ref NJointController for deletion. - * @param ctrl The \ref NJointController to delete. + * @brief Queues the given \ref NJointControllerBase for deletion. + * @param ctrl The \ref NJointControllerBase to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointControllers */ - void deleteNJointController(const NJointControllerPtr& ctrl); + void deleteNJointController(const NJointControllerBasePtr& ctrl); /** - * @brief Queues the given \ref NJointController "NJointControllers" for deletion. - * @param ctrls The \ref NJointController "NJointControllers" to delete. + * @brief Queues the given \ref NJointControllerBase "NJointControllers" for deletion. + * @param ctrls The \ref NJointControllerBase "NJointControllers" to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController */ - void deleteNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + void deleteNJointControllers(const std::vector<NJointControllerBasePtr>& ctrls); /** - * @brief Queues the given \ref NJointController for deletion and deactivates it if necessary. - * @param ctrl The \ref NJointController to delete. + * @brief Queues the given \ref NJointControllerBase for deletion and deactivates it if necessary. + * @param ctrl The \ref NJointControllerBase to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController * @see deleteNJointControllers * @see deactivateAnddeleteNJointControllers */ - void deactivateAndDeleteNJointController(const NJointControllerPtr& ctrl); + void deactivateAndDeleteNJointController(const NJointControllerBasePtr& ctrl); /** - * @brief Queues the given \ref NJointController "NJointControllers" for deletion and deactivates them if necessary. - * @param ctrls The \ref NJointController "NJointControllers" to delete. + * @brief Queues the given \ref NJointControllerBase "NJointControllers" for deletion and deactivates them if necessary. + * @param ctrls The \ref NJointControllerBase "NJointControllers" to delete. * @see removeNJointControllersToBeDeleted * @see nJointControllersToBeDeleted * @see deleteNJointController * @see deleteNJointControllers * @see deactivateAnddeleteNJointController */ - void deactivateAndDeleteNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + void deactivateAndDeleteNJointControllers(const std::vector<NJointControllerBasePtr>& ctrls); /** - * @brief Requests activation for the given \ref NJointController. - * @param ctrl The requested \ref NJointController. + * @brief Requests activation for the given \ref NJointControllerBase. + * @param ctrl The requested \ref NJointControllerBase. * @see activateNJointControllers */ - void activateNJointController(const NJointControllerPtr& ctrl); + void activateNJointController(const NJointControllerBasePtr& ctrl); /** - * @brief Requests activation for the given \ref NJointController "NJointControllers". - * @param ctrls The requested \ref NJointController "NJointControllers". + * @brief Requests activation for the given \ref NJointControllerBase "NJointControllers". + * @param ctrls The requested \ref NJointControllerBase "NJointControllers". * @see activateNJointController */ - void activateNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + void activateNJointControllers(const std::vector<NJointControllerBasePtr>& ctrls); /** - * @brief Requests deactivation for the given \ref NJointController. - * @param ctrl The \ref NJointController to be deactivated. + * @brief Requests deactivation for the given \ref NJointControllerBase. + * @param ctrl The \ref NJointControllerBase to be deactivated. * @see deactivateNJointControllers */ - void deactivateNJointController(const NJointControllerPtr& ctrl); + void deactivateNJointController(const NJointControllerBasePtr& ctrl); /** - * @brief Requests deactivation for the given \ref NJointController "NJointControllers". - * @param ctrls The \ref NJointController "NJointControllers" to be deactivated. + * @brief Requests deactivation for the given \ref NJointControllerBase "NJointControllers". + * @param ctrls The \ref NJointControllerBase "NJointControllers" to be deactivated. * @see deactivateNJointController */ - void deactivateNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + void deactivateNJointControllers(const std::vector<NJointControllerBasePtr>& ctrls); // //////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////// implementation //////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////// // private: /** - * @brief Deletes the given \ref NJointController "NJointControllers" and removes them + * @brief Deletes the given \ref NJointControllerBase "NJointControllers" and removes them * from the \ref ArmarXManager - * @param ctrls \ref NJointController "NJointControllers" to delete. + * @param ctrls \ref NJointControllerBase "NJointControllers" to delete. * @param blocking Whether removal from the \ref ArmarXManager should be blocking. * @param l Proxy to the listener topic all removal events should be sent to. */ - void removeNJointControllers(std::map<std::string, NJointControllerPtr>& ctrls, bool blocking = true, RobotUnitListenerPrx l = nullptr); + void removeNJointControllers(std::map<std::string, NJointControllerBasePtr>& ctrls, bool blocking = true, RobotUnitListenerPrx l = nullptr); /** - * @brief Calls \ref removeNJointControllers for all \ref NJointController "NJointControllers" + * @brief Calls \ref removeNJointControllers for all \ref NJointControllerBase "NJointControllers" * queued for deletion (\ref nJointControllersToBeDeleted). * @param blocking Whether removal from the \ref ArmarXManager should be blocking. * @param l Proxy to the listener topic all removal events should be sent to. @@ -409,14 +409,14 @@ namespace armarx void removeNJointControllersToBeDeleted(bool blocking = true, RobotUnitListenerPrx l = nullptr); /** - * @brief Sets the requested flag for all given \ref NJointController "NJointControllers" and unsets it for the rest. - * @param request The \ref NJointController "NJointControllers" where the requested flag should be set. + * @brief Sets the requested flag for all given \ref NJointControllerBase "NJointControllers" and unsets it for the rest. + * @param request The \ref NJointControllerBase "NJointControllers" where the requested flag should be set. */ - void updateNJointControllerRequestedState(const std::set<NJointControllerPtr>& request); + void updateNJointControllerRequestedState(const std::set<NJointControllerBasePtr>& request); /** - * @brief Throws if there is no factory for \ref NJointController "NJointControllers" for the given class name. + * @brief Throws if there is no factory for \ref NJointControllerBase "NJointControllers" for the given class name. * @param className The class to check for. - * @throw If there is no factory for \ref NJointController "NJointControllers" for the given class name. + * @throw If there is no factory for \ref NJointControllerBase "NJointControllers" for the given class name. */ void checkNJointControllerClassName(const std::string& className) const; @@ -425,9 +425,9 @@ namespace armarx // //////////////////////////////////////////////////////////////////////////////////////// // private: /// @brief Holds all currently loaded NJoint controllers (index: [instancename])(May not be accessed in rt.) - std::map<std::string, NJointControllerPtr> nJointControllers; + std::map<std::string, NJointControllerBasePtr> nJointControllers; /// @brief These controllers will be deleted in the next iteration of publish - std::map<std::string, NJointControllerPtr> nJointControllersToBeDeleted; + std::map<std::string, NJointControllerBasePtr> nJointControllersToBeDeleted; /// @brief VirtualRobot used when creating controllers / calling other functions in this module VirtualRobot::RobotPtr controllerCreateRobot; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleDevices.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleDevices.h index 490059fa6..7d5f2e519 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleDevices.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleDevices.h @@ -282,13 +282,13 @@ namespace armarx * @param deviceName \ref ControlDevice's name. * @return The \ref ControlDevice */ - ConstControlDevicePtr getControlDevice(const std::string& deviceName) const; /// TODO move to attorney for NJointController + ConstControlDevicePtr getControlDevice(const std::string& deviceName) const; /// TODO move to attorney for NJointControllerBase /** * @brief Returns the \ref SensorDevice * @param deviceName \ref SensorDevice's name. * @return The \ref SensorDevice */ - ConstSensorDevicePtr getSensorDevice(const std::string& deviceName) const; /// TODO move to attorney for NJointController + ConstSensorDevicePtr getSensorDevice(const std::string& deviceName) const; /// TODO move to attorney for NJointControllerBase /** * @brief Returns all \ref SensorDevice "SensorDevices" @@ -407,7 +407,7 @@ namespace armarx //ctrl dev /// @brief \ref ControlDevice "ControlDevices" added to this unit (data may only be added during and only be used after \ref State::InitializingDevices) KeyValueVector<std::string, ControlDevicePtr> controlDevices; - /// @brief const pointer to all ControlDevices (passed to GenerateConfigDescription of a NJointController) + /// @brief const pointer to all ControlDevices (passed to GenerateConfigDescription of a NJointControllerBase) std::map<std::string, ConstControlDevicePtr> controlDevicesConstPtr; /// @brief Guards access to all \ref ControlDevice "ControlDevices" mutable MutexType controlDevicesMutex; @@ -418,7 +418,7 @@ namespace armarx //sens dev /// @brief \ref SensorDevice "SensorDevices" added to this unit (data may only be added during and only be used after \ref State::InitializingDevices) KeyValueVector<std::string, SensorDevicePtr > sensorDevices; - /// @brief const pointer to all SensorDevices (passed to GenerateConfigDescription of a NJointController) + /// @brief const pointer to all SensorDevices (passed to GenerateConfigDescription of a NJointControllerBase) std::map<std::string, ConstSensorDevicePtr> sensorDevicesConstPtr; /// @brief Guards access to all \ref SensorDevice "SensorDevices" mutable MutexType sensorDevicesMutex; @@ -447,7 +447,7 @@ namespace armarx */ friend class DevicesAttorneyForControlThreadDataBuffer; /** - * \brief This class allows minimal access to private members of \ref armarx::RobotUnitModule::Devices in a sane fashion for \ref armarx::NJointController. + * \brief This class allows minimal access to private members of \ref armarx::RobotUnitModule::Devices in a sane fashion for \ref armarx::NJointControllerBase. * \warning !! DO NOT ADD ADDITIONAL FRIENDS IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ friend class DevicesAttorneyForNJointController; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp index c24b433f9..741119b55 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp @@ -30,27 +30,27 @@ namespace armarx namespace RobotUnitModule { /** - * \brief This class allows minimal access to private members of \ref NJointController in a sane fashion for \ref Publisher. + * \brief This class allows minimal access to private members of \ref NJointControllerBase in a sane fashion for \ref Publisher. * \warning !! DO NOT ADD ANYTHING IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !! */ class NJointControllerAttorneyForPublisher { friend class Publisher; - static bool GetStatusReportedActive(const NJointControllerPtr& nJointCtrl) + static bool GetStatusReportedActive(const NJointControllerBasePtr& nJointCtrl) { return nJointCtrl->statusReportedActive; } - static bool GetStatusReportedRequested(const NJointControllerPtr& nJointCtrl) + static bool GetStatusReportedRequested(const NJointControllerBasePtr& nJointCtrl) { return nJointCtrl->statusReportedRequested; } - static void UpdateStatusReported(const NJointControllerPtr& nJointCtrl) + static void UpdateStatusReported(const NJointControllerBasePtr& nJointCtrl) { nJointCtrl->statusReportedActive = nJointCtrl->isActive.load(); nJointCtrl->statusReportedRequested = nJointCtrl->isRequested.load(); } static void Publish( - const NJointControllerPtr& nJointCtrl, + const NJointControllerBasePtr& nJointCtrl, const SensorAndControl& sac, const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer @@ -59,7 +59,7 @@ namespace armarx nJointCtrl ->publish(sac, draw, observer); } static void DeactivatePublishing( - const NJointControllerPtr& nJointCtrl, + const NJointControllerBasePtr& nJointCtrl, const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer ) @@ -98,7 +98,7 @@ namespace armarx class ControllerManagementAttorneyForPublisher { friend class Publisher; - static const std::map<std::string, NJointControllerPtr>& GetNJointControllers(Publisher* p) + static const std::map<std::string, NJointControllerBasePtr>& GetNJointControllers(Publisher* p) { return p->_module<ControllerManagement>().nJointControllers; } @@ -127,7 +127,7 @@ namespace armarx { namespace RobotUnitModule { - const std::map<std::string, NJointControllerPtr>& Publisher::getNJointControllers() + const std::map<std::string, NJointControllerBasePtr>& Publisher::getNJointControllers() { throwIfInControlThread(BOOST_CURRENT_FUNCTION); return ControllerManagementAttorneyForPublisher::GetNJointControllers(this); @@ -169,7 +169,7 @@ namespace armarx for (const auto& pair : getNJointControllers()) { const auto begInner = TimeUtil::GetTime(true); - const NJointControllerPtr& nJointCtrl = pair.second; + const NJointControllerBasePtr& nJointCtrl = pair.second; //run some hook for active (used for visu) NJointControllerAttorneyForPublisher::Publish(nJointCtrl, controlThreadOutputBuffer, debugDrawerBatchPrx, debugObserverBatchPrx); @@ -541,7 +541,7 @@ namespace armarx haveSensorAndControlValsChanged, publishToObserver, activatedControllers, requestedJointControllers); } - //call publish hook + publish NJointController changes + //call publish hook + publish NJointControllerBase changes timingMap["NJointControllerUpdates"] = publishNJointControllerUpdates(timingMap, controlThreadOutputBuffer); //report new class names diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h index a10ed61e2..2391b2884 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h @@ -75,7 +75,7 @@ namespace armarx /** * @ingroup Library-RobotUnit-Modules * @brief This \ref ModuleBase "Module" manages publishing of all data to Topics, - * updating of all units managed by \ref Units "the Units module" and calling of \ref NJointController hooks. + * updating of all units managed by \ref Units "the Units module" and calling of \ref NJointControllerBase hooks. * * @see ModuleBase */ @@ -161,7 +161,7 @@ namespace armarx * @brief Returns a map containing all current NJointControllers. * @return A map containing all current NJointControllers. */ - const std::map<std::string, NJointControllerPtr>& getNJointControllers(); + const std::map<std::string, NJointControllerBasePtr>& getNJointControllers(); /** * @brief Returns the used RobotUnitObserver * @return The used RobotUnitObserver @@ -172,16 +172,16 @@ namespace armarx return robotUnitObserver; } /** - * @brief Publishes updtes about new classes od \ref NJointController "NJointControllers" + * @brief Publishes updtes about new classes od \ref NJointControllerBase "NJointControllers" * @return The time required by this function as a \ref Variant */ TimedVariantPtr publishNJointClassNames(); /** - * @brief Publishes updates of \ref NJointController "NJointControllers" ([de]activate + publish hooks) + * @brief Publishes updates of \ref NJointControllerBase "NJointControllers" ([de]activate + publish hooks) * @param timingMap Timings of this publish iteration (out param) * @param controlThreadOutputBuffer The output of the published \ref ControlThread iteration * @return The time required by this function as a \ref Variant - * @see NJointController::onPublish + * @see NJointControllerBase::onPublish */ TimedVariantPtr publishNJointControllerUpdates( StringVariantBaseMap& timingMap, @@ -190,7 +190,7 @@ namespace armarx * @brief Updates all sub units and publishes the timings of these updates * @param timingMap Timings of this publish iteration (out param) * @param controlThreadOutputBuffer The output of the published \ref ControlThread iteration - * @param activatedControllers The \ref JointController "JointControllers" and \ref NJointController "NJointControllers" + * @param activatedControllers The \ref JointController "JointControllers" and \ref NJointControllerBase "NJointControllers" * active in the published \ref ControlThread iteration * @return The time required by this function as a \ref Variant */ @@ -203,7 +203,7 @@ namespace armarx * @param controlThreadOutputBuffer The output of the published \ref ControlThread iteration * @param haveSensorAndControlValsChanged Whether \ref ControlTargetBase "ControlTargets" were updated by the \ref ControlThread * @param publishToObserver Whether data should be published to observers - * @param activatedControllers The \ref JointController "JointControllers" and \ref NJointController "NJointControllers" + * @param activatedControllers The \ref JointController "JointControllers" and \ref NJointControllerBase "NJointControllers" * active in the published \ref ControlThread iteration * @param requestedJointControllers * @return The time required by this function as a \ref Variant @@ -250,7 +250,7 @@ namespace armarx IceUtil::Time publishNewSensorDataTime; /// @brief The thread executing the publisher loop PublisherTaskT::pointer_type publisherTask; ///TODO use std thread - /// @brief The already reported classes of \ref NJointController "NJointControllers" + /// @brief The already reported classes of \ref NJointControllerBase "NJointControllers" std::set<std::string> lastReportedClasses; /// @brief Whether \ref SensorValueBase "SensorValues" should be published to the observers diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleUnits.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleUnits.cpp index 92d0c1162..ac6334e53 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleUnits.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleUnits.cpp @@ -231,11 +231,11 @@ namespace armarx NJointKinematicUnitPassThroughControllerConfigPtr config = new NJointKinematicUnitPassThroughControllerConfig; \ config->controlMode=controlMode; \ config->deviceName=controlDeviceName; \ - const NJointControllerPtr& nJointCtrl = _module<ControllerManagement>().createNJointController( \ - "NJointKinematicUnitPassThroughController", \ - getName() + "_" + "NJointKU_PTCtrl_"+controlDeviceName+"_"+controlMode, \ - config, \ - false, true); \ + const NJointControllerBasePtr& nJointCtrl = _module<ControllerManagement>().createNJointController( \ + "NJointKinematicUnitPassThroughController", \ + getName() + "_" + "NJointKU_PTCtrl_"+controlDeviceName+"_"+controlMode, \ + config, \ + false, true); \ pt = NJointKinematicUnitPassThroughControllerPtr::dynamicCast(nJointCtrl); \ ARMARX_CHECK_EXPRESSION(pt); \ } \ diff --git a/source/RobotAPI/components/units/RobotUnit/SyntaxCheck.cpp b/source/RobotAPI/components/units/RobotUnit/SyntaxCheck.cpp index 377f180e2..7902e41d3 100644 --- a/source/RobotAPI/components/units/RobotUnit/SyntaxCheck.cpp +++ b/source/RobotAPI/components/units/RobotUnit/SyntaxCheck.cpp @@ -20,110 +20,8 @@ * GNU General Public License */ - -//#include "RobotUnit.h" - -//#include "NJointControllers/NJointController.h" - -//#include "RobotUnitModules/RobotUnitModuleBase.h" - -/////////////////////////////////// - -//#include "RobotUnit.h" -//#include "NJointControllers/NJointController.h" - -//#include "NJointControllers/NJointController.h" -//#include "RobotUnit.h" - -//#include "NJointControllers/NJointController.h" -//#include "RobotUnitModules/RobotUnitModuleBase.h" - -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "NJointControllers/NJointController.h" - -//#include "RobotUnit.h" -//#include "RobotUnitModules/RobotUnitModuleBase.h" - -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "RobotUnit.h" - -//////////////////////////////////// - - -//#include "RobotUnit.h" -//#include "NJointControllers/NJointController.h" -//#include "RobotUnitModules/RobotUnitModuleBase.h" - #include "NJointControllers/NJointController.h" #include "RobotUnit.h" #include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "NJointControllers/NJointController.h" -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "RobotUnit.h" - -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "NJointControllers/NJointController.h" -//#include "RobotUnit.h" - -//#include "RobotUnit.h" -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "NJointControllers/NJointController.h" - -//#include "RobotUnitModules/RobotUnitModuleBase.h" -//#include "RobotUnit.h" -//#include "NJointControllers/NJointController.h" - - -/////////////////////////////////// - -//#include <atomic> -//#include <chrono> -//#include <mutex> - -//#include <boost/preprocessor/variadic/to_seq.hpp> -//#include <boost/preprocessor/seq/for_each.hpp> -//#include <boost/current_function.hpp> - -//#include <VirtualRobot/Robot.h> - -//#include <ArmarXCore/core/Component.h> - -//#include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h> - - - -/* -#include "BasicControllers.h" -#include "Constants.h" -#include "ControlModes.h" -#include "ControlTargets/ControlTargetHolonomicPlatformVelocity.h" -#include "ControlTargets/ControlTarget1DoFActuator.h" -#include "ControlTargets/ControlTargetBase.h" -#include "DefaultWidgetDescriptions.h" -#include "Devices/RTThreadTimingsSensorDevice.h" -#include "Devices/ControlDevice.h" -#include "Devices/SensorDevice.h" -#include "Devices/DeviceBase.h" -#include "JointControllers/JointController.h" -#include "NJointControllers/NJointController.h" -#include "NJointControllers/NJointKinematicUnitPassThroughController.h" -#include "NJointControllers/NJointHolonomicPlatformUnitVelocityPassThroughController.h" -#include "NJointControllers/NJointTrajectoryController.h" -#include "RobotUnit.h" -#include "SensorValues/SensorValueRTThreadTimings.h" -#include "SensorValues/SensorValueIMU.h" -#include "SensorValues/SensorValue1DoFActuator.h" -#include "SensorValues/SensorValueHolonomicPlatform.h" -#include "SensorValues/SensorValueBase.h" -#include "SensorValues/SensorValueForceTorque.h" -#include "util/JointAndNJointControllers.h" -#include "Units/KinematicSubUnit.h" -#include "Units/RobotUnitSubUnit.h" -#include "Units/PlatformSubUnit.h" -#include "Units/InertialMeasurementSubUnit.h" -#include "Units/ForceTorqueSubUnit.h" -#include "util.h" - //this file is only for syntax checks -*/ diff --git a/source/RobotAPI/components/units/RobotUnit/Units/KinematicSubUnit.cpp b/source/RobotAPI/components/units/RobotUnit/Units/KinematicSubUnit.cpp index ec6d2c5fb..66fbc66b5 100644 --- a/source/RobotAPI/components/units/RobotUnit/Units/KinematicSubUnit.cpp +++ b/source/RobotAPI/components/units/RobotUnit/Units/KinematicSubUnit.cpp @@ -93,7 +93,7 @@ void armarx::KinematicSubUnit::update(const armarx::SensorAndControl& sc, const bool statusesAvalueChanged = false; long timestamp = sc.sensorValuesTimestamp.toMicroSeconds(); - std::set<NJointController*> nJointCtrls {c.nJointControllers.begin(), c.nJointControllers.end()}; + std::set<NJointControllerBase*> nJointCtrls {c.nJointControllers.begin(), c.nJointControllers.end()}; std::vector<std::string> actuatorsWithoutSensor; actuatorsWithoutSensor.reserve(devs.size()); for (const auto& name2actuatorData : devs) @@ -243,7 +243,7 @@ void armarx::KinematicSubUnit::setJointTorques(const armarx::NameValueMap& torqu void armarx::KinematicSubUnit::switchControlMode(const armarx::NameControlModeMap& ncm, const Ice::Current&) { - std::map<std::string, NJointControllerPtr> toActivate; + std::map<std::string, NJointControllerBasePtr> toActivate; { std::lock_guard<std::mutex> guard {dataMutex}; for (const auto& n2c : ncm) @@ -282,7 +282,7 @@ void armarx::KinematicSubUnit::switchControlMode(const armarx::NameControlModeMa { const auto& name = n2NJointCtrl.first; ARMARX_DEBUG << "checking group of '" << name << "'"; - const NJointControllerPtr& nJointCtrl = n2NJointCtrl.second; + const NJointControllerBasePtr& nJointCtrl = n2NJointCtrl.second; if (!controlDeviceHardwareControlModeGroupsMerged.count(name)) { continue; diff --git a/source/RobotAPI/components/units/RobotUnit/Units/TCPControllerSubUnit.cpp b/source/RobotAPI/components/units/RobotUnit/Units/TCPControllerSubUnit.cpp index b65d6f298..f978876e5 100644 --- a/source/RobotAPI/components/units/RobotUnit/Units/TCPControllerSubUnit.cpp +++ b/source/RobotAPI/components/units/RobotUnit/Units/TCPControllerSubUnit.cpp @@ -125,7 +125,7 @@ void TCPControllerSubUnit::setTCPVelocity(const std::string& nodeSetName, const bool nodeSetAlreadyControlled = false; for (auto& name : NJointControllers) { - NJointControllerPtr controller; + NJointControllerBasePtr controller; try { controller = robotUnit->getNJointControllerNotNull(name); @@ -203,7 +203,7 @@ void armarx::TCPControllerSubUnit::componentPropertiesUpdated(const std::set<std { float avoidJointLimitsKp = getProperty<float>("AvoidJointLimitsKp").getValue(); auto activeNJointControllers = robotUnit->getNJointControllersNotNull(robotUnit->getNJointControllerNames()); - for (NJointControllerPtr controller : activeNJointControllers) + for (NJointControllerBasePtr controller : activeNJointControllers) { auto tcpController = NJointCartesianVelocityControllerWithRampPtr::dynamicCast(controller); if (tcpController) diff --git a/source/RobotAPI/components/units/RobotUnit/Units/TrajectoryControllerSubUnit.cpp b/source/RobotAPI/components/units/RobotUnit/Units/TrajectoryControllerSubUnit.cpp index ab9646af6..0a3669091 100644 --- a/source/RobotAPI/components/units/RobotUnit/Units/TrajectoryControllerSubUnit.cpp +++ b/source/RobotAPI/components/units/RobotUnit/Units/TrajectoryControllerSubUnit.cpp @@ -428,7 +428,7 @@ bool TrajectoryControllerSubUnit::controllerExists() auto allNJointControllers = robotUnit->getNJointControllersNotNull(robotUnit->getNJointControllerNames()); NJointTrajectoryControllerPtr trajController; - for (NJointControllerPtr controller : allNJointControllers) + for (const auto& controller : allNJointControllers) { trajController = NJointTrajectoryControllerPtr::dynamicCast(controller); if (!trajController) diff --git a/source/RobotAPI/components/units/RobotUnit/util/JointAndNJointControllers.h b/source/RobotAPI/components/units/RobotUnit/util/JointAndNJointControllers.h index faee01fc2..84809506f 100644 --- a/source/RobotAPI/components/units/RobotUnit/util/JointAndNJointControllers.h +++ b/source/RobotAPI/components/units/RobotUnit/util/JointAndNJointControllers.h @@ -26,7 +26,7 @@ namespace armarx { class JointController; - class NJointController; + class NJointControllerBase; /// @brief Structure used by the RobotUnit to swap lists of Joint and NJoint controllers struct JointAndNJointControllers { @@ -42,7 +42,7 @@ namespace armarx } std::vector<JointController*> jointControllers; - std::vector<NJointController*> nJointControllers; + std::vector<NJointControllerBase*> nJointControllers; /// @brief this is set by RobotUnit::writeRequestedControllers std::vector<std::size_t> jointToNJointControllerAssignement; -- GitLab