From 9bd03706e357fc3fee0e00036c428d995080b1f8 Mon Sep 17 00:00:00 2001 From: Raphael Grimm <raphael.grimm@kit.edu> Date: Sat, 21 Apr 2018 21:04:30 +0200 Subject: [PATCH] Add RobotUnitModules::ControllerManagement::deactivateAndDeleteNJointController (and memberversions for NJointController) --- .../NJointControllers/NJointController.cpp | 4 ++ .../NJointControllers/NJointController.h | 1 + .../RobotUnitModuleControllerManagement.cpp | 39 +++++++++++++++++- .../RobotUnitModuleControllerManagement.h | 41 +++++++++++++++++++ .../units/RobotUnit/NJointController.ice | 1 + .../units/RobotUnit/RobotUnitInterface.ice | 3 ++ 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp index 3343f8233..ea7f0c928 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp @@ -138,6 +138,10 @@ namespace armarx { robotUnit.deleteNJointController(this); } + void NJointController::deactivateAndDeleteController(const Ice::Current&) + { + robotUnit.deactivateAndDeleteNJointController(this); + } void NJointController::publish(const SensorAndControl& sac, const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) { diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h index f754ae66b..51df48c40 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.h @@ -249,6 +249,7 @@ namespace armarx void activateController(const Ice::Current& = GlobalIceCurrent) final override; void deactivateController(const Ice::Current& = GlobalIceCurrent) final override; void deleteController(const Ice::Current& = GlobalIceCurrent) final override; + void deactivateAndDeleteController(const Ice::Current& = GlobalIceCurrent) final override; WidgetDescription::StringWidgetDictionary getFunctionDescriptions(const Ice::Current& = GlobalIceCurrent) const override; void callDescribedFunction(const std::string&, const StringVariantBaseMap&, const Ice::Current& = GlobalIceCurrent) override; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp index 2f7a57cd9..593baca54 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp @@ -440,9 +440,46 @@ namespace armarx } } + void ControllerManagement::deactivateAndDeleteNJointController(const std::string &name, const Ice::Current &) + { + deactivateAndDeleteNJointControllers(getNJointControllersNotNull({name})); + } + void ControllerManagement::deactivateAndDeleteNJointControllers(const Ice::StringSeq &names, const Ice::Current &) + { + deactivateAndDeleteNJointControllers(getNJointControllersNotNull(names)); + } + void ControllerManagement::deactivateAndDeleteNJointController(const NJointControllerPtr &ctrl) + { + deactivateAndDeleteNJointControllers({ctrl}); + } + void ControllerManagement::deactivateAndDeleteNJointControllers(const std::vector<NJointControllerPtr>& ctrlsToDelVec) + { + auto guard = getGuard(); + throwIfDevicesNotReady(__FUNCTION__); + if (ctrlsToDelVec.empty()) + { + return; + } + deactivateNJointControllers(ctrlsToDelVec); + while( + std::any_of( + ctrlsToDelVec.begin(), + ctrlsToDelVec.end(), + [](const NJointControllerPtr& ctrl) {return ctrl->isControllerActive();} + ) + ) + { + if(isShuttingDown()) + { + return; + } + std::this_thread::sleep_for(std::chrono::microseconds{100}); + } + deleteNJointControllers(ctrlsToDelVec); + } NJointControllerClassDescription ControllerManagement::getNJointControllerClassDescription( - const std::string& className, const Ice::Current&) const + const std::string& className, const Ice::Current&) const { while (getRobotUnitState() == RobotUnitState::InitializingComponent || getRobotUnitState() == RobotUnitState::InitializingDevices) { diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h index c0b3cdfe5..91300315a 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.h @@ -209,6 +209,26 @@ namespace armarx * @see deleteNJointController */ void deleteNJointControllers(const Ice::StringSeq& names, const Ice::Current&) override; + /** + * @brief Queues the given \ref NJointController for deletion and deactivates it if necessary. + * @param name The \ref NJointController to delete. + * @see removeNJointControllersToBeDeleted + * @see nJointControllersToBeDeleted + * @see deleteNJointController + * @see deleteNJointControllers + * @see deactivateAnddeleteNJointControllers + */ + void deactivateAndDeleteNJointController(const std::string& name, const Ice::Current&) override; + /** + * @brief Queues the given \ref NJointController "NJointControllers" for deletion and deactivates them if necessary. + * @param names The \ref NJointController "NJointControllers" to delete. + * @see removeNJointControllersToBeDeleted + * @see nJointControllersToBeDeleted + * @see deleteNJointController + * @see deleteNJointControllers + * @see deactivateAnddeleteNJointController + */ + void deactivateAndDeleteNJointControllers(const Ice::StringSeq& names, const Ice::Current&) override; /** * @brief Requests activation for the given \ref NJointController. @@ -317,6 +337,27 @@ namespace armarx * @see deleteNJointController */ void deleteNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + /** + * @brief Queues the given \ref NJointController for deletion and deactivates it if necessary. + * @param ctrl The \ref NJointController to delete. + * @see removeNJointControllersToBeDeleted + * @see nJointControllersToBeDeleted + * @see deleteNJointController + * @see deleteNJointControllers + * @see deactivateAnddeleteNJointControllers + */ + void deactivateAndDeleteNJointController(const NJointControllerPtr& ctrl); + /** + * @brief Queues the given \ref NJointController "NJointControllers" for deletion and deactivates them if necessary. + * @param ctrls The \ref NJointController "NJointControllers" to delete. + * @see removeNJointControllersToBeDeleted + * @see nJointControllersToBeDeleted + * @see deleteNJointController + * @see deleteNJointControllers + * @see deactivateAnddeleteNJointController + */ + void deactivateAndDeleteNJointControllers(const std::vector<NJointControllerPtr>& ctrls); + /** * @brief Requests activation for the given \ref NJointController. diff --git a/source/RobotAPI/interface/units/RobotUnit/NJointController.ice b/source/RobotAPI/interface/units/RobotUnit/NJointController.ice index 0921d4d42..55cc87a1d 100644 --- a/source/RobotAPI/interface/units/RobotUnit/NJointController.ice +++ b/source/RobotAPI/interface/units/RobotUnit/NJointController.ice @@ -88,6 +88,7 @@ module armarx void activateController(); void deactivateController(); void deleteController() throws LogicError; + void deactivateAndDeleteController() throws LogicError; ["cpp:const"] idempotent WidgetDescription::StringWidgetDictionary getFunctionDescriptions(); void callDescribedFunction(string fuinctionName, StringVariantBaseMap values) throws InvalidArgumentException; diff --git a/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice b/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice index f5906a1fc..406d8121b 100644 --- a/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice +++ b/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice @@ -200,6 +200,9 @@ module armarx void deleteNJointController(string controllerInstanceName)throws InvalidArgumentException, LogicError; void deleteNJointControllers(Ice::StringSeq controllerInstanceNames)throws InvalidArgumentException, LogicError; + void deactivateAndDeleteNJointController(string controllerInstanceName)throws InvalidArgumentException, LogicError; + void deactivateAndDeleteNJointControllers(Ice::StringSeq controllerInstanceNames)throws InvalidArgumentException, LogicError; + //loading libs bool loadLibFromPath(string path); bool loadLibFromPackage(string package, string libname); -- GitLab