diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.cpp b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.cpp index b669bf0db9f9b3ca426e25062259373122ce25ef..7d32ae794b427f07dc27e38edd8178460ec9fbd4 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.cpp +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.cpp @@ -137,11 +137,11 @@ namespace armarx return *plugin; } - void RobotUnitComponentPluginUser::waitUntilRobotUnitIsRunning() const + void RobotUnitComponentPluginUser::waitUntilRobotUnitIsRunning(const std::function<bool()>& termCond) const { ARMARX_INFO << "Waiting until robot unit is running ..."; - while ((isNullptr(getRobotUnit()) or (not getRobotUnit()->isRunning()))) + while ((not termCond()) and ((isNullptr(getRobotUnit()) or (not getRobotUnit()->isRunning())))) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h index 5b8369776c1f67d7f0ef24db704d3a37625e16e5..63d78de7da9033399b92497a7bccf89161337588 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h @@ -80,7 +80,17 @@ namespace armarx RobotUnitComponentPluginUser(); RobotUnitInterfacePrx getRobotUnit() const; - void waitUntilRobotUnitIsRunning() const; + + /** + * @brief Waits until the robot unit is running. + * + * Although the robot unit proxy might be initialized (\see getRobotUnit()), the robot unit might + * not be fully initialized. + * + * @param termCond Termination condition. If it evaluates to true, waitUntilRobotUnitIsRunning returns without waiting + * for the robot unit to become available. + */ + void waitUntilRobotUnitIsRunning(const std::function<bool()>& termCond = [] {return false;}) const; plugins::RobotUnitComponentPlugin& getRobotUnitComponentPlugin(); private: