Skip to content

Commit

Permalink
Get parameters that aren't set (#493)
Browse files Browse the repository at this point in the history
* Document get_parameters()

* Return NOT_SET params in get params service
  • Loading branch information
sloretz authored Jun 6, 2018
1 parent 84c8d58 commit 9b294ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,35 @@ class NodeParametersInterface
set_parameters_atomically(
const std::vector<rclcpp::Parameter> & parameters) = 0;

/// Get descriptions of parameters given their names.
/*
* \param[in] names a list of parameter names to check.
* \return the list of parameters that were found.
* Any parameter not found is omitted from the returned list.
*/
RCLCPP_PUBLIC
virtual
std::vector<rclcpp::Parameter>
get_parameters(const std::vector<std::string> & names) const = 0;

/// Get the description of one parameter given a name.
/*
* \param[in] name the name of the parameter to look for.
* \return the parameter if it exists on the node.
* \throws std::out_of_range if the parameter does not exist on the node.
*/
RCLCPP_PUBLIC
virtual
rclcpp::Parameter
get_parameter(const std::string & name) const = 0;

/// Get the description of one parameter given a name.
/*
* \param[in] name the name of the parameter to look for.
* \param[out] parameter the description if parameter exists on the node.
* \return true if the parameter exists on the node, or
* \return false if the parameter does not exist.
*/
RCLCPP_PUBLIC
virtual
bool
Expand Down
9 changes: 6 additions & 3 deletions rclcpp/src/rclcpp/parameter_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ ParameterService::ParameterService(
const std::shared_ptr<rcl_interfaces::srv::GetParameters::Request> request,
std::shared_ptr<rcl_interfaces::srv::GetParameters::Response> response)
{
auto values = node_params->get_parameters(request->names);
for (auto & pvariant : values) {
response->values.push_back(pvariant.get_value_message());
for (const auto & name : request->names) {
// Default construct param to NOT_SET
rclcpp::Parameter param;
node_params->get_parameter(name, param);
// push back NOT_SET when get_parameter() call fails
response->values.push_back(param.get_value_message());
}
},
qos_profile, nullptr);
Expand Down

0 comments on commit 9b294ec

Please sign in to comment.