CalculateGraspConfiguration.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::GraspObjectGroup
17  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
30 using namespace armarx;
31 using namespace GraspObjectGroup;
32 
33 // DO NOT EDIT NEXT LINE
34 CalculateGraspConfiguration::SubClassRegistry CalculateGraspConfiguration::Registry(CalculateGraspConfiguration::GetName(), &CalculateGraspConfiguration::CreateInstance);
35 
36 
37 
39 {
40  // put your user code for the enter-point here
41  // execution time should be short (<100ms)
42  ARMARX_INFO << "Instance content: " << getWorkingMemory()->getObjectInstancesSegment()->getJSONEntityById(in.getObjectInstanceChannel()->getDataField("id")->getString());
43  memoryx::ObjectInstancePtr objInstance = memoryx::ObjectInstancePtr::dynamicCast(getWorkingMemory()->getObjectInstancesSegment()->getObjectInstanceById(in.getObjectInstanceChannel()->getDataField("id")->getString()));
44  ARMARX_INFO << "instance content local: " << *objInstance;
45  auto robot = RemoteRobot::createLocalCloneFromFile(getRobotStateComponent(), VirtualRobot::RobotIO::eCollisionModel);
46  RemoteRobot::synchronizeLocalClone(robot, getRobotStateComponent());
47  memoryx::ObjectClassPtr objclass = memoryx::ObjectClassPtr::dynamicCast(getWorkingMemory()->getObjectClassesSegment()->getEntityByName(in.getObjectInstanceChannel()->getDataField("className")->getString()));
48  ARMARX_CHECK_EXPRESSION(objclass);
49  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(getWorkingMemory()->getCommonStorage()));
50  memoryx::EntityWrappers::SimoxObjectWrapperPtr simoxObject = objclass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
51  simoxObject->getManipulationObject();
52  objInstance->setPose(objInstance->getPose()->toGlobal(robot));
53  auto endeffector = robot->getEndEffector(in.getHandName());
54  simoxObject->updateFromEntity(objInstance);
55  ARMARX_INFO << "GCP Pose: " << endeffector->getGCP()->getGlobalPose();
56  ARMARX_INFO << "ObjectPose: " << simoxObject->getManipulationObject()->getGlobalPose();
57  ARMARX_INFO << "JointConfig before: " << endeffector->getConfiguration()->getRobotNodeJointValueMap();
58  endeffector->closeActors(simoxObject->getManipulationObject());
59  // getEntityDrawerTopic()->setObjectVisu("Grasping", "TargetObjectVisu", objclass, new Pose(simoxObject->getManipulationObject()->getGlobalPose()));
60 
61  // memoryx::ObjectClassPtr handobjclass = memoryx::ObjectClassPtr::dynamicCast(getWorkingMemory()->getObjectClassesSegment()->getEntityByName(in.getHandInstanceChannel()->getDataField("className")->getString()));
62 
63  // getEntityDrawerTopic()->setObjectVisu("Grasping", "HandVisu", handobjclass, new Pose(robot->getRobotNode(in.getHandName())->getGlobalPose()));
64  // getEntityDrawerTopic()->updateObjectColor("Grasping", "HandVisu", DrawColor {1, 0, 0, 0.5});
65  out.setJointValueMap(endeffector->getConfiguration()->getRobotNodeJointValueMap());
66  emitSuccess();
67 }
68 
69 //void CalculateGraspConfiguration::run()
70 //{
71 // // put your user code for the execution-phase here
72 // // runs in seperate thread, thus can do complex operations
73 // // should check constantly whether isRunningTaskStopped() returns true
74 //
75 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
76 // while (!isRunningTaskStopped()) // stop run function if returning true
77 // {
78 // // do your calculations
79 // }
80 //}
81 
82 //void CalculateGraspConfiguration::onBreak()
83 //{
84 // // put your user code for the breaking point here
85 // // execution time should be short (<100ms)
86 //}
87 
89 {
90  // put your user code for the exit point here
91  // execution time should be short (<100ms)
92 }
93 
94 
95 // DO NOT EDIT NEXT FUNCTION
97 {
99 }
100 
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:448
armarx::RemoteRobot::createLocalCloneFromFile
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
Definition: RemoteRobot.cpp:441
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
GridFileManager.h
ObjectClass.h
IceInternal::Handle< ObjectInstance >
armarx::GraspObjectGroup::CalculateGraspConfiguration::onEnter
void onEnter() override
Definition: CalculateGraspConfiguration.cpp:38
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
CalculateGraspConfiguration.h
armarx::GraspObjectGroup::CalculateGraspConfiguration::CalculateGraspConfiguration
CalculateGraspConfiguration(const XMLStateConstructorParams &stateData)
Definition: CalculateGraspConfiguration.h:33
SimoxObjectWrapper.h
ObjectInstance.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
armarx::GraspObjectGroup::CalculateGraspConfiguration::Registry
static SubClassRegistry Registry
Definition: CalculateGraspConfiguration.h:46
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:42
MemoryXTypesObjectFactories.h
armarx::GraspObjectGroup::CalculateGraspConfiguration::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CalculateGraspConfiguration.cpp:96
armarx::GraspObjectGroup::CalculateGraspConfiguration::onExit
void onExit() override
Definition: CalculateGraspConfiguration.cpp:88
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28