diff --git a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp index 0dfbeb0705eb580bedcdcf117490c8253a368777..5113961eeebb95c1af593714fbb1eca93ea84909 100644 --- a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp +++ b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp @@ -54,7 +54,7 @@ namespace armarx if (enableHeartBeat) { - this->heartbeat->signUp(armarx::core::time::Duration::MilliSeconds(1000), + this->heartbeatPlugin->signUp(armarx::core::time::Duration::MilliSeconds(1000), armarx::core::time::Duration::MilliSeconds(1500), {"Gamepad"}, "The GamepadControlUnit"); @@ -193,9 +193,14 @@ namespace armarx { auto now = armarx::core::time::dto::DateTime(); armarx::core::time::toIce(now, armarx::core::time::DateTime::Now()); - heartbeat->heartbeat(); + heartbeatPlugin->heartbeat(); } //ARMARX_INFO << "sending targets" << data.leftStickX* scaleX << " " << data.leftStickY* scaleY << " " << data.rightStickX* scaleRotation; } + + GamepadControlUnit::GamepadControlUnit() + { + addPlugin(heartbeatPlugin); + } } // namespace armarx diff --git a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h index ee35989d9ab3c4532e4c2aa920695853d6b8e32f..9438f305fe6a96648eb4d6011112ea637a245369 100644 --- a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h +++ b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h @@ -70,10 +70,11 @@ namespace armarx */ class GamepadControlUnit : virtual public armarx::Component, - virtual public armarx::HeartbeatComponentPluginUser, virtual public GamepadUnitListener { public: + GamepadControlUnit(); + /** * @see armarx::ManagedIceObject::getDefaultName() */ @@ -111,6 +112,8 @@ namespace armarx private: PlatformUnitInterfacePrx platformUnitPrx; + plugins::HeartbeatComponentPlugin* heartbeatPlugin = nullptr; + bool enableHeartBeat = false; diff --git a/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.cpp b/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.cpp index add212dcb887d2fa1f57f688c1e2cc5fff705ddf..0d67c40a799d88c4b5471e6ea7a99004b40a398b 100644 --- a/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.cpp +++ b/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.cpp @@ -33,6 +33,12 @@ using namespace armarx; +HokuyoLaserUnit::HokuyoLaserUnit() +{ + addPlugin(heartbeat); +} + + void HokuyoLaserUnit::onInitComponent() { @@ -84,6 +90,8 @@ HokuyoLaserUnit::onInitComponent() void HokuyoLaserUnit::onConnectComponent() { + ARMARX_TRACE; + topic = getTopic<LaserScannerUnitListenerPrx>(topicName); debugObserver = getTopic<DebugObserverInterfacePrx>( getProperty<std::string>("DebugObserverName").getValue()); @@ -105,11 +113,11 @@ HokuyoLaserUnit::onConnectComponent() continue; } + ARMARX_CHECK_NOT_NULL(heartbeat); heartbeat->signUp(device.componentName + "_" + device.ip, armarx::core::time::Duration::MilliSeconds(500), armarx::core::time::Duration::MilliSeconds(800), - true, - {"LaserScanner"}, + {"LaserScanner", "Localization"}, "HokuyoLaserScanDevice"); LaserScannerInfo info; @@ -219,6 +227,7 @@ HokuyoLaserScanDevice::reconnect() void HokuyoLaserScanDevice::run() { + ARMARX_TRACE; while (!task->isStopped()) { IceUtil::Time time_start = TimeUtil::GetTime(); @@ -273,7 +282,7 @@ HokuyoLaserScanDevice::run() } IceUtil::Time time_topicSensor = TimeUtil::GetTime(); - if (robotHealthPlugin) + if (robotHealthPlugin != nullptr) { robotHealthPlugin->heartbeatOnChannel(componentName + "_" + ip); } diff --git a/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.h b/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.h index 560a5dd1274d3e6a5b03e61474ba7c22c78bf579..0b8ad3985e9e3b1825054fe1339cb41a5c59f4cd 100644 --- a/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.h +++ b/source/RobotAPI/drivers/HokuyoLaserUnit/HokuyoLaserUnit.h @@ -105,10 +105,11 @@ namespace armarx */ class HokuyoLaserUnit : virtual public armarx::LaserScannerUnitInterface, - virtual public armarx::HeartbeatComponentPluginUser, virtual public armarx::SensorActorUnit { public: + HokuyoLaserUnit(); + /** * @see armarx::ManagedIceObject::getDefaultName() */ @@ -156,5 +157,7 @@ namespace armarx std::vector<HokuyoLaserScanDevice> devices; LaserScannerInfoSeq connectedDevices; DebugObserverInterfacePrx debugObserver; + + plugins::HeartbeatComponentPlugin* heartbeat = nullptr; }; } // namespace armarx diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.cpp b/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.cpp index edcdb9966b0974d519616288d3801edec198f625..ccbe0fd978fcd6bbc91dc10ce0dd86d286b2e9dd 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.cpp +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.cpp @@ -10,7 +10,7 @@ namespace armarx::plugins { void - HeartbeatComponentPlugin::signUp(const std::vector<std::string> tags, + HeartbeatComponentPlugin::signUp(const std::vector<std::string>& tags, const std::string& description) { RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs; @@ -21,7 +21,7 @@ namespace armarx::plugins void HeartbeatComponentPlugin::signUp(const std::string& identifier, - const std::vector<std::string> tags, + const std::vector<std::string>& tags, const std::string& description) { RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs; @@ -32,10 +32,10 @@ namespace armarx::plugins } void - HeartbeatComponentPlugin::signUp(const std::string identifier, + HeartbeatComponentPlugin::signUp(const std::string& identifier, const armarx::core::time::Duration& warning, const armarx::core::time::Duration& error, - const std::vector<std::string> tags, + const std::vector<std::string>& tags, const std::string& description) { RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs; @@ -44,13 +44,15 @@ namespace armarx::plugins argsCopy.identifier = identifier; toIce(argsCopy.maximumCycleTimeWarning, warning); toIce(argsCopy.maximumCycleTimeError, error); + + ARMARX_TRACE; signUp(argsCopy); } void HeartbeatComponentPlugin::signUp(const armarx::core::time::Duration& warning, const armarx::core::time::Duration& error, - const std::vector<std::string> tags, + const std::vector<std::string>& tags, const std::string& description) { RobotHealthHeartbeatArgs argsCopy = defaultHeartbeatArgs; @@ -65,15 +67,18 @@ namespace armarx::plugins void HeartbeatComponentPlugin::signUp(const RobotHealthHeartbeatArgs& args) { + ARMARX_TRACE; + ARMARX_CHECK_NOT_NULL(rhprx); + if (args.identifier.empty()) { RobotHealthHeartbeatArgs argsCopy = args; argsCopy.identifier = componentName; - p.rhprx->signUp(argsCopy); + rhprx->signUp(argsCopy); } else { - p.rhprx->signUp(args); + rhprx->signUp(args); } } @@ -130,9 +135,10 @@ namespace armarx::plugins } void - HeartbeatComponentPlugin::preOnConnectComponent() + HeartbeatComponentPlugin::postOnConnectComponent() { - topicName = p.rhprx->getTopicName(); + ARMARX_CHECK_NOT_NULL(rhprx); + topicName = rhprx->getTopicName(); robotHealthTopic = parent<Component>().getTopic<RobotHealthInterfacePrx>(topicName); } @@ -142,7 +148,7 @@ namespace armarx::plugins if (!properties->hasDefinition(makePropertyName(healthPropertyName))) { properties->component( - p.rhprx, "RobotHealth", healthPropertyName, "Name of the robot health component."); + rhprx, "RobotHealth", healthPropertyName, "Name of the robot health component."); } if (not properties->hasDefinition(makePropertyName(maximumCycleTimeWarningMSPropertyName))) @@ -161,11 +167,3 @@ namespace armarx::plugins } } // namespace armarx::plugins - -namespace armarx -{ - HeartbeatComponentPluginUser::HeartbeatComponentPluginUser() - { - addPlugin(heartbeat); - } -} // namespace armarx diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.h b/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.h index 0ed2c5be5700fae7344f7b2fe7cc31b405619d3a..db32aa161d9008a9aa330c32b2782e969a9db6e3 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.h +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/HeartbeatComponentPlugin.h @@ -38,14 +38,14 @@ namespace armarx::plugins /** * @brief register component to heartbeat */ - void signUp(const std::vector<std::string> aliases = {}, + void signUp(const std::vector<std::string>& aliases = {}, const std::string& description = ""); /** * @brief register component to heartbeat */ void signUp(const std::string& name, - const std::vector<std::string> aliases = {}, + const std::vector<std::string>& aliases = {}, const std::string& description = ""); /** @@ -53,16 +53,16 @@ namespace armarx::plugins */ void signUp(const armarx::core::time::Duration& warning, const armarx::core::time::Duration& error, - const std::vector<std::string> aliases = {}, + const std::vector<std::string>& aliases = {}, const std::string& description = ""); /** * @brief register component to heartbeat */ - void signUp(const std::string componentName, + void signUp(const std::string& componentName, const armarx::core::time::Duration& warning, const armarx::core::time::Duration& error, - const std::vector<std::string> aliases = {}, + const std::vector<std::string>& aliases = {}, const std::string& description = ""); /** @@ -88,16 +88,17 @@ namespace armarx::plugins protected: void preOnInitComponent() override; void postOnInitComponent() override; - void preOnConnectComponent() override; + // void preOnConnectComponent() override; + void postOnConnectComponent() override; void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override; - public: + private: + //! heartbeat topic name (outgoing) RobotHealthInterfacePrx robotHealthTopic; std::string topicName{"RobotHealthTopic"}; - private: - //! heartbeat topic name (outgoing) + RobotHealthComponentInterfacePrx rhprx; //! name of this component used as identifier for heartbeats std::string componentName; @@ -111,7 +112,6 @@ namespace armarx::plugins struct Properties { - RobotHealthComponentInterfacePrx rhprx; long maximumCycleTimeWarningMS = 50; long maximumCycleTimeErrorMS = 100; } p; @@ -120,24 +120,3 @@ namespace armarx::plugins RobotHealthHeartbeatArgs defaultHeartbeatArgs; }; } // namespace armarx::plugins - -namespace armarx -{ - /** - * @brief Provides a ready-to-use ArViz client `arviz` as member variable. - */ - class HeartbeatComponentPluginUser : virtual public ManagedIceObject - { - public: - HeartbeatComponentPluginUser(); - - RobotHealthInterfacePrx - getHeartbeatTopic() - { - return heartbeat->robotHealthTopic; - } - - protected: - armarx::plugins::HeartbeatComponentPlugin* heartbeat = nullptr; - }; -} // namespace armarx