GraspCandidateObserver.h
Go to the documentation of this file.
1 /**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * ArmarX is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * @package RobotAPI
18 * @author Simon Ottenhaus
19 * @copyright 2019 Humanoids Group, H2T, KIT
20 * @license http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23 
24 #pragma once
25 
27 #include <RobotAPI/interface/observers/GraspCandidateObserverInterface.h>
30 
31 #include <mutex>
32 
33 namespace armarx
34 {
35  /**
36  * \class GraspCandidateObserverPropertyDefinitions
37  * \brief
38  */
41  {
42  public:
45  {
46  defineOptionalProperty<std::string>("GraspCandidatesTopicName", "GraspCandidatesTopic", "Name of the Grasp Candidate Topic");
47  defineOptionalProperty<std::string>("ConfigTopicName", "GraspCandidateProviderConfigTopic", "Name of the Grasp Candidate Provider Config Topic");
48  }
49  };
50 
51  /**
52  * \class GraspCandidateObserver
53  * \ingroup RobotAPI-SensorActorUnits-observers
54  */
56  virtual public Observer,
57  virtual public armarx::armem::ClientPluginUser,
58  virtual public grasping::GraspCandidateObserverInterface
59  {
60  public:
62 
63  // framework hooks
64  std::string getDefaultName() const override
65  {
66  return "GraspCandidateObserver";
67  }
68  void onInitObserver() override;
69  void onConnectObserver() override;
70 
71  /**
72  * \see PropertyUser::createPropertyDefinitions()
73  */
75 
76  public:
77  static bool FilterMatches(const grasping::CandidateFilterConditionPtr& filter, const std::string& providerName, const grasping::GraspCandidatePtr& candidate);
78  static std::string ObjectTypeToString(objpose::ObjectType type);
79 
80  // GraspCandidateProviderListener interface
81  public:
82  void reportProviderInfo(const std::string& providerName, const grasping::ProviderInfoPtr& info, const ::Ice::Current& = Ice::emptyCurrent) override;
83  void reportGraspCandidates(const std::string& providerName, const grasping::GraspCandidateSeq& candidates, const ::Ice::Current& = Ice::emptyCurrent) override;
84  void reportBimanualGraspCandidates(const std::string& providerName, const grasping::BimanualGraspCandidateSeq& candidates, const ::Ice::Current& = Ice::emptyCurrent) override;
85 
86  // GraspCandidateObserverInterface interface
87  public:
88  grasping::InfoMap getAvailableProvidersWithInfo(const ::Ice::Current& = Ice::emptyCurrent) override;
89  grasping::StringSeq getAvailableProviderNames(const ::Ice::Current&) override;
90  grasping::ProviderInfoPtr getProviderInfo(const std::string& providerName, const ::Ice::Current& = Ice::emptyCurrent) override;
91  bool hasProvider(const std::string& providerName, const Ice::Current& c) override;
92  grasping::GraspCandidateSeq getAllCandidates(const ::Ice::Current& = Ice::emptyCurrent) override;
93  grasping::GraspCandidateSeq getCandidatesByProvider(const std::string& providerName, const Ice::Current& c = Ice::emptyCurrent) override;
94  grasping::GraspCandidateSeq getCandidatesByProviders(const Ice::StringSeq& providerNames, const Ice::Current& c = Ice::emptyCurrent) override;
95  grasping::GraspCandidateSeq getCandidatesByFilter(const grasping::CandidateFilterConditionPtr& filter, const ::Ice::Current& = Ice::emptyCurrent) override;
96  Ice::Int getUpdateCounterByProvider(const std::string& providerName, const ::Ice::Current& = Ice::emptyCurrent) override;
97  grasping::IntMap getAllUpdateCounters(const Ice::Current& providerName) override;
98  bool setProviderConfig(const std::string& providerName, const StringVariantBaseMap& config, const ::Ice::Current& = Ice::emptyCurrent) override;
99 
100  void setSelectedCandidates(const grasping::GraspCandidateSeq& candidates, const ::Ice::Current& = Ice::emptyCurrent) override;
101  grasping::GraspCandidateSeq getSelectedCandidates(const ::Ice::Current& = Ice::emptyCurrent) override;
102 
103  // bimanual stuff
104  grasping::BimanualGraspCandidateSeq getAllBimanualCandidates(const ::Ice::Current& = Ice::emptyCurrent) override;
105 
106 
107  // void setSelectedBimanualCandidates(::armarx::grasping::BimanualGraspCandidateSeq, const ::Ice::Current&) = 0;
108  void setSelectedBimanualCandidates(const grasping::BimanualGraspCandidateSeq& candidates, const ::Ice::Current& = Ice::emptyCurrent) override;
109  grasping::BimanualGraspCandidateSeq getSelectedBimanualCandidates(const ::Ice::Current& = Ice::emptyCurrent) override;
110 
111 
112  void clearCandidatesByProvider(const std::string& providerName, const Ice::Current& c) override;
113 
114  private:
115  bool hasProvider(const std::string& providerName);
116  void checkHasProvider(const std::string& providerName);
117  grasping::StringSeq getAvailableProviderNames();
118  std::mutex dataMutex;
119  std::map<std::string, grasping::GraspCandidateSeq> candidates;
120  std::map<std::string, grasping::BimanualGraspCandidateSeq> bimanualCandidates;
121  grasping::InfoMap providers;
122  std::map<std::string, int> updateCounters;
123 
124  grasping::GraspCandidateProviderInterfacePrx configTopic;
125 
126  std::mutex selectedCandidatesMutex;
127  grasping::GraspCandidateSeq selectedCandidates;
128 
129  grasping::BimanualGraspCandidateSeq selectedBimanualCandidates;
130  armarx::armem::GraspCandidateWriter graspCandidateWriter;
131 
132  void handleProviderUpdate(const std::string& providerName, int candidateCount);
133  };
134 
135 }
136 
armarx::GraspCandidateObserver::FilterMatches
static bool FilterMatches(const grasping::CandidateFilterConditionPtr &filter, const std::string &providerName, const grasping::GraspCandidatePtr &candidate)
Definition: GraspCandidateObserver.cpp:69
armarx::GraspCandidateObserverPropertyDefinitions
Definition: GraspCandidateObserver.h:39
armarx::GraspCandidateObserver::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: GraspCandidateObserver.h:64
armarx::GraspCandidateObserver::getCandidatesByFilter
grasping::GraspCandidateSeq getCandidatesByFilter(const grasping::CandidateFilterConditionPtr &filter, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:247
armarx::GraspCandidateObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GraspCandidateObserver.cpp:62
armarx::GraspCandidateObserver::getProviderInfo
grasping::ProviderInfoPtr getProviderInfo(const std::string &providerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:196
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:80
armarx::GraspCandidateObserver::getAllBimanualCandidates
grasping::BimanualGraspCandidateSeq getAllBimanualCandidates(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:311
armarx::GraspCandidateObserver::reportProviderInfo
void reportProviderInfo(const std::string &providerName, const grasping::ProviderInfoPtr &info, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:162
armarx::armem::GraspCandidateWriter
Definition: GraspCandidateWriter.h:13
armarx::GraspCandidateObserver::getCandidatesByProvider
grasping::GraspCandidateSeq getCandidatesByProvider(const std::string &providerName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:223
armarx::GraspCandidateObserver::getAllCandidates
grasping::GraspCandidateSeq getAllCandidates(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:211
armarx::GraspCandidateObserver::getCandidatesByProviders
grasping::GraspCandidateSeq getCandidatesByProviders(const Ice::StringSeq &providerNames, const Ice::Current &c=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:230
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::GraspCandidateObserverPropertyDefinitions::GraspCandidateObserverPropertyDefinitions
GraspCandidateObserverPropertyDefinitions(std::string prefix)
Definition: GraspCandidateObserver.h:43
armarx::GraspCandidateObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: GraspCandidateObserver.cpp:47
armarx::GraspCandidateObserver::clearCandidatesByProvider
void clearCandidatesByProvider(const std::string &providerName, const Ice::Current &c) override
Definition: GraspCandidateObserver.cpp:339
Observer.h
armarx::armem::client::plugins::PluginUser
Adds the Memory Name System client component plugin.
Definition: PluginUser.h:29
armarx::GraspCandidateObserver::setProviderConfig
bool setProviderConfig(const std::string &providerName, const StringVariantBaseMap &config, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:282
armarx::GraspCandidateObserver::setSelectedBimanualCandidates
void setSelectedBimanualCandidates(const grasping::BimanualGraspCandidateSeq &candidates, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:323
armarx::GraspCandidateObserver::getSelectedBimanualCandidates
grasping::BimanualGraspCandidateSeq getSelectedBimanualCandidates(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:332
armarx::GraspCandidateObserver::setSelectedCandidates
void setSelectedCandidates(const grasping::GraspCandidateSeq &candidates, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:296
armarx::GraspCandidateObserver::ObjectTypeToString
static std::string ObjectTypeToString(objpose::ObjectType type)
Definition: GraspCandidateObserver.cpp:99
armarx::GraspCandidateObserver::reportBimanualGraspCandidates
void reportBimanualGraspCandidates(const std::string &providerName, const grasping::BimanualGraspCandidateSeq &candidates, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:152
armarx::GraspCandidateObserver::GraspCandidateObserver
GraspCandidateObserver()
Definition: GraspCandidateObserver.cpp:42
GraspCandidateWriter.h
armarx::GraspCandidateObserver::getAllUpdateCounters
grasping::IntMap getAllUpdateCounters(const Ice::Current &providerName) override
Definition: GraspCandidateObserver.cpp:275
armarx::GraspCandidateObserver::getAvailableProvidersWithInfo
grasping::InfoMap getAvailableProvidersWithInfo(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:182
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::GraspCandidateObserver
Definition: GraspCandidateObserver.h:55
PluginUser.h
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::GraspCandidateObserver::hasProvider
bool hasProvider(const std::string &providerName, const Ice::Current &c) override
Definition: GraspCandidateObserver.cpp:204
armarx::ObserverPropertyDefinitions
Definition: Observer.h:50
armarx::GraspCandidateObserver::getUpdateCounterByProvider
Ice::Int getUpdateCounterByProvider(const std::string &providerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:266
armarx::GraspCandidateObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: GraspCandidateObserver.cpp:54
armarx::GraspCandidateObserver::getSelectedCandidates
grasping::GraspCandidateSeq getSelectedCandidates(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:304
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::GraspCandidateObserver::reportGraspCandidates
void reportGraspCandidates(const std::string &providerName, const grasping::GraspCandidateSeq &candidates, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: GraspCandidateObserver.cpp:140