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

Split ParameterVariant into Parameter and ParameterValue #481

Merged
merged 17 commits into from
Jun 1, 2018

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented May 29, 2018

In progress while CI runs

This PR looks large, but most of the changed lines in this PR are due to renaming ParameterVariant to Parameter. I can split it into smaller PRs if need be.

Changes

  • Renamed ParameterVariant to Parameter
  • Removed rclcpp::parameter namespace (as was done for other namespaces in Remove e.g. node:: namespaces and namespace escalation #416)
  • Moved functions related to getting a parameter value into new ParameterValue class.
  • Raise ParameterTypeException instead of std::runtime_error when there is a type mismatch
  • Rename Parameter::get_parameter_value() to Parameter::get_value_message()
  • Added const to Parameter::to_parameter()

@sloretz sloretz added the in progress Actively being worked on (Kanban column) label May 29, 2018
@sloretz sloretz self-assigned this May 29, 2018
@sloretz
Copy link
Contributor Author

sloretz commented May 29, 2018

CI (6c441ca)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
    • Flaky test? projectroot.test_requester_replier__Primitives__rclpy__rmw_fastrtps_cpp
  • Windows Build Status

@sloretz sloretz mentioned this pull request May 29, 2018
10 tasks
@sloretz
Copy link
Contributor Author

sloretz commented May 30, 2018

CI (f002629)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels May 30, 2018
@dhood
Copy link
Member

dhood commented May 30, 2018

If there was context around this change on another PR, could you link to it please?

@sloretz
Copy link
Contributor Author

sloretz commented May 30, 2018

@dhood context in #477. Reason behind splitting ParameterVariant is to add

NodeParameters::create_parameter(std::string name, ParameterType type, ParameterValue default_value = ParameterValue())

There are other options with some drawbacks

  • create_parameter(std::string name, ParameterType type, ParameterVariant default_value = ParameterVariant()).
    • Need to check consistency between name in ParameterVariant and name.
  • create_parameter(ParameterVariant param, ParameterType type)
    • Currently no ParameterVariant constructor allowing param to both have a name and be initially unset.
  • create_parameter(std::string name, ParameterType type, rcl_interfaces::msg::ParameterValue default_value)
    • Loses convenience of using constructors on ParameterVariant from c++ types

Admittedly these drawbacks are all pretty minor. Subjectively splitting the classes feels nicer to me because it matches rcl_interfaces::msg::Parameter and rcl_interfaces::msg::ParameterValue, as well as ParameterValue matching rcl_variant_t added in ros2/rcl#235

};

/// Indicate the parameter type does not match the expected type.
class ParameterTypeException : public std::exception
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception type should be moved to in rclcpp/exceptions.hpp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this. Though I've gone back and forth on putting the exceptions all in one place versus in files where they might be used. You still need something like rclcpp/exceptions.hpp for exceptions which are used all over the place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing it offline a289f63 makes ParameterTypeException inherit from std::runtime_error but continue to live in this file so it's constructor can continue to use ParameterType.

@sloretz sloretz added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels May 31, 2018
Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, other than some style comments. No blockers.

typename std::enable_if<std::is_convertible<type, std::string>::value, const std::string &>::type
/// Get value of parameter using rclcpp::ParameterType as template argument.
template<ParameterType ParamT>
decltype(ParameterValue().get<ParamT>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit clunky, is it possible to use auto for the return type? or to improve it with something in the ParameterValue class? So that you could do something like ParameterValue::type<ParamT>::type?

Would just decltype(ParameterValue::get<ParamT>) work?

Or decltype(auto) (http://en.cppreference.com/w/cpp/language/auto)?

I would try one of the alternatives, but I don't have these branches setup locally.

Copy link
Contributor Author

@sloretz sloretz May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules for auto don't seem to allow for only some of the functions return references. decltype(auto) works! f8646d0

public:
/// Construct an instance.
/// \param[in] expected the expected parameter type.
/// \param[in] actual the actual parameter type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: the rest of the code uses:

/// Brief on one line.
/**
 * absolutely anything else...
 */
code...

You might want to use this style in the future for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bea1335

};

/// Indicate the parameter type does not match the expected type.
class ParameterTypeException : public std::exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this. Though I've gone back and forth on putting the exceptions all in one place versus in files where they might be used. You still need something like rclcpp/exceptions.hpp for exceptions which are used all over the place.

Copy link
Member

@dhood dhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get to finish a thorough review but these are some comments from what I got to

@@ -49,7 +49,7 @@
* - rclcpp::Node::describe_parameters()
* - rclcpp::Node::list_parameters()
* - rclcpp::Node::register_param_change_callback()
* - rclcpp::parameter::ParameterVariant
* - rclcpp::Parameter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add parameter_value.hpp below too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 18555dc

from_parameter(const rcl_interfaces::msg::Parameter & parameter);

RCLCPP_PUBLIC
rcl_interfaces::msg::Parameter
to_parameter();
to_parameter() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the name of this function ought to be renamed now. Parameter.to_parameter is confusing to me. Maybe to_rcl_parameter and from_rcl_parameter above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if xxx_rcl_parameter isn't specific enough now that ros2/rcl#235 added rcl_params_t. What do you think of xxx_parameter_message()?

Copy link
Member

@dhood dhood May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, or xx_parameter_msg (might be more natural when writing a line like this) but I don't have a strong preference either way: whatever fits better with our existing naming scheme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_parameter_msg() and from_parameter_msg() in
22d89b9

Also changed ParameterValue::get_message() to to_value_msg() to match.

@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 1, 2018
@sloretz
Copy link
Contributor Author

sloretz commented Jun 1, 2018

All comments addressed. Rerunning CI

  • Linux Build Status
    • Unrelated Flake 8 failures
  • Linux-aarch64 Build Status
    • Unrelated Flake 8 failures
  • macOS Build Status
    • Unrelated Flake 8 failures
  • Windows Build Status
    • Unrelated Flake 8 failures

@sloretz
Copy link
Contributor Author

sloretz commented Jun 1, 2018

CI looks good. @wjwwood Would you mind checking if the changes since your review look ok? https://github.com/ros2/rclcpp/pull/481/files/f0026290fe8cdddc8aa5e3966c13a139f401c51f..22d89b9ba05bbfb38b389fb120ee31e76034f65b

@sloretz sloretz merged commit d298fa4 into master Jun 1, 2018
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Jun 1, 2018
@sloretz sloretz deleted the split_parametervariant branch June 1, 2018 20:26
@mikaelarguedas
Copy link
Member

@sloretz FYI: follow up PR at ros2/navigation#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants