55 std::string graphFileName =
"RobotAPI/ViewSelection/graph40k.gra";
63 TNodeList* nodes = visibilityMaskGraph->getNodes();
64 const float maxOverallHeadTiltAngle =
66 const float borderAreaAngle = 10.0f;
69 for (
size_t i = 0; i < nodes->size(); i++)
74 maxOverallHeadTiltAngle - borderAreaAngle)
78 else if (fabs(node->
getPosition().
fPhi - centralAngle) < maxOverallHeadTiltAngle)
81 (maxOverallHeadTiltAngle - borderAreaAngle)) /
97 sleepingTimeBetweenViewDirectionChanges =
105 offsetToHeadCenter << 0, 0, 150;
108 processorTask->setDelayWarningTolerance(sleepingTimeBetweenViewDirectionChanges + 100);
119 headIKUnitProxy->request();
124 processorTask->start();
130 processorTask->stop();
134 drawer->removeArrowDebugLayerVisu(
"HeadRealViewDirection");
139 headIKUnitProxy->release();
151 delete visibilityMaskGraph;
155 ViewSelection::getActiveSaliencyMaps(std::vector<std::string>& activeSaliencyMaps)
157 std::unique_lock lock(syncMutex);
160 for (
const auto& p : saliencyMaps)
162 if (p.second->validUntil)
165 if (time->toTime() > currentTime)
167 activeSaliencyMaps.push_back(p.second->name);
170 else if ((currentTime -
171 TimestampVariantPtr::dynamicCast(p.second->timeAdded)->toTime()) <
172 IceUtil::Time::seconds(5))
174 activeSaliencyMaps.push_back(p.second->name);
180 ViewSelection::nextAutomaticViewTarget()
182 std::vector<std::string> activeSaliencyMaps;
183 getActiveSaliencyMaps(activeSaliencyMaps);
185 if (activeSaliencyMaps.empty())
192 TNodeList* visibilityMaskGraphNodes = visibilityMaskGraph->getNodes();
196 float maxSaliency = std::numeric_limits<float>::min();
198 std::unique_lock lock(syncMutex);
200 hasNewSaliencyMap =
false;
202 for (
size_t i = 0; i < visibilityMaskGraphNodes->size(); i++)
204 float saliency = 0.0f;
205 for (
const std::string& n : activeSaliencyMaps)
207 saliency += saliencyMaps[
n]->map[i];
210 saliency /= activeSaliencyMaps.size();
212 CIntensityNode* visibilityNode = (CIntensityNode*)visibilityMaskGraphNodes->at(i);
215 if (saliency > maxSaliency)
217 maxSaliency = saliency;
228 int timeSinceLastViewChange =
230 float saliencyThreshold = 0;
232 if (timeSinceLastViewChange > 0)
235 2.0f * sleepingTimeBetweenViewDirectionChanges / timeSinceLastViewChange;
238 if (maxSaliency > saliencyThreshold)
242 const float distanceFactor = 1500;
247 ViewTargetBasePtr viewTarget =
new ViewTargetBase();
248 viewTarget->priority = armarx::DEFAULT_VIEWTARGET_PRIORITY;
250 viewTarget->target = viewTargetPositionPtr;
251 viewTarget->duration = 0;
254 if (visuSaliencyThreshold > 0.0)
266 ViewSelection::process()
274 ViewTargetBasePtr viewTarget;
276 if (doAutomaticViewSelection)
278 viewTarget = nextAutomaticViewTarget();
301 if (!manualViewTargets.empty())
303 std::unique_lock lock(manualViewTargetsMutex);
305 ViewTargetBasePtr manualViewTarget = manualViewTargets.top();
307 CompareViewTargets
c;
311 viewTarget = manualViewTarget;
312 manualViewTargets.pop();
314 else if (
c(viewTarget, manualViewTarget))
316 viewTarget = manualViewTarget;
317 manualViewTargets.pop();
326 new FramedPosition(FramedPositionPtr::dynamicCast(viewTarget->target)->toEigen(),
327 viewTarget->target->frame,
328 robotPrx->getName());
330 if (drawer && robotPrx->hasRobotNode(
"Cameras") && drawViewDirection)
332 float arrowLength = 1500.0f;
334 FramedPosePtr::dynamicCast(robotPrx->getRobotNode(
"Cameras")->getGlobalPose())
337 new FramedDirection(Eigen::Vector3f(1, 0, 0),
"Cameras", robotPrx->getName());
338 drawer->setArrowDebugLayerVisu(
"CurrentHeadViewDirection",
340 currentDirection->toGlobal(robotPrx),
341 DrawColor{0, 0.5, 0.5, 0.1},
344 Eigen::Vector3f plannedDirectionEigen =
345 viewTargetPositionPtr->toGlobalEigen(robotPrx) - startPos->toEigen();
347 drawer->setArrowDebugLayerVisu(
"PlannedHeadViewDirection",
350 DrawColor{0.5, 0.5, 0, 0.1},
355 ARMARX_INFO <<
"Looking at target " << viewTargetPositionPtr->output();
356 headIKUnitProxy->setHeadTarget(headIKKinematicChainName, viewTargetPositionPtr);
360 long duration = viewTarget->duration;
361 if (!viewTarget->duration)
363 duration = sleepingTimeBetweenViewDirectionChanges;
366 viewSelectionObserver->nextViewTarget(timeOfLastViewChange.toMilliSeconds() + duration);
368 std::this_thread::sleep_for(std::chrono::milliseconds(duration));
372 std::this_thread::sleep_for(std::chrono::milliseconds(5));
379 std::unique_lock lock(manualViewTargetsMutex);
383 ViewTargetBasePtr viewTarget =
new ViewTargetBase();
384 viewTarget->priority = armarx::DEFAULT_VIEWTARGET_PRIORITY + 1;
386 viewTarget->target = target;
387 viewTarget->duration = 0;
389 manualViewTargets.push(viewTarget);
391 std::unique_lock lock2(syncMutex);
393 condition.notify_all();
399 std::unique_lock lock(manualViewTargetsMutex);
401 while (!manualViewTargets.empty())
403 manualViewTargets.pop();
413 std::unique_lock lock(manualViewTargetsMutex);
415 ViewTargetList result;
417 std::priority_queue<ViewTargetBasePtr, std::vector<ViewTargetBasePtr>,
CompareViewTargets>
418 temp(manualViewTargets);
420 while (!temp.empty())
422 result.push_back(temp.top());
433 std::unique_lock lock(syncMutex);
435 hasNewSaliencyMap =
true;
439 saliencyMaps[map->name] = map;
441 condition.notify_all();
449 drawer->clearLayer(
"saliencyMap");
453 Eigen::Matrix4f cameraToGlobal =
454 FramedPosePtr::dynamicCast(robotPrx->getRobotNode(headFrameName)->getGlobalPose())
457 std::vector<std::string> activeSaliencyMaps;
461 for (std::string n : names)
463 activeSaliencyMaps.push_back(n);
468 getActiveSaliencyMaps(activeSaliencyMaps);
471 if (!activeSaliencyMaps.size())
477 std::unique_lock lock(syncMutex);
479 TNodeList* visibilityMaskGraphNodes = visibilityMaskGraph->getNodes();
480 DebugDrawer24BitColoredPointCloud cloud;
481 cloud.points.reserve(visibilityMaskGraphNodes->size());
482 for (
size_t i = 0; i < visibilityMaskGraphNodes->size(); i++)
484 float saliency = 0.0f;
485 for (
const std::string& n : activeSaliencyMaps)
487 saliency += saliencyMaps[n]->map[i];
490 saliency /= activeSaliencyMaps.size();
499 Eigen::Matrix4f pose = Eigen::Matrix4f::Identity();
500 pose.col(3).head<3>() = out.cast<
float>() * 1000.0;
501 pose = cameraToGlobal * pose;
507 if (saliency < visuSaliencyThreshold)
511 DebugDrawer24BitColoredPointCloudElement point;
513 point.x = pose(0, 3);
514 point.y = pose(1, 3);
515 point.z = pose(2, 3);
516 cloud.points.push_back(point);
518 cloud.pointSize = 10;
519 drawer->set24BitColoredPointCloudVisu(
"saliencyMap",
"SaliencyCloud", cloud);
525 drawer->clearLayer(
"saliencyMap");
531 std::unique_lock lock(syncMutex);
533 if (saliencyMaps.count(name))
535 saliencyMaps.erase(name);
538 condition.notify_all();
544 std::vector<std::string> names;
546 std::unique_lock lock(syncMutex);
548 for (
const auto& p : saliencyMaps)
550 names.push_back(p.second->name);
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::vector< CSGNode * > TNodeList
void setIntensity(float fIntensity)
TSphereCoord getPosition()
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static void addDataPaths(const std::string &dataPathList)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Implements a Variant type for timestamps.
static TimestampVariantPtr nowPtr()
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 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 clearManualViewTargets(const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
const VariantTypeId FramedPosition
const VariantTypeId FramedDirection
DrawColor24Bit HeatMapRGBColor(float percentage)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
IceInternal::Handle< FramedDirection > FramedDirectionPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< FramedPosition > FramedPositionPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
IceInternal::Handle< TimestampVariant > TimestampVariantPtr
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
constexpr auto n() noexcept