Skip to content

Commit 1ac8882

Browse files
committed
Add option to build composites and compute kinematics
Modifies FrameBodyPoseCache, position kinematics cache, and velocity kinematics cache. Loosens two tolerances so that Mac CI passes. Rebased on body->link terminology change.
1 parent 6f645f4 commit 1ac8882

18 files changed

Lines changed: 736 additions & 98 deletions

bindings/pydrake/multibody/test/plant_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
AddMultibodyPlant,
6060
AddMultibodyPlantSceneGraph,
6161
ApplyMultibodyPlantConfig,
62-
BaseBodyJointType,
6362
CalcContactFrictionFromSurfaceProperties,
6463
ConnectContactResultsToDrakeVisualizer,
6564
ContactModel,
@@ -81,6 +80,7 @@
8180
)
8281
from pydrake.multibody.tree import (
8382
BallRpyJoint_,
83+
BaseBodyJointType,
8484
Body_, # dispreferred alias for RigidBody_
8585
BodyIndex,
8686
CalcSpatialInertia,

bindings/pydrake/multibody/tree_py.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ void DoScalarIndependentDefinitions(py::module m) {
148148
.value("kV", Enum::kV, enum_doc.kV.doc);
149149
}
150150

151+
{
152+
using Enum = BaseBodyJointType;
153+
constexpr auto& cls_doc = doc.BaseBodyJointType;
154+
py::enum_<Enum> cls(m, "BaseBodyJointType", cls_doc.doc);
155+
cls.value("kQuaternionFloatingJoint", Enum::kQuaternionFloatingJoint,
156+
cls_doc.kQuaternionFloatingJoint.doc)
157+
.value("kRpyFloatingJoint", Enum::kRpyFloatingJoint,
158+
cls_doc.kRpyFloatingJoint.doc)
159+
.value("kWeldJoint", Enum::kWeldJoint, cls_doc.kWeldJoint.doc);
160+
}
161+
151162
{
152163
using Class = ScopedName;
153164
constexpr auto& cls_doc = doc.ScopedName;

multibody/optimization/test/toppra_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ TEST_F(IiwaToppraTest, JointTorqueLimit) {
210210
auto s_path = result.value();
211211

212212
// This tolerance was tuned to work with the given gridpoints.
213-
const double tol = 1e-14;
213+
const double tol = 1e-13;
214214
Eigen::MatrixXd M(7, 7);
215215
Eigen::VectorXd Cv(7);
216216
Eigen::VectorXd G(7);

multibody/plant/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ drake_cc_googletest(
458458
],
459459
)
460460

461+
drake_cc_googletest(
462+
name = "composite_test",
463+
deps = [
464+
":plant",
465+
"//common/test_utilities:eigen_matrix_compare",
466+
],
467+
)
468+
461469
drake_cc_googletest(
462470
name = "compliant_contact_manager_scalar_conversion_test",
463471
deps = [

multibody/plant/multibody_plant.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,12 +1421,24 @@ void MultibodyPlant<T>::SetBaseBodyJointType(
14211421
mutable_tree().SetBaseBodyJointType(joint_type, model_instance);
14221422
}
14231423

1424+
template <typename T>
1425+
void MultibodyPlant<T>::SetCombineWeldedBodies(
1426+
bool combine, std::optional<ModelInstanceIndex> model_instance) {
1427+
mutable_tree().SetCombineWeldedBodies(combine, model_instance);
1428+
}
1429+
14241430
template <typename T>
14251431
BaseBodyJointType MultibodyPlant<T>::GetBaseBodyJointType(
14261432
std::optional<ModelInstanceIndex> model_instance) const {
14271433
return internal_tree().GetBaseBodyJointType(model_instance);
14281434
}
14291435

1436+
template <typename T>
1437+
bool MultibodyPlant<T>::GetCombineWeldedBodies(
1438+
std::optional<ModelInstanceIndex> model_instance) const {
1439+
return internal_tree().GetCombineWeldedBodies(model_instance);
1440+
}
1441+
14301442
template <typename T>
14311443
void MultibodyPlant<T>::Finalize() {
14321444
// After finalizing the base class, tree is read-only.

multibody/plant/multibody_plant.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,11 +1760,28 @@ class MultibodyPlant final : public internal::MultibodyTreeSystem<T> {
17601760
/// @param[in] model_instance (optional) the index of the model instance to
17611761
/// which `joint_type` is to be applied.
17621762
/// @throws std::exception if called after Finalize().
1763-
/// @see GetBaseBodyJointType(), Finalize()
1763+
/// @see GetBaseBodyJointType(), SetCombineWeldedBodies(), Finalize()
17641764
void SetBaseBodyJointType(
17651765
BaseBodyJointType joint_type,
17661766
std::optional<ModelInstanceIndex> model_instance = {});
17671767

1768+
/// Controls whether welded-together RigidBody elements are to be combined
1769+
/// into a single composite mobilized body in the generated model. If so,
1770+
/// the Weld joints will not appear in the post-Finalize() model and there
1771+
/// will be fewer bodies and joints in the generated model than in the user's
1772+
/// specification. Results for the original RigidBody elements can still be
1773+
/// obtained by name or BodyIndex, but no results (in particular, no reaction
1774+
/// forces) are available for the unmodeled Weld joints.
1775+
///
1776+
/// You can set this globally or on a per-model instance basis.
1777+
///
1778+
/// The default for Drake is _not_ to combine welded RigidBody elements.
1779+
///
1780+
/// @throws std::exception if called after Finalize().
1781+
/// @see GetCombineWeldedBodies(), SetBaseBodyJointType(), Finalize()
1782+
void SetCombineWeldedBodies(
1783+
bool combine, std::optional<ModelInstanceIndex> model_instance = {});
1784+
17681785
/// Returns the currently-set choice for base body joint type, either for
17691786
/// the global setting or for a specific model instance if provided.
17701787
/// If a model instance is provided for which no explicit choice has been
@@ -1773,10 +1790,23 @@ class MultibodyPlant final : public internal::MultibodyTreeSystem<T> {
17731790
/// This can be called any time -- pre-finalize it returns the joint type
17741791
/// that will be used by Finalize(); post-finalize it returns the joint type
17751792
/// that _was_ used if there were any base bodies in need of a joint.
1776-
/// @see SetBaseBodyJointType(), Finalize()
1793+
/// @see SetBaseBodyJointType(), GetCombineWeldedBodies(), Finalize()
17771794
BaseBodyJointType GetBaseBodyJointType(
17781795
std::optional<ModelInstanceIndex> model_instance = {}) const;
17791796

1797+
/// Returns the currently-set choice for whether welded-together bodies
1798+
/// should be combined or modeled separately, either for the global setting
1799+
/// or for a specific model instance. If a model instance is provided for
1800+
/// which no explicit choice was made, the global setting is returned. Any
1801+
/// model instance index is acceptable here; if not recognized then the global
1802+
/// setting is returned. This can be called any time -- pre-finalize it
1803+
/// returns the setting that will be used by Finalize(); post-finalize it
1804+
/// returns the setting that _was_ used if there were any welded-together
1805+
/// bodies.
1806+
/// @see SetCombineWeldedBodies(), GetBaseBodyJointType(), Finalize()
1807+
bool GetCombineWeldedBodies(
1808+
std::optional<ModelInstanceIndex> model_instance = {}) const;
1809+
17801810
/// This method must be called after all elements in the model (joints,
17811811
/// bodies, force elements, constraints, etc.) are added and before any
17821812
/// computations are performed.

0 commit comments

Comments
 (0)