joint_limit.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2020, University of Edinburgh, University of Oxford
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
31 
33 
34 namespace exotica
35 {
37 {
38  scene_ = scene;
39  Initialize();
40 }
41 
43 {
44  safe_percentage_ = parameters_.SafePercentage;
45  N = scene_->GetKinematicTree().GetNumControlledJoints();
46 }
47 
49 {
50  return N;
51 }
52 
54 {
55  if (phi.rows() != N) ThrowNamed("Wrong size of phi!");
56 
57  const Eigen::MatrixXd& limits = scene_->GetKinematicTree().GetJointLimits();
58  const Eigen::VectorXd& low_limits = limits.col(0);
59  const Eigen::VectorXd& high_limits = limits.col(1);
60  const Eigen::VectorXd tau = 0.5 * safe_percentage_ * (high_limits - low_limits);
61 
62  // apply lower bounds
63  phi = (q.array() < (low_limits + tau).array()).select(q - low_limits - tau, phi);
64  // apply higher bounds
65  phi = (q.array() > (high_limits - tau).array()).select(q - high_limits + tau, phi);
66 }
67 
69 {
70  if (jacobian.rows() != N || jacobian.cols() != N) ThrowNamed("Wrong size of jacobian! " << N);
71  Update(q, phi);
72 
73  // The jacobian is piece-wise: It's 0 when within limits, and 1 when outside.
74  const Eigen::MatrixXd& limits = scene_->GetKinematicTree().GetJointLimits();
75  const Eigen::VectorXd& low_limits = limits.col(0);
76  const Eigen::VectorXd& high_limits = limits.col(1);
77  const Eigen::VectorXd tau = 0.5 * safe_percentage_ * (high_limits - low_limits);
78  for (int i = 0; i < N; i++)
79  {
80  if (q(i) >= low_limits(i) + tau(i) && q(i) <= high_limits(i) - tau(i))
81  {
82  jacobian(i, i) = 0;
83  }
84  else
85  {
86  jacobian(i, i) = 1;
87  }
88  }
89 }
90 
92 {
93  if (hessian.size() != N) ThrowNamed("Wrong size of hessian! " << N);
94  // Hessian is 0.
95  Update(x, phi, jacobian);
96 }
97 
99 {
100  Update(x.head(scene_->get_num_positions()), phi);
101 }
102 
104 {
105  Update(x.head(scene_->get_num_positions()), phi, dphi_dx.topLeftCorner(N, N));
106 }
107 
109 {
110  // Hessian is 0.
111  Update(x.head(scene_->get_num_positions()), phi, dphi_dx.topLeftCorner(N, N));
112 }
113 
114 } // namespace exotica
Implementation of joint limits task map. Note: we dont want to always stay at the centre of the joint...
Definition: joint_limit.h:42
Eigen::Ref< Eigen::VectorXd > VectorXdRef
int TaskSpaceDim() override
Definition: joint_limit.cpp:48
REGISTER_TASKMAP_TYPE("JointLimit", exotica::JointLimit)
std::shared_ptr< Scene > ScenePtr
#define ThrowNamed(m)
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Eigen::Ref< Hessian > HessianRef
void Update(Eigen::VectorXdRefConst q, Eigen::VectorXdRef phi) override
Definition: joint_limit.cpp:53
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef
void AssignScene(ScenePtr scene) override
Definition: joint_limit.cpp:36


exotica_core_task_maps
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:36:09