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
29#include <condition_variable>
30#include <mutex>
31#include <queue>
32
33#include <Eigen/Geometry>
34
39
44#include <RobotAPI/interface/components/ViewSelectionInterface.h>
45#include <RobotAPI/interface/core/RobotState.h>
47
48namespace armarx
49{
50
52 {
53 bool
54 operator()(ViewTargetBasePtr const& t1, ViewTargetBasePtr const& t2)
55 {
56 if (t1->priority == t2->priority)
57 {
58 return t1->timeAdded->timestamp < t2->timeAdded->timestamp;
59 }
60 return t1->priority < t2->priority;
61 }
62 };
63
64 /**
65 * @class ViewSelectionPropertyDefinitions
66 * @brief
67 */
69 {
70 public:
72 {
74 "RobotStateComponentName",
75 "RobotStateComponent",
76 "Name of the robot state component that should be used");
78 "HeadIKUnitName",
79 "HeadIKUnit",
80 "Name of the head IK unit component that should be used");
81 defineOptionalProperty<std::string>("HeadIKKinematicChainName",
82 "IKVirtualGaze",
83 "Name of the kinematic chain for the head IK");
85 "HeadFrameName",
86 "Head Base",
87 "Name of the frame of the head base in the robot model");
89 "CameraFrameName",
90 "VirtualCentralGaze",
91 "Name of the frame of the head base in the robot model");
92 defineOptionalProperty<int>("SleepingTimeBetweenViewDirectionChanges",
93 2500,
94 "Time between two view changes, to keep the head looking "
95 "into one direction for a while (in ms)");
96 defineOptionalProperty<bool>("ActiveAtStartup",
97 true,
98 "Decide whether the automatic view selection will be "
99 "activated (can be changed via the proxy during runtime)");
101 "VisualizeViewDirection", true, "Draw view ray on DebugLayer.");
103 "MaxOverallHeadTiltAngle",
104 55.0f,
105 "Maximal angle the head and eyes can look down (in degrees)");
107 "CentralHeadTiltAngle",
108 110.0f,
109 "Defines the height direction that will be considered 'central' in the reachable "
110 "area of the head (in degrees). Default is looking 20 degrees downwards");
112 "ProbabilityToLookForALostObject",
113 0.03f,
114 "Probability that one of the objects that have been seen but could later not been "
115 "localized again will be included in the view selection");
117 "VisuSaliencyThreshold",
118 0.0f,
119 "If greater than zero the saliency map is drawn into the debug drawer on each "
120 "iteration. The value is used as minimum saliency threshold for a point to be "
121 "shown in debug visu");
122 }
123 };
124
125 /**
126 * @defgroup Component-ViewSelection ViewSelection
127 * @ingroup RobotAPI-Components
128 * @brief The ViewSelection component controls the head of the robot with inverse kinematics based on the uncertainty
129 * of the current requested object locations.
130 * The uncertainty of objects grow based on their motion model and the timed passed since the last localization.
131 * It can be activated or deactivated with the Ice interface and given manual target positions to look at.
132 */
133
134 /**
135 * @ingroup Component-ViewSelection
136 * @brief The ViewSelection class
137 */
138 class ViewSelection : virtual public Component, virtual public ViewSelectionInterface
139 {
140 public:
141 /**
142 * @see armarx::ManagedIceObject::getDefaultName()
143 */
144 std::string
145 getDefaultName() const override
146 {
147 return "ViewSelection";
148 }
149
150 protected:
151 /**
152 * @see armarx::ManagedIceObject::onInitComponent()
153 */
154 void onInitComponent() override;
155
156 /**
157 * @see armarx::ManagedIceObject::onConnectComponent()
158 */
159 void onConnectComponent() override;
160
161 /**
162 * @see armarx::ManagedIceObject::onDisconnectComponent()
163 */
164 void onDisconnectComponent() override;
165
166 /**
167 * @see armarx::ManagedIceObject::onExitComponent()
168 */
169 void onExitComponent() override;
170
171 /**
172 * @see PropertyUser::createPropertyDefinitions()
173 */
175
176 void addManualViewTarget(const FramedPositionBasePtr& target,
177 const Ice::Current& c = Ice::emptyCurrent) override;
178
179 void clearManualViewTargets(const Ice::Current& c = Ice::emptyCurrent) override;
180
181 ViewTargetList getManualViewTargets(const Ice::Current& c = Ice::emptyCurrent) override;
182
183 void
184 activateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
185 {
186 std::unique_lock lock(manualViewTargetsMutex);
187
188 ARMARX_INFO << "activating automatic view selection";
189
190 doAutomaticViewSelection = true;
191 viewSelectionObserver->onActivateAutomaticViewSelection();
192 }
193
194 void
195 deactivateAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
196 {
197 std::unique_lock lock(manualViewTargetsMutex);
198
199 ARMARX_INFO << "deactivating automatic view selection";
200
201 doAutomaticViewSelection = false;
202 viewSelectionObserver->onDeactivateAutomaticViewSelection();
203 }
204
205 bool
206 isEnabledAutomaticViewSelection(const Ice::Current& c = Ice::emptyCurrent) override
207 {
208 std::unique_lock lock(manualViewTargetsMutex);
209
210 return doAutomaticViewSelection;
211 }
212
213 void updateSaliencyMap(const SaliencyMapBasePtr& map,
214 const Ice::Current& c = Ice::emptyCurrent) override;
215
216 void removeSaliencyMap(const std::string& name,
217 const Ice::Current& c = Ice::emptyCurrent) override;
218
219 ::Ice::StringSeq getSaliencyMapNames(const Ice::Current& c = Ice::emptyCurrent) override;
220
221 void drawSaliencySphere(const ::Ice::StringSeq& names,
222 const Ice::Current& c = Ice::emptyCurrent) override;
223
224 void clearSaliencySphere(const Ice::Current& c = Ice::emptyCurrent) override;
225
226
227 private:
228 void process();
229
230 ViewTargetBasePtr nextAutomaticViewTarget();
231
232 void getActiveSaliencyMaps(std::vector<std::string>& activeSaliencyMaps);
233
235
236 RobotStateComponentInterfacePrx robotStateComponent;
237 HeadIKUnitInterfacePrx headIKUnitProxy;
239
240 ViewSelectionObserverPrx viewSelectionObserver;
241
242 std::string headIKKinematicChainName;
243 std::string headFrameName;
244 std::string cameraFrameName;
245
246 CIntensityGraph* visibilityMaskGraph;
247
248 float sleepingTimeBetweenViewDirectionChanges;
249 IceUtil::Time timeOfLastViewChange;
250
251 bool drawViewDirection;
252
253 std::mutex manualViewTargetsMutex;
254 std::priority_queue<ViewTargetBasePtr, std::vector<ViewTargetBasePtr>, CompareViewTargets>
255 manualViewTargets;
256
257 bool doAutomaticViewSelection;
258
259 Eigen::Vector3f offsetToHeadCenter;
260
261 std::condition_variable condition;
262 bool hasNewSaliencyMap;
263 std::mutex syncMutex;
264
265 std::map<std::string, SaliencyMapBasePtr> saliencyMaps;
266
267 float visuSaliencyThreshold;
268 };
269} // namespace armarx
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
ViewSelectionPropertyDefinitions(std::string prefix)
The ViewSelection class.
void addManualViewTarget(const FramedPositionBasePtr &target, const Ice::Current &c=Ice::emptyCurrent) override
void onInitComponent() override
void clearSaliencySphere(const Ice::Current &c=Ice::emptyCurrent) override
void removeSaliencyMap(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
void onDisconnectComponent() override
ViewTargetList getManualViewTargets(const Ice::Current &c=Ice::emptyCurrent) override
void deactivateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
void drawSaliencySphere(const ::Ice::StringSeq &names, const Ice::Current &c=Ice::emptyCurrent) override
::Ice::StringSeq getSaliencyMapNames(const Ice::Current &c=Ice::emptyCurrent) override
void updateSaliencyMap(const SaliencyMapBasePtr &map, const Ice::Current &c=Ice::emptyCurrent) override
void onConnectComponent() override
PropertyDefinitionsPtr createPropertyDefinitions() override
void activateAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
void clearManualViewTargets(const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
std::string getDefaultName() const override
bool isEnabledAutomaticViewSelection(const Ice::Current &c=Ice::emptyCurrent) override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
bool operator()(ViewTargetBasePtr const &t1, ViewTargetBasePtr const &t2)