Skip to content

Commit 2df78e2

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 c738ab7 commit 2df78e2

26 files changed

Lines changed: 721 additions & 376 deletions

bindings/generated_docstrings/multibody_tree.h

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,9 +5023,9 @@ to choose torque stiffness and damping constants" for more details.)""";
50235023
// Source: drake/multibody/tree/linear_spring_damper.h
50245024
const char* doc =
50255025
R"""(This ForceElement models a spring-damper attached between two points
5026-
on two different bodies (links). Given a point P on a body A and a
5027-
point Q on a body B with positions p_AP and p_BQ, respectively, this
5028-
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
50295029
according to:
50305030
50315031
@@ -5047,7 +5047,7 @@ its rate of change, ``r̂ = (p_WQ - p_WP) / ℓ`` is the normalized
50475047
vector from P to Q, ℓ₀ is the free length of the spring and k and c
50485048
are the stiffness and damping of the spring-damper, respectively. This
50495049
ForceElement is meant to model finite free length springs attached
5050-
between two points. In this typical arrangement springs are usually
5050+
between two points. In the typical arrangement springs are usually
50515051
pre-loaded, meaning they apply a non-zero spring force in the static
50525052
configuration of the system. Thus, neither the free length ℓ₀ nor the
50535053
current length ℓ of the spring can ever be zero. The length of the
@@ -5056,7 +5056,7 @@ and therefore this element throws a RuntimeError exception in that
50565056
case. Note that:
50575057
50585058
- The applied force is always along the line connecting points P and
5059-
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
50605060
equal and opposite according to Newton's third law.)""";
50615061
// Symbol: drake::multibody::LinearSpringDamper::CalcConservativePower
50625062
struct /* CalcConservativePower */ {
@@ -5092,11 +5092,11 @@ equal and opposite according to Newton's third law.)""";
50925092
struct /* ctor */ {
50935093
// Source: drake/multibody/tree/linear_spring_damper.h
50945094
const char* doc =
5095-
R"""(Constructor for a spring-damper between a point P on ``bodyA`` and a
5096-
point Q on ``bodyB``. Point P is defined by its position ``p_AP`` as
5097-
measured and expressed in the body frame A and similarly, point Q is
5098-
defined by its position p_BQ as measured and expressed in body frame
5099-
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:
51005100
51015101
Parameter ``free_length``:
51025102
The free length of the spring ℓ₀, in meters, at which the spring
@@ -7051,6 +7051,11 @@ its parent body in the multibody tree by its Mobilizer (also called a
70517051
permissible motion can be added using Constraint objects to remove
70527052
more degrees of freedom.
70537053
7054+
Note:
7055+
This object corresponds to a "link" in urdf/sdf terminology. We
7056+
may combine welded-together links into a composite rigid body
7057+
internally.
7058+
70547059
- [Goldstein 2001] H Goldstein, CP Poole, JL Safko, Classical Mechanics
70557060
(3rd Edition), Addison-Wesley, 2001.)""";
70567061
// Symbol: drake::multibody::RigidBody::AddInForce
@@ -7381,7 +7386,8 @@ R"""(For a floating base RigidBody, unlock its inboard joint.
73817386
struct /* body_frame */ {
73827387
// Source: drake/multibody/tree/rigid_body.h
73837388
const char* doc =
7384-
R"""((Compatibility) A synonym for link_frame().)""";
7389+
R"""(Returns a const reference to the associated RigidBodyFrame
7390+
(LinkFrame). This is a synonym for link_frame().)""";
73857391
} body_frame;
73867392
// Symbol: drake::multibody::RigidBody::default_com
73877393
struct /* default_com */ {
@@ -7542,14 +7548,14 @@ Returns ``alpha_WB_W``:
75427548
struct /* get_angular_velocity_in_world */ {
75437549
// Source: drake/multibody/tree/rigid_body.h
75447550
const char* doc =
7545-
R"""((Advanced) Extract this body's angular velocity in world, expressed in
7551+
R"""((Advanced) Extract this link's angular velocity in world, expressed in
75467552
world.
75477553
75487554
Parameter ``vc``:
75497555
velocity kinematics cache.
75507556
7551-
Returns ``w_WB_W``:
7552-
rigid body B's angular velocity in world W, expressed in W.)""";
7557+
Returns ``w_WL_W``:
7558+
link L's angular velocity in world W, expressed in W.)""";
75537559
} get_angular_velocity_in_world;
75547560
// Symbol: drake::multibody::RigidBody::get_mass
75557561
struct /* get_mass */ {
@@ -7586,35 +7592,35 @@ body's origin, expressed in world.
75867592
Parameter ``pc``:
75877593
position kinematics cache.
75887594
7589-
Returns ``p_WoBo_W``:
7590-
position vector from Wo (world origin) to Bo (this body's origin)
7595+
Returns ``p_WoLo_W``:
7596+
position vector from Wo (world origin) to Lo (this link's origin)
75917597
expressed in W (world).)""";
75927598
} get_origin_position_in_world;
75937599
// Symbol: drake::multibody::RigidBody::get_origin_velocity_in_world
75947600
struct /* get_origin_velocity_in_world */ {
75957601
// Source: drake/multibody/tree/rigid_body.h
75967602
const char* doc =
7597-
R"""((Advanced) Extract the velocity of this body's origin in world,
7603+
R"""((Advanced) Extract the velocity of this link's origin in world,
75987604
expressed in world.
75997605
76007606
Parameter ``vc``:
76017607
velocity kinematics cache.
76027608
7603-
Returns ``v_WBo_W``:
7604-
velocity of Bo (body origin) in world W, expressed in W.)""";
7609+
Returns ``v_WLo_W``:
7610+
velocity of Lo (link frame origin) in world W, expressed in W.)""";
76057611
} get_origin_velocity_in_world;
76067612
// Symbol: drake::multibody::RigidBody::get_pose_in_world
76077613
struct /* get_pose_in_world */ {
76087614
// Source: drake/multibody/tree/rigid_body.h
76097615
const char* doc =
7610-
R"""((Advanced) Extract this body's pose in world (from the position
7616+
R"""((Advanced) Extract this link's pose in world (from the position
76117617
kinematics).
76127618
76137619
Parameter ``pc``:
76147620
position kinematics cache.
76157621
7616-
Returns ``X_WB``:
7617-
pose of rigid body B in world frame W.)""";
7622+
Returns ``X_WL``:
7623+
pose of this Link (%RigidBody) L in world frame W.)""";
76187624
} get_pose_in_world;
76197625
// Symbol: drake::multibody::RigidBody::get_rotation_matrix_in_world
76207626
struct /* get_rotation_matrix_in_world */ {
@@ -7626,8 +7632,9 @@ body's frame.
76267632
Parameter ``pc``:
76277633
position kinematics cache.
76287634
7629-
Returns ``R_WB``:
7630-
rotation matrix relating rigid body B in world frame W.)""";
7635+
Returns ``R_WL``:
7636+
rotation matrix giving the orientation of this Link L in the world
7637+
frame W.)""";
76317638
} get_rotation_matrix_in_world;
76327639
// Symbol: drake::multibody::RigidBody::get_spatial_acceleration_in_world
76337640
struct /* get_spatial_acceleration_in_world */ {
@@ -7647,15 +7654,15 @@ Returns ``A_WB_W``:
76477654
struct /* get_spatial_velocity_in_world */ {
76487655
// Source: drake/multibody/tree/rigid_body.h
76497656
const char* doc =
7650-
R"""((Advanced) Returns V_WB, this RigidBody B's SpatialVelocity in the
7651-
world frame W.
7657+
R"""((Advanced) Returns V_WL, this Link (%RigidBody) L's SpatialVelocity in
7658+
the world frame W.
76527659
76537660
Parameter ``vc``:
76547661
velocity kinematics cache.
76557662
7656-
Returns ``V_WB_W``:
7657-
this rigid body B's spatial velocity in the world frame W,
7658-
expressed in W (for point Bo, the body frame's origin).)""";
7663+
Returns ``V_WL_W``:
7664+
this link L's spatial velocity in the world frame W, expressed in
7665+
W (for point Lo, the link frame's origin).)""";
76597666
} get_spatial_velocity_in_world;
76607667
// Symbol: drake::multibody::RigidBody::has_quaternion_dofs
76617668
struct /* has_quaternion_dofs */ {
@@ -7683,7 +7690,7 @@ See also:
76837690
// Source: drake/multibody/tree/rigid_body.h
76847691
const char* doc =
76857692
R"""((Advanced) Returns ``True`` if this body is a *floating base body*,
7686-
meaning it had no explicit joint to a parent body so is mobilized by
7693+
meaning it had no explicit joint to a parent body and is mobilized by
76877694
an automatically-added (ephemeral) floating (6 dof) joint to World.
76887695
76897696
Note:
@@ -7714,16 +7721,16 @@ generally Joint∷is_locked() is preferable otherwise.
77147721
// Source: drake/multibody/tree/rigid_body.h
77157722
const char* doc =
77167723
R"""(Returns a const reference to the associated LinkFrame
7717-
(RigidBodyFrame).)""";
7724+
(RigidBodyFrame). This is a synonym for body_frame().)""";
77187725
} link_frame;
77197726
// Symbol: drake::multibody::RigidBody::mobod_index
77207727
struct /* mobod_index */ {
77217728
// Source: drake/multibody/tree/rigid_body.h
77227729
const char* doc =
7723-
R"""((Advanced) Returns the index of the mobilized body ("mobod") in the
7724-
computational directed forest structure of the owning MultibodyTree to
7725-
which this RigidBody belongs. This serves as the BodyNode index and
7726-
the index into all associated quantities.)""";
7730+
R"""((Advanced) Returns the index of the mobilized body ("mobod") that is
7731+
followed by this RigidBody (Link). This serves as the BodyNode index
7732+
and the index into all associated quantities. More than one link may
7733+
follow the same mobod.)""";
77277734
} mobod_index;
77287735
// Symbol: drake::multibody::RigidBody::name
77297736
struct /* name */ {
@@ -7756,8 +7763,8 @@ name will be empty (the scope name and the element name).
77567763
struct /* RigidBodyFrame */ {
77577764
// Source: drake/multibody/tree/rigid_body.h
77587765
const char* doc =
7759-
R"""(A RigidBodyFrame is a material Frame that serves as the unique
7760-
reference frame for a RigidBody.
7766+
R"""(A RigidBodyFrame (aka LinkFrame) is a material Frame that serves as
7767+
the unique reference frame for a RigidBody (aka Link).
77617768
77627769
Each RigidBody B has a unique body frame for which we use the same
77637770
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
)

multibody/benchmarking/cassie.cc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <memory>
22

33
#include <benchmark/benchmark.h>
4+
#include <gflags/gflags.h>
45

56
#include "drake/common/drake_assert.h"
67
#include "drake/common/find_resource.h"
@@ -15,6 +16,8 @@ namespace drake {
1516
namespace multibody {
1617
namespace {
1718

19+
DEFINE_bool(composite, false, "Enable link-combining for welded bodies.");
20+
1821
using math::RigidTransform;
1922
using math::RollPitchYaw;
2023
using symbolic::Expression;
@@ -119,16 +122,25 @@ class Cassie : public benchmark::Fixture {
119122
void DoSlowSystemJacobian(benchmark::State& state) {
120123
DRAKE_DEMAND(want_grad_vdot(state) == false);
121124
DRAKE_DEMAND(want_grad_u(state) == false);
122-
const int num_mobods = ssize(plant_->graph().forest().mobods());
125+
const internal::SpanningForest& forest = plant_->graph().forest();
126+
const int num_mobods = forest.num_mobods();
123127
MatrixX<double> Jv_V_WB_W(6 * num_mobods, plant_->num_velocities());
124128
for (auto _ : state) {
125129
InvalidateState();
126130
Jv_V_WB_W.setZero();
127-
for (BodyIndex index{1}; index < plant_->num_bodies(); ++index) {
128-
const Frame<double>& body_frame = plant_->get_body(index).body_frame();
129-
auto J = Jv_V_WB_W.block(6 * index, 0, 6, plant_->num_velocities());
131+
for (internal::MobodIndex mobod_index{1}; mobod_index < num_mobods;
132+
++mobod_index) {
133+
const LinkOrdinal active_link_ordinal =
134+
forest.mobods(mobod_index).active_link_ordinal();
135+
const LinkIndex active_link_index =
136+
forest.links(active_link_ordinal).index();
137+
// The active link's link frame is also the Mobod's frame.
138+
const Frame<double>& active_link_frame =
139+
plant_->get_body(active_link_index).link_frame();
140+
auto J =
141+
Jv_V_WB_W.block(6 * mobod_index, 0, 6, plant_->num_velocities());
130142
plant_->CalcJacobianSpatialVelocity(
131-
*context_, JacobianWrtVariable::kV, body_frame,
143+
*context_, JacobianWrtVariable::kV, active_link_frame,
132144
Eigen::Vector3<double>::Zero(), plant_->world_frame(),
133145
plant_->world_frame(), &J);
134146
}
@@ -241,6 +253,7 @@ std::unique_ptr<MultibodyPlant<T>> Cassie<T>::MakePlant() {
241253
Parser parser(plant.get());
242254
const auto& model = "drake/multibody/benchmarking/cassie_v2.urdf";
243255
parser.AddModels(FindResourceOrThrow(model));
256+
plant->SetFuseWeldedLinks(FLAGS_composite);
244257
plant->Finalize();
245258
if constexpr (std::is_same_v<T, double>) {
246259
return plant;

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/multibody_plant.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,9 +1589,7 @@ void MultibodyPlant<T>::FinalizePlantOnly() {
15891589
if (use_sampled_output_ports_) {
15901590
auto cache = std::make_unique<AccelerationKinematicsCache<T>>(
15911591
internal_tree().forest());
1592-
for (SpatialAcceleration<T>& A_WB : cache->get_mutable_A_WB_pool()) {
1593-
A_WB.SetZero();
1594-
}
1592+
cache->SetToZero();
15951593
zero_acceleration_kinematics_placeholder_ = std::move(cache);
15961594
}
15971595
FinalizeConstraints();

0 commit comments

Comments
 (0)