Skip to content

Commit 35cf4c7

Browse files
0mdcaclegg3
andauthored
New Bullet bindings for teleoperation. (#2548)
* A set of minor bug fixes and exposing some bullet variables used in teleop application * Remove commented early exit. --------- Co-authored-by: Alexander Clegg <[email protected]>
1 parent 7580cbf commit 35cf4c7

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

src/esp/bindings/PhysicsObjectBindings.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,19 @@ void declareArticulatedObjectWrapper(py::module& m,
565565
"'s link specified by the given link_id.")
566566
.c_str(),
567567
"link_id"_a)
568+
.def("get_link_joint_axes", &ManagedArticulatedObject::getLinkJointAxes,
569+
("Get the axes (see btMultiBody top and bottom axis) of the parent "
570+
"joint for this " +
571+
objType + "'s link specified by the given link_id.")
572+
.c_str(),
573+
"link_id"_a)
574+
.def("get_link_joint_to_com",
575+
&ManagedArticulatedObject::getLinkJointToCoM,
576+
("Get the local vector pointing from " + objType +
577+
"'s link' the parent joint to the CoM of the link specified by the "
578+
"given link_id.")
579+
.c_str(),
580+
"link_id"_a)
568581
.def("get_link_joint_name", &ManagedArticulatedObject::getLinkJointName,
569582
("Get the name of the parent joint for this " + objType +
570583
"'s link specified by the given link_id.")
@@ -622,7 +635,8 @@ void declareArticulatedObjectWrapper(py::module& m,
622635
.def("create_all_motors",
623636
&ManagedArticulatedObject::createMotorsForAllDofs,
624637
("Make motors for all of this " + objType +
625-
"'s links which support motors (Revolute, Prismatic, Spherical).")
638+
"'s links which support motors (Revolute, Prismatic, Spherical). "
639+
"Returns a dict mapping new motor ids to link ids.")
626640
.c_str(),
627641
"settings"_a)
628642
.def("update_all_motor_targets",
@@ -638,7 +652,8 @@ void declareArticulatedObjectWrapper(py::module& m,
638652
"state_targets"_a, "velocities"_a = false)
639653
.def("create_joint_motor", &ManagedArticulatedObject::createJointMotor,
640654
("Create a joint motor for the specified DOF on this " + objType +
641-
" using the provided JointMotorSettings")
655+
" using the provided JointMotorSettings. Returns the newly created "
656+
"motor's id.")
642657
.c_str(),
643658
"link"_a, "settings"_a)
644659
.def(

src/esp/physics/ArticulatedObject.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,28 @@ class ArticulatedObject : public esp::physics::PhysicsObjectBase {
589589
return JointType::Invalid;
590590
}
591591

592+
/**
593+
* @brief Get the top and bottom axis vectors for the link's parent joint.
594+
*
595+
* @param linkId The link's index.
596+
* @return The link's parent joint's type.
597+
*/
598+
virtual std::pair<Mn::Vector3, Mn::Vector3> getLinkJointAxes(
599+
CORRADE_UNUSED int linkId) const {
600+
return std::pair<Mn::Vector3, Mn::Vector3>();
601+
}
602+
603+
/**
604+
* @brief gets a local vector pointing from the parent joint to the CoM of the
605+
* link.
606+
*
607+
* @param linkId The link's index.
608+
* @return The a local vector from joint to link CoM.
609+
*/
610+
virtual Mn::Vector3 getLinkJointToCoM(CORRADE_UNUSED int linkId) const {
611+
return Mn::Vector3();
612+
}
613+
592614
/**
593615
* @brief Get the name of the link's parent joint.
594616
*

src/esp/physics/bullet/BulletArticulatedObject.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,29 @@ JointType BulletArticulatedObject::getLinkJointType(int linkId) const {
535535
return JointType(int(btMultiBody_->getLink(linkId).m_jointType));
536536
}
537537

538+
std::pair<Mn::Vector3, Mn::Vector3> BulletArticulatedObject::getLinkJointAxes(
539+
int linkId) const {
540+
// Notes from btMultiBodyLink:
541+
// "axis" = spatial joint axis (Mirtich Defn 9 p104). (expressed in local
542+
// frame.) constant. for prismatic: m_axesTop[0] = zero;
543+
// m_axesBottom[0] = unit vector along the joint axis.
544+
// for revolute: m_axesTop[0] = unit vector along the rotation axis (u);
545+
// m_axesBottom[0] = u cross m_dVector (i.e. COM linear motion
546+
// due to the rotation at the joint)
547+
// NOTE: this implementation will not return the additional components for
548+
// multi-dof joints
549+
auto axt = btMultiBody_->getLink(linkId).m_axes->m_topVec;
550+
auto axb = btMultiBody_->getLink(linkId).m_axes->m_bottomVec;
551+
return std::pair<Mn::Vector3, Mn::Vector3>(Mn::Vector3{axt},
552+
Mn::Vector3{axb});
553+
}
554+
555+
Mn::Vector3 BulletArticulatedObject::getLinkJointToCoM(int linkId) const {
556+
// gets a local vector pointing from the parent joint to the CoM of the link
557+
// use this to solve for the joint position from the link
558+
return Mn::Vector3{btMultiBody_->getLink(linkId).m_dVector};
559+
}
560+
538561
int BulletArticulatedObject::getLinkDoFOffset(int linkId) const {
539562
CORRADE_INTERNAL_ASSERT(getNumLinks() > linkId && linkId >= 0);
540563
return btMultiBody_->getLink(linkId).m_dofOffset;

src/esp/physics/bullet/BulletArticulatedObject.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,25 @@ class BulletArticulatedObject : public ArticulatedObject {
238238
*/
239239
JointType getLinkJointType(CORRADE_UNUSED int linkId) const override;
240240

241+
/**
242+
* @brief Get the top and bottom axis vectors for the link's parent joint. See
243+
* btMultiBody for details.
244+
*
245+
* @param linkId The link's index.
246+
* @return The link's parent joint's axes.
247+
*/
248+
std::pair<Mn::Vector3, Mn::Vector3> getLinkJointAxes(
249+
CORRADE_UNUSED int linkId) const override;
250+
251+
/**
252+
* @brief gets a local vector pointing from the parent joint to the CoM of the
253+
* link.
254+
*
255+
* @param linkId The link's index.
256+
* @return The a local vector from joint to link CoM.
257+
*/
258+
Mn::Vector3 getLinkJointToCoM(CORRADE_UNUSED int linkId) const override;
259+
241260
/**
242261
* @brief Get the starting position for this link's parent joint in the global
243262
* DoFs array.

src/esp/physics/bullet/BulletPhysicsManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,15 @@ bool BulletPhysicsManager::attachLinkGeometry(
371371
// cache the visual component for later query
372372
linkObject->visualAttachments_.emplace_back(
373373
&visualGeomComponent, visual.m_geometry.m_meshFileName);
374-
return true;
374+
} else {
375+
return false;
375376
}
377+
} else {
378+
return false;
376379
}
377380
}
378381

379-
return false;
382+
return true;
380383
}
381384

382385
void BulletPhysicsManager::setGravity(const Magnum::Vector3& gravity) {

src/esp/physics/objectWrappers/ManagedArticulatedObject.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ class ManagedArticulatedObject
219219
return JointType::Invalid;
220220
}
221221

222+
std::pair<Mn::Vector3, Mn::Vector3> getLinkJointAxes(int linkId) const {
223+
if (auto sp = getObjectReference()) {
224+
return sp->getLinkJointAxes(linkId);
225+
}
226+
return std::pair<Mn::Vector3, Mn::Vector3>();
227+
}
228+
229+
Mn::Vector3 getLinkJointToCoM(CORRADE_UNUSED int linkId) const {
230+
if (auto sp = getObjectReference()) {
231+
return sp->getLinkJointToCoM(linkId);
232+
}
233+
return Mn::Vector3();
234+
}
235+
222236
std::string getLinkJointName(int linkId) const {
223237
if (auto sp = getObjectReference()) {
224238
return sp->getLinkJointName(linkId);

0 commit comments

Comments
 (0)