PickNikRobotics / generate_parameter_library

Declarative ROS 2 Parameters
BSD 3-Clause "New" or "Revised" License
240 stars 45 forks source link

Statically Sized Parameters #190

Open jcarpinelli-bdai opened 6 months ago

jcarpinelli-bdai commented 6 months ago

Is it possible to configure std::array-valued parameters for fixed-size definitions? For example, for Cartesian stiffness gains, I'm currently using...

cartesian_impedance_parameters:
  stiffness: 
    x: {
        type: double,
    }, 
    y: {
        type: double,
    },
    ...

It may be nice to have a single parameter for stiffness gains, but still have stack-allocated values. For example...

cartesian_impedance_parameters:
  stiffness: {
    type: double_array_fixed_06,
  }

Do you agree this feature does not currently exist, but may be a nice feature to have?

pac48 commented 6 months ago

@jcarpinelli-bdai we do support a feature that is similar to what you are asking for. You can check here in the example for how it is used. The referenced example creates a vector that is at most size 10 and is stack-allocated. If you want to require a specific size, you could probably use gt<> and lt<> validators.

To answer your question, we somewhat support that and it is useful. Also, you may have issues with the leading zero in front of the 6. I'm not positive if that is valid.

jcarpinelli-bdai commented 6 months ago

Thank you, @pac48! To clarify, what value should the resulting parameter take? Is it an std::vector that is somehow stack allocated, with a maximum size? Or is it supposed to be an std::array?

pac48 commented 6 months ago

@jcarpinelli-bdai The type is a rsl::StaticVector<double, 10>, which is a custom type in the Robot Support Library. Here is the definition https://github.com/PickNikRobotics/RSL/blob/e93c5456c2a328de6ae18f4b663a7dbc74c1a81d/include/rsl/static_vector.hpp#L18 . Under the hood, it does use a std::array.