libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
HRICS_CostManager.h
1 #ifndef HRICS_COSTMANAGER_H
2 #define HRICS_COSTMANAGER_H
3 
4 
5 #include "Logging/Logger.h"
6 #include "database/semantics/Sem_ActionsManager.hpp"
7 #include <boost/function.hpp>
8 #include <boost/bind.hpp>
9 #include "API/ConfigSpace/localpath.hpp"
10 #include "HRICS_CostSettingType.h"
11 
12 namespace HRICS {
13 
15 {
16  MOVE3D_STATIC_LOGGER;
17 public:
18  CostManager();
19  CostManager(const std::string &global_path, bool proactive=false);
20  ~CostManager();
21  static CostManager * mainCostManager();
22 
26  void takeControlAndSet();
27 
28  void setActionType(Sem::ActionType act_t);
29  void setCostType(CostSettingType cost_t);
30  void updatePlannerSettings();
31 
32  double getCost(Configuration &q);
33  double getCostPath(std::vector<LocalPath*>& path);
34  double getCostAggregationNormalized(std::vector<LocalPath*> &path);
35 
36  boost::function<double (std::vector<LocalPath*>&)> getCostPathFunction(CostSettingType type);
37 
38  void clear();
39 
40  void prepareForSmoothing(API:: Trajectory &path);
41  void endSmoothing(API::Trajectory *path=0);
42 
43 
44  typedef enum{CONF_COST,PATH_COST,PATH_SMOOTHING_COST} CostAppliesWhen_t;
45 
50  bool fetchSettings();
51  bool readActionsCostMapping(std::string path);
52  bool readCostSetting(const CostSettingType &cost, CostAppliesWhen_t when);
53  bool readCostSetting(std::string path,const CostSettingType &cost,CostAppliesWhen_t when);
54 
55  bool readAlgoParams(const Sem::AgentType &agent_type);
56  bool readAlgoParams(const Sem::AgentType &agent_type, const std::string &path);
57 
58  boost::function<double(Configuration&)> jsonToFunction(Json::Value &f);
59  static boost::function<double(double,double)> elementaryOperation(std::string const &name);
60  static boost::function<double(double)> elementaryFunction(std::string const &name, const Json::Value &json);
61  boost::function<double(std::vector<LocalPath*>&)> jsonToFunctionTraj(Json::Value &f);
62 
63  std::string getPath();
64  std::string getPath(CostAppliesWhen_t when);
65 
66 
67  bool proactive() const;
68  void setProactive(bool proactive);
69 
70  std::string globalPath() const;
71  void setGlobalPath(const std::string &globalPath);
72 
73  CostSettingType currentCostType() const;
74 
75  bool isSmoothing() const;
76 
77  double pathCostNormalizationFactor() const;
78  void setPathCostNormalizationFactor(double pathCostNormalizationFactor);
79 
80  static double sigmoidFunction(double val, double upper, double lower, double min, double max);
81  static double boundFunction(double val,double min,double max);
82  static double affineFunction(double val,double a,double b);
83 
84  Env::boolParameter planningMethod();
85 
86  bool hasControlOnPlanning() const;
87  void setHasControlOnPlanning(bool hasControlOnPlanning);
88 
89  std::map<std::string, double> const &functionCostStack() const;
90 
91 protected:
92  double getCostStack(std::string const &name,Configuration &q);
93  double getCostStackPath(std::string const &name,std::vector<LocalPath*>& path);
94 
95 
96 private:
97  bool _proactive;
98  bool _hasControlOnPlanning;
99 
100  std::string _globalPath;
101 
102  std::map<Sem::ActionType,CostSettingType> _actionCostMapping;
103  std::map<CostSettingType,boost::function<double(Configuration&)> > _functions;
104 
105  std::map<CostSettingType,boost::function<double(std::vector<LocalPath*>&)> > _functionsTraj;
106  std::map<CostSettingType,boost::function<double(std::vector<LocalPath*>&)> > _functionsTrajSmoothing;
107 
108  std::map<std::string,double> _functionCostStack;
109  bool _lockFunctionsCostStack;
110  std::map<std::string,double> _functionCostStackPath;
111  bool _lockFunctionsCostStackPath;
112 
113  struct AlgoParams {
114  AlgoParams():extStep(0),finalGap(0){}
115  AlgoParams(double extStep,double finalGap):extStep(extStep),finalGap(finalGap){}
116  double extStep,finalGap;
117  };
118 
119  void updatePlannerSettings(AlgoParams &params);
120  std::map<Sem::AgentType,AlgoParams> _algoParams;
121 
122  CostSettingType _currentCostType;
123 
124  static CostManager* __mainCostManger;
125 
126  bool _isSmoothing;
127 
128  double _pathCostNormalizationFactor;
129 
130 };
131 
132 } // namespace HRICS
133 
134 #endif // HRICS_COSTMANAGER_H
Definition: Sem_AgentType.hpp:12
void takeControlAndSet()
set the planner and cost space according to given settings
Definition: HRICS_CostManager.cpp:47
Definition: HRICS_CostSettingType.h:9
This file implements macros to help with the logging, in a way similar to ROS, using log4cxx...
Definition: trajectory.hpp:40
Definition: Sem_Actions.hpp:14
Definition: HRICS_CostManager.h:14
Classe représentant une Configuration d'un Robot.
Definition: configuration.hpp:25
bool fetchSettings()
fetchSettings get settings from json files at default emplacement
Definition: HRICS_CostManager.cpp:245