Skip to content

Commit f132ca1

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 1b9ae2f commit f132ca1

18 files changed

Lines changed: 788 additions & 120 deletions

bindings/generated_docstrings/multibody_plant.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4942,7 +4942,7 @@ be used by Finalize(); post-finalize it returns the joint type that
49424942
*was* used if there were any base bodies in need of a joint.
49434943
49444944
See also:
4945-
SetBaseBodyJointType(), Finalize())""";
4945+
SetBaseBodyJointType(), GetCombineWeldedBodies(), Finalize())""";
49464946
} GetBaseBodyJointType;
49474947
// Symbol: drake::multibody::MultibodyPlant::GetBodiesKinematicallyAffectedBy
49484948
struct /* GetBodiesKinematicallyAffectedBy */ {
@@ -5099,6 +5099,23 @@ geometries for ``body`` previously registered with a SceneGraph.
50995099
See also:
51005100
RegisterCollisionGeometry(), Finalize())""";
51015101
} GetCollisionGeometriesForBody;
5102+
// Symbol: drake::multibody::MultibodyPlant::GetCombineWeldedBodies
5103+
struct /* GetCombineWeldedBodies */ {
5104+
// Source: drake/multibody/plant/multibody_plant.h
5105+
const char* doc =
5106+
R"""(Returns the currently-set choice for whether welded-together bodies
5107+
should be combined or modeled separately, either for the global
5108+
setting or for a specific model instance. If a model instance is
5109+
provided for which no explicit choice was made, the global setting is
5110+
returned. Any model instance index is acceptable here; if not
5111+
recognized then the global setting is returned. This can be called any
5112+
time -- pre-finalize it returns the setting that will be used by
5113+
Finalize(); post-finalize it returns the setting that *was* used if
5114+
there were any welded-together bodies.
5115+
5116+
See also:
5117+
SetCombineWeldedBodies(), GetBaseBodyJointType(), Finalize())""";
5118+
} GetCombineWeldedBodies;
51025119
// Symbol: drake::multibody::MultibodyPlant::GetConstraintActiveStatus
51035120
struct /* GetConstraintActiveStatus */ {
51045121
// Source: drake/multibody/plant/multibody_plant.h
@@ -6602,8 +6619,30 @@ Parameter ``model_instance``:
66026619
RuntimeError if called after Finalize().
66036620
66046621
See also:
6605-
GetBaseBodyJointType(), Finalize())""";
6622+
GetBaseBodyJointType(), SetCombineWeldedBodies(), Finalize())""";
66066623
} SetBaseBodyJointType;
6624+
// Symbol: drake::multibody::MultibodyPlant::SetCombineWeldedBodies
6625+
struct /* SetCombineWeldedBodies */ {
6626+
// Source: drake/multibody/plant/multibody_plant.h
6627+
const char* doc =
6628+
R"""(Controls whether welded-together RigidBody elements are to be combined
6629+
into a single composite mobilized body in the generated model. If so,
6630+
the Weld joints will not appear in the post-Finalize() model and there
6631+
will be fewer bodies and joints in the generated model than in the
6632+
user's specification. Results for the original RigidBody elements can
6633+
still be obtained by name or BodyIndex, but no results (in particular,
6634+
no reaction forces) are available for the unmodeled Weld joints.
6635+
6636+
You can set this globally or on a per-model instance basis.
6637+
6638+
The default for Drake is *not* to combine welded RigidBody elements.
6639+
6640+
Raises:
6641+
RuntimeError if called after Finalize().
6642+
6643+
See also:
6644+
GetCombineWeldedBodies(), SetBaseBodyJointType(), Finalize())""";
6645+
} SetCombineWeldedBodies;
66076646
// Symbol: drake::multibody::MultibodyPlant::SetConstraintActiveStatus
66086647
struct /* SetConstraintActiveStatus */ {
66096648
// Source: drake/multibody/plant/multibody_plant.h

bindings/generated_docstrings/multibody_tree.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7370,7 +7370,8 @@ R"""(For a floating base RigidBody, unlock its inboard joint.
73707370
struct /* body_frame */ {
73717371
// Source: drake/multibody/tree/rigid_body.h
73727372
const char* doc =
7373-
R"""((Compatibility) A synonym for link_frame().)""";
7373+
R"""(Returns a const reference to the associated RigidBodyFrame
7374+
(LinkFrame). This is a synonym for link_frame().)""";
73747375
} body_frame;
73757376
// Symbol: drake::multibody::RigidBody::default_com
73767377
struct /* default_com */ {
@@ -7531,14 +7532,14 @@ Returns ``alpha_WB_W``:
75317532
struct /* get_angular_velocity_in_world */ {
75327533
// Source: drake/multibody/tree/rigid_body.h
75337534
const char* doc =
7534-
R"""((Advanced) Extract this body's angular velocity in world, expressed in
7535+
R"""((Advanced) Extract this link's angular velocity in world, expressed in
75357536
world.
75367537
75377538
Parameter ``vc``:
75387539
velocity kinematics cache.
75397540
7540-
Returns ``w_WB_W``:
7541-
rigid body B's angular velocity in world W, expressed in W.)""";
7541+
Returns ``w_WL_W``:
7542+
link L's angular velocity in world W, expressed in W.)""";
75427543
} get_angular_velocity_in_world;
75437544
// Symbol: drake::multibody::RigidBody::get_mass
75447545
struct /* get_mass */ {
@@ -7575,35 +7576,35 @@ body's origin, expressed in world.
75757576
Parameter ``pc``:
75767577
position kinematics cache.
75777578
7578-
Returns ``p_WoBo_W``:
7579-
position vector from Wo (world origin) to Bo (this body's origin)
7579+
Returns ``p_WoLo_W``:
7580+
position vector from Wo (world origin) to Lo (this link's origin)
75807581
expressed in W (world).)""";
75817582
} get_origin_position_in_world;
75827583
// Symbol: drake::multibody::RigidBody::get_origin_velocity_in_world
75837584
struct /* get_origin_velocity_in_world */ {
75847585
// Source: drake/multibody/tree/rigid_body.h
75857586
const char* doc =
7586-
R"""((Advanced) Extract the velocity of this body's origin in world,
7587+
R"""((Advanced) Extract the velocity of this link's origin in world,
75877588
expressed in world.
75887589
75897590
Parameter ``vc``:
75907591
velocity kinematics cache.
75917592
7592-
Returns ``v_WBo_W``:
7593-
velocity of Bo (body origin) in world W, expressed in W.)""";
7593+
Returns ``v_WLo_W``:
7594+
velocity of Lo (link frame origin) in world W, expressed in W.)""";
75947595
} get_origin_velocity_in_world;
75957596
// Symbol: drake::multibody::RigidBody::get_pose_in_world
75967597
struct /* get_pose_in_world */ {
75977598
// Source: drake/multibody/tree/rigid_body.h
75987599
const char* doc =
7599-
R"""((Advanced) Extract this body's pose in world (from the position
7600+
R"""((Advanced) Extract this link's pose in world (from the position
76007601
kinematics).
76017602
76027603
Parameter ``pc``:
76037604
position kinematics cache.
76047605
7605-
Returns ``X_WB``:
7606-
pose of rigid body B in world frame W.)""";
7606+
Returns ``X_WL``:
7607+
pose of this Link (%RigidBody) L in world frame W.)""";
76077608
} get_pose_in_world;
76087609
// Symbol: drake::multibody::RigidBody::get_rotation_matrix_in_world
76097610
struct /* get_rotation_matrix_in_world */ {
@@ -7615,8 +7616,9 @@ body's frame.
76157616
Parameter ``pc``:
76167617
position kinematics cache.
76177618
7618-
Returns ``R_WB``:
7619-
rotation matrix relating rigid body B in world frame W.)""";
7619+
Returns ``R_WL``:
7620+
rotation matrix giving the orientation of this Link L in the world
7621+
frame W.)""";
76207622
} get_rotation_matrix_in_world;
76217623
// Symbol: drake::multibody::RigidBody::get_spatial_acceleration_in_world
76227624
struct /* get_spatial_acceleration_in_world */ {
@@ -7636,15 +7638,15 @@ Returns ``A_WB_W``:
76367638
struct /* get_spatial_velocity_in_world */ {
76377639
// Source: drake/multibody/tree/rigid_body.h
76387640
const char* doc =
7639-
R"""((Advanced) Returns V_WB, this RigidBody B's SpatialVelocity in the
7640-
world frame W.
7641+
R"""((Advanced) Returns V_WL, this Link (%RigidBody) L's SpatialVelocity in
7642+
the world frame W.
76417643
76427644
Parameter ``vc``:
76437645
velocity kinematics cache.
76447646
7645-
Returns ``V_WB_W``:
7646-
this rigid body B's spatial velocity in the world frame W,
7647-
expressed in W (for point Bo, the body frame's origin).)""";
7647+
Returns ``V_WL_W``:
7648+
this link L's spatial velocity in the world frame W, expressed in
7649+
W (for point Lo, the link frame's origin).)""";
76487650
} get_spatial_velocity_in_world;
76497651
// Symbol: drake::multibody::RigidBody::has_quaternion_dofs
76507652
struct /* has_quaternion_dofs */ {
@@ -7682,7 +7684,7 @@ R"""((Deprecated.)
76827684
// Source: drake/multibody/tree/rigid_body.h
76837685
const char* doc =
76847686
R"""((Advanced) Returns ``True`` if this body is a *floating base body*,
7685-
meaning it had no explicit joint to a parent body so is mobilized by
7687+
meaning it had no explicit joint to a parent body and is mobilized by
76867688
an automatically-added (ephemeral) floating (6 dof) joint to World.
76877689
76887690
Note:
@@ -7713,7 +7715,7 @@ generally Joint∷is_locked() is preferable otherwise.
77137715
// Source: drake/multibody/tree/rigid_body.h
77147716
const char* doc =
77157717
R"""(Returns a const reference to the associated LinkFrame
7716-
(RigidBodyFrame).)""";
7718+
(RigidBodyFrame). This is a synonym for body_frame().)""";
77177719
} link_frame;
77187720
// Symbol: drake::multibody::RigidBody::mobod_index
77197721
struct /* mobod_index */ {

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)