rby1-sdk
Loading...
Searching...
No Matches
link.h
1#pragma once
2
3#include <Eigen/Core>
4#include <memory>
5
6#include "rby1-sdk/dynamics/inertial.h"
7#include "rby1-sdk/export.h"
8#include "rby1-sdk/math/liegroup.h"
9
10namespace rb::dyn {
11
12template <int DOF>
13class Robot;
14class Link;
15class Joint;
16class Collision;
17struct CollisionResult;
18class Geom;
19class GeomCapsule;
20
21enum class GeomType { kCapsule = 0 };
22
23class RBY1_SDK_API Link : public std::enable_shared_from_this<Link> {
24 public:
25 template <int DOF>
26 friend class Robot;
27
28 friend class Joint;
29
30 static std::shared_ptr<Link> Make(std::string name, Inertial::MatrixType I = Inertial::I(1.));
31
32 std::string GetName() const;
33
34 std::weak_ptr<const Joint> GetParentJoint() const;
35
36 std::weak_ptr<Joint> GetParentJoint();
37
38 std::vector<std::shared_ptr<Joint>> GetChildJointList();
39
40 const std::vector<std::shared_ptr<Joint>>& GetChildJointList() const;
41
42 void AddCollision(const std::shared_ptr<Collision>& collision);
43
44 std::vector<std::shared_ptr<Collision>> GetCollisions();
45
46 const std::vector<std::shared_ptr<Collision>>& GetCollisions() const;
47
48 private:
49 Link(std::string name, Inertial::MatrixType I);
50
51 private:
52 std::string name_{};
53 Inertial::MatrixType I_{};
54
55 std::weak_ptr<Joint> parent_joint_;
56 std::vector<std::shared_ptr<Joint>> child_joints_;
57
58 std::vector<std::shared_ptr<Collision>> collisions_;
59};
60
61class RBY1_SDK_API Collision : public std::enable_shared_from_this<Collision> {
62 public:
63 explicit Collision(std::string name);
64
65 std::string GetName() const;
66
67 void SetOrigin(const math::SE3::MatrixType& T);
68
69 math::SE3::MatrixType GetOrigin() const;
70
71 void AddGeom(const std::shared_ptr<Geom>& geom);
72
73 std::vector<std::shared_ptr<Geom>> GetGeoms();
74
75 const std::vector<std::shared_ptr<Geom>>& GetGeoms() const;
76
77 private:
78 std::string name_;
79 math::SE3::MatrixType T_{math::SE3::Identity()};
80 std::vector<std::shared_ptr<Geom>> geoms_;
81};
82
83class RBY1_SDK_API Geom : public std::enable_shared_from_this<Geom> {
84 public:
85 Geom(unsigned int coltype = 0, unsigned int colaffinity = 0) : coltype_(coltype), colaffinity_(colaffinity) {}
86
87 virtual ~Geom() = default;
88
89 virtual GeomType GetType() const = 0;
90
91 unsigned int GetColtype() const { return coltype_; }
92
93 unsigned int GetColaffinity() const { return colaffinity_; }
94
95 virtual std::optional<CollisionResult> ComputeMinimumDistance(const math::SE3::MatrixType& T, const Geom& other_geom,
96 const math::SE3::MatrixType& other_T) const = 0;
97
98 bool Filter(const Geom& other_geom) const {
99 return (coltype_ & other_geom.colaffinity_) || (other_geom.coltype_ & colaffinity_);
100 }
101
102 protected:
103 unsigned int coltype_;
104 unsigned int colaffinity_;
105};
106
107class RBY1_SDK_API GeomCapsule : public Geom {
108 public:
109 GeomCapsule(double length, double radius, unsigned int coltype = 0, unsigned int colaffinity = 0);
110
111 GeomCapsule(Eigen::Vector3d sp, Eigen::Vector3d ep, double radius, unsigned int coltype = 0,
112 unsigned int colaffinity = 0);
113
114 GeomType GetType() const override;
115
116 std::optional<CollisionResult> ComputeMinimumDistance(const math::SE3::MatrixType& T, const Geom& other_geom,
117 const math::SE3::MatrixType& other_T) const override;
118
119 Eigen::Vector3d GetStartPoint() const;
120
121 Eigen::Vector3d GetEndPoint() const;
122
123 double GetRadius() const;
124
125 private:
126 Eigen::Vector3d sp_;
127 Eigen::Vector3d ep_;
128 double radius_;
129};
130
131struct RBY1_SDK_API CollisionResult {
132 std::string link1;
133 std::string link2;
134 Eigen::Vector3d position1;
135 Eigen::Vector3d position2;
136 double distance;
137};
138
139} // namespace rb::dyn
Definition link.h:61
Definition link.h:107
Definition link.h:83
Definition joint.h:16
Definition state.h:10
Definition link.h:131