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