VFMechanicalWorkOptimizationObjective.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Caleb Voss and Wilson Beebe
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Authors: Caleb Voss, Wilson Beebe */
36 
37 #ifndef OMPL_BASE_OBJECTIVES_VF_MECHANICAL_WORK_OPTIMIZATION_OBJECTIVE_
38 #define OMPL_BASE_OBJECTIVES_VF_MECHANICAL_WORK_OPTIMIZATION_OBJECTIVE_
39 
40 #include <utility>
41 
42 #include "ompl/base/objectives/MechanicalWorkOptimizationObjective.h"
43 #include "ompl/geometric/planners/rrt/VFRRT.h"
44 
45 namespace ompl
46 {
47  namespace base
48  {
52  class VFMechanicalWorkOptimizationObjective : public ompl::base::MechanicalWorkOptimizationObjective
53  {
54  public:
57  geometric::VFRRT::VectorField vf)
58  : ompl::base::MechanicalWorkOptimizationObjective(si), vf_(std::move(vf))
59  {
60  }
61 
63  bool isSatisfied(ompl::base::Cost) const override
64  {
65  return false;
66  }
67 
69  ompl::base::Cost motionCost(const ompl::base::State *s1, const ompl::base::State *s2) const override
70  {
71  const base::StateSpacePtr &space = si_->getStateSpace();
72  // Per equation 7 in the paper
73  Eigen::VectorXd f = vf_(s2);
74  unsigned int vfdim = f.size();
75  Eigen::VectorXd qprime(vfdim);
76 
77  for (unsigned int i = 0; i < vfdim; i++)
78  qprime[i] = *space->getValueAddressAtIndex(s2, i) - *space->getValueAddressAtIndex(s1, i);
79 
80  // Don't included negative work
81  double positiveCostAccrued = std::max(-(f.dot(qprime)), 0.);
82  return ompl::base::Cost(positiveCostAccrued + pathLengthWeight_ * si_->distance(s1, s2));
83  }
84 
85  bool isSymmetric() const override
86  {
87  return false;
88  }
89 
90  protected:
92  geometric::VFRRT::VectorField vf_;
93  };
94  }
95 }
96 
97 #endif
VFMechanicalWorkOptimizationObjective(const ompl::base::SpaceInformationPtr &si, geometric::VFRRT::VectorField vf)
SpaceInformationPtr si_
The space information for this objective.
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:113
An optimization objective which defines path cost using the idea of mechanical work....
MechanicalWorkOptimizationObjective(const SpaceInformationPtr &si, double pathLengthWeight=0.00001)
The mechanical work formulation requires a weighing factor to use for the length of a path in order t...
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:111
ompl::base::Cost motionCost(const ompl::base::State *s1, const ompl::base::State *s2) const override
bool isSymmetric() const override
Check if this objective has a symmetric cost metric, i.e. motionCost(s1, s2) = motionCost(s2,...
double pathLengthWeight_
The weighing factor for the path length in the mechanical work objective formulation.
Main namespace. Contains everything in this library.