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
30
32
34
36#include <MemoryX/interface/components/PriorKnowledgeInterface.h>
37#include <MemoryX/interface/components/WorkingMemoryInterface.h>
40
41namespace armarx
42{
44 {
45 public:
48 {
50 "objectToGrasp", "", "the object for which the grasp should be planned");
51 }
52 };
53
54 /**
55 * @class GraspingManagerTest
56 * @brief A brief description
57 *
58 * Detailed Description
59 */
61 virtual public armarx::ManagedIceObject,
62 virtual public armarx::Component
63 {
64 public:
65 /**
66 * @see armarx::ManagedIceObject::getDefaultName()
67 */
68 std::string
69 getDefaultName() const override
70 {
71 return "GraspingManagerTest";
72 }
73
80
81 protected:
82 /**
83 * @see armarx::ManagedIceObject::onInitComponent()
84 */
85 void
86 onInitComponent() override
87 {
88 usingProxy("GraspingManager");
89 usingProxy("WorkingMemory");
90 usingProxy("PriorKnowledge");
91 usingProxy("RobotStateComponent");
92 srand(IceUtil::Time::now().toMicroSeconds());
93 }
94
95 /**
96 * @see armarx::ManagedIceObject::onConnectComponent()
97 */
98 void
100 {
101 std::string objectName = getProperty<std::string>("objectToGrasp").getValue();
104 getProxy<RobotStateComponentInterfacePrx>("RobotStateComponent");
105 while (true)
106 {
107 auto object = wm->getObjectInstancesSegment()->getEntityByName(objectName);
108 // Eigen::Quaternionf q(
109 // 0.5174515247344971,
110 // -0.5286158323287964,
111 // 0.4808708131313324,
112 // -0.4707148373126984);
113 // Eigen::Vector3f pos(4130.22705078125,
114 // 7142.34765625,
115 // 1170.102416992188);
116 // pos(0) += (rand() % 1000) - 500;
117 // pos(1) += (rand() % 1000) - 500;
118 // // pos(2) += (rand() % 1500) - 1000;
119 // if (object)
120 // {
121 //
122 // wm->getObjectInstancesSegment()->removeEntity(object->getId());
123 // }
124 //
125 // wm->getObjectInstancesSegment()->addObjectInstance(objectName, objectName,
126 // new LinkedPose(q.toRotationMatrix(),
127 // pos, GlobalFrame, robot->getSynchronizedRobot()),
128 // new memoryx::MotionModelStaticObject(robot));
129
130
131 prior = getProxy<memoryx::PriorKnowledgeInterfacePrx>("PriorKnowledge");
132 getProxy(gm, "GraspingManager");
133
134 ARMARX_INFO << "initializing object";
135 object = wm->getObjectInstancesSegment()->getEntityByName(objectName);
137
138 ARMARX_INFO << "object initialized, generating grasping trajectory";
139 auto result = gm->generateGraspingTrajectory(object->getId());
140 sleep(2);
141 //
142 ARMARX_INFO << "Got result:";
143 ARMARX_INFO << "=== Pose Trajectory ===";
144 JSONObjectPtr poseTraj = new JSONObject();
145 poseTraj->setVariant("posetrajectory", new Variant(result.poseTrajectory));
146 ARMARX_INFO << "Pose Trajectory: " << poseTraj->asString(true);
147 // TrajectoryPtr platformTraj = TrajectoryPtr ::dynamicCast(result.poseTrajectory);
148 // for (const Trajectory::TrajData& point : *platformTraj)
149 // {
150 // ARMARX_INFO << "ts " << point.getTimestamp() << ": ";
151 // ARMARX_INFO << VAROUT(point.getPositions());
152 // }
153
154 ARMARX_INFO << "=== Joint Trajectory ===";
155 JSONObjectPtr jointTraj = new JSONObject();
156 jointTraj->setVariant("jointtrajectory", new Variant(result.poseTrajectory));
157 ARMARX_INFO << "Joint Trajectory: " << jointTraj->asString(true);
158 // TrajectoryPtr jointTraj = TrajectoryPtr ::dynamicCast(result.configTrajectory);
159 // for (const Trajectory::TrajData& point : *jointTraj)
160 // {
161 // ARMARX_INFO << "ts " << point.getTimestamp() << ": ";
162 // ARMARX_INFO << point.getPositions();
163 // }
164 }
165 }
166
167 /**
168 * @see armarx::ManagedIceObject::onDisconnectComponent()
169 */
170 void
172 {
173 }
174
175 /**
176 * @see armarx::ManagedIceObject::onExitComponent()
177 */
178 void
180 {
181 }
182
183 private:
184 memoryx::PriorKnowledgeInterfacePrx prior;
185 memoryx::WorkingMemoryInterfacePrx wm;
186 GraspingManagerInterfacePrx gm;
187 };
188} // namespace armarx
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const override
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition JSONObject.h:44
The ManagedIceObject is the base class for all ArmarX objects.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The Variant class is described here: Variants.
Definition Variant.h:224
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx