Get parameters that aren't set (#493)

* Document get_parameters()

* Return NOT_SET params in get params service
This commit is contained in:
Shane Loretz 2018-06-06 10:23:42 -07:00 committed by GitHub
parent 84c8d58612
commit 9b294ec720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -49,16 +49,35 @@ public:
set_parameters_atomically( set_parameters_atomically(
const std::vector<rclcpp::Parameter> & parameters) = 0; 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 RCLCPP_PUBLIC
virtual virtual
std::vector<rclcpp::Parameter> std::vector<rclcpp::Parameter>
get_parameters(const std::vector<std::string> & names) const = 0; 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 RCLCPP_PUBLIC
virtual virtual
rclcpp::Parameter rclcpp::Parameter
get_parameter(const std::string & name) const = 0; 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 RCLCPP_PUBLIC
virtual virtual
bool bool

View file

@ -39,9 +39,12 @@ ParameterService::ParameterService(
const std::shared_ptr<rcl_interfaces::srv::GetParameters::Request> request, const std::shared_ptr<rcl_interfaces::srv::GetParameters::Request> request,
std::shared_ptr<rcl_interfaces::srv::GetParameters::Response> response) std::shared_ptr<rcl_interfaces::srv::GetParameters::Response> response)
{ {
auto values = node_params->get_parameters(request->names); for (const auto & name : request->names) {
for (auto & pvariant : values) { // Default construct param to NOT_SET
response->values.push_back(pvariant.get_value_message()); 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); qos_profile, nullptr);