MIRA
Objective.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_OBJECTIVE_H_
31 #define _MIRA_PILOT_OBJECTIVE_H_
32 
33 #include <factory/Factory.h>
34 
35 #include <transform/Velocity.h>
36 
37 #include <fw/Framework.h>
38 
39 #include <navigation/Task.h>
40 
42 #include <pilot/Module.h>
43 #include <robot/Trajectory.h>
44 
45 namespace mira { namespace pilot {
46 
48 
49 class Task; // forward decl
50 class Pilot;
51 
52 class Objective : public Module
53 {
54  MIRA_OBJECT(Objective);
55 public:
56 
57  enum Permit
58  {
62  };
63 
65  {
68  DONT_CARE = 2,
70  };
71 
72  struct Vote
73  {
74  static const Vote UNREACHABLE;
75  static const Vote DENY;
76  static const Vote ALLOW;
77 
78  Vote() :
80  costs(0.0) {}
81 
82  Vote(Permit p, double c) :
83  permit(p),
84  costs(c) {}
85 
86  template<typename Reflector>
87  void reflect(Reflector& r)
88  {
89  r.member("Permit", permit, "");
90  r.member("Costs", costs, "");
91  }
92 
93  bool operator<(const Vote& rhs) {
94  if(permit==ADMISSIBLE && rhs.permit!=ADMISSIBLE)
95  return true;
96  if(permit==ADMISSIBLE && rhs.permit==ADMISSIBLE)
97  return costs < rhs.costs;
98  return false;
99  }
100 
102  double costs;
103  };
104 
105 public:
106 
108  mHaveWork(false),
109  mSatisfaction(DONT_CARE),
110  mDissatisfactionReason(DissatisfactionReason::NO_REASON) {}
111  virtual ~Objective() {}
112 
113  template<typename Reflector>
114  void reflect(Reflector& r)
115  {
117  }
118 
119 public:
120 
122  bool hasWork() const { return mHaveWork; }
123 
131  return mSatisfaction;
132  }
133 
137  virtual void resetDissatisfaction() {
138  mSatisfaction = DONT_CARE;
139  mDissatisfactionReason = DissatisfactionReason::NO_REASON;
140  }
141 
145  virtual DissatisfactionReason getDissatisfactionReason() {
146  return mDissatisfactionReason;
147  }
148 
155  virtual void prepareVote(float lookAheadTime) {};
156 
165  virtual Vote vote(const Velocity2& v, float lookAheadTime) {
166  MIRA_THROW(XNotImplemented, "You need to implement ONE of the vote() methods");
167  }
168 
178  virtual Vote vote(const Velocity2& v, const robot::PoseVelocityTrajectory& trajectory, float lookAheadTime) {
179  return vote(v,lookAheadTime);
180  }
181 
189  virtual Vote vote(const robot::PoseVelocityTrajectory& trajectory, float lookAheadTime) {
190  assert(!trajectory.empty());
191  return vote(trajectory.back().v, trajectory, lookAheadTime);
192  }
193 
201  virtual void informDecision(const Velocity2& chosen, float dt) {}
202 
209  virtual void informDecision(const robot::PoseVelocityTrajectory& trajectory, float dt) {
210  assert(!trajectory.empty());
211  informDecision(trajectory.back().v, dt);
212  };
213 
214  virtual void setTask(navigation::TaskPtr task) {};
215 
216  virtual bool reachedTask() { return true; }
217 
218  virtual void update() {}
219 
220  virtual void plan(Duration plantime) {}
221 
222  virtual void updateRobotModel() {}
223 
224 protected:
225 
227  void setHaveWork(bool haveWork) {
228  mHaveWork = haveWork;
229  }
230 
232  void setSatisfaction(Satisfaction satisfaction, DissatisfactionReason reason=DissatisfactionReason::NO_REASON) {
233  mSatisfaction = satisfaction;
234  mDissatisfactionReason = reason;
235  }
236 
237 private:
238 
239  bool mHaveWork;
240  Satisfaction mSatisfaction;
241  DissatisfactionReason mDissatisfactionReason;
242 };
243 
244 
246 
247 }} // namespace
248 
249 #endif
Vote(Permit p, double c)
Definition: Objective.h:82
virtual void informDecision(const robot::PoseVelocityTrajectory &trajectory, float dt)
Is called after the decision was made by the local motion planner to inform each objective about the ...
Definition: Objective.h:209
virtual Vote vote(const Velocity2 &v, float lookAheadTime)
DEPRECATED - Please implement vote(const Trajectory& trajectory, float lookAheadTime) Is called multi...
Definition: Objective.h:165
void setHaveWork(bool haveWork)
indicate whether this objective has work or not. If not, it will be skipped by the planner...
Definition: Objective.h:227
virtual void informDecision(const Velocity2 &chosen, float dt)
DEPRECATED - Please implement informDecision(const Trajectory& trajectory, float dt) Is called after ...
Definition: Objective.h:201
std::vector< PoseVelocityTrajectorySample, Eigen::aligned_allocator< PoseVelocityTrajectorySample > > PoseVelocityTrajectory
Objective()
Definition: Objective.h:107
virtual bool reachedTask()
Definition: Objective.h:216
virtual void prepareVote(float lookAheadTime)
Is called before the vote() calls and gives the objective a change to prepare itself, e.g.
Definition: Objective.h:155
Definition: Objective.h:52
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Definition: Objective.h:59
boost::shared_ptr< Task > TaskPtr
Definition: Objective.h:69
static const Vote DENY
Definition: Objective.h:75
virtual Vote vote(const Velocity2 &v, const robot::PoseVelocityTrajectory &trajectory, float lookAheadTime)
DEPRECATED - Please implement vote(const Trajectory& trajectory, float lookAheadTime) Is called multi...
Definition: Objective.h:178
void reflect(Reflector &r)
Definition: Objective.h:87
virtual Vote vote(const robot::PoseVelocityTrajectory &trajectory, float lookAheadTime)
Is called multiple times after prepareVote() to compute a cost value for the given trajectory...
Definition: Objective.h:189
TODO Add description.
#define MIRA_THROW(ex, msg)
Definition: Objective.h:67
Satisfaction
Definition: Objective.h:64
static const Vote UNREACHABLE
Definition: Objective.h:74
bool hasWork() const
Definition: Objective.h:122
virtual DissatisfactionReason getDissatisfactionReason()
Returns the reason for dissatisfaction.
Definition: Objective.h:145
Permit
Definition: Objective.h:57
virtual void updateRobotModel()
Definition: Objective.h:222
virtual ~Objective()
Definition: Objective.h:111
virtual void setTask(navigation::TaskPtr task)
Definition: Objective.h:214
Definition: Module.h:41
virtual Satisfaction getSatisfaction()
Returns satisfaction for this Objective.
Definition: Objective.h:130
bool operator<(const Vote &rhs)
Definition: Objective.h:93
virtual void resetDissatisfaction()
Reset any kind of dissatisfaction.
Definition: Objective.h:137
Definition: Objective.h:60
Permit permit
Definition: Objective.h:101
static const Vote ALLOW
Definition: Objective.h:76
Vote()
Definition: Objective.h:78
virtual void update()
Definition: Objective.h:218
Definition: Objective.h:61
Definition: Objective.h:72
virtual void plan(Duration plantime)
Definition: Objective.h:220
Definition: Objective.h:68
double costs
Definition: Objective.h:102
void reflect(Reflector &r)
Definition: Objective.h:114
Definition: Objective.h:66
void setSatisfaction(Satisfaction satisfaction, DissatisfactionReason reason=DissatisfactionReason::NO_REASON)
indicate whether this objective is satisfied, dissatisfied or doesn&#39;t care.
Definition: Objective.h:232