Skip to content

Commit 0dff9a2

Browse files
committed
Adding SetTopologyOptions(); needs work
1 parent ba8714d commit 0dff9a2

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

multibody/plant/multibody_plant.cc

+13
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,19 @@ void MultibodyPlant<T>::RenameModelInstance(ModelInstanceIndex model_instance,
12661266
}
12671267
}
12681268

1269+
template <typename T>
1270+
void MultibodyPlant<T>::SetTopologyOptions(
1271+
internal::ForestBuildingOptions options,
1272+
std::optional<ModelInstanceIndex> model_instance) {
1273+
DRAKE_THROW_UNLESS(!is_finalized());
1274+
internal::LinkJointGraph& graph = mutable_tree().mutable_graph();
1275+
if (model_instance.has_value()) {
1276+
graph.SetForestBuildingOptions(*model_instance, options);
1277+
} else {
1278+
graph.SetGlobalForestBuildingOptions(options);
1279+
}
1280+
}
1281+
12691282
template <typename T>
12701283
void MultibodyPlant<T>::Finalize() {
12711284
// After finalizing the base class, tree is read-only.

multibody/plant/multibody_plant.h

+23
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,29 @@ class MultibodyPlant : public internal::MultibodyTreeSystem<T> {
16671667
void RenameModelInstance(ModelInstanceIndex model_instance,
16681668
const std::string& name);
16691669

1670+
/// Sets options that affect the topology of the graph that will be
1671+
/// constructed to model this system when Finalize() is called. Options can be
1672+
/// set globally or for a particular ModelInstance. Global options are used
1673+
/// for any model elements that belong to model instances for which no
1674+
/// options have been set explicitly.
1675+
///
1676+
/// | TopologyOption | Description |
1677+
/// | --------------------- | ----------------------------------- |
1678+
/// | kDefault | QuaternionFloatingJoint base bodies |
1679+
/// | kUseRpyFloatingJoints | RpyFloatingJoint base bodies |
1680+
/// | kUseFixedBase | WeldJoint base bodies |
1681+
/// | kStatic | Weld each body to World |
1682+
///
1683+
/// @param[in] options TopologyOptions, or-ed together
1684+
/// @param[in] model_instance (optional) the index of the model instance to
1685+
/// which `options` is to be applied.
1686+
/// @note Options set for a ModelInstance are used _instead_ of the global
1687+
/// options; they are not merged.
1688+
/// @throws std::exception if called after Finalize().
1689+
void SetTopologyOptions(
1690+
internal::ForestBuildingOptions options,
1691+
std::optional<ModelInstanceIndex> model_instance = {});
1692+
16701693
/// This method must be called after all elements in the model (joints,
16711694
/// bodies, force elements, constraints, etc.) are added and before any
16721695
/// computations are performed.

multibody/tree/mobilizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class Mobilizer : public MultibodyElement<T> {
395395
// Sets the default state stored with the mobilizer to some approximation of
396396
// this pose. It's up to the concrete mobilizer to figure out what to do.
397397
// (Only QuaternionFloatingMobilizer can represent this pose bit-exactly.) The
398-
// result will affect MultibodyPlant::SetDefaultContext().
398+
// result will affect CreateDefaultContext().
399399
// TODO(sherm1) Currently this is only implemented for 6dof mobilizers.
400400
// It's still useful for other joints; broaden support.
401401
virtual void SetDefaultPosePair(const Eigen::Quaternion<double> q_FM,

multibody/tree/multibody_tree.h

+2
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ class MultibodyTree {
959959
return link_joint_graph_;
960960
}
961961

962+
[[nodiscard]] LinkJointGraph& mutable_graph() { return link_joint_graph_; }
963+
962964
[[nodiscard]] const SpanningForest& forest() const {
963965
DRAKE_ASSERT(graph().forest_is_valid());
964966
return graph().forest();

0 commit comments

Comments
 (0)