control_regularization.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020, 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 {
36 // As this is a control-task-map, the configuration updates are all empty.
38 {
39 }
40 
42 {
43 }
44 
46 {
47 }
48 
49 // Dynamic update methods
51 {
52  if (phi.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Wrong size of Phi!");
53  for (std::size_t i = 0; i < joint_map_.size(); ++i)
54  {
55  phi(i) = u(joint_map_[i]) - joint_ref_(i);
56  }
57 }
58 
60 {
61  if (phi.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Wrong size of Phi!");
62  if (dphi_du.rows() != static_cast<int>(joint_map_.size()) || dphi_du.cols() != num_controlled_joints_) ThrowNamed("Wrong size of jacobian! " << num_controlled_joints_);
63  for (std::size_t i = 0; i < joint_map_.size(); ++i)
64  {
65  phi(i) = u(joint_map_[i]) - joint_ref_(i);
66  dphi_du(i, joint_map_[i]) = 1.0;
67  }
68 }
69 
71 {
72  Eigen::VectorXd x_none(1);
73  Eigen::MatrixXd dphi_dx_none(1, 1);
74  Update(x_none, u, phi, dphi_dx_none, dphi_du);
75 }
76 
78 {
79  scene_ = scene;
80  Initialize();
81 }
82 
84 {
85  num_controlled_joints_ = scene_->get_num_controls();
86 
87  if (num_controlled_joints_ == 0) ThrowPretty("Not a dynamic scene? Number of controls is 0.");
88 
89  if (parameters_.JointMap.rows() > 0)
90  {
91  joint_map_.resize(parameters_.JointMap.rows());
92  for (int i = 0; i < parameters_.JointMap.rows(); ++i)
93  {
94  joint_map_[i] = parameters_.JointMap(i);
95  }
96  }
97  else
98  {
100  for (int i = 0; i < num_controlled_joints_; ++i)
101  {
102  joint_map_[i] = i;
103  }
104  }
105 
106  if (parameters_.JointRef.rows() > 0)
107  {
108  joint_ref_ = parameters_.JointRef;
109  if (joint_ref_.rows() != static_cast<int>(joint_map_.size())) ThrowNamed("Invalid joint reference size! Expecting " << joint_map_.size() << " but received " << joint_ref_.rows());
110  }
111  else
112  {
113  joint_ref_ = Eigen::VectorXd::Zero(joint_map_.size());
114  }
115 }
116 
118 {
119  return joint_map_.size();
120 }
121 
122 const std::vector<int>& ControlRegularization::get_joint_map() const
123 {
124  return joint_map_;
125 }
126 
127 const Eigen::VectorXd& ControlRegularization::get_joint_ref() const
128 {
129  return joint_ref_;
130 }
131 
132 } // namespace exotica
const Eigen::VectorXd & get_joint_ref() const
Eigen::VectorXd joint_ref_
! Subset selection matrix
std::vector< int > joint_map_
! Number of controlled joints
Eigen::Ref< Eigen::VectorXd > VectorXdRef
#define ThrowPretty(m)
std::shared_ptr< Scene > ScenePtr
#define ThrowNamed(m)
void AssignScene(ScenePtr scene) override
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Eigen::Ref< Hessian > HessianRef
const std::vector< int > & get_joint_map() const
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef
REGISTER_TASKMAP_TYPE("ControlRegularization", exotica::ControlRegularization)
void Update(Eigen::VectorXdRefConst q, Eigen::VectorXdRef phi) override


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