ViewSelection.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2015-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents::ViewSelection
19  * @author David Schiebener (schiebener at kit dot edu)
20  * @author Markus Grotz ( markus dot grotz at kit dot edu )
21  * @date 2015
22  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23  * GNU General Public License
24  */
25 
26 #pragma once
27 
28 
33 
35 #include <RobotAPI/interface/core/RobotState.h>
36 
37 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
38 
40 
44 
45 
46 #include <Eigen/Geometry>
47 
48 
49 #include <condition_variable>
50 #include <mutex>
51 #include <queue>
52 
53 namespace armarx
54 {
55 
57  {
58  bool operator()(ViewTargetBasePtr const& t1, ViewTargetBasePtr const& t2)
59  {
60  if (t1->priority == t2->priority)
61  {
62  return t1->timeAdded->timestamp < t2->timeAdded->timestamp;
63 
64  }
65  return t1->priority < t2->priority;
66  }
67  };
68 
69 
70  /**
71  * @class ViewSelectionPropertyDefinitions
72  * @brief
73  */
76  {
77  public:
80  {
81  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
82  defineOptionalProperty<std::string>("HeadIKUnitName", "HeadIKUnit", "Name of the head IK unit component that should be used");
83  defineOptionalProperty<std::string>("HeadIKKinematicChainName", "IKVirtualGaze", "Name of the kinematic chain for the head IK");
84  defineOptionalProperty<std::string>("HeadFrameName", "Head Base", "Name of the frame of the head base in the robot model");
85  defineOptionalProperty<std::string>("CameraFrameName", "VirtualCentralGaze", "Name of the frame of the head base in the robot model");
86  defineOptionalProperty<int>("SleepingTimeBetweenViewDirectionChanges", 2500, "Time between two view changes, to keep the head looking into one direction for a while (in ms)");
87  defineOptionalProperty<bool>("ActiveAtStartup", true, "Decide whether the automatic view selection will be activated (can be changed via the proxy during runtime)");
88  defineOptionalProperty<bool>("VisualizeViewDirection", true, "Draw view ray on DebugLayer.");
89  defineOptionalProperty<float>("MaxOverallHeadTiltAngle", 55.0f, "Maximal angle the head and eyes can look down (in degrees)");
90  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");
91  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");
92  defineOptionalProperty<float>("VisuSaliencyThreshold", 0.0f, "If greater than zero the saliency map is drawn into the debug drawer on each iteration. The value is used as minimum saliency threshold for a point to be shown in debug visu");
93  }
94  };
95 
96  /**
97  * @defgroup Component-ViewSelection ViewSelection
98  * @ingroup RobotAPI-Components
99  * @brief The ViewSelection component controls the head of the robot with inverse kinematics based on the uncertainty
100  * of the current requested object locations.
101  * The uncertainty of objects grow based on their motion model and the timed passed since the last localization.
102  * It can be activated or deactivated with the Ice interface and given manual target positions to look at.
103  */
104 
105  /**
106  * @ingroup Component-ViewSelection
107  * @brief The ViewSelection class
108  */
110  virtual public Component,
111  virtual public ViewSelectionInterface
112  {
113  public:
114  /**
115  * @see armarx::ManagedIceObject::getDefaultName()
116  */
117  std::string getDefaultName() const override
118  {
119  return "ViewSelection";
120  }
121 
122  protected:
123  /**
124  * @see armarx::ManagedIceObject::onInitComponent()
125  */
126  void onInitComponent() override;
127 
128  /**
129  * @see armarx::ManagedIceObject::onConnectComponent()
130  */
131  void onConnectComponent() override;
132 
133  /**
134  * @see armarx::ManagedIceObject::onDisconnectComponent()
135  */
136  void onDisconnectComponent() override;
137 
138  /**
139  * @see armarx::ManagedIceObject::onExitComponent()
140  */
141  void onExitComponent() override;
142 
143  /**
144  * @see PropertyUser::createPropertyDefinitions()
145  */
147 
148  void addManualViewTarget(const FramedPositionBasePtr& target, const Ice::Current& c = Ice::emptyCurrent) override;
149 
150  void clearManualViewTargets(const Ice::Current& c = Ice::emptyCurrent) override;
151 
152  ViewTargetList getManualViewTargets(const Ice::Current& c = Ice::emptyCurrent) override;
153 
154  void activateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
155  {
156  std::unique_lock lock(manualViewTargetsMutex);
157 
158  ARMARX_INFO << "activating automatic view selection";
159 
160  doAutomaticViewSelection = true;
161  viewSelectionObserver->onActivateAutomaticViewSelection();
162  }
163 
164  void deactivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
165  {
166  std::unique_lock lock(manualViewTargetsMutex);
167 
168  ARMARX_INFO << "deactivating automatic view selection";
169 
170  doAutomaticViewSelection = false;
171  viewSelectionObserver->onDeactivateAutomaticViewSelection();
172  }
173 
174  bool isEnabledAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
175  {
176  std::unique_lock lock(manualViewTargetsMutex);
177 
178  return doAutomaticViewSelection;
179  }
180 
181  void updateSaliencyMap(const SaliencyMapBasePtr& map, const Ice::Current& c = Ice::emptyCurrent) override;
182 
183  void removeSaliencyMap(const std::string& name, const Ice::Current& c = Ice::emptyCurrent) override;
184 
185  ::Ice::StringSeq getSaliencyMapNames(const Ice::Current& c = Ice::emptyCurrent) override;
186 
187  void drawSaliencySphere(const ::Ice::StringSeq& names, const Ice::Current& c = Ice::emptyCurrent) override;
188 
189  void clearSaliencySphere(const Ice::Current& c = Ice::emptyCurrent) override;
190 
191 
192  private:
193 
194  void process();
195 
196  ViewTargetBasePtr nextAutomaticViewTarget();
197 
198  void getActiveSaliencyMaps(std::vector<std::string>& activeSaliencyMaps);
199 
201 
202  RobotStateComponentInterfacePrx robotStateComponent;
203  HeadIKUnitInterfacePrx headIKUnitProxy;
205 
206  ViewSelectionObserverPrx viewSelectionObserver;
207 
208  std::string headIKKinematicChainName;
209  std::string headFrameName;
210  std::string cameraFrameName;
211 
212  CIntensityGraph* visibilityMaskGraph;
213 
214  float sleepingTimeBetweenViewDirectionChanges;
215  IceUtil::Time timeOfLastViewChange;
216 
217  bool drawViewDirection;
218 
219  std::mutex manualViewTargetsMutex;
220  std::priority_queue<ViewTargetBasePtr, std::vector<ViewTargetBasePtr>, CompareViewTargets> manualViewTargets;
221 
222  bool doAutomaticViewSelection;
223 
224  Eigen::Vector3f offsetToHeadCenter;
225 
226  std::condition_variable condition;
227  bool hasNewSaliencyMap;
228  std::mutex syncMutex;
229 
230  std::map<std::string, SaliencyMapBasePtr> saliencyMaps;
231 
232  float visuSaliencyThreshold;
233 
234  };
235 }
236 
armarx::ViewSelection::deactivateAutomaticViewSelection
void deactivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.h:164
armarx::ViewSelection::drawSaliencySphere
void drawSaliencySphere(const ::Ice::StringSeq &names, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:414
armarx::ViewSelection::getSaliencyMapNames
::Ice::StringSeq getSaliencyMapNames(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:507
armarx::ViewSelectionPropertyDefinitions::ViewSelectionPropertyDefinitions
ViewSelectionPropertyDefinitions(std::string prefix)
Definition: ViewSelection.h:78
armarx::ViewSelection::updateSaliencyMap
void updateSaliencyMap(const SaliencyMapBasePtr &map, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:399
armarx::ViewSelection::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ViewSelection.cpp:522
armarx::ViewSelection::onConnectComponent
void onConnectComponent() override
Definition: ViewSelection.cpp:104
armarx::ViewSelection::onExitComponent
void onExitComponent() override
Definition: ViewSelection.cpp:139
Pose.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::ViewSelection::getManualViewTargets
ViewTargetList getManualViewTargets(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:379
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
RunningTask.h
armarx::CompareViewTargets
Definition: ViewSelection.h:56
GraphPyramidLookupTable.h
IntensityGraph.h
armarx::ViewSelection
The ViewSelection class.
Definition: ViewSelection.h:109
armarx::ViewSelection::addManualViewTarget
void addManualViewTarget(const FramedPositionBasePtr &target, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:347
armarx::ViewSelection::removeSaliencyMap
void removeSaliencyMap(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:495
CIntensityGraph
Definition: IntensityGraph.h:51
MathTools.h
TimestampVariant.h
armarx::ViewSelection::clearManualViewTargets
void clearManualViewTargets(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:366
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ViewSelection::activateAutomaticViewSelection
void activateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.h:154
armarx::ViewSelection::clearSaliencySphere
void clearSaliencySphere(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.cpp:490
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:14
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ViewSelection::getDefaultName
std::string getDefaultName() const override
Definition: ViewSelection.h:117
IceUtil::Handle
Definition: forward_declarations.h:29
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::CompareViewTargets::operator()
bool operator()(ViewTargetBasePtr const &t1, ViewTargetBasePtr const &t2)
Definition: ViewSelection.h:58
armarx::ViewSelection::onInitComponent
void onInitComponent() override
Definition: ViewSelection.cpp:38
armarx::ViewSelection::onDisconnectComponent
void onDisconnectComponent() override
Definition: ViewSelection.cpp:118
HeadIKUnit.h
armarx::ViewSelection::isEnabledAutomaticViewSelection
bool isEnabledAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ViewSelection.h:174
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ViewSelectionPropertyDefinitions
Definition: ViewSelection.h:74