Drake: RigidBodyPlant needs named (vs numbered) output port getters

Created on 4 Nov 2016  路  9Comments  路  Source: RobotLocomotion/drake

See https://github.com/RobotLocomotion/drake/pull/3995#issuecomment-258405893

Users should never have to write rigid_body_plant->get_output_port(0); the 0 is a magic number. There should instead be an accessor like rigid_body_plant->get_state_vector_port() or similar.

Perhaps even the get_output_port(int) visibility should be narrowed in the plant, to encourage users to call the named accessor.

medium dynamics bug

All 9 comments

I agree! There are several entities in System 2 that are crying out for names IMO:

  • input and output ports
  • subsystems
  • parameters

I would like to see these with unique pathnames so that everything in a Diagram can be easily named.

String names are _might be_ fine, too. We also need (and this PR is about) compile-time-checked names.

Oh. Sorry, I got excited and lost my mind. You just mean some handy enumszzzzz...

Well, enums are better that nothing, but still suffer from death-by-integer. I think that rigid_body_plant->get_state_vector_port() is superior to rigid_body_plan->get_output_port(int(RigidBodyPlantPorts::kStateVector)).

For the usage case in #3995 I think you are asking for methods in RigidBodyPlant that look more like const SystemPortDescriptor<T>& get_generalized_forces_port() const and const SystemPortDescriptor<T>& get_state_vector_port() const? essentially something I can pass to `DiagramBuilder::Connect(src_port, dst_port)?

@amcastro-tri Yes, exactly. And then make the get_output_port(int) hidden on the RBP class, if possible. (Users would have to upcast to System in order to call if, they really needed to.)

I think @siyuanfeng-tri has already fixed this?

I also have a further refined version in #4766.

i think we have state_output_port(), kinematics_results_output_port() and contact_results_output_port().

Was this page helpful?
0 / 5 - 0 ratings