DetachObjectInMemory.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 Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "DetachObjectInMemory.h"
24 
25 //#include <ArmarXCore/core/time/TimeUtil.h>
26 //#include <ArmarXCore/observers/variant/DatafieldRef.h>
27 
29 
30 using namespace armarx;
31 using namespace MemoryXUtility;
32 
33 // DO NOT EDIT NEXT LINE
34 DetachObjectInMemory::SubClassRegistry
35  DetachObjectInMemory::Registry(DetachObjectInMemory::GetName(),
37 
38 void
40 {
41  memoryx::ObjectInstanceMemorySegmentBasePrx instanceMemory =
42  getWorkingMemory()->getObjectInstancesSegment();
43  std::string attachedObjectId;
44 
45  if (in.isAttachedObjectChannelSet() and in.getAttachedObjectChannel())
46  {
47  try
48  {
49  TimedVariantPtr idField =
50  ChannelRefPtr::dynamicCast(in.getAttachedObjectChannel())->getDataField("id");
51  attachedObjectId = idField->getString();
52  }
53  catch (std::exception const& ex)
54  {
55  ARMARX_WARNING << "Could not get ID of attached object from channel. Reason:\n"
56  << ex.what();
57  throw;
58  }
59  }
60  else if (in.isAttachedObjectIDSet())
61  {
62  attachedObjectId = in.getAttachedObjectID();
63  }
64  else
65  {
66  ARMARX_INFO << "Attached object is not defined. Either set ID or channel!";
67  emitFailure();
68  return;
69  }
70 
72  new memoryx::MotionModelStaticObject(getRobotStateComponent()));
73  getWorkingMemory()->getObjectInstancesSegment()->setNewMotionModel(attachedObjectId,
74  newMotionModel);
75  emitSuccess();
76 }
77 
78 //void DetachObjectInMemory::run()
79 //{
80 // // put your user code for the execution-phase here
81 // // runs in seperate thread, thus can do complex operations
82 // // should check constantly whether isRunningTaskStopped() returns true
83 //
84 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
85 // while (!isRunningTaskStopped()) // stop run function if returning true
86 // {
87 // // do your calculations
88 // }
89 //}
90 
91 //void DetachObjectInMemory::onBreak()
92 //{
93 // // put your user code for the breaking point here
94 // // execution time should be short (<100ms)
95 //}
96 
97 void
99 {
100  // put your user code for the exit point here
101  // execution time should be short (<100ms)
102 }
103 
104 // DO NOT EDIT NEXT FUNCTION
107 {
108  return XMLStateFactoryBasePtr(new DetachObjectInMemory(stateData));
109 }
armarx::MemoryXUtility::DetachObjectInMemory::onEnter
void onEnter() override
Definition: DetachObjectInMemory.cpp:39
armarx::MemoryXUtility::DetachObjectInMemory::onExit
void onExit() override
Definition: DetachObjectInMemory.cpp:98
armarx::MemoryXUtility::DetachObjectInMemory::DetachObjectInMemory
DetachObjectInMemory(const XMLStateConstructorParams &stateData)
Definition: DetachObjectInMemory.h:31
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::MemoryXUtility::DetachObjectInMemory::Registry
static SubClassRegistry Registry
Definition: DetachObjectInMemory.h:45
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle
Definition: forward_declarations.h:8
MotionModelStaticObject.h
memoryx::MotionModelStaticObject
Definition: MotionModelStaticObject.h:32
DetachObjectInMemory.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::MemoryXUtility::DetachObjectInMemory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DetachObjectInMemory.cpp:106
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27