libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
Wrap.hpp
1 /*
2  * Wrap.hpp : Wrapper between Move3D and HPP that provides an interface for handling robots
3  *
4  * Author : renaud Viry (renaud.viry@laas.fr)
5  * Copyright LAAS-CNRS 2014
6  *
7  */
8 
9 #ifndef WRAP_HPP
10 #define WRAP_HPP
11 
12 #ifdef HPP
13 
14 #include <string>
15 #include <vector>
16 #include <map>
17 
18 #include <hpp/constraints/fwd.hh>
19 #include <hpp/constraints/position.hh>
20 #include <hpp/constraints/orientation.hh>
21 #include <hpp/constraints/relative-com.hh>
22 #include <hpp/constraints/relative-position.hh>
23 #include <hpp/constraints/relative-orientation.hh>
24 #include <hpp/wholebody-step/fwd.hh>
25 #include <hpp/model/urdf/util.hh>
26 #include <hpp/core/manipulation-solver.hh>
27 #include <hpp/core/locked-dof.hh>
28 #include <hpp/core/path-vector.hh>
29 
30 #include "configuration.hpp"
31 #include "graspPlanning/include/gpGrasp.h"
32 #include "p3d/proto/p3d_matrix_proto.h"
33 #include "API/Device/robot.hpp"
34 #include "Planner-pkg.h"
35 
36 
37 class Wrap {
38 public:
39  Wrap();
40 
41  /* Load a robot model in HPP from URDF/SRDF
42  *
43  * \param robotName is the name of the robot in HPP
44  * \param rootJointType is the type of rootJoint of the robot (freeflyer, planar, anchor, ...)
45  * \param packageName is the name of the ros package containing the robot description
46  * \param modelName is the name of the robot model
47  * \param urdfSuffix is a suffix to the URDF file name
48  * \param srdfSuffix is a suffix to the SRDF file name
49  * \param move3dRobot is the corresponding robot strucutre in Move3D
50  * \return a boolean value whether the model was correctly loaded in HPP or not
51  */
52  bool loadRobot(const std::string& robotName, const std::string& rootJointType,
53  const std::string& packageName, const std::string& modelName,
54  const std::string& urdfSuffix, const std::string& srdfSuffix,
55  Robot *move3dRobot);
56 
57  /* Lock a DoF
58  *
59  * \param jointName is the name of the DoF to lock
60  * \param value is the value of the locked DoF
61  */
62  void addLockDof(const std::string& jointName, double value);
63 
64  /* Add a position constraints to the solver
65  *
66  * \param name is the full qualified and unique name of the constraints
67  * \param jointName is the name of the joint to constrain
68  * \param posLocal is the position of the joint in its own local frame
69  * \param posGlobal is the position of the joint in the global frame
70  * \param mask specifies which of the 3 coordinates are to be constrain
71  */
72  void addPositionConstraint(const std::string& name, const std::string& jointName,
73  hpp::model::vector3_t posLocal, hpp::model::vector3_t posGlobal,
74  std::vector<bool> mask);
75 
76  /* Add an orientation constraints to the solver
77  *
78  * \param name is the full qualified and unique name of the constraints
79  * \param jointName is the name of the joint to constrain
80  * \param rotation is the rotation matrix of the joint
81  * \param mask specifies which of the 3 coordinates are to be constrain
82  */
83  void addOrientationConstraint(const std::string& name, const std::string& jointName,
84  hpp::model::matrix3_t rotation, std::vector<bool> mask);
85 
86  /* Apply all constraints and find an IK solution
87  *
88  * \param config is both the input configuration and the updated output solution
89  * \param timer is a pointer updated with the total time spent in solving the IK
90  * \return whether a solution have been found or not
91  */
92  bool applyConstraints(hpp::core::ConfigurationPtr_t config, double *timer);
93 
94  /* Reset all the constraints
95  */
96  void resetConstraints();
97 
98  /* Update a position constraints already stored in the solver
99  *
100  * \param constraintName is the name of the constraints to update
101  * \param globalValue is the new position of the joint in the global frame
102  */
103  void updatePositionConstraintRef(const std::string& constraintName, hpp::model::vector3_t globalValue);
104 
105  /* Update a position constraints already stored in the solver
106  *
107  * \param constraintName is the name of the constraints to update
108  * \param localValue is the new position of the joint in its own local frame
109  * \param globalValue is the new position of the joint in the global frame
110  */
111  void updatePositionConstraintRef(const std::string& constraintName, hpp::model::vector3_t localValue,
112  hpp::model::vector3_t globalValue);
113 
114  /* Update an orientation constraints already stored in the solver
115  *
116  * \param constraintName is the name of the constraints to update
117  * \param rot is the new rotation matrix of the joint
118  */
119  void updateOrientationConstraintRef(const std::string& constraintName, hpp::model::matrix3_t rot);
120 
121  /* Virtual method to generate 1 single configuration, specific to each robot */
122  virtual bool generateConfig(confPtr_t &inputConf, confPtr_t &outputConf, p3d_matrix4 tragetPos, int armId, bool randomize) = 0;
123  /* Virtual method to generate 4 grasp configurations, specific to each robot */
124  virtual std::vector<confPtr_t> generateGraspConfigs(confPtr_t &q, gpGrasp grasp, p3d_matrix4 objectPos,
125  p3d_vector3 approachDir, double approachOffset,
126  p3d_vector3 extractDir, double extractOffset) = 0;
127 
128  /* Find a trajectory
129  *
130  * \param initConf is the starting conf of the trajectory to plan
131  * \param goalConf is the goal conf of the trajectory to plan
132  * \param outputTraj is the solution trajectory planned
133  * \param timer is the output duration of planing
134  * \return whether a path has been found or not
135  */
136  bool findTrajectory(confPtr_t &initConf, confPtr_t &goalConf, p3d_traj *outputTraj, double *timer);
137 
138 
139 
140 protected:
141  /* Generate the open config for a grasp
142  *
143  * \param inputConf is the input configuration to be updated
144  * \param outputConf is the output solution configuration with the open hand (fingers)
145  * \return whether the config have been updated or not
146  */
147  bool generateOpenGraspConf(confPtr_t inputConf, confPtr_t outputConf);
148 
149  /* Generate the closed config for a grasp
150  *
151  * \param inputConf is the input configuration to be updated
152  * \param outputConf is the output solution configuration with the closed hand (fingers)
153  * \return whether the config have been updated or not
154  */
155  bool generateClosedGraspConf(confPtr_t inputConf, confPtr_t outputConf);
156 
157  /* Shoot a random config of the robot
158  *
159  * \param config is the output randomized config
160  */
161  void randomizeFullConfig(hpp::core::ConfigurationPtr_t config);
162 
163  /* Get the current HPP configuration of the robot
164  *
165  * \return the current configuration of the robot in HPP
166  */
167  hpp::core::ConfigurationPtr_t getCurrentConfig() {
168  return boost::shared_ptr<hpp::model::Configuration_t> (new hpp::model::Configuration_t(_manipulationSolver->robot()->currentConfiguration()));
169  }
170 
171  /* Set the current HPP configuration of the robot
172  *
173  * \param the configuration of the robot to be set in HPP
174  */
175  void setCurrentConfig(hpp::core::ConfigurationPtr_t conf) {
176  _manipulationSolver->robot()->currentConfiguration(*conf);
177  }
178 
179  /* Set bounds to a specific joint
180  *
181  * \param jointName is the name of the joint to bound
182  * \param bounds is the sequence of bounds for each DoF of the joint
183  */
184  void setJointBound(std::string jointName, std::vector<double> bounds);
185 
186  /* Generate a Move3D configuration from an HPP configuration
187  *
188  * \param config is a sharedPtr to the input HPP config
189  * \return a sharedPtr the corresponding Move3D config
190  */
191  confPtr_t createConfiguration(hpp::core::ConfigurationPtr_t config);
192 
193  /* Generate an HPP configuration from a Move3D configuration
194  *
195  * \param config is a sharedPtr to the input Move3D config
196  * \return a sharedPtr the corresponding HPP config
197  */
198  hpp::core::ConfigurationPtr_t createHppConfiguration(confPtr_t q);
199 
200  /* Get the current value of a joint
201  *
202  * \param name is the name of the joint
203  * \return the value of the current configuration of the joint
204  */
205  double getJointDofValue(const std::string& name);
206 
207  /* Create a Move3D trajectory from an HPP path
208  *
209  * \param inputPath is the HPP input localPath
210  * \param outputTrajectory is the Move3D output trajectory generated
211  * \return whether the trajectory has been created or not
212  */
213  bool createTrajectory(hpp::core::PathPtr_t inputPath, p3d_traj *outputTrajectory);
214 
215  char *_eef_joint;
216  gpGrasp _grasp;
217  Robot *_move3dRobot;
218 
219  hpp::core::ManipulationSolverPtr_t _manipulationSolver;
220  hpp::core::ConfigurationPtr_t confSol;
221 };
222 
223 #endif /* HPP */
224 #endif /* WRAP_HPP */
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42