DeleteObjectInstancesFromMemory.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 RobotSkillTemplates::MemoryXUtility
17 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
30
31//#include <ArmarXCore/core/time/TimeUtil.h>
32//#include <ArmarXCore/observers/variant/DatafieldRef.h>
33
34using namespace armarx;
35using namespace MemoryXUtility;
36
37// DO NOT EDIT NEXT LINE
38DeleteObjectInstancesFromMemory::SubClassRegistry
39 DeleteObjectInstancesFromMemory::Registry(DeleteObjectInstancesFromMemory::GetName(),
41
42void
44{
45 // put your user code for the enter-point here
46 // execution time should be short (<100ms)
47}
48
49void
51{
52 // put your user code for the execution-phase here
53 // runs in seperate thread, thus can do complex operations
54 // should check constantly whether isRunningTaskStopped() returns true
55
56 auto channels = getObjectMemoryObserver()->getAvailableChannels(false);
57
58 for (auto& channel : channels)
59 {
60 if (channel.first.find("_query_") != std::string::npos)
61 {
62 ChannelRefPtr ref = new ChannelRef(getObjectMemoryObserver(), channel.first);
63 getObjectMemoryObserver()->releaseObjectClass(ref);
64 ARMARX_INFO << "Releasing channel for " << ref->getChannelName();
65 }
66 }
67 auto entities = getPriorKnowledge()->getObjectClassesSegment()->getAllEntities();
68 auto instanceSegment = getWorkingMemory()->getObjectInstancesSegment();
69 for (memoryx::EntityBasePtr base : entities)
70 {
71 memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(base);
72 auto var = entity->getAttributeValue("recognitionMethod");
73 if (var && !var->getString().empty() && var->getString() != "<none>")
74 {
75 auto objInstances = instanceSegment->getObjectInstancesByClass(entity->getName());
76 ARMARX_INFO << "Checking instances of class: " << entity->getName() << " got "
77 << objInstances.size() << " instances";
78 for (auto& obj : objInstances)
79 {
80 instanceSegment->removeEntity(obj->getId());
81 ARMARX_INFO << "Removing instance " << obj->getName() << " with id "
82 << obj->getId();
83 }
84 }
85 }
86 emitSuccess();
87
88 // // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
89 // while (!isRunningTaskStopped()) // stop run function if returning true
90 // {
91 // // do your calculations
92 // }
93}
94
95//void DeleteObjectInstancesFromMemory::onBreak()
96//{
97// // put your user code for the breaking point here
98// // execution time should be short (<100ms)
99//}
100
101void
103{
104 // put your user code for the exit point here
105 // execution time should be short (<100ms)
106}
107
108// DO NOT EDIT NEXT FUNCTION
The ChannelRef class is a reference to a channel on an Observer.
Definition ChannelRef.h:51
DeleteObjectInstancesFromMemory(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
Definition Entity.h:45