MIRA
AbstractObjectiveBasedPlanner.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_PILOT_ABSTRACTOBJECTIVEBASEDPLANNER_H_
31 #define _MIRA_PILOT_ABSTRACTOBJECTIVEBASEDPLANNER_H_
32 
33 #include <serialization/adapters/std/list>
34 
36 
37 #include <pilot/AbstractPlanner.h>
38 #include <pilot/Objective.h>
39 
40 // for debugging
41 #include <image/Img.h>
42 
43 #include <fw/Channel.h>
44 
45 
46 namespace mira { namespace pilot {
47 
49 
51 {
53 public:
54 
55  template<typename Reflector>
56  void reflect(Reflector& r)
57  {
58  r.property("PlanningHorizon", mPlanningHorizon,
59  "The planning horizon [ms]. It should be equal or"
60  "larger than the Pilots cycle time", Duration::milliseconds(250));
61  r.property("MinLookAhead", mMinLookAhead,
62  "The min. lookahead time [ms]",Duration::seconds(2));
63  r.property("MaxLookAhead", mMaxLookAhead,
64  "The max. lookahead time [ms]",Duration::seconds(4));
65  r.property("TrajectorySamples", mTrajectorySamples,
66  "Number of samples along the predicted trajectory (default: 10)", 10);
67  r.property("MaxNoCommandTime", mMaxNoCommandTime,
68  "How long is it allowed to have no valid velocity command", Duration::seconds(10));
69  r.property("Objectives", mObjectives, "The objectives");
70 
71  r.method("enableObjective", &AbstractObjectiveBasedPlanner::enableObjective, this,
72  "Enable/Disable an objective which is specified by its class name",
73  "name", "The objective's name", "PathObjective",
74  "enable", "true/false to enable/disable", true);
75  }
76 
77 protected:
78 
79  virtual void initialize();
80  virtual void resume();
81  virtual void pause();
82 
83 public: // implements AbstractPlanner
84 
85  virtual void setTask(boost::shared_ptr<navigation::Task> task);
86 
88  virtual bool reachedTasks();
89 
91  virtual bool satisfied();
92 
94  virtual void resetDissatisfaction();
95 
97  virtual std::list<DissatisfactionReason> getDissatisfactionReasons();
98 
99  // must be implemented in derived classes
100  // virtual Velocity2 planMotion() = 0;
101 
102  virtual void update();
103 
104  virtual void plan(Duration plantime);
105 
106  virtual void updateRobotModel();
107 
108 public:
109 
110 
116  void addObjective(boost::shared_ptr<Objective> o, float weight);
117 
118  boost::shared_ptr<Objective> getObjective(const std::string& name);
119 
120 
124  //boost::shared_ptr<IObjective> getObjective(const std::string& name);
125 
126 
127  void enableObjective(const std::string& name, bool enable);
128 
130 
131 protected:
132 
134  {
135  ObjectiveInfo() : weight(0.0f), disabled(false) {}
136  ObjectiveInfo(boost::shared_ptr<Objective> o, float w) :
137  objective(o), weight(w), disabled(false) {}
138 
139  template<typename Reflector>
140  void reflect(Reflector& r)
141  {
142  if(objective)
143  r.itemName(objective->getItemName());
144  r.roproperty("Has Work", getter<bool>(&ObjectiveInfo::hasWork, this),
145  "Do the objective has some work");
146  r.roproperty("Reached Task", getter<bool>(&ObjectiveInfo::reachedTask, this),
147  "Does the objective has reached its task?");
148  r.roproperty("Satisfaction", getter<Objective::Satisfaction>(&ObjectiveInfo::getSatisfaction, this),
149  "Satisfaction of this objective", PropertyHints::enumeration("INTOLERABLE;DISSATISFIED;DONT_CARE;SATISFIED"));
150 
151  r.property("Disabled", disabled, "If true, the objective is disabled",false);
152  r.property("Weight", weight, "The weight for this objective",1.0f);
153  r.property("Objective", objective, "The objective");
154  }
155 
157  return objective ? objective->getSatisfaction() : Objective::DONT_CARE;
158  }
159 
161  if (objective)
162  objective->resetDissatisfaction();
163  }
164 
165  bool hasWork() const {
166  return objective ? objective->hasWork() : false;
167  }
168 
169  bool reachedTask() const {
170  return objective ? objective->reachedTask() : true;
171  }
172 
174  bool isActive() const { return !disabled && objective->hasWork(); }
175 
176  boost::shared_ptr<Objective> objective;
177  float weight;
178  bool disabled;
179  };
180 
181  typedef std::list<ObjectiveInfo> Objectives;
183 
184 protected:
185 
190 
193 
195 
196 protected:
197 
198  void prepareVote(float dt);
199 
200  void informDecision(const robot::PoseVelocityTrajectory& chosen, float dt);
201 
203  const Velocity2& targetv,
204  float lookAheadTime);
205 
206  virtual void updateRobotModel(bool updateObjectives);
207 };
208 
210 }}
211 
212 #endif
robot::UnicycleBasedRobotModelPtr getRobotModel()
Definition: AbstractObjectiveBasedPlanner.h:129
Time mLastCommand
Definition: AbstractObjectiveBasedPlanner.h:192
virtual void update()
is called before plan even if there is no plantime left
void reflect(Reflector &r)
Definition: AbstractObjectiveBasedPlanner.h:56
tick_type milliseconds() const
robot::UnicycleBasedRobotModelPtr mRobotModel
Definition: AbstractObjectiveBasedPlanner.h:194
Duration mMaxLookAhead
Definition: AbstractObjectiveBasedPlanner.h:188
bool reachedTask() const
Definition: AbstractObjectiveBasedPlanner.h:169
std::vector< PoseVelocityTrajectorySample, Eigen::aligned_allocator< PoseVelocityTrajectorySample > > PoseVelocityTrajectory
void informDecision(const robot::PoseVelocityTrajectory &chosen, float dt)
virtual bool satisfied()
Returns true when all objectives are satisfied with the progress of their respective tasks...
virtual void setTask(boost::shared_ptr< navigation::Task > task)
PropertyHint enumeration(const std::string &values)
Definition: AbstractObjectiveBasedPlanner.h:133
Duration mMaxNoCommandTime
Definition: AbstractObjectiveBasedPlanner.h:191
Description.
bool isActive() const
returns true, if the objective is enabled and has work, hence if it is active.
Definition: AbstractObjectiveBasedPlanner.h:174
boost::shared_ptr< UnicycleBasedRobotModel > UnicycleBasedRobotModelPtr
virtual void updateRobotModel()
Update the robot model. Default implementation is empty.
Objectives mObjectives
Definition: AbstractObjectiveBasedPlanner.h:182
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
int mTrajectorySamples
Definition: AbstractObjectiveBasedPlanner.h:189
void reflect(Reflector &r)
Definition: AbstractObjectiveBasedPlanner.h:140
std::list< ObjectiveInfo > Objectives
Definition: AbstractObjectiveBasedPlanner.h:181
virtual void plan(Duration plantime)
Satisfaction
Definition: Objective.h:64
Duration mPlanningHorizon
Definition: AbstractObjectiveBasedPlanner.h:186
void resetDissatisfaction()
Definition: AbstractObjectiveBasedPlanner.h:160
void addObjective(boost::shared_ptr< Objective > o, float weight)
Adds a new objective to the dynamic window with the weight.
Duration mMinLookAhead
Definition: AbstractObjectiveBasedPlanner.h:187
sec_type seconds() const
Definition: AbstractPlanner.h:49
virtual std::list< DissatisfactionReason > getDissatisfactionReasons()
Returns reasons (strings) that caused the overall state of dissatisfaction.
void enableObjective(const std::string &name, bool enable)
Returns the objective with the given name, if available.
bool disabled
Definition: AbstractObjectiveBasedPlanner.h:178
Objective::Satisfaction getSatisfaction()
Definition: AbstractObjectiveBasedPlanner.h:156
boost::shared_ptr< Objective > objective
Definition: AbstractObjectiveBasedPlanner.h:176
Definition: AbstractObjectiveBasedPlanner.h:50
float weight
Definition: AbstractObjectiveBasedPlanner.h:177
robot::PoseVelocityTrajectory generateTrajectory(Velocity2 v, const Velocity2 &targetv, float lookAheadTime)
Definition: Objective.h:68
Description.
boost::shared_ptr< Objective > getObjective(const std::string &name)
bool hasWork() const
Definition: AbstractObjectiveBasedPlanner.h:165
virtual bool reachedTasks()
Returns true, if all objectives have reached their task.
ObjectiveInfo(boost::shared_ptr< Objective > o, float w)
Definition: AbstractObjectiveBasedPlanner.h:136
ObjectiveInfo()
Definition: AbstractObjectiveBasedPlanner.h:135
virtual void resetDissatisfaction()
Reset any kind of dissatisfaction.