ObjectInstanceSegmentWrapper.cpp
Go to the documentation of this file.
2
3// Factory shenanigans: Do not remove, these are required
4// and runtime errors will be thrown if they are not included
5#include <VirtualRobot/ManipulationObject.h>
6
8
10
14
15namespace memoryx
16{
17
18 void
20 PriorKnowledgeInterfacePrx const& priorKnowledge,
21 WorkingMemoryInterfacePrx const& workingMemory,
22 armarx::RobotStateComponentInterfacePrx const& robotStateComponent)
23 {
24 ARMARX_CHECK_NOT_NULL(workingMemory);
25 ARMARX_CHECK_NOT_NULL(priorKnowledge);
26 ARMARX_CHECK_NOT_NULL(robotStateComponent);
27
28 objectClassSegment.initFromProxy(priorKnowledge, {});
29
30 this->robotStateComponent = robotStateComponent;
31 sharedRobot = robotStateComponent->getSynchronizedRobot();
32 localRobot = armarx::RemoteRobot::createLocalClone(sharedRobot);
33 objectInstancesSegment = workingMemory->getObjectInstancesSegment();
34 }
35
36 std::vector<ObjectInstanceWrapper>
37 ObjectInstanceSegmentWrapper::queryObjects(std::set<std::string> const& ids)
38 {
39 memoryx::EntityBaseList entities = objectInstancesSegment->getAllEntities();
40 std::vector<memoryx::ObjectInstancePtr> objectInstances;
41 for (auto& entity : entities)
42 {
43 memoryx::ObjectInstancePtr object = memoryx::ObjectInstancePtr::dynamicCast(entity);
44 if (object)
45 {
46 if (ids.empty() || ids.count(object->getId()))
47 {
48 objectInstances.push_back(object);
49 }
50 }
51 }
52
53 std::vector<ObjectInstanceWrapper> result;
54 for (auto& objectInstance : objectInstances)
55 {
56 std::string objectName = objectInstance->getName();
57
58 // TODO: Only synchronize if the timestamp is new
59 if (objectInstance->hasLocalizationTimestamp())
60 {
61 IceUtil::Time localizationTimestamp = objectInstance->getLocalizationTimestamp();
63 localRobot, robotStateComponent, localizationTimestamp.toMicroSeconds());
64 }
65 else
66 {
67 armarx::RemoteRobot::synchronizeLocalClone(localRobot, sharedRobot);
68 }
69 Eigen::Matrix4f globalPose = objectInstance->getPose()->toGlobalEigen(localRobot);
70
71 std::string objectClass = objectInstance->getMostProbableClass();
72 auto entry = objectClassSegment.getClass(objectClass);
73 if (!entry)
74 {
75 ARMARX_WARNING << deactivateSpam(1) << "Could not find object class '"
76 << objectClass << "'."
77 << " Skipping object '" << objectName << "'.";
78 continue;
79 }
80
81 // This operation can be quite expensive (~ 300ms for 10 objects).
82 VirtualRobot::ManipulationObjectPtr manipulationObject =
83 entry->manipulationObject->clone(objectName);
84 manipulationObject->setGlobalPose(globalPose);
85
87 object.instanceInMemory = objectInstance;
88 object.manipulationObject = manipulationObject;
89 result.push_back(object);
90 }
91
92 return result;
93 }
94
95} // namespace memoryx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
std::vector< ObjectInstanceWrapper > queryObjects(std::set< std::string > const &ids={})
void initFromProxies(memoryx::PriorKnowledgeInterfacePrx const &priorKnowledge, memoryx::WorkingMemoryInterfacePrx const &workingMemory, armarx::RobotStateComponentInterfacePrx const &robotStateComponent)
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
VirtualRobot headers.
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
memoryx::ObjectInstancePtr instanceInMemory