- 3.0.2 optimal control module.
TermStateBarrier-impl.hpp
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 
11 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
13  const state_vector_t& lb,
14  const state_vector_t& alpha)
15  : ub_(ub), lb_(lb), alpha_(alpha)
16 {
17 }
18 
19 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
21  : ub_(state_vector_t::Zero()), lb_(state_vector_t::Zero()), alpha_(state_vector_t::Zero())
22 {
23 }
24 
25 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
27  : ub_(arg.ub_), lb_(arg.lb_), alpha_(arg.alpha_)
28 {
29  initialize();
30 }
31 
32 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
34 {
35 }
36 
37 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
40 {
41  return new TermStateBarrier(*this);
42 }
43 
44 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
46 {
47  barriers_.clear();
48  for (size_t i = 0; i < STATE_DIM; i++)
49  {
51  }
52 }
53 
54 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
56  const Eigen::Matrix<SCALAR, STATE_DIM, 1>& x,
57  const Eigen::Matrix<SCALAR, CONTROL_DIM, 1>& u,
58  const SCALAR& t)
59 {
60  SCALAR c = SCALAR(0.0);
61  for (size_t i = 0; i < STATE_DIM; i++)
63  return c;
64 }
65 
66 #ifdef CPPADCG
67 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
71  ct::core::ADCGScalar t)
72 {
73  ct::core::ADCGScalar c = ct::core::ADCGScalar(0.0);
74  for (size_t i = 0; i < STATE_DIM; i++)
76  return c;
77 }
78 #endif
79 
80 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR_EVAL, typename SCALAR>
82  const std::string& termName,
83  bool verbose)
84 {
85  state_matrix_t Alpha;
86  state_matrix_t Ub;
87  state_matrix_t Lb;
88 
89  loadMatrixCF(filename, "alpha", Alpha, termName);
90  loadMatrixCF(filename, "upper_bound", Ub, termName);
91  loadMatrixCF(filename, "lower_bound", Lb, termName);
92 
93  alpha_ = Alpha.diagonal();
94  ub_ = Ub.diagonal();
95  lb_ = Lb.diagonal();
96 
97  if (verbose)
98  {
99  std::cout << "Read alpha as = \n" << alpha_.transpose() << std::endl;
100  std::cout << "Read upper_bound as = \n" << ub_.transpose() << std::endl;
101  std::cout << "Read lower_bound as = \n" << lb_.transpose() << std::endl;
102  }
103 }
104 } // namespace optcon
105 } // namespace ct
void initialize()
Definition: TermStateBarrier-impl.hpp:45
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual ~TermStateBarrier()
Definition: TermStateBarrier-impl.hpp:33
state_vector_t ub_
Definition: TermStateBarrier.hpp:68
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
CppAD::AD< CppAD::cg::CG< double > > SCALAR
for i
Definition: mpc_unittest_plotting.m:14
A state barrier term (could also be considered a soft constraint) Note that this term explicitly excl...
Definition: TermStateBarrier.hpp:26
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
std::vector< ct::core::tpl::BarrierActivation< SCALAR, ct::core::tpl::TraitSelector< SCALAR > > > barriers_
Definition: TermStateBarrier.hpp:71
state_vector_t alpha_
Definition: TermStateBarrier.hpp:67
TermStateBarrier< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR > * clone() const override
Deep-copy term.
Definition: TermStateBarrier-impl.hpp:39
SCALAR_EVAL computeActivation(SCALAR_EVAL t)
compute time activation
Definition: TermBase-impl.hpp:58
virtual SCALAR evaluate(const Eigen::Matrix< SCALAR, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > &u, const SCALAR &t) override
Evaluates the term at x, u, t.
Definition: TermStateBarrier-impl.hpp:55
TermStateBarrier()
Definition: TermStateBarrier-impl.hpp:20
state_vector_t lb_
Definition: TermStateBarrier.hpp:69
Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > state_matrix_t
Definition: TermBase.hpp:39
Eigen::Matrix< double, nStates, 1 > state_vector_t
const bool verbose
Definition: ConstraintComparison.h:18
void loadMatrixCF(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &termName="")
Definition: utilities.hpp:46
virtual void loadConfigFile(const std::string &filename, const std::string &termName, bool verbose=false) override
load the term from config file, where the bounds are stored as matrices
Definition: TermStateBarrier-impl.hpp:81