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 
27 #include <condition_variable>
28 #include <mutex>
29 
32 
36 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
37 
39 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
40 #include <MemoryX/interface/memorytypes/MemorySegments.h>
41 #include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
48 
49 namespace armarx
50 {
51  /**
52  * @class ObjectLocalizationSaliencyPropertyDefinitions
53  * @brief
54  */
57  {
58  public:
61  {
62  defineOptionalProperty<std::string>(
63  "RobotStateComponentName",
64  "RobotStateComponent",
65  "Name of the robot state component that should be used");
66  defineOptionalProperty<std::string>(
67  "HeadIKUnitName",
68  "HeadIKUnit",
69  "Name of the head IK unit component that should be used");
70  defineOptionalProperty<std::string>(
71  "WorkingMemoryName",
72  "WorkingMemory",
73  "Name of the WorkingMemory component that should be used");
74  defineOptionalProperty<std::string>(
75  "PriorKnowledgeName",
76  "PriorKnowledge",
77  "Name of the PriorKnowledge component that should be used");
78  defineOptionalProperty<std::string>(
79  "ViewSelectionName",
80  "ViewSelection",
81  "Name of the ViewSelection component that should be used");
82  defineOptionalProperty<std::string>(
83  "CameraFrameName",
84  "VirtualCentralGaze",
85  "Name of the frame of the head base in the robot model");
86 
87  defineOptionalProperty<std::string>(
88  "HeadFrameName",
89  "Head Base",
90  "Name of the frame of the head base in the robot model");
91  defineOptionalProperty<float>(
92  "RandomNoiseLevel",
93  1.0f,
94  "Maximum for the random noise that will be added to the localization necessities");
95  defineOptionalProperty<float>("HalfCameraOpeningAngle",
96  12.0 * M_PI / 180.0,
97  "0.5 * minimal opening angles of the used cameras");
98  defineOptionalProperty<float>(
99  "MaxObjectDistance",
100  1500.f,
101  "Maximum distance of objects the head to be considered for observation");
102  defineOptionalProperty<float>(
103  "CentralHeadTiltAngle",
104  110.0f,
105  "Defines the height direction that will be considered 'central' in the reachable "
106  "area of the head (in degrees). Default is looking 20 degrees downwards");
107  defineOptionalProperty<float>(
108  "ProbabilityToLookForALostObject",
109  0.03f,
110  "Probability that one of the objects that have been seen but could later not been "
111  "localized again will be included in the view selection");
112  defineOptionalProperty<float>(
113  "UpdateFrequency", 10.0f, "Frequency of the saliency update");
114  }
115  };
116 
117  /**
118  * @defgroup Component-ObjectLocalizationSaliency ObjectLocalizationSaliency
119  * @ingroup RobotComponents-Components
120  * A description of the component ObjectLocalizationSaliency.
121  *
122  * @class ObjectLocalizationSaliency
123  * @ingroup Component-ObjectLocalizationSaliency
124  * @brief Brief description of class ObjectLocalizationSaliency.
125  *
126  * Detailed description of class ObjectLocalizationSaliency.
127  */
129  virtual public armarx::Component,
130  virtual public armarx::ViewSelectionObserver
131  {
132  public:
133  /**
134  * @see armarx::ManagedIceObject::getDefaultName()
135  */
136  std::string
137  getDefaultName() const override
138  {
139  return "ObjectLocalizationSaliency";
140  }
141 
142  void
143  onActivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
144  {
145  ARMARX_LOG << "enabling object saliency computation";
146 
147  next = IceUtil::Time::seconds(0);
148 
149  if (!(processorTask && processorTask->isRunning()))
150  {
151  processorTask->start();
152  }
153  else
154  {
155  ARMARX_INFO << "view selection already active";
156  }
157  }
158 
159  void
160  onDeactivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
161  {
162 
163  ARMARX_LOG << "disabling object saliency computation";
164  if (processorTask && processorTask->isRunning())
165  {
166  processorTask->stop();
167  }
168  }
169 
170  void nextViewTarget(Ice::Long timestamp,
171  const Ice::Current& c = Ice::emptyCurrent) override;
172 
173 
174  protected:
175  /**
176  * @see armarx::ManagedIceObject::onInitComponent()
177  */
178  void onInitComponent() override;
179 
180  /**
181  * @see armarx::ManagedIceObject::onConnectComponent()
182  */
183  void onConnectComponent() override;
184 
185  /**
186  * @see armarx::ManagedIceObject::onDisconnectComponent()
187  */
188  void onDisconnectComponent() override;
189 
190  /**
191  * @see armarx::ManagedIceObject::onExitComponent()
192  */
193  void onExitComponent() override;
194 
195  /**
196  * @see PropertyUser::createPropertyDefinitions()
197  */
199 
200 
201  private:
202  void process();
203 
204  void generateObjectLocalizationSaliency();
205 
206  void addSaliencyRecursive(const int currentNodeIndex,
207  const float saliency,
208  const TSphereCoord objectSphereCoord,
209  const int objectIndex,
210  const float maxDistanceOnArc);
211 
212  void setRandomNoise(const float centralAngleForVerticalDirection,
213  const float directionVariabilityFactor = 1.0f);
214  void generateRandomNoise(std::vector<memoryx::ObjectInstancePtr>& localizableObjects,
215  memoryx::EntityBaseList& objectInstances);
216 
217 
218  std::mutex mutex;
219  IceUtil::Time next;
220  IceUtil::Time lastDiff;
221 
222  RobotStateComponentInterfacePrx robotStateComponent;
223 
224  memoryx::WorkingMemoryInterfacePrx memoryProxy;
225  memoryx::PriorKnowledgeInterfacePrx priorKnowledge;
226  memoryx::ObjectInstanceMemorySegmentBasePrx objectInstancesProxy;
227  memoryx::ObjectClassMemorySegmentBasePrx objectClassesProxy;
229 
230 
231  ViewSelectionInterfacePrx viewSelection;
232 
234 
235 
236  std::map<std::string, memoryx::ObjectClassPtr> recognizableObjClasses;
237 
238  CIntensityGraph* saliencyEgosphereGraph;
239  CIntensityGraph* randomNoiseGraph;
240  CGraphPyramidLookupTable* graphLookupTable;
241 
242  std::vector<int> nodeVisitedForObject;
243 
244 
245  Eigen::Vector3f offsetToHeadCenter;
246 
247  float centralHeadTiltAngle;
248 
249  float halfCameraOpeningAngle;
250  float deviationFromCameraCenterFactor;
251  float randomNoiseLevel;
252 
253  std::string headFrameName, cameraFrameName;
254  };
255 } // namespace armarx
armarx::ObjectLocalizationSaliencyPropertyDefinitions::ObjectLocalizationSaliencyPropertyDefinitions
ObjectLocalizationSaliencyPropertyDefinitions(std::string prefix)
Definition: ObjectLocalizationSaliency.h:59
armarx::ObjectLocalizationSaliencyPropertyDefinitions
Definition: ObjectLocalizationSaliency.h:55
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
ObjectRecognitionWrapper.h
ObjectClass.h
GraphPyramidLookupTable.h
armarx::ObjectLocalizationSaliency::nextViewTarget
void nextViewTarget(Ice::Long timestamp, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.cpp:425
armarx::ObjectLocalizationSaliency::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ObjectLocalizationSaliency.cpp:468
armarx::ObjectLocalizationSaliency::onInitComponent
void onInitComponent() override
Definition: ObjectLocalizationSaliency.cpp:34
IntensityGraph.h
armarx::ObjectLocalizationSaliency
Brief description of class ObjectLocalizationSaliency.
Definition: ObjectLocalizationSaliency.h:128
ObjectMemoryObserver.h
armarx::ObjectLocalizationSaliency::onDisconnectComponent
void onDisconnectComponent() override
Definition: ObjectLocalizationSaliency.cpp:138
CGraphPyramidLookupTable
Definition: GraphPyramidLookupTable.h:23
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:918
armarx::ObjectLocalizationSaliency::getDefaultName
std::string getDefaultName() const override
Definition: ObjectLocalizationSaliency.h:137
MemoryXCoreObjectFactories.h
armarx::ObjectLocalizationSaliency::onExitComponent
void onExitComponent() override
Definition: ObjectLocalizationSaliency.cpp:145
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ObjectLocalizationSaliency::onConnectComponent
void onConnectComponent() override
Definition: ObjectLocalizationSaliency.cpp:89
ObjectInstance.h
armarx::ObjectLocalizationSaliency::onDeactivateAutomaticViewSelection
void onDeactivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.h:160
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ObjectLocalizationSaliency::onActivateAutomaticViewSelection
void onActivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizationSaliency.h:143
MemoryXTypesObjectFactories.h
TSphereCoord
Definition: Structs.h:23
MemoryXUpdaterObjectFactories.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19