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 
34 using namespace armarx;
35 using namespace MemoryXUtility;
36 
37 // DO NOT EDIT NEXT LINE
38 DeleteObjectInstancesFromMemory::SubClassRegistry
39  DeleteObjectInstancesFromMemory::Registry(DeleteObjectInstancesFromMemory::GetName(),
41 
42 void
44 {
45  // put your user code for the enter-point here
46  // execution time should be short (<100ms)
47 }
48 
49 void
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 
101 void
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
111 {
113 }
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DeleteObjectInstancesFromMemory.cpp:110
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::Registry
static SubClassRegistry Registry
Definition: DeleteObjectInstancesFromMemory.h:46
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::onExit
void onExit() override
Definition: DeleteObjectInstancesFromMemory.cpp:102
IceInternal::Handle< ChannelRef >
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:169
MemoryXCoreObjectFactories.h
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::onEnter
void onEnter() override
Definition: DeleteObjectInstancesFromMemory.cpp:43
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::run
void run() override
Definition: DeleteObjectInstancesFromMemory.cpp:50
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
Entity.h
MemoryXTypesObjectFactories.h
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::DeleteObjectInstancesFromMemory
DeleteObjectInstancesFromMemory(const XMLStateConstructorParams &stateData)
Definition: DeleteObjectInstancesFromMemory.h:32
DeleteObjectInstancesFromMemory.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ChannelRef.h