DirectTrajectoryOptimization  v0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
ReachGoalCostBolza.hpp
Go to the documentation of this file.
1 /***********************************************************************************
2 Copyright (c) 2017, Diego Pardo. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be used
12  to endorse or promote products derived from this software without specific
13  prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18 SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 ***************************************************************************************/
25 
31 #ifndef REACHGOALCOSTBOLZA_HPP_
32 #define REACHGOALCOSTBOLZA_HPP_
33 
35 
36 namespace DirectTrajectoryOptimization {
37 namespace Costs {
38 
42 template<class DIMENSIONS>
44 
45 public :
46 
47  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 
49  typedef typename DIMENSIONS::state_vector_t state_vector_t;
50  typedef typename DIMENSIONS::state_matrix_t state_matrix_t;
51 
52  typedef typename DIMENSIONS::control_vector_t control_vector_t;
53  typedef typename DIMENSIONS::control_matrix_t control_matrix_t;
54 
61  ReachGoalCostBolza(const state_vector_t & goal, const state_matrix_t & Q=state_matrix_t::Identity(), const state_matrix_t & H = state_matrix_t::Identity()):Q_(Q),goal_(goal),H_(H)
62  {}
63 
64  double phi(const state_vector_t & x, const control_vector_t & u);
65  state_vector_t phi_x(const state_vector_t &x, const control_vector_t & u);
66  control_vector_t phi_u(const state_vector_t &x, const control_vector_t & u);
67 
68  double terminalCost(const state_vector_t &x_f);
69  state_vector_t terminalCostDerivative(const state_vector_t &x_f);
70 
71  virtual ~ReachGoalCostBolza() {}
72 
73  state_vector_t goal_;
74  state_matrix_t Q_;
75  state_matrix_t H_;
76 };
77 
78 template <class DIMENSIONS>
79 double ReachGoalCostBolza<DIMENSIONS>::phi(const state_vector_t & x, const control_vector_t & u) {
80 
81  double val = (x-goal_).transpose()*Q_*(x-goal_);
82  return val;
83 }
84 
85 template <class DIMENSIONS>
86 typename DIMENSIONS::state_vector_t ReachGoalCostBolza<DIMENSIONS>::phi_x(const state_vector_t & x,
87  const control_vector_t & u ) {
88 
89  return(2*Q_*(x-goal_));
90 }
91 
92 template <class DIMENSIONS>
93 typename DIMENSIONS::control_vector_t ReachGoalCostBolza<DIMENSIONS>::phi_u(const state_vector_t & x,
94  const control_vector_t & u) {
95 
96  return(control_vector_t::Zero());
97 }
98 
99 
100 template <class DIMENSIONS>
101 double ReachGoalCostBolza<DIMENSIONS>::terminalCost(const state_vector_t & x_f) {
102 
103  double terminal_cost = (x_f-goal_).transpose()*H_*(x_f-goal_);
104 
105  return terminal_cost;
106 }
107 
108 template <class DIMENSIONS>
109 typename DIMENSIONS::state_vector_t ReachGoalCostBolza<DIMENSIONS>::terminalCostDerivative(const state_vector_t & x_f) {
110 
111  return(2*H_*(x_f-goal_));
112 
113 }
114 }
115 }
116 #endif /* REACHGOALCOSTBOLZA_HPP_ */
Bolza type cost function minimizing the distance to a goal state.
Definition: ReachGoalCostBolza.hpp:43
Base class to derive cost function of the type J = sum_k( phi_k(x_k,u_k,k) ) + H(X_K) ...
ReachGoalCostBolza(const state_vector_t &goal, const state_matrix_t &Q=state_matrix_t::Identity(), const state_matrix_t &H=state_matrix_t::Identity())
Constructor.
Definition: ReachGoalCostBolza.hpp:61
Base class to derive cost function of the type J = sum_k( phi_k(x_k,u_k,k) ) + H(X_K) ...
Definition: CostFunctionBolza.hpp:44