GraspingManagerTestApp.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents::ArmarXObjects::GraspingManagerTest
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot kit dot edu )
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
31 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
32 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
37 
38 namespace armarx
39 {
42  {
43  public:
46  {
47  defineOptionalProperty<std::string>("objectToGrasp", "", "the object for which the grasp should be planned");
48  }
49  };
50 
51  /**
52  * @class GraspingManagerTest
53  * @brief A brief description
54  *
55  * Detailed Description
56  */
58  virtual public armarx::ManagedIceObject,
59  virtual public armarx::Component
60  {
61  public:
62  /**
63  * @see armarx::ManagedIceObject::getDefaultName()
64  */
65  std::string getDefaultName() const override
66  {
67  return "GraspingManagerTest";
68  }
69 
71  {
74  }
75 
76  protected:
77  /**
78  * @see armarx::ManagedIceObject::onInitComponent()
79  */
80  void onInitComponent() override
81  {
82  usingProxy("GraspingManager");
83  usingProxy("WorkingMemory");
84  usingProxy("PriorKnowledge");
85  usingProxy("RobotStateComponent");
86  srand(IceUtil::Time::now().toMicroSeconds());
87  }
88 
89  /**
90  * @see armarx::ManagedIceObject::onConnectComponent()
91  */
92  void onConnectComponent() override
93  {
94  std::string objectName = getProperty<std::string>("objectToGrasp").getValue();
95  wm = getProxy<memoryx::WorkingMemoryInterfacePrx>("WorkingMemory");
96  RobotStateComponentInterfacePrx robot = getProxy<RobotStateComponentInterfacePrx>("RobotStateComponent");
97  while (true)
98  {
99  auto object = wm->getObjectInstancesSegment()->getEntityByName(objectName);
100  // Eigen::Quaternionf q(
101  // 0.5174515247344971,
102  // -0.5286158323287964,
103  // 0.4808708131313324,
104  // -0.4707148373126984);
105  // Eigen::Vector3f pos(4130.22705078125,
106  // 7142.34765625,
107  // 1170.102416992188);
108  // pos(0) += (rand() % 1000) - 500;
109  // pos(1) += (rand() % 1000) - 500;
110  // // pos(2) += (rand() % 1500) - 1000;
111  // if (object)
112  // {
113  //
114  // wm->getObjectInstancesSegment()->removeEntity(object->getId());
115  // }
116  //
117  // wm->getObjectInstancesSegment()->addObjectInstance(objectName, objectName,
118  // new LinkedPose(q.toRotationMatrix(),
119  // pos, GlobalFrame, robot->getSynchronizedRobot()),
120  // new memoryx::MotionModelStaticObject(robot));
121 
122 
123  prior = getProxy<memoryx::PriorKnowledgeInterfacePrx>("PriorKnowledge");
124  getProxy(gm, "GraspingManager");
125 
126  ARMARX_INFO << "initializing object";
127  object = wm->getObjectInstancesSegment()->getEntityByName(objectName);
128  ARMARX_CHECK_EXPRESSION(object);
129 
130  ARMARX_INFO << "object initialized, generating grasping trajectory";
131  auto result = gm->generateGraspingTrajectory(object->getId());
132  sleep(2);
133  //
134  ARMARX_INFO << "Got result:";
135  ARMARX_INFO << "=== Pose Trajectory ===";
136  JSONObjectPtr poseTraj = new JSONObject();
137  poseTraj->setVariant("posetrajectory", new Variant(result.poseTrajectory));
138  ARMARX_INFO << "Pose Trajectory: " << poseTraj->asString(true);
139  // TrajectoryPtr platformTraj = TrajectoryPtr ::dynamicCast(result.poseTrajectory);
140  // for (const Trajectory::TrajData& point : *platformTraj)
141  // {
142  // ARMARX_INFO << "ts " << point.getTimestamp() << ": ";
143  // ARMARX_INFO << VAROUT(point.getPositions());
144  // }
145 
146  ARMARX_INFO << "=== Joint Trajectory ===";
147  JSONObjectPtr jointTraj = new JSONObject();
148  jointTraj->setVariant("jointtrajectory", new Variant(result.poseTrajectory));
149  ARMARX_INFO << "Joint Trajectory: " << jointTraj->asString(true);
150  // TrajectoryPtr jointTraj = TrajectoryPtr ::dynamicCast(result.configTrajectory);
151  // for (const Trajectory::TrajData& point : *jointTraj)
152  // {
153  // ARMARX_INFO << "ts " << point.getTimestamp() << ": ";
154  // ARMARX_INFO << point.getPositions();
155  // }
156  }
157  }
158 
159  /**
160  * @see armarx::ManagedIceObject::onDisconnectComponent()
161  */
162  void onDisconnectComponent() override
163  {
164 
165  }
166 
167  /**
168  * @see armarx::ManagedIceObject::onExitComponent()
169  */
170  void onExitComponent() override
171  {
172 
173  }
174 
175  private:
176  memoryx::PriorKnowledgeInterfacePrx prior;
177  memoryx::WorkingMemoryInterfacePrx wm;
178  GraspingManagerInterfacePrx gm;
179  };
180 }
181 
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
LinkedPose.h
JSONObject.h
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
GraspingManager.h
armarx::GraspingManagerTest::onConnectComponent
void onConnectComponent() override
Definition: GraspingManagerTestApp.h:92
armarx::GraspingManagerTest::onDisconnectComponent
void onDisconnectComponent() override
Definition: GraspingManagerTestApp.h:162
IceInternal::Handle< JSONObject >
ManagedIceObject.h
armarx::GraspingManagerTest::onExitComponent
void onExitComponent() override
Definition: GraspingManagerTestApp.h:170
armarx::GraspingManagerTest::getDefaultName
std::string getDefaultName() const override
Definition: GraspingManagerTestApp.h:65
MotionModelStaticObject.h
MemoryXCoreObjectFactories.h
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
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::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::GraspingManagerTest
A brief description.
Definition: GraspingManagerTestApp.h:57
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::GraspingManagerTestPropertyDefinitions::GraspingManagerTestPropertyDefinitions
GraspingManagerTestPropertyDefinitions(std::string prefix)
Definition: GraspingManagerTestApp.h:44
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
MemoryXTypesObjectFactories.h
armarx::GraspingManagerTestPropertyDefinitions
Definition: GraspingManagerTestApp.h:40
armarx::GraspingManagerTest::onInitComponent
void onInitComponent() override
Definition: GraspingManagerTestApp.h:80
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:393
armarx::GraspingManagerTest::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GraspingManagerTestApp.h:70
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28