diff --git a/source/RobotAPI/components/units/BusInspectionUnitObserver.cpp b/source/RobotAPI/components/units/BusInspectionUnitObserver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cce4c9b8a223af9502df2808ffbd914d381fc4c --- /dev/null +++ b/source/RobotAPI/components/units/BusInspectionUnitObserver.cpp @@ -0,0 +1,121 @@ +/* +* This file is part of ArmarX. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @package ArmarX:: +* @author Peter Kaiser (peter dot kaiser at kit dot edu) +* @date 2015 +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#include "BusInspectionUnitObserver.h" + +#include <ArmarXCore/observers/checks/ConditionCheckUpdated.h> +#include <ArmarXCore/observers/checks/ConditionCheckEquals.h> +#include <ArmarXCore/observers/checks/ConditionCheckInRange.h> +#include <ArmarXCore/observers/checks/ConditionCheckLarger.h> +#include <ArmarXCore/observers/checks/ConditionCheckSmaller.h> +#include <ArmarXCore/observers/checks/ConditionCheckEqualsWithTolerance.h> +#include <RobotAPI/libraries/core/checks/ConditionCheckMagnitudeChecks.h> +#include <RobotAPI/libraries/core/observerfilters/OffsetFilter.h> +#include <ArmarXCore/observers/variant/DatafieldRef.h> + +#include <RobotAPI/libraries/core/RobotAPIObjectFactories.h> + +using namespace armarx; + +BusInspectionUnitObserver::BusInspectionUnitObserver() +{ +} + +void BusInspectionUnitObserver::setTopicName(std::string topicName) +{ + this->topicName = topicName; +} + +void BusInspectionUnitObserver::onInitObserver() +{ + if (topicName.empty()) + { + usingTopic(getProperty<std::string>("BusInspectionUnitTopicName").getValue()); + ARMARX_INFO << "Using topic " << getProperty<std::string>("BusInspectionUnitTopicName").getValue(); + } + else + { + usingTopic(topicName); + ARMARX_INFO << "Using topic " << topicName; + } +} + +void BusInspectionUnitObserver::onConnectObserver() +{ +} + +PropertyDefinitionsPtr BusInspectionUnitObserver::createPropertyDefinitions() +{ + return PropertyDefinitionsPtr(new BusInspectionUnitObserverPropertyDefinitions(getConfigIdentifier())); +} + +void BusInspectionUnitObserver::reportCycleTimeStatistics(int averageCycleTime, int minCycleTime, int maxCycleTime, const Ice::Current&) +{ + ScopedLock lock(dataMutex); + + try + { + std::string channelName = "HALCycleTimes"; + + DataFieldIdentifierPtr id_avg = new DataFieldIdentifier(getName(), channelName, "Average HAL Cycle"); + if (!existsChannel(id_avg->channelName)) + { + offerChannel(id_avg->channelName, "HAL Cycle times"); + } + + if (!existsDataField(id_avg->channelName, id_avg->datafieldName)) + { + offerDataFieldWithDefault(id_avg->channelName, id_avg->datafieldName, Variant(averageCycleTime), "Average HAL cycle time"); + } + else + { + setDataField(id_avg->channelName, id_avg->datafieldName, Variant(averageCycleTime)); + } + + DataFieldIdentifierPtr id_min = new DataFieldIdentifier(getName(), channelName, "Minimum HAL Cycle"); + if (!existsDataField(id_min->channelName, id_min->datafieldName)) + { + offerDataFieldWithDefault(id_min->channelName, id_min->datafieldName, Variant(minCycleTime), "Minimum HAL cycle time"); + } + else + { + setDataField(id_min->channelName, id_min->datafieldName, Variant(minCycleTime)); + } + + DataFieldIdentifierPtr id_max = new DataFieldIdentifier(getName(), channelName, "Maximum HAL Cycle"); + if (!existsDataField(id_max->channelName, id_max->datafieldName)) + { + offerDataFieldWithDefault(id_max->channelName, id_max->datafieldName, Variant(maxCycleTime), "Maximum HAL cycle time"); + } + else + { + setDataField(id_max->channelName, id_max->datafieldName, Variant(maxCycleTime)); + } + + updateChannel(channelName); + } + catch (std::exception& e) + { + ARMARX_ERROR << "Reporting HAL cycle time failed! "; + handleExceptions(); + } +} diff --git a/source/RobotAPI/components/units/BusInspectionUnitObserver.h b/source/RobotAPI/components/units/BusInspectionUnitObserver.h new file mode 100644 index 0000000000000000000000000000000000000000..5002dcddd02eadb4f2098a470c27dc4c68bb70fe --- /dev/null +++ b/source/RobotAPI/components/units/BusInspectionUnitObserver.h @@ -0,0 +1,75 @@ +/* +* This file is part of ArmarX. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @package ArmarX:: +* @author Peter Kaiser (peter dot kaiser at kit dot edu) +* @date 2015 +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#ifndef _ARMARX_ROBOTAPI_BUSINSPECTIONUNITOBSERVER_H +#define _ARMARX_ROBOTAPI_BUSINSPECTIONUNITOBSERVER_H + +#include <RobotAPI/interface/hardware/BusInspectionInterface.h> +#include <ArmarXCore/observers/Observer.h> + +namespace armarx +{ + /** + * \class ForceTorqueObserverPropertyDefinitions + * \brief + */ + class BusInspectionUnitObserverPropertyDefinitions: + public ComponentPropertyDefinitions + { + public: + BusInspectionUnitObserverPropertyDefinitions(std::string prefix): + ComponentPropertyDefinitions(prefix) + { + defineOptionalProperty<std::string>("BusInspectionUnitTopicName", "HALCycleTimes", "Name of the BusInspectionUnit Topic"); + } + }; + + class BusInspectionUnitObserver : + virtual public Observer, + virtual public BusInspectionUnitObserverInterface + { + public: + BusInspectionUnitObserver(); + + void setTopicName(std::string topicName); + + virtual std::string getDefaultName() const + { + return "BusInspectionUnitObserver"; + } + void onInitObserver(); + void onConnectObserver(); + + virtual void reportCycleTimeStatistics(int averageCycleTime, int minCycleTime, int maxCycleTime, const Ice::Current&); + + /** + * @see PropertyUser::createPropertyDefinitions() + */ + virtual PropertyDefinitionsPtr createPropertyDefinitions(); + + private: + armarx::Mutex dataMutex; + std::string topicName; + }; +} + +#endif diff --git a/source/RobotAPI/components/units/CMakeLists.txt b/source/RobotAPI/components/units/CMakeLists.txt index 88a819376ebf0782b936810614319d8adef17994..451bf415e5348eb57981f88ee3aa3488facbb233 100644 --- a/source/RobotAPI/components/units/CMakeLists.txt +++ b/source/RobotAPI/components/units/CMakeLists.txt @@ -38,6 +38,7 @@ set(LIB_HEADERS HandUnit.h HandUnitSimulation.h BusInspectionUnit.h + BusInspectionUnitObserver.h KinematicUnit.h KinematicUnitSimulation.h PlatformUnit.h @@ -63,6 +64,7 @@ set(LIB_FILES HandUnit.cpp HandUnitSimulation.cpp BusInspectionUnit.cpp + BusInspectionUnitObserver.cpp KinematicUnit.cpp KinematicUnitSimulation.cpp PlatformUnit.cpp diff --git a/source/RobotAPI/interface/hardware/BusInspectionInterface.ice b/source/RobotAPI/interface/hardware/BusInspectionInterface.ice index e479ca292ca75fba67dc2633402200e3c5188782..3def44040c467eb3fe8a3bff5f82cd5df0a3b065 100644 --- a/source/RobotAPI/interface/hardware/BusInspectionInterface.ice +++ b/source/RobotAPI/interface/hardware/BusInspectionInterface.ice @@ -28,6 +28,7 @@ #include <ArmarXCore/interface/core/UserException.ice> #include <ArmarXCore/interface/core/BasicTypes.ice> +#include <ArmarXCore/interface/observers/ObserverInterface.ice> module armarx { @@ -46,7 +47,6 @@ module armarx string commandName; }; - struct DeviceStatus { OperationStatus operation; @@ -101,6 +101,11 @@ module armarx */ void reportCycleTimeStatistics(int averageCycleTime, int minCycleTime, int maxCycleTime); }; + + interface BusInspectionUnitObserverInterface extends ObserverInterface, BusInspectionListener + { + }; + }; #endif