joint_pose.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  if (phi.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Wrong size of Phi!");
39  for (std::size_t i = 0; i < joint_map_.size(); ++i)
40  {
41  phi(i) = q(joint_map_[i]) - joint_ref_(i);
42  }
43 }
44 
46 {
47  if (phi.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Wrong size of Phi!");
48  if (jacobian.rows() != static_cast<int>(joint_map_.size()) || jacobian.cols() != num_controlled_joints_) ThrowNamed("Wrong size of jacobian! " << num_controlled_joints_);
49  for (std::size_t i = 0; i < joint_map_.size(); ++i)
50  {
51  phi(i) = q(joint_map_[i]) - joint_ref_(i);
52  jacobian(i, joint_map_[i]) = 1.0;
53  }
54 }
55 
57 {
58  // Hessian is 0
59  Update(q, phi, jacobian);
60 }
61 
63 {
64  scene_ = scene;
65  Initialize();
66 }
67 
69 {
70  num_controlled_joints_ = scene_->GetKinematicTree().GetNumControlledJoints();
71  if (parameters_.JointMap.rows() > 0)
72  {
73  joint_map_.resize(parameters_.JointMap.rows());
74  for (int i = 0; i < parameters_.JointMap.rows(); ++i)
75  {
76  joint_map_[i] = parameters_.JointMap(i);
77  }
78  }
79  else
80  {
82  for (int i = 0; i < num_controlled_joints_; ++i)
83  {
84  joint_map_[i] = i;
85  }
86  }
87 
88  if (parameters_.JointRef.rows() > 0)
89  {
90  joint_ref_ = parameters_.JointRef;
91  if (joint_ref_.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Invalid joint reference size! Expecting " << joint_map_.size() << " but received " << joint_ref_.rows());
92  }
93  else
94  {
95  joint_ref_ = Eigen::VectorXd::Zero(joint_map_.size());
96  }
97 }
98 
100 {
101  return joint_map_.size();
102 }
103 
104 const std::vector<int>& JointPose::get_joint_map() const
105 {
106  return joint_map_;
107 }
108 
109 const Eigen::VectorXd& JointPose::get_joint_ref() const
110 {
111  return joint_ref_;
112 }
113 
115 {
116  if (ref.size() == joint_ref_.size())
117  joint_ref_ = ref;
118  else
119  ThrowPretty("Wrong size - expected " << joint_ref_.size() << ", but received " << ref.size());
120 }
121 
122 } // namespace exotica
int TaskSpaceDim() override
Definition: joint_pose.cpp:99
int num_controlled_joints_
Definition: joint_pose.h:54
std::vector< int > joint_map_
! Number of controlled joints
Definition: joint_pose.h:55
Eigen::Ref< Eigen::VectorXd > VectorXdRef
REGISTER_TASKMAP_TYPE("JointPose", exotica::JointPose)
#define ThrowPretty(m)
void Update(Eigen::VectorXdRefConst q, Eigen::VectorXdRef phi) override
Definition: joint_pose.cpp:36
const std::vector< int > & get_joint_map() const
Definition: joint_pose.cpp:104
std::shared_ptr< Scene > ScenePtr
void set_joint_ref(Eigen::VectorXdRefConst ref)
Definition: joint_pose.cpp:114
#define ThrowNamed(m)
Eigen::VectorXd joint_ref_
! Subset selection matrix
Definition: joint_pose.h:56
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Eigen::Ref< Hessian > HessianRef
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef
const Eigen::VectorXd & get_joint_ref() const
Definition: joint_pose.cpp:109
void AssignScene(ScenePtr scene) override
Definition: joint_pose.cpp:62
void Initialize()
! Joint reference value
Definition: joint_pose.cpp:68


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