2

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,

cjds
  • 8,268
  • 10
  • 49
  • 84

1 Answers1

4

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.

Russ Tedrake
  • 4,703
  • 1
  • 7
  • 10
  • 1
    I agree with Russ, that is not a workflow Drake systems support. Systems are "const" once instantiated and you cannot add more ports to them. You could for instance make MBP part of a Diagram that does happen to export a port useful to you for instance. But as Russ mentioned, we'd need to know more about your problem. What quantity are you looking to expose in an output port? – Alejandro Dec 04 '20 at 15:16
  • 1
    Yeah, I think y'all's answer covers their question here: "Am I thinking of MultiBodyPlants wrong and should I define create my own LeafSystem". So yup! Definitely should create a separate `LeafSystem`! – Eric Cousineau Dec 04 '20 at 22:30
  • Yep thanks @RussTedrake. That makes a lot of sense. I think I was struggling to understand where `MultibodyPlant`s as a concept fit in the `System`s heirarchy, @Alejandro I'm just playing with Drake so was trying to make a MBP from a Pendulum URDF and expose angle between the joints as an output port. I think I can do that as part of my Diagram – cjds Dec 05 '20 at 20:06