-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathManagedArticulatedObject.h
373 lines (321 loc) · 9.66 KB
/
ManagedArticulatedObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Copyright (c) Meta Platforms, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#ifndef ESP_PHYSICS_MANAGEDARTICULATEDOBJECT_H_
#define ESP_PHYSICS_MANAGEDARTICULATEDOBJECT_H_
#include "ManagedPhysicsObjectBase.h"
#include "esp/physics/ArticulatedObject.h"
namespace esp {
namespace physics {
/**
* @brief Class describing wrapper for ArticulatedObject constructions.
* Provides bindings for all ArticulatedObject-specific functionality.
*/
class ManagedArticulatedObject
: public esp::physics::AbstractManagedPhysicsObject<
esp::physics::ArticulatedObject> {
public:
explicit ManagedArticulatedObject(
const std::string& classKey = "ManagedArticulatedObject")
: AbstractManagedPhysicsObject<esp::physics::ArticulatedObject>::
AbstractManagedPhysicsObject(classKey) {}
/**
* @brief Get a copy of the template attributes describing the initial state
* of this articulated object. These attributes have the combination of date
* from the original articulated object attributes and specific instance
* attributes used to create this articulated object. Note : values will
* reflect both sources, and should not be saved to disk as articulated object
* attributes, since instance attribute modifications will still occur on
* subsequent loads
*/
std::shared_ptr<metadata::attributes::ArticulatedObjectAttributes>
getInitializationAttributes() const {
if (auto sp = this->getObjectReference()) {
return sp->getInitializationAttributes();
}
return nullptr;
} // getInitializationAttributes()
float getGlobalScale() const {
if (auto sp = getObjectReference()) {
return sp->getGlobalScale();
}
return 1.0;
}
scene::SceneNode* getLinkSceneNode(int linkId = BASELINK_ID) const {
if (auto sp = getObjectReference()) {
return &const_cast<scene::SceneNode&>(sp->getLinkSceneNode(linkId));
}
return nullptr;
}
std::vector<scene::SceneNode*> getLinkVisualSceneNodes(
int linkId = BASELINK_ID) const {
if (auto sp = getObjectReference()) {
return sp->getLinkVisualSceneNodes(linkId);
}
return {};
}
ArticulatedLink* getLink(int linkId) const {
if (auto sp = getObjectReference()) {
return &sp->getLink(linkId);
}
return nullptr;
}
int getNumLinks() const {
if (auto sp = getObjectReference()) {
return sp->getNumLinks();
}
return ID_UNDEFINED;
}
std::vector<int> getLinkIds() const {
if (auto sp = getObjectReference()) {
return sp->getLinkIds();
}
return {};
}
std::vector<int> getLinkIdsWithBase() const {
if (auto sp = getObjectReference()) {
return sp->getLinkIdsWithBase();
}
return {};
}
int getLinkIdFromName(const std::string& _name) const {
if (auto sp = getObjectReference()) {
return sp->getLinkIdFromName(_name);
}
return ID_UNDEFINED;
}
std::unordered_map<int, int> getLinkObjectIds() const {
if (auto sp = getObjectReference()) {
return sp->getLinkObjectIds();
}
return {};
}
std::unordered_map<int, int> getLinkIdsToObjectIds() const {
if (auto sp = getObjectReference()) {
return sp->getLinkIdsToObjectIds();
}
return {};
}
void setRootLinearVelocity(const Mn::Vector3& linVel) {
if (auto sp = getObjectReference()) {
sp->setRootLinearVelocity(linVel);
}
}
Mn::Vector3 getRootLinearVelocity() const {
if (auto sp = getObjectReference()) {
return sp->getRootLinearVelocity();
}
return Mn::Vector3(0);
}
void setRootAngularVelocity(const Mn::Vector3& angVel) {
if (auto sp = getObjectReference()) {
sp->setRootAngularVelocity(angVel);
}
}
Mn::Vector3 getRootAngularVelocity() const {
if (auto sp = getObjectReference()) {
return sp->getRootAngularVelocity();
}
return Mn::Vector3(0);
}
void setJointForces(const std::vector<float>& forces) {
if (auto sp = getObjectReference()) {
sp->setJointForces(forces);
}
}
void addJointForces(const std::vector<float>& forces) {
if (auto sp = getObjectReference()) {
sp->addJointForces(forces);
}
}
std::vector<float> getJointForces() {
if (auto sp = getObjectReference()) {
return sp->getJointForces();
}
return {};
}
void setJointVelocities(const std::vector<float>& vels) {
if (auto sp = getObjectReference()) {
sp->setJointVelocities(vels);
}
}
std::vector<float> getJointVelocities() {
if (auto sp = getObjectReference()) {
return sp->getJointVelocities();
}
return {};
}
void setJointPositions(const std::vector<float>& positions) {
if (auto sp = getObjectReference()) {
sp->setJointPositions(positions);
}
}
std::vector<float> getJointPositions() {
if (auto sp = getObjectReference()) {
return sp->getJointPositions();
}
return {};
}
std::vector<float> getJointMotorTorques(double fixedTimeStep) {
if (auto sp = getObjectReference()) {
return sp->getJointMotorTorques(fixedTimeStep);
}
return {};
}
std::pair<std::vector<float>, std::vector<float>> getJointPositionLimits() {
if (auto sp = getObjectReference()) {
return sp->getJointPositionLimits();
}
return {};
}
void addArticulatedLinkForce(int linkId, Magnum::Vector3 force) {
if (auto sp = getObjectReference()) {
sp->addArticulatedLinkForce(linkId, force);
}
}
float getArticulatedLinkFriction(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getArticulatedLinkFriction(linkId);
}
return 0.0;
}
void setArticulatedLinkFriction(int linkId, float friction) {
if (auto sp = getObjectReference()) {
sp->setArticulatedLinkFriction(linkId, friction);
}
}
JointType getLinkJointType(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkJointType(linkId);
}
return JointType::Invalid;
}
std::string getLinkJointName(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkJointName(linkId);
}
return "";
}
std::string getLinkName(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkName(linkId);
}
return "";
}
int getLinkDoFOffset(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkDoFOffset(linkId);
}
return ID_UNDEFINED;
}
int getLinkNumDoFs(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkNumDoFs(linkId);
}
return 0;
}
int getLinkJointPosOffset(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkJointPosOffset(linkId);
}
return ID_UNDEFINED;
}
int getLinkNumJointPos(int linkId) const {
if (auto sp = getObjectReference()) {
return sp->getLinkNumJointPos(linkId);
}
return 0;
}
void reset() {
if (auto sp = getObjectReference()) {
sp->reset();
}
}
bool getCanSleep() const {
if (auto sp = getObjectReference()) {
return sp->getCanSleep();
}
return false;
}
void setAutoClampJointLimits(bool autoClamp) {
if (auto sp = getObjectReference()) {
sp->setAutoClampJointLimits(autoClamp);
}
}
bool getAutoClampJointLimits() const {
if (auto sp = getObjectReference()) {
return sp->getAutoClampJointLimits();
}
return false;
}
void clampJointLimits() {
if (auto sp = getObjectReference()) {
sp->clampJointLimits();
}
}
int createJointMotor(const int dof,
const JointMotorSettings& settings) const {
if (auto sp = getObjectReference()) {
return sp->createJointMotor(dof, settings);
}
return ID_UNDEFINED;
}
void removeJointMotor(const int motorId) {
if (auto sp = getObjectReference()) {
sp->removeJointMotor(motorId);
}
}
JointMotorSettings getJointMotorSettings(const int motorId) const {
if (auto sp = getObjectReference()) {
return sp->getJointMotorSettings(motorId);
}
return {};
}
void updateJointMotor(const int motorId, const JointMotorSettings& settings) {
if (auto sp = getObjectReference()) {
sp->updateJointMotor(motorId, settings);
}
}
std::unordered_map<int, int> getExistingJointMotors() const {
if (auto sp = getObjectReference()) {
return sp->getExistingJointMotors();
}
return {};
}
std::unordered_map<int, int> createMotorsForAllDofs(
const JointMotorSettings& settings) {
if (auto sp = getObjectReference()) {
return sp->createMotorsForAllDofs(settings);
}
return {};
}
void updateAllMotorTargets(const std::vector<float>& stateTargets,
bool velocities) {
if (auto sp = getObjectReference()) {
sp->updateAllMotorTargets(stateTargets, velocities);
}
}
protected:
/**
* @brief Retrieve a comma-separated string holding the header values for the
* info returned for this managed object, type-specific.
*/
std::string getPhyObjInfoHeaderInternal() const override {
// TODO fill out appropriate reporting values
return "# links";
}
/**
* @brief Specialization-specific extension of getObjectInfo, comma separated
* info ideal for saving to csv
*/
std::string getPhysObjInfoInternal(
std::shared_ptr<esp::physics::ArticulatedObject>& sp) const override {
// TODO fill out appropriate reporting values
return std::to_string(sp->getNumLinks());
}
public:
ESP_SMART_POINTERS(ManagedArticulatedObject)
}; // namespace physics
} // namespace physics
} // namespace esp
#endif // ESP_PHYSICS_MANAGEDARTICULATEDOBJECT_H_