|
12 | 12 | namespace rcs { |
13 | 13 | namespace common { |
14 | 14 |
|
15 | | -struct RobotMetaConfig { |
16 | | - VectorXd q_home; |
17 | | - int dof; |
18 | | - Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor> joint_limits; |
19 | | -}; |
20 | 15 |
|
21 | | -enum RobotType { FR3 = 0, UR5e, SO101, XArm7, Panda }; |
22 | 16 | enum RobotPlatform { SIMULATION = 0, HARDWARE }; |
23 | 17 |
|
24 | | -static const std::unordered_map<RobotType, RobotMetaConfig> robots_meta_config = |
25 | | - {{// -------------- FR3 -------------- |
26 | | - {FR3, |
27 | | - RobotMetaConfig{ |
28 | | - // q_home: |
29 | | - (VectorXd(7) << 0.0, -M_PI_4, 0.0, -3.0 * M_PI_4, 0.0, M_PI_2, |
30 | | - M_PI_4) |
31 | | - .finished(), |
32 | | - // dof: |
33 | | - 7, |
34 | | - // joint_limits: |
35 | | - (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 7) << |
36 | | - // low 7‐tuple |
37 | | - -2.3093, |
38 | | - -1.5133, -2.4937, -2.7478, -2.4800, 0.8521, -2.6895, |
39 | | - // high 7‐tuple |
40 | | - 2.3093, 1.5133, 2.4937, -0.4461, 2.4800, 4.2094, 2.6895) |
41 | | - .finished()}}, |
42 | | - {Panda, |
43 | | - RobotMetaConfig{ |
44 | | - // q_home: |
45 | | - (VectorXd(7) << 0.0, -M_PI_4, 0.0, -3.0 * M_PI_4, 0.0, M_PI_2, |
46 | | - M_PI_4) |
47 | | - .finished(), |
48 | | - // dof: |
49 | | - 7, |
50 | | - // joint_limits: |
51 | | - (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 7) << |
52 | | - // low 7‐tuple |
53 | | - -166. / 180. * M_PI, -101. / 180. * M_PI, -166. / 180. * M_PI, -176. / 180. * M_PI, -166. / 180. * M_PI, -1. / 180. * M_PI, -166. / 180. * M_PI, |
54 | | - // high 7‐tuple |
55 | | - 166. / 180. * M_PI, 101. / 180. * M_PI, 166. / 180. * M_PI, -4. / 180. * M_PI, 166. / 180. * M_PI, 215. / 180. * M_PI, 166. / 180. * M_PI |
56 | | - ) |
57 | | - .finished()}}, |
58 | | - |
59 | | - // -------------- UR5e -------------- |
60 | | - {UR5e, |
61 | | - RobotMetaConfig{ |
62 | | - // q_home (6‐vector): |
63 | | - (VectorXd(6) << 0.0, -2.02711196, 1.64630026, -1.18999615, |
64 | | - -1.57079762, 0.0) |
65 | | - .finished(), |
66 | | - // dof: |
67 | | - 6, |
68 | | - // joint_limits (2×6): |
69 | | - (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 6) << |
70 | | - // low 6‐tuple |
71 | | - -2 * M_PI, |
72 | | - -2 * M_PI, -1 * M_PI, -2 * M_PI, -2 * M_PI, -2 * M_PI, |
73 | | - // high 6‐tuple |
74 | | - 2 * M_PI, 2 * M_PI, 1 * M_PI, 2 * M_PI, 2 * M_PI, 2 * M_PI) |
75 | | - .finished()}}, |
76 | | - // -------------- XArm7 -------------- |
77 | | - {XArm7, RobotMetaConfig{ |
78 | | - // q_home (7‐vector): |
79 | | - (VectorXd(7) << 0, |
80 | | - -45. / 180. * M_PI, |
81 | | - 0, |
82 | | - 15. / 180. * M_PI, |
83 | | - 0, |
84 | | - -25. / 180. * M_PI, |
85 | | - 0 |
86 | | - ).finished(), |
87 | | - // dof: |
88 | | - 7, |
89 | | - // joint_limits (2×7): |
90 | | - (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 7) << |
91 | | - // low 7‐tuple |
92 | | - -2 * M_PI, -2.094395, -2 * M_PI, -3.92699, -2 * M_PI, -M_PI, -2 * M_PI, |
93 | | - // high 7‐tuple |
94 | | - 2 * M_PI, 2.059488, 2 * M_PI, 0.191986, 2 * M_PI, 1.692969, 2 * M_PI).finished()}}, |
95 | | - // -------------- SO101 -------------- |
96 | | - {SO101, |
97 | | - RobotMetaConfig{ |
98 | | - // q_home (5‐vector): |
99 | | - // (VectorXd(5) << -9.40612320177057, -99.66130397967824, |
100 | | - // 99.9124726477024, 69.96996996996998, -9.095744680851055) |
101 | | - // .finished(), |
102 | | - (VectorXd(5) << -0.01914898, -1.90521916, 1.56476701, 1.04783839, -1.40323926) |
103 | | - .finished(), |
104 | | - // dof: |
105 | | - 5, |
106 | | - // joint_limits (2×5): |
107 | | - (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 5) << |
108 | | - // low 5‐tuple |
109 | | - -1.9198621771937616, |
110 | | - -1.9198621771937634, -1.7453292519943295, -1.6580627969561903, |
111 | | - -2.7925268969992407, |
112 | | - |
113 | | - // high 5‐tuple |
114 | | - 1.9198621771937616, 1.9198621771937634, 1.5707963267948966, |
115 | | - 1.6580627969561903, 2.7925268969992407) |
116 | | - .finished()}}}}; |
| 18 | +template <typename Derived> |
| 19 | +struct TypeBase { |
| 20 | + std::string id; |
| 21 | + |
| 22 | + // Each subclass gets its own unique static map |
| 23 | + static std::map<std::string, const Derived*>& registry() { |
| 24 | + static std::map<std::string, const Derived*> _registry; |
| 25 | + return _registry; |
| 26 | + } |
| 27 | + |
| 28 | + // Constructor automatically registers the instance |
| 29 | + TypeBase(std::string id_) : id(std::move(id_)) { |
| 30 | + auto& reg = registry(); |
| 31 | + if (reg.find(id) == reg.end()) { |
| 32 | + reg[id] = static_cast<const Derived*>(this); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // Returns all registered instances of this specific type |
| 37 | + static std::vector<Derived> get_all() { |
| 38 | + std::vector<Derived> all; |
| 39 | + for (const auto& [key, ptr] : registry()) { |
| 40 | + all.push_back(*ptr); |
| 41 | + } |
| 42 | + return all; |
| 43 | + } |
| 44 | + |
| 45 | + bool operator==(const TypeBase& other) const { return id == other.id; } |
| 46 | +}; |
| 47 | +struct RobotType : public TypeBase<RobotType> { |
| 48 | + using TypeBase::TypeBase; // Inherit the constructor |
| 49 | + |
| 50 | + static const RobotType FR3; |
| 51 | +}; |
| 52 | +inline const RobotType RobotType::FR3{"FR3"}; |
117 | 53 |
|
118 | 54 | struct RobotConfig { |
119 | 55 | RobotType robot_type = RobotType::FR3; |
120 | 56 | RobotPlatform robot_platform = RobotPlatform::SIMULATION; |
121 | 57 | rcs::common::Pose tcp_offset = rcs::common::Pose::Identity(); |
122 | 58 | std::string attachment_site = "attachment_site"; |
123 | 59 | std::string kinematic_model_path = "assets/scenes/fr3_empty_world/robot.xml"; |
124 | | - bool home_on_reset = true; |
125 | 60 | std::optional<VectorXd> q_home = std::nullopt; |
| 61 | + size_t dof = 7; |
| 62 | + Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor> joint_limits = |
| 63 | + (Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 7) << |
| 64 | + // low 7‐tuple |
| 65 | + -2.3093, |
| 66 | + -1.5133, -2.4937, -2.7478, -2.4800, 0.8521, -2.6895, |
| 67 | + // high 7‐tuple |
| 68 | + 2.3093, 1.5133, 2.4937, -0.4461, 2.4800, 4.2094, 2.6895) |
| 69 | + .finished(); |
126 | 70 | virtual ~RobotConfig(){}; |
127 | 71 | }; |
128 | 72 | struct RobotState { |
129 | 73 | virtual ~RobotState(){}; |
130 | 74 | }; |
131 | 75 |
|
| 76 | + |
| 77 | +struct GripperType : public TypeBase<GripperType> { |
| 78 | + using TypeBase::TypeBase; |
| 79 | + |
| 80 | + static const GripperType FrankaHand; |
| 81 | +}; |
| 82 | +inline const GripperType GripperType::FrankaHand{"FrankaHand"}; |
| 83 | + |
132 | 84 | struct GripperConfig { |
133 | | - bool binary = true; |
| 85 | + GripperType gripper_type = GripperType::FrankaHand; |
134 | 86 | virtual ~GripperConfig(){}; |
135 | 87 | }; |
136 | 88 | struct GripperState { |
|
0 commit comments