ObjectLocalizationSaliency.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 version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotComponents::ArmarXObjects::ObjectLocalizationSaliency
17  * @author David Schiebener (schiebener at kit dot edu)
18  * @author Markus Grotz ( markus dot grotz at kit dot edu )
19  * @date 2016
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 
28 
30 
31 
32 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
36 
37 #include <MemoryX/interface/memorytypes/MemorySegments.h>
38 #include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
39 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
40 
42 
49 
50 #include <mutex>
51 #include <condition_variable>
52 
53 
54 namespace armarx
55 {
56  /**
57  * @class ObjectLocalizationSaliencyPropertyDefinitions
58  * @brief
59  */
62  {
63  public:
66  {
67  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
68  defineOptionalProperty<std::string>("HeadIKUnitName", "HeadIKUnit", "Name of the head IK unit component that should be used");
69  defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory", "Name of the WorkingMemory component that should be used");
70  defineOptionalProperty<std::string>("PriorKnowledgeName", "PriorKnowledge", "Name of the PriorKnowledge component that should be used");
71  defineOptionalProperty<std::string>("ViewSelectionName", "ViewSelection", "Name of the ViewSelection component that should be used");
72  defineOptionalProperty<std::string>("CameraFrameName", "VirtualCentralGaze", "Name of the frame of the head base in the robot model");
73 
74  defineOptionalProperty<std::string>("HeadFrameName", "Head Base", "Name of the frame of the head base in the robot model");
75  defineOptionalProperty<float>("RandomNoiseLevel", 1.0f, "Maximum for the random noise that will be added to the localization necessities");
76  defineOptionalProperty<float>("HalfCameraOpeningAngle", 12.0 * M_PI / 180.0, "0.5 * minimal opening angles of the used cameras");
77  defineOptionalProperty<float>("MaxObjectDistance", 1500.f, "Maximum distance of objects the head to be considered for observation");
78  defineOptionalProperty<float>("CentralHeadTiltAngle", 110.0f, "Defines the height direction that will be considered 'central' in the reachable area of the head (in degrees). Default is looking 20 degrees downwards");
79  defineOptionalProperty<float>("ProbabilityToLookForALostObject", 0.03f, "Probability that one of the objects that have been seen but could later not been localized again will be included in the view selection");
80  defineOptionalProperty<float>("UpdateFrequency", 10.0f, "Frequency of the saliency update");
81 
82  }
83  };
84 
85  /**
86  * @defgroup Component-ObjectLocalizationSaliency ObjectLocalizationSaliency
87  * @ingroup RobotComponents-Components
88  * A description of the component ObjectLocalizationSaliency.
89  *
90  * @class ObjectLocalizationSaliency
91  * @ingroup Component-ObjectLocalizationSaliency
92  * @brief Brief description of class ObjectLocalizationSaliency.
93  *
94  * Detailed description of class ObjectLocalizationSaliency.
95  */
97  virtual public armarx::Component,
98  virtual public armarx::ViewSelectionObserver
99  {
100  public:
101  /**
102  * @see armarx::ManagedIceObject::getDefaultName()
103  */
104  std::string getDefaultName() const override
105  {
106  return "ObjectLocalizationSaliency";
107  }
108 
109  void onActivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
110  {
111  ARMARX_LOG << "enabling object saliency computation";
112 
113  next = IceUtil::Time::seconds(0);
114 
115  if (!(processorTask && processorTask->isRunning()))
116  {
117  processorTask->start();
118  }
119  else
120  {
121  ARMARX_INFO << "view selection already active";
122  }
123 
124 
125  }
126 
127  void onDeactivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
128  {
129 
130  ARMARX_LOG << "disabling object saliency computation";
131  if (processorTask && processorTask->isRunning())
132  {
133  processorTask->stop();
134  }
135  }
136 
137 
138  void nextViewTarget(Ice::Long timestamp, const Ice::Current& c = Ice::emptyCurrent) override;
139 
140 
141  protected:
142  /**
143  * @see armarx::ManagedIceObject::onInitComponent()
144  */
145  void onInitComponent() override;
146 
147  /**
148  * @see armarx::ManagedIceObject::onConnectComponent()
149  */
150  void onConnectComponent() override;
151 
152  /**
153  * @see armarx::ManagedIceObject::onDisconnectComponent()
154  */
155  void onDisconnectComponent() override;
156 
157  /**
158  * @see armarx::ManagedIceObject::onExitComponent()
159  */
160  void onExitComponent() override;
161 
162  /**
163  * @see PropertyUser::createPropertyDefinitions()
164  */
166 
167 
168  private:
169  void process();
170 
171  void generateObjectLocalizationSaliency();
172 
173  void addSaliencyRecursive(const int currentNodeIndex, const float saliency, const TSphereCoord objectSphereCoord, const int objectIndex, const float maxDistanceOnArc);
174 
175  void setRandomNoise(const float centralAngleForVerticalDirection, const float directionVariabilityFactor = 1.0f);
176  void generateRandomNoise(std::vector<memoryx::ObjectInstancePtr>& localizableObjects, memoryx::EntityBaseList& objectInstances);
177 
178 
179 
180  std::mutex mutex;
181  IceUtil::Time next;
182  IceUtil::Time lastDiff;
183 
184  RobotStateComponentInterfacePrx robotStateComponent;
185 
186  memoryx::WorkingMemoryInterfacePrx memoryProxy;
187  memoryx::PriorKnowledgeInterfacePrx priorKnowledge;
188  memoryx::ObjectInstanceMemorySegmentBasePrx objectInstancesProxy;
189  memoryx::ObjectClassMemorySegmentBasePrx objectClassesProxy;
191 
192 
193  ViewSelectionInterfacePrx viewSelection;
194 
196 
197 
198  std::map<std::string, memoryx::ObjectClassPtr> recognizableObjClasses;
199 
200  CIntensityGraph* saliencyEgosphereGraph;
201  CIntensityGraph* randomNoiseGraph;
202  CGraphPyramidLookupTable* graphLookupTable;
203 
204  std::vector<int> nodeVisitedForObject;
205 
206 
207  Eigen::Vector3f offsetToHeadCenter;
208 
209  float centralHeadTiltAngle;
210 
211  float halfCameraOpeningAngle;
212  float deviationFromCameraCenterFactor;
213  float randomNoiseLevel;
214 
215  std::string headFrameName, cameraFrameName;
216 
217  };
218 }
219 
armarx::ObjectLocalizationSaliencyPropertyDefinitions::ObjectLocalizationSaliencyPropertyDefinitions
ObjectLocalizationSaliencyPropertyDefinitions(std::string prefix)
Definition: ObjectLocalizationSaliency.h:64
armarx::ObjectLocalizationSaliencyPropertyDefinitions
Definition: ObjectLocalizationSaliency.h:60
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
ObjectRecognitionWrapper.h
ObjectClass.h
GraphPyramidLookupTable.h
armarx::ObjectLocalizationSaliency::nextViewTarget
void nextViewTarget(Ice::Long timestamp, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.cpp:369
armarx::ObjectLocalizationSaliency::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObjectLocalizationSaliency.cpp:407
armarx::ObjectLocalizationSaliency::onInitComponent
void onInitComponent() override
Definition: ObjectLocalizationSaliency.cpp:33
IntensityGraph.h
armarx::ObjectLocalizationSaliency
Brief description of class ObjectLocalizationSaliency.
Definition: ObjectLocalizationSaliency.h:96
ObjectMemoryObserver.h
armarx::ObjectLocalizationSaliency::onDisconnectComponent
void onDisconnectComponent() override
Definition: ObjectLocalizationSaliency.cpp:121
CGraphPyramidLookupTable
Definition: GraphPyramidLookupTable.h:22
CIntensityGraph
Definition: IntensityGraph.h:51
M_PI
#define M_PI
Definition: MathTools.h:17
MathTools.h
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::ObjectLocalizationSaliency::getDefaultName
std::string getDefaultName() const override
Definition: ObjectLocalizationSaliency.h:104
MemoryXCoreObjectFactories.h
armarx::ObjectLocalizationSaliency::onExitComponent
void onExitComponent() override
Definition: ObjectLocalizationSaliency.cpp:128
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ObjectLocalizationSaliency::onConnectComponent
void onConnectComponent() override
Definition: ObjectLocalizationSaliency.cpp:81
ObjectInstance.h
armarx::ObjectLocalizationSaliency::onDeactivateAutomaticViewSelection
void onDeactivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.h:127
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ObjectLocalizationSaliency::onActivateAutomaticViewSelection
void onActivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.h:109
MemoryXTypesObjectFactories.h
TSphereCoord
Definition: Structs.h:22
MemoryXUpdaterObjectFactories.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18