From ce379957b3abc439f8ebdab7d24cd74ebf1bac44 Mon Sep 17 00:00:00 2001 From: David <david.schiebener@kit.edu> Date: Thu, 14 Aug 2014 11:05:50 +0200 Subject: [PATCH] created hand unit observer --- .../interface/units/HandUnitInterface.ice | 11 +- .../RobotAPI/robotstate/remote/CMakeLists.txt | 2 +- .../RobotAPI/robotstate/remote/LinkedPose.cpp | 2 + source/RobotAPI/units/CMakeLists.txt | 2 + source/RobotAPI/units/HandUnitObserver.cpp | 121 ++++++++++++++++++ source/RobotAPI/units/HandUnitObserver.h | 77 +++++++++++ 6 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 source/RobotAPI/units/HandUnitObserver.cpp create mode 100644 source/RobotAPI/units/HandUnitObserver.h diff --git a/source/RobotAPI/interface/units/HandUnitInterface.ice b/source/RobotAPI/interface/units/HandUnitInterface.ice index 524aa2dea..6e1e94a81 100644 --- a/source/RobotAPI/interface/units/HandUnitInterface.ice +++ b/source/RobotAPI/interface/units/HandUnitInterface.ice @@ -30,6 +30,8 @@ #include <Core/interface/core/UserException.ice> #include <Core/interface/core/BasicTypes.ice> #include <Core/interface/observers/VariantContainers.ice> +#include <Core/interface/observers/ObserverInterface.ice> + module armarx { @@ -43,11 +45,12 @@ module armarx NameValueMap getPreshapeJointValues(string preshapeName); }; - interface HandUnitListener + interface HandUnitListener extends armarx::ObserverInterface { - void reportHandClosed(); - void reportHandOpened(); - void reportHandPreshaped(); + void reportHandClosed(bool isLeftHand); + void reportHandOpened(bool isLeftHand); + void reportHandPreshaped(bool isLeftHand); + void reportNewHandShapeName(bool isLeftHand, string handShapeName); }; }; diff --git a/source/RobotAPI/robotstate/remote/CMakeLists.txt b/source/RobotAPI/robotstate/remote/CMakeLists.txt index e2467fb00..3c2fe56ef 100644 --- a/source/RobotAPI/robotstate/remote/CMakeLists.txt +++ b/source/RobotAPI/robotstate/remote/CMakeLists.txt @@ -1,5 +1,5 @@ -armarx_set_target("Core Library: ArmarXCoreRemoteRobot") +armarx_set_target("Core Library: RobotAPIRemoteRobot") find_package(Eigen3 QUIET) if (NOT Simox_FOUND) find_package(Simox 2.3.0 QUIET) diff --git a/source/RobotAPI/robotstate/remote/LinkedPose.cpp b/source/RobotAPI/robotstate/remote/LinkedPose.cpp index 23de4ee3e..fb57250f6 100644 --- a/source/RobotAPI/robotstate/remote/LinkedPose.cpp +++ b/source/RobotAPI/robotstate/remote/LinkedPose.cpp @@ -158,6 +158,8 @@ namespace armarx { void LinkedVector3::changeFrame(const std::string &newFrame, const Ice::Current &c) { + ARMARX_WARNING_S << "This function doesn't work!"; + if(newFrame == frame) return; diff --git a/source/RobotAPI/units/CMakeLists.txt b/source/RobotAPI/units/CMakeLists.txt index fd4a6fda6..0164bfecc 100644 --- a/source/RobotAPI/units/CMakeLists.txt +++ b/source/RobotAPI/units/CMakeLists.txt @@ -37,6 +37,7 @@ set(LIB_HEADERS TCPControlUnitObserver.h HandUnit.h + HandUnitObserver.h HardwareUnit.h KinematicUnit.h KinematicUnitSimulation.h @@ -58,6 +59,7 @@ set(LIB_FILES TCPControlUnitObserver.cpp HandUnit.cpp + HandUnitObserver.cpp HardwareUnit.cpp KinematicUnit.cpp KinematicUnitSimulation.cpp diff --git a/source/RobotAPI/units/HandUnitObserver.cpp b/source/RobotAPI/units/HandUnitObserver.cpp new file mode 100644 index 000000000..cdb899d59 --- /dev/null +++ b/source/RobotAPI/units/HandUnitObserver.cpp @@ -0,0 +1,121 @@ +#include "HandUnitObserver.h" + + +#include <Core/observers/checks/ConditionCheckEquals.h> +#include <Core/observers/checks/ConditionCheckUpdated.h> + + + + +using namespace armarx; + + +void HandUnitObserver::onInitObserver() +{ + usingTopic("LeftHandState"); + usingTopic("RightHandState"); + + offerChannel("leftHand", "Gives information about the state of the left robot hand."); + offerDataField("leftHand", "isOpen", VariantType::Bool, "Is true when the hand is open, false if not."); + setDataField("leftHand", "isOpen", false); + offerDataField("leftHand", "isClosed", VariantType::Bool, "Is true when the hand is closed, false if not."); + setDataField("leftHand", "isClosed", false); + offerDataField("leftHand", "shapeName", VariantType::String, "Contains the name of the current hand shape."); + setDataField("leftHand", "shapeName", "unknown"); + updateChannel("leftHand"); + + offerChannel("rightHand", "Gives information about the state of the right robot hand."); + offerDataField("rightHand", "isOpen", VariantType::Bool, "Is true when the hand is open, false if not."); + setDataField("rightHand", "isOpen", false); + offerDataField("rightHand", "isClosed", VariantType::Bool, "Is true when the hand is closed, false if not."); + setDataField("rightHand", "isClosed", false); + offerDataField("rightHand", "shapeName", VariantType::String, "Contains the name of the current hand shape."); + setDataField("rightHand", "shapeName", "unknown"); + updateChannel("rightHand"); + + offerConditionCheck("equals", new armarx::ConditionCheckEquals()); + offerConditionCheck("updated", new armarx::ConditionCheckUpdated()); +} + + + +void HandUnitObserver::onConnectObserver() +{ + +} + + + +void HandUnitObserver::onExitObserver() +{ + +} + + + +void HandUnitObserver::reportHandClosed(bool isLeftHand, const Ice::Current&) +{ + if (isLeftHand) + { + setDataField("leftHand", "isOpen", false); + setDataField("leftHand", "isClosed", true); + updateChannel("leftHand"); + } + else + { + setDataField("rightHand", "isOpen", false); + setDataField("rightHand", "isClosed", true); + updateChannel("rightHand"); + } +} + + + +void HandUnitObserver::reportHandOpened(bool isLeftHand, const Ice::Current&) +{ + if (isLeftHand) + { + setDataField("leftHand", "isOpen", true); + setDataField("leftHand", "isClosed", false); + updateChannel("leftHand"); + } + else + { + setDataField("rightHand", "isOpen", true); + setDataField("rightHand", "isClosed", false); + updateChannel("rightHand"); + } +} + + +void HandUnitObserver::reportHandPreshaped(bool isLeftHand, const Ice::Current&) +{ + if (isLeftHand) + { + setDataField("leftHand", "isOpen", false); + setDataField("leftHand", "isClosed", false); + updateChannel("leftHand"); + } + else + { + setDataField("rightHand", "isOpen", false); + setDataField("rightHand", "isClosed", false); + updateChannel("rightHand"); + } +} + + + +void HandUnitObserver::reportNewHandShapeName(bool isLeftHand, const std::string& handShapeName, const Ice::Current&) +{ + if (isLeftHand) + { + setDataField("leftHand", "shapeName", handShapeName); + updateChannel("leftHand"); + } + else + { + setDataField("rightHand", "shapeName", handShapeName); + updateChannel("rightHand"); + } +} diff --git a/source/RobotAPI/units/HandUnitObserver.h b/source/RobotAPI/units/HandUnitObserver.h new file mode 100644 index 000000000..74d9a20d5 --- /dev/null +++ b/source/RobotAPI/units/HandUnitObserver.h @@ -0,0 +1,77 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * 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 Lesser 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 RobotAPI::units + * @author David Schiebener <schiebener at kit dot edu> + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl.txt + * GNU General Public License + */ + +#ifndef _ARMARX_ROBOTAPI_HAND_UNIT_OBSERVER_H +#define _ARMARX_ROBOTAPI_HAND_UNIT_OBSERVER_H + +#include <RobotAPI/interface/units/HandUnitInterface.h> +#include <Core/observers/Observer.h> + + +namespace armarx +{ + + class HandUnitObserverPropertyDefinitions: + public ComponentPropertyDefinitions + { + public: + HandUnitObserverPropertyDefinitions(std::string prefix): + ComponentPropertyDefinitions(prefix) + { + //defineRequiredProperty<std::string>("HapticTopicName", "Name of the HapticUnit Topic"); + } + }; + + + class HandUnitObserver : + virtual public Observer, + virtual public HandUnitListener + { + public: + HandUnitObserver(); + + //void setTopicName(std::string topicName); + + // framework hooks + virtual std::string getDefaultName() const { return "HandUnitObserver"; } + virtual void onInitObserver(); + virtual void onConnectObserver(); + virtual void onExitObserver(); + + // observer interface + virtual void reportHandClosed(bool isLeftHand, const ::Ice::Current& = ::Ice::Current()); + virtual void reportHandOpened(bool isLeftHand, const ::Ice::Current& = ::Ice::Current()); + virtual void reportHandPreshaped(bool isLeftHand, const ::Ice::Current& = ::Ice::Current()); + virtual void reportNewHandShapeName(bool isLeftHand, const ::std::string& handShapeName, const ::Ice::Current& = ::Ice::Current()); + + /** + * @see PropertyUser::createPropertyDefinitions() + */ + //virtual PropertyDefinitionsPtr createPropertyDefinitions(); + private: + + + }; +} + +#endif -- GitLab