- 3.0.2 optimal control module.
compareCostFunctions.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4  **********************************************************************************************************************/
5 
6 #pragma once
7 
8 namespace ct {
9 namespace optcon {
10 namespace example {
11 
17 template <size_t state_dim, size_t control_dim>
20 {
21  ASSERT_NEAR(costFunction.evaluateIntermediate(), costFunction2.evaluateIntermediate(), 1e-9);
22  ASSERT_NEAR(costFunction.evaluateTerminal(), costFunction2.evaluateTerminal(), 1e-9);
23 
24  ASSERT_TRUE(costFunction.stateDerivativeIntermediate().isApprox(costFunction2.stateDerivativeIntermediate()));
25  ASSERT_TRUE(costFunction.stateDerivativeTerminal().isApprox(costFunction2.stateDerivativeTerminal()));
26 
27  ASSERT_TRUE(
28  costFunction.stateSecondDerivativeIntermediate().isApprox(costFunction2.stateSecondDerivativeIntermediate()));
29  ASSERT_TRUE(costFunction.stateSecondDerivativeTerminal().isApprox(costFunction2.stateSecondDerivativeTerminal()));
30 
31  ASSERT_TRUE(costFunction.controlDerivativeIntermediate().isApprox(costFunction2.controlDerivativeIntermediate()));
32  ASSERT_TRUE(costFunction.controlDerivativeTerminal().isApprox(costFunction2.controlDerivativeTerminal()));
33 
34  ASSERT_TRUE(costFunction.controlSecondDerivativeIntermediate().isApprox(
35  costFunction2.controlSecondDerivativeIntermediate()));
36  ASSERT_TRUE(
37  costFunction.controlSecondDerivativeTerminal().isApprox(costFunction2.controlSecondDerivativeTerminal()));
38 
39  ASSERT_TRUE(
40  costFunction.stateControlDerivativeIntermediate().isApprox(costFunction2.stateControlDerivativeIntermediate()));
41  ASSERT_TRUE(costFunction.stateControlDerivativeTerminal().isApprox(costFunction2.stateControlDerivativeTerminal()));
42 
43  // second derivatives have to be symmetric
44  ASSERT_TRUE(costFunction.stateSecondDerivativeIntermediate().isApprox(
45  costFunction.stateSecondDerivativeIntermediate().transpose()));
46  ASSERT_TRUE(costFunction.controlSecondDerivativeIntermediate().isApprox(
47  costFunction.controlSecondDerivativeIntermediate().transpose()));
48 }
49 
50 } // namespace example
51 } // namesapce optcon
52 } // namespace ct
virtual state_vector_t stateDerivativeIntermediate()=0
Computes intermediate-cost first-order derivative with respect to state.
virtual SCALAR evaluateIntermediate()=0
evaluate intermediate costs
virtual control_state_matrix_t stateControlDerivativeTerminal()
Computes final-cost derivative with respect to state and control.
Definition: CostFunctionQuadratic-impl.hpp:85
virtual control_matrix_t controlSecondDerivativeIntermediate()=0
Computes intermediate-cost second-order derivative with respect to input.
Describes a cost function with a quadratic approximation, i.e. one that can compute first and second ...
Definition: CostFunctionQuadratic.hpp:29
virtual state_vector_t stateDerivativeTerminal()=0
virtual state_matrix_t stateSecondDerivativeIntermediate()=0
Computes intermediate-cost second-order derivative with respect to state.
virtual control_vector_t controlDerivativeIntermediate()=0
Computes intermediate-cost first-order derivative with respect to control.
virtual control_vector_t controlDerivativeTerminal()
Computes terminal-cost first-order derivative with respect to control.
Definition: CostFunctionQuadratic-impl.hpp:71
virtual control_state_matrix_t stateControlDerivativeIntermediate()=0
Computes intermediate-cost derivative with respect to state and control.
virtual SCALAR evaluateTerminal()=0
evaluate terminal costs
void compareCostFunctionOutput(CostFunctionQuadratic< state_dim, control_dim > &costFunction, CostFunctionQuadratic< state_dim, control_dim > &costFunction2)
This method is called from different unit tests in order to compare the cost, first and second order ...
Definition: compareCostFunctions.h:18
virtual state_matrix_t stateSecondDerivativeTerminal()=0
Computes final-cost second-order derivative with respect to state.
virtual control_matrix_t controlSecondDerivativeTerminal()
Computes final-cost second-order derivative with respect to input.
Definition: CostFunctionQuadratic-impl.hpp:78