SimpleEpisodicMemoryWorkingMemoryConnector.cpp
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 MemoryX::ArmarXObjects::SimpleEpisodicMemoryWorkingMemoryConnector
17 * @author fabian.peller-konrad@kit.edu ( fabian dot peller-konrad at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
27
29
32#include <MemoryX/interface/memorytypes/MemoryEntities.h>
37
38namespace memoryx
39{
40
43 {
46
47 def->topic<WorkingMemoryListenerInterface>("WorkingMemory", "WorkingMemoryName");
48 def->optional(minOrientationDistance,
49 "MinOrientationDistance",
50 "Min Distance an object has to rotate until the memory receives an update");
51 def->optional(minPositionDistance,
52 "MinPositrionDistance",
53 "Min Distance an object has to move until the memory receives an update");
54 return def;
55 }
56
58 minOrientationDistance(0.25 * M_PI), minPositionDistance(100)
59 {
60 }
61
62 std::string
64 {
65 return "SimpleEpisodicMemoryWorkingMemoryConnector";
66 }
67
68 std::string
70 {
71 return "SimpleEpisodicMemoryWorkingMemoryConnector";
72 }
73
74 void
81
82 void
88
89 void
93
94 void
98
99 void
101 const std::string& segmentName,
102 const memoryx::EntityBasePtr& newEntity,
103 const Ice::Current&)
104 {
105 if (segmentName != "objectInstances")
106 {
107 return;
108 }
109
110 EntityPtr entity = EntityPtr::dynamicCast(newEntity);
111
112 //ARMARX_DEBUG << "Entity created in segment " << segmentName << ": " << entity;
113 std::map<int, memoryx::EntityBasePtr> entitiesForSegment = entityMap[segmentName];
114 entitiesForSegment[std::stoi(entity->getId())] = entity;
115
116 EntityAttributePtr pos = EntityAttributePtr::dynamicCast(entity->getAttribute("position"));
117 armarx::VariantPtr posValue = armarx::VariantPtr::dynamicCast(pos->getValue());
118 auto framedPos = posValue->getClass<armarx::FramedPositionBase>();
119
120 memoryx::ObjectPoseEvent o;
121 o.objectName = entity->getName();
122 o.x = framedPos->x;
123 o.y = framedPos->y;
124 o.z = framedPos->z;
125 o.frame = framedPos->frame;
126 o.type = memoryx::ObjectPoseEventType::NEW_OBJECT_RECOGNIZED;
127 o.receivedInMs = IceUtil::Time::now().toMilliSecondsDouble();
128 m_simple_episodic_memory->registerObjectPoseEvent(o);
129 }
130
131 void
133 const std::string& segmentName,
134 const memoryx::EntityBasePtr& entityOld,
135 const memoryx::EntityBasePtr& entityNew,
136 const Ice::Current&)
137 {
138 //ARMARX_DEBUG << "Entity changed: ";
139 //ARMARX_DEBUG << "Old: " << EntityPtr::dynamicCast(entityOld);
140 //ARMARX_DEBUG << "New: " << EntityPtr::dynamicCast(entityNew);
141 if (segmentName != "objectInstances")
142 {
143 return;
144 }
145
146 EntityPtr prevEntity = EntityPtr::dynamicCast(entityOld);
147 EntityPtr currEntity = EntityPtr::dynamicCast(entityNew);
148
149 EntityAttributePtr prevPos =
150 EntityAttributePtr::dynamicCast(prevEntity->getAttribute("position"));
151 armarx::VariantPtr prevPosValue = armarx::VariantPtr::dynamicCast(prevPos->getValue());
152 auto prevFramedPos = prevPosValue->getClass<armarx::FramedPositionBase>();
153
154 EntityAttributePtr currPos =
155 EntityAttributePtr::dynamicCast(currEntity->getAttribute("position"));
156 armarx::VariantPtr currPosValue = armarx::VariantPtr::dynamicCast(currPos->getValue());
157 auto currFramedPos = currPosValue->getClass<armarx::FramedPositionBase>();
158
159 Eigen::Vector3f prevPosVector(prevFramedPos->x, prevFramedPos->y, prevFramedPos->z);
160 Eigen::Vector3f currPosVector(currFramedPos->x, currFramedPos->y, currFramedPos->z);
161
162 float distance = (currPosVector - prevPosVector).norm();
163
164 if (distance > minPositionDistance /* && rotation */)
165 {
166 // update entity
167 std::map<int, memoryx::EntityBasePtr> entitiesForSegment = entityMap[segmentName];
168 entitiesForSegment[std::stoi(currEntity->getId())] = currEntity;
169
170 memoryx::ObjectPoseEvent o;
171 o.objectName = currEntity->getName();
172 o.x = currPosVector(0);
173 o.y = currPosVector(1);
174 o.z = currPosVector(2);
175 o.type = memoryx::ObjectPoseEventType::OBJECT_POSE_UPDATE;
176 o.receivedInMs = IceUtil::Time::now().toMilliSecondsDouble();
177 m_simple_episodic_memory->registerObjectPoseEvent(o);
178 }
179 }
180
181 void
183 const std::string& segmentName,
184 const memoryx::EntityBasePtr& entity,
185 const Ice::Current&)
186 {
187 ARMARX_DEBUG << "Entity removed: id = " << entity->getId();
188 }
189
190 void
192 const Ice::Current&)
193 {
194 ARMARX_DEBUG << "Snapshot loaded!";
195 }
196
197 void
199 const Ice::Current& c)
200 {
201 ARMARX_DEBUG << "Snapshot completely loaded!";
202 }
203
204 void
206 const Ice::Current&)
207 {
208 ARMARX_DEBUG << "Scene cleared!";
209 }
210
211} // namespace memoryx
212
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#define M_PI
Definition MathTools.h:17
constexpr T c
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
memoryx::SimpleEpisodicMemoryInterface::ProxyType m_simple_episodic_memory
void reportEntityUpdated(const std::string &, const EntityBasePtr &, const EntityBasePtr &, const Ice::Current &) override
void reportEntityRemoved(const std::string &, const EntityBasePtr &, const Ice::Current &) override
void reportSnapshotLoaded(const std::string &, const Ice::Current &) override
void reportEntityCreated(const std::string &, const EntityBasePtr &, const Ice::Current &) override
void reportMemoryCleared(const std::string &, const Ice::Current &) override
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
VirtualRobot headers.
IceInternal::Handle< EntityAttribute > EntityAttributePtr
Typedef of EntityAttributePtr as IceInternal::Handle<EntityAttribute> for convenience.
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
Definition Entity.h:45
double norm(const Point &a)
Definition point.hpp:102
double distance(const Point &a, const Point &b)
Definition point.hpp:95