SimpleRobotPlacement.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2015-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::SimpleRobotPlacement
19 * @author Harry Arnst (harry dot arnst at student dot kit dot edu)
20 * Valerij Wittenbeck (valerij dot wittenbeck at student dot kit dot edu)
21 * @date 2016
22 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23 * GNU General Public License
24 */
25
26#pragma once
27
28#include <VirtualRobot/CollisionDetection/CDManager.h>
29#include <VirtualRobot/SceneObjectSet.h>
30#include <VirtualRobot/Workspace/Manipulability.h>
31#include <VirtualRobot/Workspace/Reachability.h>
32#include <VirtualRobot/Workspace/WorkspaceGrid.h>
33
35
37#include <RobotAPI/interface/core/RobotState.h>
38
40#include <RobotComponents/interface/components/GraspingManager/RobotPlacementInterface.h>
41#include <RobotComponents/interface/components/RobotIK.h>
42
44#include <MemoryX/interface/components/WorkingMemoryInterface.h>
45#include <MemoryX/interface/gui/EntityDrawerInterface.h>
46#include <MemoryX/interface/memorytypes/MemorySegments.h>
47//#include <RobotComponents/interface/components/MotionPlanning/Tasks/MotionPlanningTask.h>
48//#include <RobotComponents/components/MotionPlanning/Tasks/AStar/Task.h>
49#include <Eigen/Geometry>
50
52
53namespace armarx
54{
55 /**
56 * @class SimpleRobotPlacementPropertyDefinitions
57 * @brief
58 */
64
65 /**
66 * @defgroup Component-SimpleRobotPlacement SimpleRobotPlacement
67 * @ingroup RobotComponents-Components
68 * @brief The SimpleRobotPlacement component provides methods to calculate candidate robot placements (i.e. base poses) in order to grasp a given object.
69 *
70 * This component requires following properties:
71 * \li RobotName: The name of the robot
72 * \li RobotFilePath: Filepath of the VirtualRobot robot to use (relative to an armarx package).
73 * \li CollisionModel: The RobotNodeSet name to be used for collision testing with the environment.
74 * \li WorkspaceFilePaths: Paths to manipulability and reachability files (';' delimited). Each path is relative to an armarx package.
75 *
76 * This component is a processing stage in the grasping pipeline run by the GraspingManager-Component.
77 * It receives an object instance id and a set of grasps (i.e. global tcp poses and -names) via an Ice interface method and returns a list of possible
78 * robot placements (i.e. global base poses). The generated robot placements are collisionfree between the collision model (given in the properties)
79 * in its default configuration and the collision model of the environment. The collision model of the environment is created via the WorkingMemory-Instance.
80 * Resulting robot placements and workspaceGrids are visualized via 'DebugDrawerUpdates'.
81 */
82
83 /**
84 * @ingroup Component-SimpleRobotPlacement
85 * @brief refer to \ref Component-SimpleRobotPlacement
86 */
87 class SimpleRobotPlacement : virtual public Component, virtual public RobotPlacementInterface
88 {
89 public:
90 /**
91 * @see armarx::ManagedIceObject::getDefaultName()
92 */
93 std::string
94 getDefaultName() const override
95 {
96 return "SimpleRobotPlacement";
97 }
98
100 {
101 float x;
102 float y;
103 float z;
104 float score;
105 };
106
107 /**
108 * @brief Computes a list of candidate robot placements for a list of grasps.
109 * More precisely: computes global (x,y) coordinates and a yaw rotation for the robot's base pose such that the given object becomes reachable for the robot.
110 * The (x,y) positions are computed based on Simox Workspacegrids created from the preloaded workspace files given in the properties.
111 * This method tries to find (x,y) positions of high reachability by using a randomized approach, thus the returned robot placements are not
112 * best possible solutions in terms of reachability.
113 * The computed yaw rotations are chosen, such that the robot is directly facing the given object (i.e. the angle between the robot's x-axis and the object's (x,y) position is 0).
114 * @param grasps the grasps associated with the given object
115 * @param objectInstanceEntityId the id of the object instance located in the WorkingMemory-Instance
116 * @param c
117 * @return A list of possible robot placements
118 */
119 GraspingPlacementList
120 generateRobotPlacements(const GeneratedGraspList& grasps,
121 const Ice::Current& c = Ice::emptyCurrent) override;
122
123 /**
124 * @brief Computes a list of candidate robot placements for a grasp pose.
125 *
126 * @see generateRobotPlacements
127 * @param endEffectorName Name of the Endeffector
128 * @param target Pointer to the FramedPose of the target
129 * @param planarObstacles List of planar obstacles
130 * @param placementArea Convex hull of the placement Area
131 * @param c Ice::Current
132 * @return A list of possible robot placements
133 */
134 GraspingPlacementList
135 generateRobotPlacementsForGraspPose(const std::string& endEffectorName,
136 const FramedPoseBasePtr& target,
137 const PlanarObstacleList& planarObstacles,
138 const ConvexHull& placementArea,
139 const Ice::Current& c = Ice::emptyCurrent) override;
140
141
142 GraspingPlacementList
143 generateRobotPlacementsEx(const GeneratedGraspList& grasps,
144 const Ice::Current& c = Ice::emptyCurrent) override;
145
146 protected:
147 /**
148 * @see armarx::ManagedIceObject::onInitComponent()
149 */
150 void onInitComponent() override;
151
152 /**
153 * @see armarx::ManagedIceObject::onConnectComponent()
154 */
155 void onConnectComponent() override;
156
157 /**
158 * @see armarx::ManagedIceObject::onDisconnectComponent()
159 */
160 void onDisconnectComponent() override;
161
162 /**
163 * @see armarx::ManagedIceObject::onExitComponent()
164 */
165 void onExitComponent() override;
166
167 /**
168 * @see PropertyUser::createPropertyDefinitions()
169 */
176
177 /**
178 * @brief Tries to get a workspace with the same TCP as the EEF of the robot
179 *
180 * @param g generated Grasps
181 * @return Pointer to the WorkspaceRepresentation
182 */
183 VirtualRobot::WorkspaceRepresentationPtr
184 getWorkspaceRepresentation(const GeneratedGrasp& g);
185
186 private:
187 memoryx::WorkingMemoryInterfacePrx wm;
188 memoryx::WorkingMemoryEntitySegmentBasePrx objectInstances;
189 memoryx::AgentInstancesSegmentBasePrx agentInstances;
190 memoryx::PriorKnowledgeInterfacePrx prior;
191 memoryx::PersistentObjectClassSegmentBasePrx objectClasses;
192
193 memoryx::GridFileManagerPtr fileManager;
194
195 std::string robotName;
196 std::string robotFilePath;
197 std::string colModel;
198 std::vector<std::string> workspaceFilePaths;
199 std::vector<VirtualRobot::WorkspaceRepresentationPtr> workspaces;
200 std::string drawRobotId;
201 std::string visuLayerName;
202 VirtualRobot::WorkspaceGridPtr visualizedGrid;
203
204 armarx::DebugDrawerInterfacePrx debugDrawerPrx;
205 memoryx::EntityDrawerInterfacePrx entityDrawerPrx;
206 RobotIKInterfacePrx rik;
207 RobotStateComponentInterfacePrx robotStateComponentPrx;
208
210 VirtualRobot::SceneObjectSetPtr sceneObjects;
211 // VirtualRobot::CDManager cd;
212 SimoxCSpacePtr cspace;
213 SimoxCSpacePtr cacheCSpace;
214
215 std::vector<CSpaceVisualizerTaskHandle> planningTasks;
216
217
218 VirtualRobot::WorkspaceGridPtr createWorkspaceGrid(GeneratedGrasp g,
219 const Eigen::Matrix4f& globalObjectPose);
220 void drawWorkspaceGrid(VirtualRobot::WorkspaceGridPtr reachGrid);
221 // finds a collision free position, tries to maximize the position score
222 bool getSuitablePosition(const GeneratedGrasp& g,
223 VirtualRobot::WorkspaceGridPtr reachGrid,
224 const Eigen::Matrix4f& globalGraspPose,
225 float& storeGlobalX,
226 float& storeGlobalY,
227 float& storeGlobalYaw,
228 int& score,
229 const VirtualRobot::MathTools::ConvexHull2DPtr& placementArea =
230 VirtualRobot::MathTools::ConvexHull2DPtr());
231
232 std::vector<RobotPlacement>
233 getSuitablePositions(const GeneratedGrasp& g,
234 VirtualRobot::WorkspaceGridPtr reachGrid,
235 const Eigen::Matrix4f& globalGraspPose,
236 float requiredReachabilityFraction,
237 int requiredCount,
238 int maxIterations,
239 const VirtualRobot::MathTools::ConvexHull2DPtr& placementArea =
240 VirtualRobot::MathTools::ConvexHull2DPtr());
241 // loads the robot given in the properties for collision testing
242 void loadRobot();
243 // loads the workspaces with the file paths given in the properties
244 void loadWorkspaces();
245 // checks whether there is a preloaded workspace with the given tcp
246 bool hasWorkspace(std::string tcp);
247 // filters all generated grasps, whose tcp is not given in any of the preloaded workspaces
248 GeneratedGraspList filterGrasps(const GeneratedGraspList grasps);
249 // returns the rotation needed for the robot to face the given target pose
250 float getPlatformRotation(const Eigen::Matrix4f& frameGlobal,
251 const Eigen::Matrix4f& globalTarget);
252
253 void updateRobot(std::string id, Eigen::Matrix4f globalPose, DrawColor color);
254 void drawNewRobot(Eigen::Matrix4f globalPose);
255 void drawWorkspaceGrid(const ::armarx::GeneratedGrasp&,
256 const std::string& objectInstanceEntityId);
257 };
258} // namespace armarx
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
refer to SimpleRobotPlacement
GraspingPlacementList generateRobotPlacements(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
Computes a list of candidate robot placements for a list of grasps.
PropertyDefinitionsPtr createPropertyDefinitions() override
GraspingPlacementList generateRobotPlacementsEx(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
VirtualRobot::WorkspaceRepresentationPtr getWorkspaceRepresentation(const GeneratedGrasp &g)
Tries to get a workspace with the same TCP as the EEF of the robot.
GraspingPlacementList generateRobotPlacementsForGraspPose(const std::string &endEffectorName, const FramedPoseBasePtr &target, const PlanarObstacleList &planarObstacles, const ConvexHull &placementArea, const Ice::Current &c=Ice::emptyCurrent) override
Computes a list of candidate robot placements for a grasp pose.
std::string getDefaultName() const override
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< SimoxCSpace > SimoxCSpacePtr
An ice handle for a SimoxCSpace.
Definition SimoxCSpace.h:56
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
std::shared_ptr< GridFileManager > GridFileManagerPtr