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 
29 #include <RobotComponents/interface/components/GraspingManager/RobotPlacementInterface.h>
30 #include <MemoryX/interface/memorytypes/MemorySegments.h>
31 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
33 #include <RobotAPI/interface/core/RobotState.h>
34 
35 #include <VirtualRobot/Workspace/WorkspaceGrid.h>
36 #include <RobotComponents/interface/components/RobotIK.h>
37 #include <VirtualRobot/Workspace/Manipulability.h>
38 #include <VirtualRobot/Workspace/Reachability.h>
39 #include <VirtualRobot/SceneObjectSet.h>
40 
42 #include <MemoryX/interface/gui/EntityDrawerInterface.h>
43 #include <VirtualRobot/CollisionDetection/CDManager.h>
45 //#include <RobotComponents/interface/components/MotionPlanning/Tasks/MotionPlanningTask.h>
46 //#include <RobotComponents/components/MotionPlanning/Tasks/AStar/Task.h>
48 
49 #include <Eigen/Geometry>
50 
51 namespace armarx
52 {
53  /**
54  * @class SimpleRobotPlacementPropertyDefinitions
55  * @brief
56  */
59  {
60  public:
62  };
63 
64  /**
65  * @defgroup Component-SimpleRobotPlacement SimpleRobotPlacement
66  * @ingroup RobotComponents-Components
67  * @brief The SimpleRobotPlacement component provides methods to calculate candidate robot placements (i.e. base poses) in order to grasp a given object.
68  *
69  * This component requires following properties:
70  * \li RobotName: The name of the robot
71  * \li RobotFilePath: Filepath of the VirtualRobot robot to use (relative to an armarx package).
72  * \li CollisionModel: The RobotNodeSet name to be used for collision testing with the environment.
73  * \li WorkspaceFilePaths: Paths to manipulability and reachability files (';' delimited). Each path is relative to an armarx package.
74  *
75  * This component is a processing stage in the grasping pipeline run by the GraspingManager-Component.
76  * 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
77  * robot placements (i.e. global base poses). The generated robot placements are collisionfree between the collision model (given in the properties)
78  * in its default configuration and the collision model of the environment. The collision model of the environment is created via the WorkingMemory-Instance.
79  * Resulting robot placements and workspaceGrids are visualized via 'DebugDrawerUpdates'.
80  */
81 
82  /**
83  * @ingroup Component-SimpleRobotPlacement
84  * @brief refer to \ref Component-SimpleRobotPlacement
85  */
87  virtual public Component,
88  virtual public RobotPlacementInterface
89  {
90  public:
91  /**
92  * @see armarx::ManagedIceObject::getDefaultName()
93  */
94  std::string 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 generateRobotPlacements(const GeneratedGraspList& grasps, const Ice::Current& c = Ice::emptyCurrent) override;
120 
121  /**
122  * @brief Computes a list of candidate robot placements for a grasp pose.
123  *
124  * @see generateRobotPlacements
125  * @param endEffectorName Name of the Endeffector
126  * @param target Pointer to the FramedPose of the target
127  * @param planarObstacles List of planar obstacles
128  * @param placementArea Convex hull of the placement Area
129  * @param c Ice::Current
130  * @return A list of possible robot placements
131  */
132  GraspingPlacementList generateRobotPlacementsForGraspPose(const std::string& endEffectorName, const FramedPoseBasePtr& target, const PlanarObstacleList& planarObstacles, const ConvexHull& placementArea, const Ice::Current& c = Ice::emptyCurrent) override;
133 
134 
135  GraspingPlacementList generateRobotPlacementsEx(const GeneratedGraspList& grasps, const Ice::Current& c = Ice::emptyCurrent) override;
136 
137  protected:
138  /**
139  * @see armarx::ManagedIceObject::onInitComponent()
140  */
141  void onInitComponent() override;
142 
143  /**
144  * @see armarx::ManagedIceObject::onConnectComponent()
145  */
146  void onConnectComponent() override;
147 
148  /**
149  * @see armarx::ManagedIceObject::onDisconnectComponent()
150  */
151  void onDisconnectComponent() override;
152 
153  /**
154  * @see armarx::ManagedIceObject::onExitComponent()
155  */
156  void onExitComponent() override;
157 
158  /**
159  * @see PropertyUser::createPropertyDefinitions()
160  */
162  {
164  }
165 
166  /**
167  * @brief Tries to get a workspace with the same TCP as the EEF of the robot
168  *
169  * @param g generated Grasps
170  * @return Pointer to the WorkspaceRepresentation
171  */
172  VirtualRobot::WorkspaceRepresentationPtr getWorkspaceRepresentation(const GeneratedGrasp& g);
173  private:
174  memoryx::WorkingMemoryInterfacePrx wm;
175  memoryx::WorkingMemoryEntitySegmentBasePrx objectInstances;
176  memoryx::AgentInstancesSegmentBasePrx agentInstances;
177  memoryx::PriorKnowledgeInterfacePrx prior;
178  memoryx::PersistentObjectClassSegmentBasePrx objectClasses;
179 
180  memoryx::GridFileManagerPtr fileManager;
181 
182  std::string robotName;
183  std::string robotFilePath;
184  std::string colModel;
185  std::vector<std::string> workspaceFilePaths;
186  std::vector<VirtualRobot::WorkspaceRepresentationPtr> workspaces;
187  std::string drawRobotId;
188  std::string visuLayerName;
189  VirtualRobot::WorkspaceGridPtr visualizedGrid;
190 
191  armarx::DebugDrawerInterfacePrx debugDrawerPrx;
192  memoryx::EntityDrawerInterfacePrx entityDrawerPrx;
193  RobotIKInterfacePrx rik;
194  RobotStateComponentInterfacePrx robotStateComponentPrx;
195 
197  VirtualRobot::SceneObjectSetPtr sceneObjects;
198  // VirtualRobot::CDManager cd;
199  SimoxCSpacePtr cspace;
200  SimoxCSpacePtr cacheCSpace;
201 
202  std::vector<CSpaceVisualizerTaskHandle> planningTasks;
203 
204 
205  VirtualRobot::WorkspaceGridPtr createWorkspaceGrid(GeneratedGrasp g, const Eigen::Matrix4f& globalObjectPose);
206  void drawWorkspaceGrid(VirtualRobot::WorkspaceGridPtr reachGrid);
207  // finds a collision free position, tries to maximize the position score
208  bool getSuitablePosition(const GeneratedGrasp& g, VirtualRobot::WorkspaceGridPtr reachGrid, const Eigen::Matrix4f& globalGraspPose, float& storeGlobalX, float& storeGlobalY, float& storeGlobalYaw, int& score, const VirtualRobot::MathTools::ConvexHull2DPtr& placementArea = VirtualRobot::MathTools::ConvexHull2DPtr());
209 
210  std::vector<RobotPlacement> getSuitablePositions(const GeneratedGrasp& g, VirtualRobot::WorkspaceGridPtr reachGrid, const Eigen::Matrix4f& globalGraspPose, float requiredReachabilityFraction, int requiredCount, int maxIterations, const VirtualRobot::MathTools::ConvexHull2DPtr& placementArea = VirtualRobot::MathTools::ConvexHull2DPtr());
211  // loads the robot given in the properties for collision testing
212  void loadRobot();
213  // loads the workspaces with the file paths given in the properties
214  void loadWorkspaces();
215  // checks whether there is a preloaded workspace with the given tcp
216  bool hasWorkspace(std::string tcp);
217  // filters all generated grasps, whose tcp is not given in any of the preloaded workspaces
218  GeneratedGraspList filterGrasps(const GeneratedGraspList grasps);
219  // returns the rotation needed for the robot to face the given target pose
220  float getPlatformRotation(const Eigen::Matrix4f& frameGlobal, const Eigen::Matrix4f& globalTarget);
221 
222  void updateRobot(std::string id, Eigen::Matrix4f globalPose, DrawColor color);
223  void drawNewRobot(Eigen::Matrix4f globalPose);
224  void drawWorkspaceGrid(const ::armarx::GeneratedGrasp&, const std::string& objectInstanceEntityId);
225  };
226 }
227 
DebugDrawerComponent.h
armarx::SimpleRobotPlacement::RobotPlacement::score
float score
Definition: SimpleRobotPlacement.h:104
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
GridFileManager.h
armarx::SimpleRobotPlacement::onExitComponent
void onExitComponent() override
Definition: SimpleRobotPlacement.cpp:158
armarx::SimpleRobotPlacement
refer to SimpleRobotPlacement
Definition: SimpleRobotPlacement.h:86
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::SimpleRobotPlacementPropertyDefinitions
Definition: SimpleRobotPlacement.h:57
armarx::SimpleRobotPlacement::RobotPlacement::z
float z
Definition: SimpleRobotPlacement.h:103
armarx::SimpleRobotPlacement::RobotPlacement
Definition: SimpleRobotPlacement.h:99
armarx::SimpleRobotPlacement::RobotPlacement::y
float y
Definition: SimpleRobotPlacement.h:102
armarx::SimpleRobotPlacement::getWorkspaceRepresentation
VirtualRobot::WorkspaceRepresentationPtr getWorkspaceRepresentation(const GeneratedGrasp &g)
Tries to get a workspace with the same TCP as the EEF of the robot.
Definition: SimpleRobotPlacement.cpp:515
IceInternal::Handle< SimoxCSpace >
armarx::SimpleRobotPlacement::onDisconnectComponent
void onDisconnectComponent() override
Definition: SimpleRobotPlacement.cpp:154
armarx::SimpleRobotPlacement::generateRobotPlacements
GraspingPlacementList generateRobotPlacements(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
Computes a list of candidate robot placements for a list of grasps.
Definition: SimpleRobotPlacement.cpp:162
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::SimpleRobotPlacement::onInitComponent
void onInitComponent() override
Definition: SimpleRobotPlacement.cpp:94
armarx::SimpleRobotPlacement::generateRobotPlacementsEx
GraspingPlacementList generateRobotPlacementsEx(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
Definition: SimpleRobotPlacement.cpp:294
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
SimoxCSpace.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::SimpleRobotPlacement::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SimpleRobotPlacement.h:161
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
ConvexHull
Definition: convexHull.hpp:366
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
CSpaceVisualizerTask.h
armarx::SimpleRobotPlacementPropertyDefinitions::SimpleRobotPlacementPropertyDefinitions
SimpleRobotPlacementPropertyDefinitions(std::string prefix)
Definition: SimpleRobotPlacement.cpp:65
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::SimpleRobotPlacement::getDefaultName
std::string getDefaultName() const override
Definition: SimpleRobotPlacement.h:94
armarx::SimpleRobotPlacement::onConnectComponent
void onConnectComponent() override
Definition: SimpleRobotPlacement.cpp:131
armarx::SimpleRobotPlacement::generateRobotPlacementsForGraspPose
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.
Definition: SimpleRobotPlacement.cpp:395
armarx::SimpleRobotPlacement::RobotPlacement::x
float x
Definition: SimpleRobotPlacement.h:101
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18