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  if (parameters_.JointMap(i) >= num_controlled_joints_) ThrowPretty("JointMap index (" << parameters_.JointMap(i) << ") is greater than number of controlled joints (" << num_controlled_joints_ << ")!");
77  joint_map_[i] = parameters_.JointMap(i);
78  }
79  }
80  else
81  {
83  for (int i = 0; i < num_controlled_joints_; ++i)
84  {
85  joint_map_[i] = i;
86  }
87  }
88 
89  if (parameters_.JointRef.rows() > 0)
90  {
91  joint_ref_ = parameters_.JointRef;
92  if (joint_ref_.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Invalid joint reference size! Expecting " << joint_map_.size() << " but received " << joint_ref_.rows());
93  }
94  else
95  {
96  joint_ref_ = Eigen::VectorXd::Zero(joint_map_.size());
97  }
98 }
99 
101 {
102  return joint_map_.size();
103 }
104 
105 const std::vector<int>& JointPose::get_joint_map() const
106 {
107  return joint_map_;
108 }
109 
110 const Eigen::VectorXd& JointPose::get_joint_ref() const
111 {
112  return joint_ref_;
113 }
114 
116 {
117  if (ref.size() == joint_ref_.size())
118  joint_ref_ = ref;
119  else
120  ThrowPretty("Wrong size - expected " << joint_ref_.size() << ", but received " << ref.size());
121 }
122 
123 } // namespace exotica
exotica::Instantiable< JointPoseInitializer >::parameters_
C parameters_
exotica::JointPose::num_controlled_joints_
int num_controlled_joints_
Definition: joint_pose.h:54
exotica::JointPose::joint_map_
std::vector< int > joint_map_
! Number of controlled joints
Definition: joint_pose.h:55
exotica::JointPose::Update
void Update(Eigen::VectorXdRefConst q, Eigen::VectorXdRef phi) override
Definition: joint_pose.cpp:36
exotica::JointPose::get_joint_map
const std::vector< int > & get_joint_map() const
Definition: joint_pose.cpp:105
exotica
exotica::JointPose
Definition: joint_pose.h:39
exotica::ScenePtr
std::shared_ptr< Scene > ScenePtr
Eigen::VectorXdRef
Eigen::Ref< Eigen::VectorXd > VectorXdRef
Eigen::VectorXdRefConst
const typedef Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
exotica::TaskMap::scene_
ScenePtr scene_
exotica::JointPose::get_joint_ref
const Eigen::VectorXd & get_joint_ref() const
Definition: joint_pose.cpp:110
Eigen::MatrixXdRef
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef
exotica::HessianRef
Eigen::Ref< Hessian > HessianRef
exotica::JointPose::TaskSpaceDim
int TaskSpaceDim() override
Definition: joint_pose.cpp:100
exotica::JointPose::joint_ref_
Eigen::VectorXd joint_ref_
! Subset selection matrix
Definition: joint_pose.h:56
exotica::JointPose::set_joint_ref
void set_joint_ref(Eigen::VectorXdRefConst ref)
Definition: joint_pose.cpp:115
exotica::JointPose::Initialize
void Initialize()
! Joint reference value
Definition: joint_pose.cpp:68
exotica::JointPose::AssignScene
void AssignScene(ScenePtr scene) override
Definition: joint_pose.cpp:62
ThrowPretty
#define ThrowPretty(m)
joint_pose.h
REGISTER_TASKMAP_TYPE
REGISTER_TASKMAP_TYPE("JointPose", exotica::JointPose)
ThrowNamed
#define ThrowNamed(m)


exotica_core_task_maps
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Fri Aug 2 2024 08:44:10