- 3.0.2 optimal control module.
ObstacleConstraint-impl.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 #ifndef CT_OPTCON_CONSTRAINT_TERM_CONSTRAINT_OBSTACLE_IMPL_HPP_
7 #define CT_OPTCON_CONSTRAINT_TERM_CONSTRAINT_OBSTACLE_IMPL_HPP_
8 
9 namespace ct {
10 namespace optcon {
11 
12 
13 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
15  std::shared_ptr<ct::core::tpl::Ellipsoid<SCALAR>> obstacle,
16  std::function<void(const state_vector_t&, Vector3s&)> getPosition,
17  std::function<void(const state_vector_t&, Eigen::Matrix<SCALAR, 3, STATE_DIM>&)> getJacobian)
18  : obstacle_(obstacle), xFun_(getPosition), dXFun_(getJacobian)
19 {
20  this->lb_.resize(1);
21  this->ub_.resize(1);
22  this->lb_(0) = SCALAR(0.0);
23  this->ub_(0) = std::numeric_limits<SCALAR>::max();
24 }
25 
26 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
28 {
29 }
30 
31 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
33 {
35 }
36 
37 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
39  : Base(arg), obstacle_(arg.obstacle_), xFun_(arg.xFun_), dXFun_(arg.dXFun_)
40 {
41 }
42 
43 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
45 {
46  return 1;
47 }
48 
49 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
50 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> ObstacleConstraint<STATE_DIM, CONTROL_DIM, SCALAR>::evaluate(
51  const state_vector_t& x,
52  const control_vector_t& u,
53  const SCALAR t)
54 {
55  Vector3s xRef;
56  xFun_(x, xRef);
57  val_(0) = obstacle_->insideEllipsoid(xRef);
58  return val_;
59 }
60 
61 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
64  const control_vector_t& u,
65  const SCALAR t)
66 {
67  Vector3s xRef;
68  Eigen::Matrix<SCALAR, 3, STATE_DIM> dXRef;
69  xFun_(x, xRef);
70  dXFun_(x, dXRef);
71  VectorXs dist = xRef - obstacle_->x0();
72  jac_ = 2 * dist.transpose() * obstacle_->S() * obstacle_->A().transpose() * obstacle_->A() *
73  obstacle_->S().transpose() * dXRef;
74  return jac_;
75 }
76 
77 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
80  const control_vector_t& u,
81  const SCALAR t)
82 {
83  return Eigen::Matrix<SCALAR, 1, CONTROL_DIM>::Zero();
84 }
85 
86 
87 } // namespace optcon
88 } // namespace core
89 
90 #endif //CT_OPTCON_CONSTRAINT_TERM_CONSTRAINT_OBSTACLE_IMPL_HPP_
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual MatrixXs jacobianState(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt state.
Definition: ObstacleConstraint-impl.h:63
Class for obstacle constraint.
Definition: ObstacleConstraint.h:19
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: ConstraintBase.h:31
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual ~ObstacleConstraint()
Definition: ObstacleConstraint-impl.h:27
VectorXs ub_
lower bound on the constraints
Definition: ConstraintBase.h:203
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
VectorXs lb_
Definition: ConstraintBase.h:202
virtual Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > evaluate(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
The evaluation of the constraint violation. Note this method is SCALAR typed.
Definition: ObstacleConstraint-impl.h:50
ObstacleConstraint(std::shared_ptr< ct::core::tpl::Ellipsoid< SCALAR >> obstacle, std::function< void(const state_vector_t &, Vector3s &)> getPosition, std::function< void(const state_vector_t &, Eigen::Matrix< SCALAR, 3, STATE_DIM > &)> getJacobian)
Definition: ObstacleConstraint-impl.h:14
virtual MatrixXs jacobianInput(const state_vector_t &x, const control_vector_t &u, const SCALAR t) override
Returns the constraint jacobian wrt input.
Definition: ObstacleConstraint-impl.h:79
Eigen::Matrix< SCALAR, 3, 1 > Vector3s
Definition: ObstacleConstraint.h:33
virtual size_t getConstraintSize() const override
The evaluate method used for jit compilation in constraint container ad.
Definition: ObstacleConstraint-impl.h:44
virtual ObstacleConstraint< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
Creates a new instance of the object with same properties than original.
Definition: ObstacleConstraint-impl.h:32
Base class for the constraints used in this toolbox.
Definition: ConstraintBase.h:21
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > MatrixXs
Definition: ObstacleConstraint.h:31