Skip to content

Commit 87bf89a

Browse files
committed
Changes to MbP and MbT
Passes all tests now (except space_xyz_floating_mobilizer is disabled)
1 parent 52c0177 commit 87bf89a

28 files changed

+574
-587
lines changed

bindings/pydrake/planning/test/collision_checker_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_linear_distance_interpolation_provider(self):
7979

8080
mut.LinearDistanceAndInterpolationProvider(plant=plant)
8181

82-
box_joint_index = plant.GetJointByName("$world_box").index()
82+
box_joint_index = plant.GetJointByName("box").index()
8383
box_joint_weights = np.array([1.0, 0.0, 0.0, 0.0, 2.0, 3.0, 4.0])
8484
joint_distance_weights = {box_joint_index: box_joint_weights}
8585
mut.LinearDistanceAndInterpolationProvider(

multibody/parsing/test/detail_mujoco_parser_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,13 @@ TEST_F(MujocoParserTest, Joint) {
905905
Vector3d pos{.1, .2, .3};
906906

907907
const Body<double>& freejoint_body = plant_.GetBodyByName("freejoint");
908-
EXPECT_FALSE(plant_.HasJointNamed("freejoint"));
908+
EXPECT_TRUE(plant_.HasJointNamed("freejoint"));
909909
EXPECT_TRUE(freejoint_body.is_floating());
910910
EXPECT_TRUE(plant_.GetFreeBodyPose(*context, freejoint_body)
911911
.IsNearlyEqualTo(X_WB, 1e-14));
912912

913913
const Body<double>& free_body = plant_.GetBodyByName("free");
914-
EXPECT_FALSE(plant_.HasJointNamed("free"));
914+
EXPECT_TRUE(plant_.HasJointNamed("free"));
915915
EXPECT_TRUE(free_body.is_floating());
916916
EXPECT_TRUE(
917917
plant_.GetFreeBodyPose(*context, free_body).IsNearlyEqualTo(X_WB, 1e-14));

multibody/plant/compliant_contact_manager.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ template <typename T>
4040
AccelerationsDueNonConstraintForcesCache<
4141
T>::AccelerationsDueNonConstraintForcesCache(const MultibodyTreeTopology&
4242
topology)
43-
: forces(topology.num_bodies(), topology.num_velocities()),
43+
: forces(topology.num_links(), topology.num_velocities()),
4444
abic(topology),
45-
Zb_Bo_W(topology.num_bodies()),
45+
Zb_Bo_W(topology.num_body_nodes()),
4646
aba_forces(topology),
4747
ac(topology) {}
4848

multibody/plant/multibody_plant.cc

+9-67
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "drake/multibody/plant/hydroelastic_traction_calculator.h"
2626
#include "drake/multibody/plant/make_discrete_update_manager.h"
2727
#include "drake/multibody/plant/slicing_and_indexing.h"
28-
#include "drake/multibody/topology/spanning_forest_model.h"
28+
#include "drake/multibody/topology/link_joint_graph.h"
2929
#include "drake/multibody/tree/prismatic_joint.h"
3030
#include "drake/multibody/tree/quaternion_floating_joint.h"
3131
#include "drake/multibody/tree/revolute_joint.h"
@@ -992,7 +992,7 @@ void MultibodyPlant<T>::SetFreeBodyPoseInAnchoredFrame(
992992
DRAKE_MBP_THROW_IF_NOT_FINALIZED();
993993
this->ValidateContext(context);
994994

995-
if (!internal_tree().get_topology().IsBodyAnchored(frame_F.body().index())) {
995+
if (!internal_tree().get_topology().IsLinkAnchored(frame_F.body().index())) {
996996
throw std::logic_error(
997997
"Frame '" + frame_F.name() + "' must be anchored to the world frame.");
998998
}
@@ -1016,17 +1016,17 @@ void MultibodyPlant<T>::CalcSpatialAccelerationsFromVdot(
10161016
internal_tree().CalcSpatialAccelerationsFromVdot(
10171017
context, internal_tree().EvalPositionKinematics(context),
10181018
internal_tree().EvalVelocityKinematics(context), known_vdot, A_WB_array);
1019-
// Permute BodyNodeIndex -> BodyIndex.
1019+
// Permute BodyNodeIndex -> LinkIndex.
10201020
// TODO(eric.cousineau): Remove dynamic allocations. Making this in-place
10211021
// still required dynamic allocation for recording permutation indices.
10221022
// Can change implementation once MultibodyTree becomes fully internal.
10231023
std::vector<SpatialAcceleration<T>> A_WB_array_node = *A_WB_array;
10241024
const internal::MultibodyTreeTopology& topology =
10251025
internal_tree().get_topology();
10261026
for (internal::BodyNodeIndex node_index(1);
1027-
node_index < topology.get_num_body_nodes(); ++node_index) {
1028-
const BodyIndex body_index = topology.get_body_node(node_index).body;
1029-
(*A_WB_array)[body_index] = A_WB_array_node[node_index];
1027+
node_index < topology.num_body_nodes(); ++node_index) {
1028+
const LinkIndex link_index = topology.get_body_node(node_index).link;
1029+
(*A_WB_array)[link_index] = A_WB_array_node[node_index];
10301030
}
10311031
}
10321032

@@ -1097,65 +1097,13 @@ void MultibodyPlant<T>::RenameModelInstance(ModelInstanceIndex model_instance,
10971097

10981098
template<typename T>
10991099
void MultibodyPlant<T>::Finalize() {
1100-
/* Given the user-defined directed graph of Links and Joints, decide how we're
1101-
going to model this using a spanning forest comprised of
1102-
- bodies and their mobilizers, paired as "mobilized bodies" (mobods) and
1103-
directed by inboard/outboard edges, and
1104-
- added constraints where needed to close kinematic loops in the graph.
1105-
The modeler sorts the mobilized bodies into depth-first order.
1106-
1107-
Every Link will be modeled with one "primary" body and possibly several
1108-
"shadow" bodies. Every Joint will be modeled with a mobilizer, with the
1109-
Joint's parent/child connections mapped to the mobilizer's inboard/outboard
1110-
connection or to the reverse, as necessary for the mobilizers to form a
1111-
properly-directed tree. Every body in the tree must have a path in the
1112-
inboard direction connecting it to World. If necessary, additional "floating"
1113-
(6 dof) or "weld" (0 dof) mobilizers are added to make the final connection
1114-
to World.
1115-
1116-
During the modeling process, the LinkJointGraph is augmented to have
1117-
additional elements to provide an interface to the additional elements that
1118-
were required to build the model. Below, we will augment the MultibodyPlant
1119-
elements to match, so that advanced users can use the familiar Plant API to
1120-
access and control these elements. */
1121-
this->mutable_tree().BuildSpanningForest();
1122-
1123-
/* Add Links, Joints, and Constraints that were created during the modeling
1124-
process. */
1125-
1126-
const internal::LinkJointGraph& graph = internal_tree().link_joint_graph();
1127-
unused(graph);
1128-
1129-
/* TODO(sherm1) why not use MbP as the LinkJointGraph and do away with
1130-
the extra class? Then we wouldn't have to repeat these additions.
1131-
// Added floating mobods are in the order the new joints were added so
1132-
// the index we get in the plant should match the one stored with the mobod.
1133-
for (auto index : graph.added_floating_mobods()) {
1134-
const internal::SpanningForestModel::Mobod& floating_mobod =
1135-
model.mobods()[index];
1136-
const JointIndex floating = AddFloatingJointToWorld(floating_mobod);
1137-
DRAKE_DEMAND(floating == floating_mobod.joint_index);
1138-
}
1139-
1140-
// Shadow mobods are in the order the new bodies were added so the body
1141-
// index should match.
1142-
for (auto index : model.shadow_mobods()) {
1143-
const internal::SpanningForestModel::Mobod shadow_mobod = model.mobods()[index];
1144-
const BodyIndex shadow = AddShadowBody(shadow_mobod);
1145-
DRAKE_DEMAND(shadow == shadow_mobod.link_index_);
1146-
}
1147-
1148-
// The modeler only knows about constraints it adds so there is no
1149-
// indexing correspondence.
1150-
for (auto& loop_constraint : model.added_constraints()) {
1151-
const ConstraintIndex constraint =
1152-
AddLoopClosingConstraint(loop_constraint);
1153-
}
1154-
*/
1100+
// After finalizing the base class, tree is read-only.
1101+
internal::MultibodyTreeSystem<T>::Finalize();
11551102

11561103
if (geometry_source_is_registered()) {
11571104
ApplyDefaultCollisionFilters();
11581105
}
1106+
11591107
FinalizePlantOnly();
11601108

11611109
// Make the manager of discrete updates.
@@ -1173,12 +1121,6 @@ void MultibodyPlant<T>::Finalize() {
11731121
"only supported for discrete models. Refer to MultibodyPlant's "
11741122
"documentation for further details.");
11751123
}
1176-
1177-
/* The Plant is complete now. Next, build an efficient computational
1178-
representation structured in accordance with `model`. */
1179-
1180-
// After finalizing the base class, tree is read-only.
1181-
internal::MultibodyTreeSystem<T>::Finalize();
11821124
}
11831125

11841126
template<typename T>

multibody/plant/multibody_plant.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -4347,9 +4347,10 @@ class MultibodyPlant : public internal::MultibodyTreeSystem<T> {
43474347
/// Returns the number of bodies in the model, including the "world" body,
43484348
/// which is always part of the model.
43494349
/// @see AddRigidBody().
4350-
int num_bodies() const {
4351-
return internal_tree().num_bodies();
4352-
}
4350+
int num_links() const { return internal_tree().num_links(); }
4351+
4352+
/// Alternate spelling for num_links(). Prefer num_links().
4353+
int num_bodies() const { return num_links(); }
43534354

43544355
/// Returns a constant reference to the body with unique index `body_index`.
43554356
/// @throws std::exception if `body_index` does not correspond to a body in
@@ -4363,7 +4364,7 @@ class MultibodyPlant : public internal::MultibodyTreeSystem<T> {
43634364
/// @throws std::exception if called pre-finalize.
43644365
bool IsAnchored(const Body<T>& body) const {
43654366
DRAKE_MBP_THROW_IF_NOT_FINALIZED();
4366-
return internal_tree().get_topology().IsBodyAnchored(body.index());
4367+
return internal_tree().get_topology().IsLinkAnchored(body.index());
43674368
}
43684369

43694370
/// @returns `true` if a body named `name` was added to the %MultibodyPlant.

0 commit comments

Comments
 (0)