- 3.0.2 rigid body dynamics module.
JointLimitConstraints.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 rbd {
10 
14 template <typename KINEMATICS, typename SCALAR = double>
16 {
17 public:
18  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
19 
20  using VectorXs = Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>;
22 
24  const JointPosition& lowerBound,
25  const JointPosition& upperBound)
26  : optVector_(optVector)
27  {
28  lowerBounds_ = lowerBound;
29  upperBounds_ = upperBound;
30  }
31 
32  ~JointLimitConstraints() override = default;
33 
34  VectorXs eval() override
35  {
36  contraints_.setZero();
37  contraints_ = optVector_->getOptimizationVars();
38  return contraints_;
39  }
40 
42  {
43  jacobian_.setConstant(static_cast<SCALAR>(1.0));
44  return jacobian_;
45  }
46 
47  size_t getConstraintSize() override { return KINEMATICS::NJOINTS; }
48  size_t getNumNonZerosJacobian() override { return KINEMATICS::NJOINTS; }
49  void genSparsityPattern(Eigen::VectorXi& iRow_vec, Eigen::VectorXi& jCol_vec) override
50  {
51  iRow_vec.resize(KINEMATICS::NJOINTS);
52  jCol_vec.resize(KINEMATICS::NJOINTS);
53 
54  for (size_t i = 0; i < KINEMATICS::NJOINTS; i++)
55  {
56  iRow_vec(i) = i;
57  jCol_vec(i) = i;
58  }
59  }
60 
61 
62  void genSparsityPatternHessian(Eigen::VectorXi& iRow_vec, Eigen::VectorXi& jCol_vec) override
63  {
64  // do nothing
65  }
66 
67  void sparseHessianValues(const Eigen::VectorXd& optVec,
68  const Eigen::VectorXd& lambda,
69  Eigen::VectorXd& sparseHes) override
70  {
71  // do nothing
72  }
73 
74  VectorXs getLowerBound() override { return lowerBounds_; }
75  VectorXs getUpperBound() override { return upperBounds_; }
76  const VectorXs getLowerBound() const { return lowerBounds_; }
77  const VectorXs getUpperBound() const { return upperBounds_; }
78 private:
79  std::shared_ptr<ct::optcon::tpl::OptVector<SCALAR>> optVector_;
80  Eigen::Matrix<SCALAR, KINEMATICS::NJOINTS, 1> contraints_;
81  Eigen::Matrix<SCALAR, KINEMATICS::NJOINTS, 1> jacobian_; // sparse jacobian
82  Eigen::Matrix<SCALAR, KINEMATICS::NJOINTS, 1> lowerBounds_; // lower bound
83  Eigen::Matrix<SCALAR, KINEMATICS::NJOINTS, 1> upperBounds_; // upper bound
84 };
85 
86 } // namespace rbd
87 } // namespace ct
VectorXs getLowerBound() override
Definition: JointLimitConstraints.h:74
typename ct::rbd::JointState< KINEMATICS::NJOINTS, SCALAR >::Position JointPosition
Definition: JointLimitConstraints.h:21
~JointLimitConstraints() override=default
joint state and joint velocity
Definition: JointState.h:21
const VectorXs getLowerBound() const
Definition: JointLimitConstraints.h:76
VectorXs getUpperBound() override
Definition: JointLimitConstraints.h:75
Inverse Kinematics joint limit constraints.
Definition: JointLimitConstraints.h:15
size_t getConstraintSize() override
Definition: JointLimitConstraints.h:47
for i
JointLimitConstraints(std::shared_ptr< ct::optcon::tpl::OptVector< SCALAR >> optVector, const JointPosition &lowerBound, const JointPosition &upperBound)
Definition: JointLimitConstraints.h:23
void genSparsityPatternHessian(Eigen::VectorXi &iRow_vec, Eigen::VectorXi &jCol_vec) override
Definition: JointLimitConstraints.h:62
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: JointLimitConstraints.h:20
VectorXs eval() override
Definition: JointLimitConstraints.h:34
size_t getNumNonZerosJacobian() override
Definition: JointLimitConstraints.h:48
const VectorXs getUpperBound() const
Definition: JointLimitConstraints.h:77
VectorXs evalSparseJacobian() override
Definition: JointLimitConstraints.h:41
void sparseHessianValues(const Eigen::VectorXd &optVec, const Eigen::VectorXd &lambda, Eigen::VectorXd &sparseHes) override
Definition: JointLimitConstraints.h:67
void genSparsityPattern(Eigen::VectorXi &iRow_vec, Eigen::VectorXi &jCol_vec) override
Definition: JointLimitConstraints.h:49