CollisionFunction.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_tvm/Convex.h>
8 
9 #include <tvm/function/abstract/Function.h>
10 
11 #include <sch/CD/CD_Pair.h>
12 
13 #include <RBDyn/Jacobian.h>
14 
15 namespace mc_tvm
16 {
17 
19 class MC_TVM_DLLAPI CollisionFunction : public tvm::function::abstract::Function
20 {
21 public:
22  SET_UPDATES(CollisionFunction, Value, Velocity, Jacobian, NormalAcceleration)
23 
24 
38  Convex & c2,
39  const Eigen::VectorXd & r1Selector,
40  const Eigen::VectorXd & r2Selector,
41  double dt);
42 
44  void tick();
45 
47  inline double distance() const noexcept { return this->value()(0); }
48 
50  inline const Convex & c1() const noexcept { return *c1_; }
51 
53  inline const Eigen::Vector3d & p1() const noexcept { return p1_; }
54 
56  inline const Convex & c2() const noexcept { return *c2_; }
57 
59  inline const Eigen::Vector3d & p2() const noexcept { return p2_; }
60 
61 protected:
62  /* Update functions */
63  void updateValue();
64  void updateVelocity();
65  void updateJacobian();
66  void updateNormalAcceleration();
67 
68  uint64_t iter_ = 0;
69  uint64_t prevIter_ = 0;
70 
73  double dt_;
74 
75  Eigen::Vector3d p1_ = Eigen::Vector3d::Zero();
76  Eigen::Vector3d p2_ = Eigen::Vector3d::Zero();
77 
78  sch::CD_Pair pair_;
79 
80  struct ObjectData
81  {
82  Eigen::Vector3d nearestPoint_;
83  rbd::Jacobian jac_;
84  Eigen::VectorXd selector_;
85  };
86  std::vector<ObjectData> data_;
87 
88  Eigen::Vector3d normVecDist_ = Eigen::Vector3d::Zero();
89  Eigen::Vector3d prevNormVecDist_ = Eigen::Vector3d::Zero();
90  Eigen::Vector3d speedVec_ = Eigen::Vector3d::Zero();
91 
93  Eigen::MatrixXd fullJac_;
94  Eigen::MatrixXd distJac_;
95 };
96 
97 using CollisionFunctionPtr = std::shared_ptr<CollisionFunction>;
98 
99 } // namespace mc_tvm
mc_tvm::CollisionFunction::ObjectData::selector_
Eigen::VectorXd selector_
Definition: CollisionFunction.h:84
mc_tvm::CollisionFunctionPtr
std::shared_ptr< CollisionFunction > CollisionFunctionPtr
Definition: CollisionFunction.h:97
mc_tvm::CollisionFunction::p2
const Eigen::Vector3d & p2() const noexcept
Definition: CollisionFunction.h:59
MC_TVM_DLLAPI
#define MC_TVM_DLLAPI
Definition: api.h:47
mc_tvm::CollisionFunction::dt_
double dt_
Definition: CollisionFunction.h:73
mc_tvm
Definition: CollisionFunction.h:15
mc_tvm::CollisionFunction::c2
const Convex & c2() const noexcept
Definition: CollisionFunction.h:56
mc_tvm::CollisionFunction::ObjectData::jac_
rbd::Jacobian jac_
Definition: CollisionFunction.h:83
mc_tvm::CollisionFunction::distJac_
Eigen::MatrixXd distJac_
Definition: CollisionFunction.h:94
Convex.h
mc_tvm::CollisionFunction::c1_
Convex * c1_
Definition: CollisionFunction.h:71
mc_tvm::CollisionFunction::p1
const Eigen::Vector3d & p1() const noexcept
Definition: CollisionFunction.h:53
mc_tvm::CollisionFunction::c2_
Convex * c2_
Definition: CollisionFunction.h:72
mc_tvm::CollisionFunction::c1
const Convex & c1() const noexcept
Definition: CollisionFunction.h:50
mc_tvm::CollisionFunction::fullJac_
Eigen::MatrixXd fullJac_
Definition: CollisionFunction.h:93
mc_tvm::CollisionFunction::pair_
sch::CD_Pair pair_
Definition: CollisionFunction.h:78
mc_tvm::CollisionFunction::ObjectData::nearestPoint_
Eigen::Vector3d nearestPoint_
Definition: CollisionFunction.h:82
mc_tvm::CollisionFunction::data_
std::vector< ObjectData > data_
Definition: CollisionFunction.h:86
mc_tvm::CollisionFunction::distance
double distance() const noexcept
Definition: CollisionFunction.h:47
mc_tvm::CollisionFunction::ObjectData
Definition: CollisionFunction.h:80
mc_tvm::Convex
Definition: Convex.h:23
mc_tvm::CollisionFunction
Definition: CollisionFunction.h:19