sum_of_penetrations.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, Wolfgang Merkt
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 {
38 {
39  if (phi.rows() != dim_) ThrowNamed("Wrong size of phi!");
40  phi.setZero();
41  Eigen::MatrixXd J;
42 
43  // 1) Create vector to store CollisionProxy
44  std::vector<CollisionProxy> proxies;
45 
46  // 2) For each robot link, check against each robot link
48  {
49  AppendVector(proxies, cscene_->GetRobotToRobotCollisionDistance(robot_margin_));
50  }
51 
52  // 3) For each robot link, check against each environment link
53  AppendVector(proxies, cscene_->GetRobotToWorldCollisionDistance(world_margin_));
54 
55  double& d = phi(0);
56  for (const auto& proxy : proxies)
57  {
58  bool is_robot_to_robot = (proxy.e1->is_robot_link || proxy.e1->closest_robot_link.lock()) && (proxy.e2->is_robot_link || proxy.e2->closest_robot_link.lock());
59  double& margin = is_robot_to_robot ? robot_margin_ : world_margin_;
60  if (proxy.distance < margin)
61  {
62  if (proxy.distance < 0)
63  {
64  d += std::abs(proxy.distance);
65  }
66  else
67  {
68  d += std::abs(proxy.distance - margin);
69  }
70  }
71  }
72 }
73 
75 {
76  scene_ = scene;
77  Initialize();
78 }
79 
81 {
82  cscene_ = scene_->GetCollisionScene();
83  world_margin_ = parameters_.WorldMargin;
84  robot_margin_ = parameters_.RobotMargin;
85  check_self_collision_ = parameters_.CheckSelfCollision;
86 
87  HIGHLIGHT_NAMED("Sum of Penetrations",
88  "World Margin: " << world_margin_ << " Robot Margin: " << robot_margin_);
89 }
90 
92 } // namespace exotica
d
void Update(Eigen::VectorXdRefConst x, Eigen::VectorXdRef phi) override
Eigen::Ref< Eigen::VectorXd > VectorXdRef
std::shared_ptr< Scene > ScenePtr
#define ThrowNamed(m)
void AssignScene(ScenePtr scene) override
REGISTER_TASKMAP_TYPE("SumOfPenetrations", exotica::SumOfPenetrations)
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
#define HIGHLIGHT_NAMED(name, x)
void AppendVector(std::vector< Val > &orig, const std::vector< Val > &extra)


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