joint_velocity_limit_constraint.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019, Christopher E. Mower
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 
32 REGISTER_TASKMAP_TYPE("JointVelocityLimitConstraint", exotica::JointVelocityLimitConstraint);
33 
34 namespace exotica
35 {
37 {
38  scene_ = scene;
39 
40  // Get num dofs and double
41  N_ = scene_->GetKinematicTree().GetNumControlledJoints();
42  two_times_N_ = 2 * N_;
43 
44  // Get safe percentage and check
45  double percent = static_cast<double>(parameters_.SafePercentage);
46  if (percent > 1.0 || percent < 0.0) ThrowNamed("The safe percentage must be given such that it lies within the range [0, 1].");
47 
48  // Get current joint state
49  if (parameters_.StartState.rows() != N_) ThrowNamed("Wrong size for start state.");
50  current_joint_state_.resize(N_, 1);
51  current_joint_state_ = parameters_.StartState;
52 
53  // Get joint velocity limits
54  if (parameters_.MaximumJointVelocity.rows() == 1)
55  {
56  joint_velocity_limits_.setConstant(N_, 1, std::abs(static_cast<double>(parameters_.MaximumJointVelocity(0))));
57  }
58  else if (parameters_.MaximumJointVelocity.rows() == N_)
59  {
60  joint_velocity_limits_.resize(N_, 1);
61  joint_velocity_limits_ = parameters_.MaximumJointVelocity.cwiseAbs();
62  }
63  else
64  {
65  ThrowNamed("Maximum joint velocity vector needs to be either of size 1 or N, but got " << parameters_.MaximumJointVelocity.rows());
66  }
67  joint_velocity_limits_ *= percent;
68 
69  // Compute 1/dt and init jacobian_
71 
72  jacobian_.resize(two_times_N_, N_);
73  jacobian_.setZero();
74  for (int i = 0; i < N_; ++i)
75  {
77  jacobian_(i + N_, i) = -one_divided_by_dt_;
78  }
79 }
80 
82 {
83  if (joint_state.rows() != N_) ThrowNamed("Wrong size for joint_state!");
84  current_joint_state_ = joint_state;
85 }
86 
88 {
89  // Input check
90  if (phi.rows() != two_times_N_) ThrowNamed("Wrong size of phi!");
91 
92  // Set phi
93  Eigen::VectorXd x_dot = one_divided_by_dt_ * (x - current_joint_state_);
94  for (int i = 0; i < N_; ++i)
95  {
96  phi(i) = x_dot(i) - joint_velocity_limits_(i);
97  phi(i + N_) = -x_dot(i) - joint_velocity_limits_(i);
98  }
99 }
100 
102 {
103  // Input check
104  if (phi.rows() != two_times_N_) ThrowNamed("Wrong size of phi!");
105  if (jacobian.rows() != two_times_N_ || jacobian.cols() != N_) ThrowNamed("Wrong size of jacobian!");
106 
107  // Set phi and jacobian
108  Update(x, phi);
109  jacobian = jacobian_;
110 }
111 
113 {
114  return two_times_N_;
115 }
116 
117 } // namespace exotica
void SetPreviousJointState(Eigen::VectorXdRefConst joint_state)
Logs current joint state. SetPreviousJointState must be called after solve is called in a Python/C++ ...
Eigen::VectorXd joint_velocity_limits_
The joint velocity limits for the robot.
Eigen::Ref< Eigen::VectorXd > VectorXdRef
std::shared_ptr< Scene > ScenePtr
int two_times_N_
Two multiplied by the number of dofs for robot (task space dimension).
#define ThrowNamed(m)
REGISTER_TASKMAP_TYPE("JointVelocityLimitConstraint", exotica::JointVelocityLimitConstraint)
Joint velocity limit task map for non time-indexed problems.
Eigen::VectorXd current_joint_state_
Log of current joint state.
void Update(Eigen::VectorXdRefConst x, Eigen::VectorXdRef phi) override
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef
Eigen::MatrixXd jacobian_
Task map jacobian matrix.


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