How do you declare an abstract port on a MultiBodyPlant

Viewed 70

I would like to do declare an AbstractOutputPort is so I can use calculations from the abstract port in my controller.

Am I thinking of MultiBodyPlants wrong and should I define create my own LeafSystem

void outputGeometryPose(
    const drake::systems::Context<double>& context,
    drake::geometry::FramePoseVector<double>* poses) {
}

// I also tried
// void outputGeometryPose(
//  const drake::systems::Context<double>& context,
//  drake::geometry::FrameKinematicsVector<drake::math::RigidTransform<double> >* ) {
// }


MultibodyPlant<double>* dp = builder.AddSystem<MultibodyPlant<double>>(max_time_step);
dp->set_name("plant");
dp->RegisterAsSourceForSceneGraph(&scene_graph);

Parser parser(dp);
parser.AddModelFromFile(kDoublePendulumSdfPath);

dp->DeclareAbstractOutputPort("geometry_pose", outputGeometryPose);

This is what I'm trying but I get the following compile error

bazel-out/k8-opt/bin/external/drake/systems/framework/_virtual_includes/leaf_system/drake/systems/framework/leaf_system.h:1573:3: note: candidate template ignored: could not match 'void (MySystem::*)(const Context<double> &, OutputType *) const' against 'void (*)(const drake::systems::Context<double> &, drake::geometry::FrameKinematicsVector<drake::math::RigidTransform<double> > *)'
  DeclareAbstractOutputPort(const OutputType& model_value,

1 Answers

A LeafSystem (like MultibodyPlant) is responsible for creating its own input / output ports internally. You cannot add additional ports to the MultibodyPlant from outside it.

But I would think that MultibodyPlant already offers output ports for any multibody-related quantities that you would need. If you tell us a little more about what you are trying to achieve, we might be able to suggest an architecture.

Related