Skip to content

Commit 76a9173

Browse files
authored
Name changes & infrastructure in support of composites to come (#24443)
Also miscellaneous opportunistic comment cleanups.
1 parent 28ea7bf commit 76a9173

85 files changed

Lines changed: 1935 additions & 1588 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bindings/generated_docstrings/multibody_math.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ Parameter ``translational_tolerance``:
10051005
elements of ``this`` and ``other`` are equal within
10061006
translational_tolerance.)""";
10071007
} IsNearlyEqualWithinAbsoluteTolerance;
1008+
// Symbol: drake::multibody::SpatialVector::NaN
1009+
struct /* NaN */ {
1010+
// Source: drake/multibody/math/spatial_vector.h
1011+
const char* doc =
1012+
R"""(Factory to create a *NaN* spatial vector, i.e., a SpatialVector whose
1013+
rotational and translational components are all NaN.)""";
1014+
} NaN;
10081015
// Symbol: drake::multibody::SpatialVector::SetNaN
10091016
struct /* SetNaN */ {
10101017
// Source: drake/multibody/math/spatial_vector.h

bindings/generated_docstrings/multibody_plant.h

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,6 @@ This method must be called pre-Finalize.
186186
Raises:
187187
RuntimeError if ``plant`` is finalized or if time_step is changed.)""";
188188
} ApplyMultibodyPlantConfig;
189-
// Symbol: drake::multibody::BaseBodyJointType
190-
struct /* BaseBodyJointType */ {
191-
// Source: drake/multibody/plant/multibody_plant.h
192-
const char* doc =
193-
R"""(The kind of joint to be used to connect base bodies to world at
194-
Finalize(). See mbp_working_with_free_bodies "Working with free
195-
bodies" for definitions and discussion.
196-
197-
See also:
198-
SetBaseBodyJointType() for details.)""";
199-
// Symbol: drake::multibody::BaseBodyJointType::kQuaternionFloatingJoint
200-
struct /* kQuaternionFloatingJoint */ {
201-
// Source: drake/multibody/plant/multibody_plant.h
202-
const char* doc = R"""(6 dofs, unrestricted orientation.)""";
203-
} kQuaternionFloatingJoint;
204-
// Symbol: drake::multibody::BaseBodyJointType::kRpyFloatingJoint
205-
struct /* kRpyFloatingJoint */ {
206-
// Source: drake/multibody/plant/multibody_plant.h
207-
const char* doc = R"""(6 dofs using 3 angles; has singularity.)""";
208-
} kRpyFloatingJoint;
209-
// Symbol: drake::multibody::BaseBodyJointType::kWeldJoint
210-
struct /* kWeldJoint */ {
211-
// Source: drake/multibody/plant/multibody_plant.h
212-
const char* doc = R"""(0 dofs, fixed to World.)""";
213-
} kWeldJoint;
214-
} BaseBodyJointType;
215189
// Symbol: drake::multibody::CalcContactFrictionFromSurfaceProperties
216190
struct /* CalcContactFrictionFromSurfaceProperties */ {
217191
// Source: drake/multibody/plant/coulomb_friction.h
@@ -4968,7 +4942,7 @@ be used by Finalize(); post-finalize it returns the joint type that
49684942
*was* used if there were any base bodies in need of a joint.
49694943
49704944
See also:
4971-
SetBaseBodyJointType())""";
4945+
SetBaseBodyJointType(), Finalize())""";
49724946
} GetBaseBodyJointType;
49734947
// Symbol: drake::multibody::MultibodyPlant::GetBodiesKinematicallyAffectedBy
49744948
struct /* GetBodiesKinematicallyAffectedBy */ {
@@ -6625,7 +6599,10 @@ Parameter ``model_instance``:
66256599
is to be applied.
66266600
66276601
Raises:
6628-
RuntimeError if called after Finalize().)""";
6602+
RuntimeError if called after Finalize().
6603+
6604+
See also:
6605+
GetBaseBodyJointType(), Finalize())""";
66296606
} SetBaseBodyJointType;
66306607
// Symbol: drake::multibody::MultibodyPlant::SetConstraintActiveStatus
66316608
struct /* SetConstraintActiveStatus */ {

bindings/generated_docstrings/multibody_tree.h

Lines changed: 200 additions & 137 deletions
Large diffs are not rendered by default.

bindings/pydrake/multibody/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ drake_pybind_library(
156156
name = "plant_py",
157157
cc_deps = [
158158
"//bindings/generated_docstrings:multibody_plant",
159+
"//bindings/generated_docstrings:multibody_tree",
159160
"//bindings/pydrake/common:cpp_template_pybind",
160161
"//bindings/pydrake/common:default_scalars_pybind",
161162
"//bindings/pydrake/common:deprecation_pybind",

bindings/pydrake/multibody/plant_py.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66

77
#include "drake/bindings/generated_docstrings/multibody_plant.h"
8+
#include "drake/bindings/generated_docstrings/multibody_tree.h"
89
#include "drake/bindings/pydrake/common/cpp_template_pybind.h"
910
#include "drake/bindings/pydrake/common/default_scalars_pybind.h"
1011
#include "drake/bindings/pydrake/common/deprecation_pybind.h"
@@ -1776,8 +1777,11 @@ PYBIND11_MODULE(plant, m) {
17761777
}
17771778

17781779
{
1780+
// This enum comes from a MultibodyTree header but for historical
1781+
// reasons we've bound it in plant.
17791782
using Class = BaseBodyJointType;
1780-
constexpr auto& cls_doc = doc.BaseBodyJointType;
1783+
constexpr auto& tree_doc = pydrake_doc_multibody_tree.drake.multibody;
1784+
constexpr auto& cls_doc = tree_doc.BaseBodyJointType;
17811785
py::enum_<Class> cls(m, "BaseBodyJointType", cls_doc.doc);
17821786
cls.value("kQuaternionFloatingJoint", Class::kQuaternionFloatingJoint,
17831787
cls_doc.kQuaternionFloatingJoint.doc)

multibody/benchmarks/kuka_iiwa_robot/drake_kuka_iiwa_robot.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ class DrakeKukaIIwaRobot {
8585
MakeKukaIiwaModel<T>(false /* finalized model */,
8686
gravity /* acceleration of gravity */));
8787

88-
linkN_ = &tree().world_body();
88+
linkN_ = &tree().world_link();
8989

9090
// Get this robot's seven links.
91-
linkA_ = &tree().GetRigidBodyByName("iiwa_link_1");
92-
linkB_ = &tree().GetRigidBodyByName("iiwa_link_2");
93-
linkC_ = &tree().GetRigidBodyByName("iiwa_link_3");
94-
linkD_ = &tree().GetRigidBodyByName("iiwa_link_4");
95-
linkE_ = &tree().GetRigidBodyByName("iiwa_link_5");
96-
linkF_ = &tree().GetRigidBodyByName("iiwa_link_6");
97-
linkG_ = &tree().GetRigidBodyByName("iiwa_link_7");
91+
linkA_ = &tree().GetLinkByName("iiwa_link_1");
92+
linkB_ = &tree().GetLinkByName("iiwa_link_2");
93+
linkC_ = &tree().GetLinkByName("iiwa_link_3");
94+
linkD_ = &tree().GetLinkByName("iiwa_link_4");
95+
linkE_ = &tree().GetLinkByName("iiwa_link_5");
96+
linkF_ = &tree().GetLinkByName("iiwa_link_6");
97+
linkG_ = &tree().GetLinkByName("iiwa_link_7");
9898

9999
// Get this robot's seven joints.
100100
NA_joint_ = &tree().template GetJointByName<RevoluteJoint>("iiwa_joint_1");
@@ -111,7 +111,7 @@ class DrakeKukaIIwaRobot {
111111

112112
/// This method gets the number of rigid bodies in this robot.
113113
/// @returns the number of rigid bodies in this robot.
114-
int get_number_of_rigid_bodies() const { return tree().num_bodies(); }
114+
int get_number_of_rigid_bodies() const { return tree().num_links(); }
115115

116116
/// This method calculates kinematic properties of the end-effector (herein
117117
/// denoted as rigid body G) of a 7-DOF KUKA LBR iiwa robot (14 kg payload).
@@ -145,7 +145,7 @@ class DrakeKukaIIwaRobot {
145145
const SpatialVelocity<T>& V_NG_N = vc.get_V_WB(linkG_->mobod_index());
146146

147147
// Retrieve end-effector spatial acceleration from acceleration cache.
148-
std::vector<SpatialAcceleration<T>> A_WB(tree().num_bodies());
148+
std::vector<SpatialAcceleration<T>> A_WB(tree().num_links());
149149
// TODO(eric.cousineau): For this model, the end effector's BodyIndex
150150
// matches its MobodIndex, thus we're not really checking the difference
151151
// between MultibodyPlant and MultibodyTree's ordering.

multibody/benchmarks/kuka_iiwa_robot/make_kuka_iiwa_model.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ KukaIiwaModelBuilder<T>::Build() const {
7575
I_GGcm_G_);
7676

7777
// Add this robot's seven links.
78-
const RigidBody<T>& linkA = model->AddRigidBody("iiwa_link_1", M_AAo_A);
79-
const RigidBody<T>& linkB = model->AddRigidBody("iiwa_link_2", M_BBo_B);
80-
const RigidBody<T>& linkC = model->AddRigidBody("iiwa_link_3", M_CCo_C);
81-
const RigidBody<T>& linkD = model->AddRigidBody("iiwa_link_4", M_DDo_D);
82-
const RigidBody<T>& linkE = model->AddRigidBody("iiwa_link_5", M_EEo_E);
83-
const RigidBody<T>& linkF = model->AddRigidBody("iiwa_link_6", M_FFo_F);
84-
const RigidBody<T>& linkG = model->AddRigidBody("iiwa_link_7", M_GGo_G);
78+
const Link<T>& linkA = model->AddLink("iiwa_link_1", M_AAo_A);
79+
const Link<T>& linkB = model->AddLink("iiwa_link_2", M_BBo_B);
80+
const Link<T>& linkC = model->AddLink("iiwa_link_3", M_CCo_C);
81+
const Link<T>& linkD = model->AddLink("iiwa_link_4", M_DDo_D);
82+
const Link<T>& linkE = model->AddLink("iiwa_link_5", M_EEo_E);
83+
const Link<T>& linkF = model->AddLink("iiwa_link_6", M_FFo_F);
84+
const Link<T>& linkG = model->AddLink("iiwa_link_7", M_GGo_G);
8585

8686
// Create a revolute joint between linkN (Newtonian frame/world) and linkA
8787
// using two joint-frames, namely "Na" and "An". The "inboard frame" Na is
@@ -91,7 +91,7 @@ KukaIiwaModelBuilder<T>::Build() const {
9191
// angles and a position vector. Alternately, frame An is regarded as
9292
// coincident with linkA.
9393
const Joint<T>* joint{nullptr};
94-
const RigidBody<T>& linkN = model->world_body();
94+
const Link<T>& linkN = model->world_link();
9595
joint = &AddRevoluteJointFromSpaceXYZAnglesAndXYZ(
9696
"iiwa_joint_1", linkN, joint_1_rpy_, joint_1_xyz_, linkA,
9797
Eigen::Vector3d::UnitZ(), model.get());
@@ -109,7 +109,7 @@ KukaIiwaModelBuilder<T>::Build() const {
109109
Eigen::Vector3d::UnitZ(), model.get());
110110
model->AddJointActuator("iiwa_actuator_3", *joint);
111111

112-
// Create a revolute joint between linkB and linkC.
112+
// Create a revolute joint between linkC and linkD.
113113
joint = &AddRevoluteJointFromSpaceXYZAnglesAndXYZ(
114114
"iiwa_joint_4", linkC, joint_4_rpy_, joint_4_xyz_, linkD,
115115
Eigen::Vector3d::UnitZ(), model.get());

multibody/math/spatial_vector.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ class SpatialVector {
291291
/// rotational and translational components are both zero.
292292
static SpatialQuantity Zero() { return SpatialQuantity{}.SetZero(); }
293293

294+
/// Factory to create a _NaN_ spatial vector, i.e., a %SpatialVector whose
295+
/// rotational and translational components are all NaN.
296+
static SpatialQuantity NaN() {
297+
SpatialQuantity quantity;
298+
quantity.SetNaN();
299+
return quantity;
300+
}
301+
294302
private:
295303
// Helper method to return a mutable reference to the derived spatial
296304
// quantity.

multibody/math/test/spatial_algebra_test.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ TYPED_TEST(SpatialQuantityTest, ZeroFactory) {
110110
EXPECT_TRUE(V.translational() == Vector3<T>::Zero());
111111
}
112112

113+
// Construction of a "NaN" spatial vector.
114+
TYPED_TEST(SpatialQuantityTest, NaNFactory) {
115+
typedef typename TestFixture::SpatialQuantityType SpatialQuantity;
116+
typedef typename TestFixture::ScalarType T;
117+
SpatialQuantity V = SpatialQuantity::NaN();
118+
auto is_nan = [](const T& x) -> bool {
119+
if constexpr (std::is_same_v<T, Expression>) {
120+
return symbolic::is_nan(x);
121+
}
122+
if constexpr (std::is_same_v<T, AutoDiffXd>) {
123+
return std::isnan(x.value());
124+
}
125+
if constexpr (std::is_same_v<T, double>) {
126+
return std::isnan(x);
127+
}
128+
};
129+
for (int i = 0; i < V.size(); ++i) {
130+
EXPECT_TRUE(is_nan(V[i]));
131+
}
132+
}
133+
113134
// Tests:
114135
// - Construction from a Eigen expressions.
115136
// - SetZero() method.

multibody/plant/deformable_model.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ template <typename T>
333333
void DeformableModel<T>::SetParallelism(Parallelism parallelism) {
334334
parallelism_ = parallelism;
335335
const std::vector<DeformableBodyIndex>& body_indices =
336-
deformable_bodies_.indices();
336+
deformable_bodies_.valid_indices();
337337
for (const DeformableBodyIndex& index : body_indices) {
338338
deformable_bodies_.get_mutable_element(index).set_parallelism(parallelism);
339339
}
@@ -346,7 +346,8 @@ void DeformableModel<T>::SetDefaultState(const systems::Context<T>& context,
346346
DRAKE_DEMAND(is_empty());
347347
return;
348348
} else {
349-
for (const DeformableBodyIndex& index : deformable_bodies_.indices()) {
349+
for (const DeformableBodyIndex& index :
350+
deformable_bodies_.valid_indices()) {
350351
const DeformableBody<T>& body = deformable_bodies_.get_element(index);
351352
body.SetDefaultState(context, state);
352353
}
@@ -372,7 +373,8 @@ std::unique_ptr<PhysicalModel<double>> DeformableModel<T>::CloneToDouble(
372373

373374
/* Copy over deformable_bodies_. */
374375
result->deformable_bodies_.ResizeToMatch(deformable_bodies_);
375-
for (const DeformableBodyIndex& index : deformable_bodies_.indices()) {
376+
for (const DeformableBodyIndex& index :
377+
deformable_bodies_.valid_indices()) {
376378
const DeformableBody<T>& body = deformable_bodies_.get_element(index);
377379
result->deformable_bodies_.Add(body.CloneToDouble());
378380
}
@@ -430,7 +432,7 @@ void DeformableModel<T>::DoDeclareSystemResources() {
430432

431433
/* Declare discrete states and parameters. */
432434
const std::vector<DeformableBodyIndex>& body_indices =
433-
deformable_bodies_.indices();
435+
deformable_bodies_.valid_indices();
434436
for (const DeformableBodyIndex& index : body_indices) {
435437
DeformableBody<T>& body = deformable_bodies_.get_mutable_element(index);
436438
body.DeclareDiscreteState(static_cast<internal::MultibodyTreeSystem<T>*>(
@@ -482,7 +484,7 @@ void DeformableModel<T>::CopyVertexPositions(const systems::Context<T>& context,
482484
output->get_mutable_value<geometry::GeometryConfigurationVector<T>>();
483485
output_value.clear();
484486
const std::vector<DeformableBodyIndex>& body_indices =
485-
deformable_bodies_.indices();
487+
deformable_bodies_.valid_indices();
486488
for (const DeformableBodyIndex& index : body_indices) {
487489
const DeformableBody<T>& body = deformable_bodies_.get_element(index);
488490
const GeometryId geometry_id = body.geometry_id();

0 commit comments

Comments
 (0)