Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow declaring parameters with uninitialized values #1649

Closed
jacobperron opened this issue Apr 30, 2021 · 3 comments · Fixed by #1673
Closed

Allow declaring parameters with uninitialized values #1649

jacobperron opened this issue Apr 30, 2021 · 3 comments · Fixed by #1673
Assignees
Labels
enhancement New feature or request

Comments

@jacobperron
Copy link
Member

Feature request

Feature description

There are situations where we want to declare a parameter, but not initialize it until later.

For example, it would be nice to declare a parameter, with a type like this without it throwing an exception because the user did not provide an override at runtime:

node->declare_parameter(name, type);

We could then later set the value of the parameter programmatically from the node itself (e.g. with set_parameter) or let the user set it later with a service call (e.g. ros2 param set).

Implementation considerations

After declaring a parameter without an initial value and if there is no user-provided override, then I would expect the parameter to have a value of "UNSET", and trying to access a value might throw an exception.

@jacobperron jacobperron added the enhancement New feature or request label Apr 30, 2021
@jacobperron
Copy link
Member Author

Follow-up from #1588

@jacobperron
Copy link
Member Author

Although this would be a behavior change, IMO, we should backport this to Galactic. My reasoning is that, currently, there is no way to support "optional" parameters besides allowing undeclared parameters or optionally declaring parameters (I consider the latter as an anti-pattern as discussed in #1588). Therefore, without this feature users will have to resort to less than desirable solutions for scenarios where they need optional parameter values. Prior to Galactic, this feature was possible as users could declare a parameter with an unset type with:

node->declare_parameter("my_param");

@jacobperron jacobperron self-assigned this May 13, 2021
jacobperron added a commit that referenced this issue May 13, 2021
Fixes #1649

Allow declaring parameters without an initial value or override.
This was possible prior to Galactic, but was made impossible since we started enforcing the types of parameters in Galactic.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@jacobperron
Copy link
Member Author

For reference, this is the original PR adding static typing of parameters: #1522

jacobperron added a commit that referenced this issue May 19, 2021
* Declare parameters uninitialized

Fixes #1649

Allow declaring parameters without an initial value or override.
This was possible prior to Galactic, but was made impossible since we started enforcing the types of parameters in Galactic.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove assertion

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Throw NoParameterOverrideProvided exception if accessed before initialized

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Add test getting static parameter after it is set

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Do not throw on access of uninitialized dynamically typed parameter

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Rename exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove unused exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Uncrustify

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
jacobperron added a commit that referenced this issue May 19, 2021
* Declare parameters uninitialized

Fixes #1649

Allow declaring parameters without an initial value or override.
This was possible prior to Galactic, but was made impossible since we started enforcing the types of parameters in Galactic.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove assertion

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Throw NoParameterOverrideProvided exception if accessed before initialized

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Add test getting static parameter after it is set

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Do not throw on access of uninitialized dynamically typed parameter

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Rename exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove unused exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Uncrustify

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
jacobperron added a commit that referenced this issue May 20, 2021
* Declare parameters uninitialized

Fixes #1649

Allow declaring parameters without an initial value or override.
This was possible prior to Galactic, but was made impossible since we started enforcing the types of parameters in Galactic.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove assertion

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Throw NoParameterOverrideProvided exception if accessed before initialized

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Add test getting static parameter after it is set

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Do not throw on access of uninitialized dynamically typed parameter

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Rename exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Remove unused exception type

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Uncrustify

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant