Git Product home page Git Product logo

Comments (4)

clalancette avatar clalancette commented on July 19, 2024 1
  • The name on_set_parameters_callback suggests that this is when the parameters are set, or should be set, while in fact the internal state should not be altered,

While I don't disagree, we've already renamed this callback 3 times. And since this is the oldest of the callbacks, it has the most users. So I'm not super inclined to change this one yet again.

  • But in the example code, the post_set callback is used to update the node parameters.

No, that example code does not change the node parameters. It changes internal class state, which is a different thing. That is, there is a (private) database of node parameters that rclcpp tracks, and by the time that post_set is called, that database has been updated. The purpose of the post_set is to give the user the chance to make internal changes based on that, which is what the example shows. Maybe we should update the name of the member fields in the example code, and/or update the documentation?

from rclcpp.

jrutgeer avatar jrutgeer commented on July 19, 2024

So I'm not super inclined to change

That's why I used the wording "I propose to consider". ;-)

this one yet again.

I would rename all, or none.
Or maybe add the new names as an alias and also keep the current ones?
Anyway if it is deemed not important enough than that's fine as well.

No, that example code does not change the node parameters. It changes internal class state, which is a different thing.

Ok, I totally missed that the internal_tracked_class_parameter_X_ variables are of type double.
I assumed that this->declare_parameter() would return a rclcpp::Parameter, similar to this->get_parameter().
So I was expecting rather:

internal_tracked_class_parameter_1_ = this->declare_parameter("param1", 0.0).as_double();
[...]
internal_tracked_class_parameter_1_ = this->get_parameter("param1").as_double();

from rclcpp.

clalancette avatar clalancette commented on July 19, 2024

Ok, I totally missed that the internal_tracked_class_parameter_X_ variables are of type double.
I assumed that this->declare_parameter() would return a rclcpp::Parameter, similar to this->get_parameter().

It has a bunch of overloads, some of which return an rclcpp::ParameterValue and some of which return the type given based on template automagic; see

RCLCPP_PUBLIC
const rclcpp::ParameterValue &
declare_parameter(
const std::string & name,
const rclcpp::ParameterValue & default_value,
const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
rcl_interfaces::msg::ParameterDescriptor(),
bool ignore_override = false);
/// Declare and initialize a parameter, return the effective value.
/**
* Same as the previous one, but a default value is not provided and the user
* must provide a parameter override of the correct type.
*
* \param[in] name The name of the parameter.
* \param[in] type Desired type of the parameter, which will enforced at runtime.
* \param[in] parameter_descriptor An optional, custom description for
* the parameter.
* \param[in] ignore_override When `true`, the parameter override is ignored.
* Default to `false`.
* \return A const reference to the value of the parameter.
* \throws Same as the previous overload taking a default value.
* \throws rclcpp::exceptions::InvalidParameterTypeException
* if an override is not provided or the provided override is of the wrong type.
*/
RCLCPP_PUBLIC
const rclcpp::ParameterValue &
declare_parameter(
const std::string & name,
rclcpp::ParameterType type,
const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
rcl_interfaces::msg::ParameterDescriptor{},
bool ignore_override = false);
/// Declare and initialize a parameter with a type.
/**
* See the non-templated declare_parameter() on this class for details.
*
* If the type of the default value, and therefore also the type of return
* value, differs from the initial value provided in the node options, then
* a rclcpp::exceptions::InvalidParameterTypeException may be thrown.
* To avoid this, use the declare_parameter() method which returns an
* rclcpp::ParameterValue instead.
*
* Note, this method cannot return a const reference, because extending the
* lifetime of a temporary only works recursively with member initializers,
* and cannot be extended to members of a class returned.
* The return value of this class is a copy of the member of a ParameterValue
* which is returned by the other version of declare_parameter().
* See also:
*
* - https://en.cppreference.com/w/cpp/language/lifetime
* - https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/
* - https://www.youtube.com/watch?v=uQyT-5iWUow (cppnow 2018 presentation)
*/
template<typename ParameterT>
auto
declare_parameter(
const std::string & name,
const ParameterT & default_value,
const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
rcl_interfaces::msg::ParameterDescriptor(),
bool ignore_override = false);
/// Declare and initialize a parameter with a type.
/**
* See the non-templated declare_parameter() on this class for details.
*/
template<typename ParameterT>
auto
declare_parameter(
const std::string & name,
const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
rcl_interfaces::msg::ParameterDescriptor(),
bool ignore_override = false);

That said, I'm not sure whether we have examples showing all of those overloads (though we do seem to have tests for it).

Given what you've said so far, I think for now what we should do is to update the demos to make it clear that those are internal class variables, and possibly update the documentation to better describe what is going on here. @jrutgeer would you be willing to take a shot at doing those?

from rclcpp.

jrutgeer avatar jrutgeer commented on July 19, 2024

@clalancette Can you check this proposal ros2/demos#651? See also the open questions in the comment.

from rclcpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.