Crocoddyl
 
Loading...
Searching...
No Matches
squashing-base.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2020, University of Edinburgh, IRI: CSIC-UPC
5// Copyright note valid unless otherwise stated in individual files.
6// All rights reserved.
8
9#ifndef CROCODDYL_CORE_SQUASHING_BASE_HPP_
10#define CROCODDYL_CORE_SQUASHING_BASE_HPP_
11
12#include <boost/make_shared.hpp>
13#include <memory>
14#include <stdexcept>
15
16#include "crocoddyl/core/fwd.hpp"
17#include "crocoddyl/core/mathbase.hpp"
18#include "crocoddyl/core/utils/exception.hpp"
19
20namespace crocoddyl {
21
22template <typename _Scalar>
24 public:
25 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26
27 typedef _Scalar Scalar;
30 typedef typename MathBase::VectorXs VectorXs;
31
32 SquashingModelAbstractTpl(const std::size_t ns) : ns_(ns) {
33 if (ns_ == 0) {
34 throw_pretty("Invalid argument: " << "ns cannot be zero");
35 }
36 };
37 virtual ~SquashingModelAbstractTpl() {};
38
39 virtual void calc(const std::shared_ptr<SquashingDataAbstract>& data,
40 const Eigen::Ref<const VectorXs>& s) = 0;
41 virtual void calcDiff(const std::shared_ptr<SquashingDataAbstract>& data,
42 const Eigen::Ref<const VectorXs>& s) = 0;
43 virtual std::shared_ptr<SquashingDataAbstract> createData() {
44 return std::allocate_shared<SquashingDataAbstract>(
45 Eigen::aligned_allocator<SquashingDataAbstract>(), this);
46 }
47
48 std::size_t get_ns() const { return ns_; };
49 const VectorXs& get_s_lb() const { return s_lb_; };
50 const VectorXs& get_s_ub() const { return s_ub_; };
51
52 void set_s_lb(const VectorXs& s_lb) { s_lb_ = s_lb; };
53 void set_s_ub(const VectorXs& s_ub) { s_ub_ = s_ub; };
54
55 protected:
56 std::size_t ns_;
57 VectorXs u_ub_; // Squashing function upper bound
58 VectorXs u_lb_; // Squashing function lower bound
59 VectorXs
60 s_ub_; // Bound for the s variable (to apply using the Quadratic barrier)
61 VectorXs
62 s_lb_; // Bound for the s variable (to apply using the Quadratic barrier)
63};
64
65template <typename _Scalar>
67 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
68
69 typedef _Scalar Scalar;
71 typedef typename MathBase::VectorXs VectorXs;
72 typedef typename MathBase::MatrixXs MatrixXs;
73
74 template <template <typename Scalar> class Model>
75 explicit SquashingDataAbstractTpl(Model<Scalar>* const model)
76 : u(model->get_ns()), du_ds(model->get_ns(), model->get_ns()) {
77 u.setZero();
78 du_ds.setZero();
79 }
80 virtual ~SquashingDataAbstractTpl() {}
81
82 VectorXs u;
83 MatrixXs du_ds;
84};
85
86} // namespace crocoddyl
87
88#endif // CROCODDYL_CORE_SQUASHING_BASE_HPP_