libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
cost_space.hpp
1 #ifndef COST_SPACE_HPP_INCLUDED
2 #define COST_SPACE_HPP_INCLUDED
3 
4 #include <boost/function.hpp>
5 #include <map>
6 #include <string>
7 
8 #include "API/ConfigSpace/configuration.hpp"
9 #include "API/ConfigSpace/localpath.hpp"
10 #include "API/Roadmap/graph.hpp"
11 #include "Logging/Logger.h"
12 
13 
17 typedef Eigen::Matrix<double, 6, 1> Vector6d;
18 typedef Eigen::Matrix<double, 6, 6> Matrix6d;
19 typedef Eigen::Matrix<double, 5, 6> Matrix56d;
20 
21 
25 enum CostSpaceDeltaStepMethod
26 {
27  cs_integral,
28  cs_mechanical_work,
29  cs_visibility,
30  cs_average,
31  cs_config_cost_and_dist,
32  cs_boltzman_cost,
33  cs_max,
34  cs_average_and_max
35 };
36 
40 enum CostSpaceResolutionMethod
41 {
42  cs_classic,
43  cs_pr2_manip
44 };
45 
49 class CostSpace
50 {
51  MOVE3D_STATIC_LOGGER;
52 public:
53  CostSpace();
54 
55  // Get selected cost function name
56  std::string getSelectedCostName();
57 
58  // Get All Cost Functions
59  std::vector<std::string> getAllCost();
60 
61  boost::function<double(Configuration&)> getCostFunction(std::string name);
62  boost::function<double(std::vector<LocalPath*>&)> getCostFunctionTrajectories(std::string name);
63 
64  // Select the cost function with the given name in the map
65  bool setCost(std::string name);
66  bool setCostTraj(std::string name);
67 
68  // Register a new cost function.
69  void addCost(std::string name,
70  boost::function<double(Configuration&)> f);
71  void addCostTrajectories(std::string name,
72  boost::function<double(std::vector<LocalPath*>&)> f);
73 
74  // Delete a cost function
75  void deleteCost(std::string name);
76  void deleteCostTraj(std::string name);
77 
78  // Compute the cost of the configuration conf.
79  double cost(Configuration& conf);
80 
81  // Compute the cost of
82  double cost(LocalPath * path);
83 
84  double cost(std::vector<LocalPath*>::iterator first, std::vector<LocalPath*>::iterator last);
85  double cost(std::vector<LocalPath*>& path);
86 
87  double costAggregationOverTraj(std::vector<LocalPath*> &path);
88  double costAggregationOverTraj(std::vector<LocalPath*>::iterator first, std::vector<LocalPath*>::iterator last);
89 
90  // Compute the cost of
91  double cost(LocalPath& path, int& nb_test);
92 
93  // Set node cost
94  void setNodeCost(Node* node, Node* parent);
95 
96  // Initializes the Cost space motion planning problem
97  void initMotionPlanning(graph* graph, node* start, node* goal);
98 
99  // Set DeltaStepCost
100  void setDistanceMethod(CostSpaceResolutionMethod method) { m_resolution = method; }
101 
102  // Set DeltaStepCost
103  void setDeltaStepMethod(CostSpaceDeltaStepMethod method) { m_deltaMethod = method; }
104 
105  // Get DeltaStepCost
106  CostSpaceDeltaStepMethod getDeltaStepMethod() { return m_deltaMethod; }
107 
108  // Compute the delta step cost
109  double deltaStepCost(double cost1, double cost2, double length);
110  double edgeCost(confPtr_t from, confPtr_t to);
111  double edgeCost(LocalPath lp);
112 
113  //Composite cost
114  double compositeCost(Configuration &conf);
115  void setCompositeCostFactor(std::string func, double factor);
116  double getCompositeCostFactor(std::string func);
117  doubleContainer *getCompositeCostFactorObject(std::string func);
118 
119  void initCompositeCostFactors();
120  void setCompositeSumFunction(std::string f);
121  std::vector<std::string> getCompositeSumFunctions(void);
122  std::string getCompositeSumFunction();
123 
124  // distance start goal
125  double startGoalDist_ratio() const;
126  void setStartGoalDist_ratio(double startGoalDist_ratio);
127  double startGoalDist_power() const;
128  void setStartGoalDist_power(double startGoalDist_power);
129 
130 
131 
132 
133 
134 protected:
135  std::string mSelectedCostName;
136  boost::function<double(Configuration&)> mSelectedCost;
137  std::map<std::string, boost::function<double(Configuration&)> > mFunctions;
138 
139  std::string mSelectedCostTrajectoriesName;
140  boost::function<double(std::vector<LocalPath*>&)> mSelectedFunctionsTrajectories;
141  std::map<std::string, boost::function<double(std::vector<LocalPath*>&)> > mFunctionsTrajectories;
142 
143  void getPr2ArmConfiguration( Eigen::VectorXd& x, confPtr_t q );
144  double getPr2ArmDistance( Robot* robot, Eigen::VectorXd& q_i, Eigen::VectorXd& q_f );
145 private:
146 
147  // Delta
148  enum CostSpaceDeltaStepMethod m_deltaMethod;
149  enum CostSpaceResolutionMethod m_resolution;
150 
151  // Composite
152  std::map<std::string , doubleContainer* > mCompositionFactors;
153  enum{ COST_COMPOSITE_PLUS, COST_COMPOSITE_MAX, COST_COMPOSITE_MIN} mCompostionFunction;
154 
155  // distance start goal
156  double mStartGoalDist_ratio, mStartGoalDist_power;
157 
158  double m_dmax;
159 
160  /*************************************************************************************
161  **************** FlyCrane ***********************************************
162  NOTATION:
163  (quadrotor 1)
164  A21
165  . .
166  . .
167  . .
168  . .
169  B2---------B1
170  // \\
171  B3 B0
172  .\ / .
173  . \ Platform / .
174  . \ / .
175  . \ / .
176  . \ / .
177  (quadrotor 2) A43 . . . . \ / . . . . A05 (quadrotor 0)
178  B4==B5
179  *************************************************************************************/
180 
181 public:
182  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
183 
186 
191  Eigen::Matrix3d RotationMatrix(double orientation[]);
192 
198 
200  double flyCraneCost(Configuration * conf);
201 
202 private:
204  Eigen::Vector3d B[6];
205 
207  double cableLength[6];
208 
210  double admissibleTension[6][2];
211 
213  Vector6d wrench;
214 
216  Eigen::Vector3d wrenchPoint;
217 
219  Matrix6d Ellipsoid;
220 
222  double quadMass[3];
223 
225  double quadThrust[3];
226 
228  double offsetAnchorCM[3];
229 
231  double dCMmotor[3];
232 
234  Eigen::Vector3d vB[3];
235 
237  double beta[3];
238 
240  Eigen::Vector3d quadWeight[3];
241 };
242 
243 namespace GlobalCostSpace
244 {
245  void initialize();
246 };
247 
248 double computeIntersectionWithGround(Configuration& conf);
249 double computeFlatCost(Configuration& conf);
250 double computeClearance(Configuration& conf);
251 double computeOBBClearance(Configuration& conf);
252 double computeClearanceAll(Configuration& conf);
253 double computeDistanceToObstacles(Configuration& conf);
254 double computeARCAScost(Configuration& conf);
255 double computeInCollisionCost(Configuration& conf);
256 double computeCollisionSpaceCost(Configuration& conf);
257 double computeLocalpathKinematicCost(p3d_rob* rob, p3d_localpath* LP);
258 double computeHotCost(Configuration &conf);
259 double computeCompositeCost(Configuration &conf);
260 double computeHandoverCost(Configuration &conf);
261 double computeStartGoalMin(Configuration &conf);
262 double computeStraightPenalty(Configuration &conf);
263 double computeSaphariCost(Configuration &conf);
264 
268 double computeFlyCranecost(Configuration& conf);
269 
270 
271 extern CostSpace* global_costSpace;
272 
273 #endif
double deltaStepCost(double cost1, double cost2, double length)
ComputeDeltaStepCost Compute the cost of a portion of path.
Definition: cost_space.cpp:366
Classe représentant un Node d'un Graph.
Definition: node.hpp:39
Classe représentant un chemin local.
Definition: localpath.hpp:15
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
double flyCraneCost(Configuration *conf)
Cost function involving the tensions exerted on the cables and the quadrotor thrusts.
Definition: cost_space.cpp:1015
This file implements macros to help with the logging, in a way similar to ROS, using log4cxx...
void computeQuadAnchorPoints(Configuration *conf)
Compute the coordinates (in the global reference frame) of the anchor points, Aij, of the quadrotors and fill the corresponding attributes in the given configuration.
Definition: cost_space.cpp:982
void initializeFlyCraneCostSpace()
Initialize the FlyCrane cost space.
Definition: cost_space.cpp:876
Classe représentant une Configuration d'un Robot.
Definition: configuration.hpp:25
Class thats holding the CostSpace.
Definition: cost_space.hpp:49
Eigen::Matrix3d RotationMatrix(double orientation[])
Compute the rotation matrix of a given vector of angles.
Definition: cost_space.cpp:968