Skip to content

Commit 91b0c93

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. Working on acceleration kinematics. Working on force elements
1 parent b72c800 commit 91b0c93

35 files changed

Lines changed: 1341 additions & 474 deletions

bindings/generated_docstrings/multibody_plant.h

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,7 +3744,7 @@ method computes:
37443744
where ``M(q)`` is the model's mass matrix (including rigid body mass
37453745
properties and reflected_inertia "reflected inertias"), ``C(q, v)v``
37463746
is the bias term for Coriolis and gyroscopic effects and ``tau_app``
3747-
consists of a vector applied generalized forces. The last term is a
3747+
consists of a vector of applied generalized forces. The last term is a
37483748
summation over all bodies in the model where ``Fapp_Bo_W`` is an
37493749
applied spatial force on body B at ``Bo`` which gets projected into
37503750
the space of generalized forces with the transpose of ``Jv_V_WB(q)``
@@ -5003,7 +5003,7 @@ be used by Finalize(); post-finalize it returns the joint type that
50035003
*was* used if there were any base bodies in need of a joint.
50045004
50055005
See also:
5006-
SetBaseBodyJointType(), Finalize())""";
5006+
SetBaseBodyJointType(), GetCombineWeldedBodies(), Finalize())""";
50075007
} GetBaseBodyJointType;
50085008
// Symbol: drake::multibody::MultibodyPlant::GetBodiesKinematicallyAffectedBy
50095009
struct /* GetBodiesKinematicallyAffectedBy */ {
@@ -5160,6 +5160,23 @@ geometries for ``body`` previously registered with a SceneGraph.
51605160
See also:
51615161
RegisterCollisionGeometry(), Finalize())""";
51625162
} GetCollisionGeometriesForBody;
5163+
// Symbol: drake::multibody::MultibodyPlant::GetCombineWeldedBodies
5164+
struct /* GetCombineWeldedBodies */ {
5165+
// Source: drake/multibody/plant/multibody_plant.h
5166+
const char* doc =
5167+
R"""(Returns the currently-set choice for whether welded-together bodies
5168+
should be combined or modeled separately, either for the global
5169+
setting or for a specific model instance. If a model instance is
5170+
provided for which no explicit choice was made, the global setting is
5171+
returned. Any model instance index is acceptable here; if not
5172+
recognized then the global setting is returned. This can be called any
5173+
time -- pre-finalize it returns the setting that will be used by
5174+
Finalize(); post-finalize it returns the setting that *was* used if
5175+
there were any welded-together bodies.
5176+
5177+
See also:
5178+
SetCombineWeldedBodies(), GetBaseBodyJointType(), Finalize())""";
5179+
} GetCombineWeldedBodies;
51635180
// Symbol: drake::multibody::MultibodyPlant::GetConstraintActiveStatus
51645181
struct /* GetConstraintActiveStatus */ {
51655182
// Source: drake/multibody/plant/multibody_plant.h
@@ -6633,8 +6650,30 @@ Parameter ``model_instance``:
66336650
RuntimeError if called after Finalize().
66346651
66356652
See also:
6636-
GetBaseBodyJointType(), Finalize())""";
6653+
GetBaseBodyJointType(), SetCombineWeldedBodies(), Finalize())""";
66376654
} SetBaseBodyJointType;
6655+
// Symbol: drake::multibody::MultibodyPlant::SetCombineWeldedBodies
6656+
struct /* SetCombineWeldedBodies */ {
6657+
// Source: drake/multibody/plant/multibody_plant.h
6658+
const char* doc =
6659+
R"""(Controls whether welded-together RigidBody elements are to be combined
6660+
into a single composite mobilized body in the generated model. If so,
6661+
the Weld joints will not appear in the post-Finalize() model and there
6662+
will be fewer bodies and joints in the generated model than in the
6663+
user's specification. Results for the original RigidBody elements can
6664+
still be obtained by name or BodyIndex, but no results (in particular,
6665+
no reaction forces) are available for the unmodeled Weld joints.
6666+
6667+
You can set this globally or on a per-model instance basis.
6668+
6669+
The default for Drake is *not* to combine welded RigidBody elements.
6670+
6671+
Raises:
6672+
RuntimeError if called after Finalize().
6673+
6674+
See also:
6675+
GetCombineWeldedBodies(), SetBaseBodyJointType(), Finalize())""";
6676+
} SetCombineWeldedBodies;
66386677
// Symbol: drake::multibody::MultibodyPlant::SetConstraintActiveStatus
66396678
struct /* SetConstraintActiveStatus */ {
66406679
// Source: drake/multibody/plant/multibody_plant.h

bindings/generated_docstrings/multibody_tree.h

Lines changed: 76 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,14 +1956,14 @@ R"""(Returns the owning MultibodyPlant LeafSystem.
19561956
// Source: drake/multibody/tree/force_element.h
19571957
const char* doc =
19581958
R"""(A ForceElement allows modeling state and time dependent forces in a
1959-
MultibodyTree model. Examples of such forces are springs, dampers,
1959+
MultibodyPlant model. Examples of such forces are springs, dampers,
19601960
drag and gravity. Forces that depend on accelerations such as virtual
19611961
mass cannot be modeled with a ForceElement. This abstract class
19621962
provides an API that all force elements subclasses must implement in
19631963
order to be fully defined. These are:
19641964
19651965
- CalcAndAddForceContribution(): computes the force contribution of a force
1966-
element in a MultibodyTree model.
1966+
element in a MultibodyPlant model.
19671967
- CalcPotentialEnergy(): computes a force element potential energy
19681968
contribution.
19691969
- CalcConservativePower(): computes the power generated by conservative
@@ -1980,7 +1980,7 @@ model, different force elements may write into the array of spatial
19801980
forces ``F_B_W`` or the array of generalized forces ``tau``.
19811981
19821982
Parameter ``context``:
1983-
The context containing the state of the MultibodyTree model.
1983+
The context containing the state of the MultibodyPlant model.
19841984
19851985
Parameter ``pc``:
19861986
A position kinematics cache object already updated to be in sync
@@ -1995,7 +1995,7 @@ Parameter ``forces``:
19951995
output ``this`` force element adds its contribution into
19961996
``forces``. This method will abort if the ``forces`` pointer is
19971997
null or if the forces object is not compatible with ``this``
1998-
MultibodyTree, see MultibodyForces∷CheckInvariants().
1998+
MultibodyPlant, see MultibodyForces∷CheckInvariants().
19991999
20002000
Precondition:
20012001
The position kinematics ``pc`` must have been previously updated
@@ -2076,6 +2076,13 @@ parameters of this method. It assumes ``forces`` to be a valid pointer
20762076
to a MultibodyForces object compatible with the MultibodyTree model
20772077
owning ``this`` force element.
20782078
2079+
Note:
2080+
Although spatial forces are applied to *links*, it is the
2081+
responsibility of the implementation to shift those forces to the
2082+
mobilized bodies that the links follow. When we are combining
2083+
welded-together links into composites, there can be multiple links
2084+
on the same mobilized body.
2085+
20792086
Precondition:
20802087
The position kinematics ``pc`` must have been previously updated
20812088
with a call to CalcPositionKinematicsCache().
@@ -4596,16 +4603,16 @@ class documentation states that a Space-fixed (extrinsic) X-Y-Z
45964603
rotation with roll-pitch-yaw angles [q₀ q₁ q₂] is equivalent to a
45974604
Body-fixed (intrinsic) Z-Y-X rotation by yaw-pitch-roll angles [q₂ q₁
45984605
q₀]. In the context of "gimbal torques", the Body-fixed Z-Y-X rotation
4599-
sequence with angles [q₂ q₁ q₀] is physical meaningful as it produces
4600-
torques associated with successive frames in a gimbal as τ₂ 𝐀𝐳, τ₁ 𝐏𝐲,
4601-
τ₀ 𝐂𝐱, where each of 𝐀𝐳, 𝐏𝐲, 𝐂𝐱 are unit vectors associated with a
4602-
frame in the yaw-pitch-roll rotation sequence and 𝐏𝐲 is a unit vector
4603-
of the "pitch" intermediate frame. As described earlier, torque 𝐭 is
4604-
the moment of the bushing forces on frame C about Cp. Scalars tx, ty,
4605-
tz are defined so 𝐭 can be expressed ``𝐭 = [tx ty tz]ᴀ = tx 𝐀𝐱 + ty 𝐀𝐲
4606-
+ tz 𝐀𝐳``. As shown in code documentation, the relationship of [tx ty
4607-
tz] to [τ₀ τ₁ τ₂] was found by equating 𝐭's power to τ's power as 𝐭 ⋅
4608-
w_AC = τ ⋅ q̇.
4606+
sequence with angles [q₂ q₁ q₀] is physically meaningful as it
4607+
produces torques associated with successive frames in a gimbal as τ₂
4608+
𝐀𝐳, τ₁ 𝐏𝐲, τ₀ 𝐂𝐱, where each of 𝐀𝐳, 𝐏𝐲, 𝐂𝐱 are unit vectors associated
4609+
with a frame in the yaw-pitch-roll rotation sequence and 𝐏𝐲 is a unit
4610+
vector of the "pitch" intermediate frame. As described earlier, torque
4611+
𝐭 is the moment of the bushing forces on frame C about Cp. Scalars tx,
4612+
ty, tz are defined so 𝐭 can be expressed ``𝐭 = [tx ty tz]ᴀ = tx 𝐀𝐱 +
4613+
ty 𝐀𝐲 + tz 𝐀𝐳``. As shown in code documentation, the relationship of
4614+
[tx ty tz] to [τ₀ τ₁ τ₂] was found by equating 𝐭's power to τ's power
4615+
as 𝐭 ⋅ w_AC = τ ⋅ q̇.
46094616
46104617
46114618
.. raw:: html
@@ -5016,9 +5023,9 @@ to choose torque stiffness and damping constants" for more details.)""";
50165023
// Source: drake/multibody/tree/linear_spring_damper.h
50175024
const char* doc =
50185025
R"""(This ForceElement models a spring-damper attached between two points
5019-
on two different bodies (links). Given a point P on a body A and a
5020-
point Q on a body B with positions p_AP and p_BQ, respectively, this
5021-
spring-damper applies equal and opposite forces on bodies A and B
5026+
on two different links (bodies). Given a point P on a link A and a
5027+
point Q on a link B with positions p_AP and p_BQ, respectively, this
5028+
spring-damper applies equal and opposite forces on links A and B
50225029
according to:
50235030
50245031
@@ -5040,7 +5047,7 @@ its rate of change, ``r̂ = (p_WQ - p_WP) / ℓ`` is the normalized
50405047
vector from P to Q, ℓ₀ is the free length of the spring and k and c
50415048
are the stiffness and damping of the spring-damper, respectively. This
50425049
ForceElement is meant to model finite free length springs attached
5043-
between two points. In this typical arrangement springs are usually
5050+
between two points. In the typical arrangement springs are usually
50445051
pre-loaded, meaning they apply a non-zero spring force in the static
50455052
configuration of the system. Thus, neither the free length ℓ₀ nor the
50465053
current length ℓ of the spring can ever be zero. The length of the
@@ -5049,7 +5056,7 @@ and therefore this element throws a RuntimeError exception in that
50495056
case. Note that:
50505057
50515058
- The applied force is always along the line connecting points P and
5052-
Q. - Damping always dissipates energy. - Forces on bodies A and B are
5059+
Q. - Damping always dissipates energy. - Forces on links A and B are
50535060
equal and opposite according to Newton's third law.)""";
50545061
// Symbol: drake::multibody::LinearSpringDamper::CalcConservativePower
50555062
struct /* CalcConservativePower */ {
@@ -5085,11 +5092,11 @@ equal and opposite according to Newton's third law.)""";
50855092
struct /* ctor */ {
50865093
// Source: drake/multibody/tree/linear_spring_damper.h
50875094
const char* doc =
5088-
R"""(Constructor for a spring-damper between a point P on ``bodyA`` and a
5089-
point Q on ``bodyB``. Point P is defined by its position ``p_AP`` as
5090-
measured and expressed in the body frame A and similarly, point Q is
5091-
defined by its position p_BQ as measured and expressed in body frame
5092-
B. The remaining parameters define:
5095+
R"""(Constructor for a spring-damper between a point P on link ``bodyA``
5096+
and a point Q on link ``bodyB``. Point P is defined by its position
5097+
``p_AP`` as measured and expressed in the link frame A and similarly,
5098+
point Q is defined by its position p_BQ as measured and expressed in
5099+
link frame B. The remaining parameters define:
50935100
50945101
Parameter ``free_length``:
50955102
The free length of the spring ℓ₀, in meters, at which the spring
@@ -5438,11 +5445,11 @@ that is added during Finalize() should set this flag to ``True``.)""";
54385445
struct /* MultibodyForces */ {
54395446
// Source: drake/multibody/tree/multibody_forces.h
54405447
const char* doc =
5441-
R"""(A class to hold a set of forces applied to a MultibodyTree system.
5442-
Forces can include generalized forces as well as body spatial forces.
5443-
MultibodyPlant∷CalcGeneralizedForces() can be used to compute the
5444-
*total* generalized force, combining generalized_forces() and
5445-
body_forces().)""";
5448+
R"""(Holds a set of forces applied to a MultibodyTree system. Forces can
5449+
include generalized forces as well as mobilized body (mobod) spatial
5450+
forces. MultibodyPlant∷CalcGeneralizedForces() can be used to compute
5451+
the *total* generalized force, combining generalized_forces() with the
5452+
generalized force equivalent of the body_forces().)""";
54465453
// Symbol: drake::multibody::MultibodyForces::AddInForces
54475454
struct /* AddInForces */ {
54485455
// Source: drake/multibody/tree/multibody_forces.h
@@ -5475,9 +5482,12 @@ abort.)""";
54755482
const char* doc_1args_model = R"""((Advanced) Tree overload.)""";
54765483
// Source: drake/multibody/tree/multibody_forces.h
54775484
const char* doc_2args_nb_nv =
5478-
R"""(Number of bodies and number of generalized velocities overload. This
5479-
constructor is useful for constructing the MultibodyForces structure
5480-
before a MultibodyPlant has been constructed.)""";
5485+
R"""((Advanced) Number of bodies and number of generalized velocities
5486+
overload. This constructor may be useful for constructing the
5487+
MultibodyForces structure before a MultibodyPlant has been
5488+
constructed. However, this must be used cautiously since the number of
5489+
mobilized bodies and their mobilities are not known until after
5490+
Finalize().)""";
54815491
} ctor;
54825492
// Symbol: drake::multibody::MultibodyForces::SetZero
54835493
struct /* SetZero */ {
@@ -7040,6 +7050,11 @@ its parent body in the multibody tree by its Mobilizer (also called a
70407050
permissible motion can be added using Constraint objects to remove
70417051
more degrees of freedom.
70427052
7053+
Note:
7054+
This object corresponds to a "link" in urdf/sdf terminology. We
7055+
may combine welded-together links into a composite rigid body
7056+
internally.
7057+
70437058
- [Goldstein 2001] H Goldstein, CP Poole, JL Safko, Classical Mechanics
70447059
(3rd Edition), Addison-Wesley, 2001.)""";
70457060
// Symbol: drake::multibody::RigidBody::AddInForce
@@ -7370,7 +7385,8 @@ R"""(For a floating base RigidBody, unlock its inboard joint.
73707385
struct /* body_frame */ {
73717386
// Source: drake/multibody/tree/rigid_body.h
73727387
const char* doc =
7373-
R"""((Compatibility) A synonym for link_frame().)""";
7388+
R"""(Returns a const reference to the associated RigidBodyFrame
7389+
(LinkFrame). This is a synonym for link_frame().)""";
73747390
} body_frame;
73757391
// Symbol: drake::multibody::RigidBody::default_com
73767392
struct /* default_com */ {
@@ -7531,14 +7547,14 @@ Returns ``alpha_WB_W``:
75317547
struct /* get_angular_velocity_in_world */ {
75327548
// Source: drake/multibody/tree/rigid_body.h
75337549
const char* doc =
7534-
R"""((Advanced) Extract this body's angular velocity in world, expressed in
7550+
R"""((Advanced) Extract this link's angular velocity in world, expressed in
75357551
world.
75367552
75377553
Parameter ``vc``:
75387554
velocity kinematics cache.
75397555
7540-
Returns ``w_WB_W``:
7541-
rigid body B's angular velocity in world W, expressed in W.)""";
7556+
Returns ``w_WL_W``:
7557+
link L's angular velocity in world W, expressed in W.)""";
75427558
} get_angular_velocity_in_world;
75437559
// Symbol: drake::multibody::RigidBody::get_mass
75447560
struct /* get_mass */ {
@@ -7575,35 +7591,35 @@ body's origin, expressed in world.
75757591
Parameter ``pc``:
75767592
position kinematics cache.
75777593
7578-
Returns ``p_WoBo_W``:
7579-
position vector from Wo (world origin) to Bo (this body's origin)
7594+
Returns ``p_WoLo_W``:
7595+
position vector from Wo (world origin) to Lo (this link's origin)
75807596
expressed in W (world).)""";
75817597
} get_origin_position_in_world;
75827598
// Symbol: drake::multibody::RigidBody::get_origin_velocity_in_world
75837599
struct /* get_origin_velocity_in_world */ {
75847600
// Source: drake/multibody/tree/rigid_body.h
75857601
const char* doc =
7586-
R"""((Advanced) Extract the velocity of this body's origin in world,
7602+
R"""((Advanced) Extract the velocity of this link's origin in world,
75877603
expressed in world.
75887604
75897605
Parameter ``vc``:
75907606
velocity kinematics cache.
75917607
7592-
Returns ``v_WBo_W``:
7593-
velocity of Bo (body origin) in world W, expressed in W.)""";
7608+
Returns ``v_WLo_W``:
7609+
velocity of Lo (link frame origin) in world W, expressed in W.)""";
75947610
} get_origin_velocity_in_world;
75957611
// Symbol: drake::multibody::RigidBody::get_pose_in_world
75967612
struct /* get_pose_in_world */ {
75977613
// Source: drake/multibody/tree/rigid_body.h
75987614
const char* doc =
7599-
R"""((Advanced) Extract this body's pose in world (from the position
7615+
R"""((Advanced) Extract this link's pose in world (from the position
76007616
kinematics).
76017617
76027618
Parameter ``pc``:
76037619
position kinematics cache.
76047620
7605-
Returns ``X_WB``:
7606-
pose of rigid body B in world frame W.)""";
7621+
Returns ``X_WL``:
7622+
pose of this Link (%RigidBody) L in world frame W.)""";
76077623
} get_pose_in_world;
76087624
// Symbol: drake::multibody::RigidBody::get_rotation_matrix_in_world
76097625
struct /* get_rotation_matrix_in_world */ {
@@ -7615,8 +7631,9 @@ body's frame.
76157631
Parameter ``pc``:
76167632
position kinematics cache.
76177633
7618-
Returns ``R_WB``:
7619-
rotation matrix relating rigid body B in world frame W.)""";
7634+
Returns ``R_WL``:
7635+
rotation matrix giving the orientation of this Link L in the world
7636+
frame W.)""";
76207637
} get_rotation_matrix_in_world;
76217638
// Symbol: drake::multibody::RigidBody::get_spatial_acceleration_in_world
76227639
struct /* get_spatial_acceleration_in_world */ {
@@ -7636,15 +7653,15 @@ Returns ``A_WB_W``:
76367653
struct /* get_spatial_velocity_in_world */ {
76377654
// Source: drake/multibody/tree/rigid_body.h
76387655
const char* doc =
7639-
R"""((Advanced) Returns V_WB, this RigidBody B's SpatialVelocity in the
7640-
world frame W.
7656+
R"""((Advanced) Returns V_WL, this Link (%RigidBody) L's SpatialVelocity in
7657+
the world frame W.
76417658
76427659
Parameter ``vc``:
76437660
velocity kinematics cache.
76447661
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).)""";
7662+
Returns ``V_WL_W``:
7663+
this link L's spatial velocity in the world frame W, expressed in
7664+
W (for point Lo, the link frame's origin).)""";
76487665
} get_spatial_velocity_in_world;
76497666
// Symbol: drake::multibody::RigidBody::has_quaternion_dofs
76507667
struct /* has_quaternion_dofs */ {
@@ -7672,7 +7689,7 @@ See also:
76727689
// Source: drake/multibody/tree/rigid_body.h
76737690
const char* doc =
76747691
R"""((Advanced) Returns ``True`` if this body is a *floating base body*,
7675-
meaning it had no explicit joint to a parent body so is mobilized by
7692+
meaning it had no explicit joint to a parent body and is mobilized by
76767693
an automatically-added (ephemeral) floating (6 dof) joint to World.
76777694
76787695
Note:
@@ -7703,16 +7720,16 @@ generally Joint∷is_locked() is preferable otherwise.
77037720
// Source: drake/multibody/tree/rigid_body.h
77047721
const char* doc =
77057722
R"""(Returns a const reference to the associated LinkFrame
7706-
(RigidBodyFrame).)""";
7723+
(RigidBodyFrame). This is a synonym for body_frame().)""";
77077724
} link_frame;
77087725
// Symbol: drake::multibody::RigidBody::mobod_index
77097726
struct /* mobod_index */ {
77107727
// Source: drake/multibody/tree/rigid_body.h
77117728
const char* doc =
7712-
R"""((Advanced) Returns the index of the mobilized body ("mobod") in the
7713-
computational directed forest structure of the owning MultibodyTree to
7714-
which this RigidBody belongs. This serves as the BodyNode index and
7715-
the index into all associated quantities.)""";
7729+
R"""((Advanced) Returns the index of the mobilized body ("mobod") that is
7730+
followed by this RigidBody (Link). This serves as the BodyNode index
7731+
and the index into all associated quantities. More than one link may
7732+
follow the same mobod.)""";
77167733
} mobod_index;
77177734
// Symbol: drake::multibody::RigidBody::name
77187735
struct /* name */ {
@@ -7745,8 +7762,8 @@ name will be empty (the scope name and the element name).
77457762
struct /* RigidBodyFrame */ {
77467763
// Source: drake/multibody/tree/rigid_body.h
77477764
const char* doc =
7748-
R"""(A RigidBodyFrame is a material Frame that serves as the unique
7749-
reference frame for a RigidBody.
7765+
R"""(A RigidBodyFrame (aka LinkFrame) is a material Frame that serves as
7766+
the unique reference frame for a RigidBody (aka Link).
77507767
77517768
Each RigidBody B has a unique body frame for which we use the same
77527769
symbol B (with meaning clear from context). We represent a body frame

multibody/benchmarking/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ drake_cc_googlebench_binary(
4040
"//multibody/parsing:parser",
4141
"//tools/performance:fixture_common",
4242
"//tools/performance:gflags_main",
43+
"@gflags",
4344
],
4445
add_test_rule = True,
4546
)

0 commit comments

Comments
 (0)