Get parameters that aren't set (#493)
* Document get_parameters() * Return NOT_SET params in get params service
This commit is contained in:
parent
84c8d58612
commit
9b294ec720
2 changed files with 25 additions and 3 deletions
|
@ -49,16 +49,35 @@ public:
|
|||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue