-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:ctu-mrs/mrs_lib
- Loading branch information
Showing
8 changed files
with
181 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,79 @@ | ||
// clang: MatousFormat | ||
/** \file | ||
\brief Defines ParamProvider - a helper class for ParamLoader. | ||
\author Matouš Vrba - [email protected] | ||
*/ | ||
|
||
#ifndef PARAM_PROVIDER_H | ||
#define PARAM_PROVIDER_H | ||
|
||
#include <string> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <yaml-cpp/yaml.h> | ||
#include <ros/node_handle.h> | ||
|
||
namespace mrs_lib | ||
{ | ||
|
||
/*** ParamProvider CLASS //{ **/ | ||
|
||
/** | ||
* \brief Helper class for ParamLoader. | ||
* | ||
* This class abstracts away loading of parameters from ROS parameter server and directly from | ||
* YAML files ("static" parameters). The user can specify a number of YAML files that will be | ||
* parsed and when a parameter value is requested, these are checked first before attempting | ||
* to load the parameter from the ROS server (which can be slow). The YAML files are searched | ||
* in FIFO order and when a matching name is found in a file, its value is returned. | ||
* | ||
*/ | ||
class ParamProvider | ||
{ | ||
public: | ||
|
||
/*! | ||
* \brief Main constructor. | ||
* | ||
* \param nh The parameters will be loaded from rosparam using this node handle. | ||
* \param node_name Optional node name used when printing the loaded values or loading errors. | ||
* \param use_rosparam If true, parameters that weren't found in the YAML files will be attempted to be loaded from ROS. | ||
*/ | ||
ParamProvider(const ros::NodeHandle& nh, std::string node_name, const bool use_rosparam = true); | ||
|
||
/*! | ||
* \brief Add a YAML file to be parsed and used for loading parameters. | ||
* | ||
* The first file added will be the first file searched for a parameter when using getParam(). | ||
* | ||
* \param filepath Path to the YAML file. | ||
*/ | ||
bool addYamlFile(const std::string& filepath); | ||
|
||
/*! | ||
* \brief Gets the value of a parameter. | ||
* | ||
* Firstly, the parameter is attempted to be loaded from the YAML files added by the addYamlFile() method | ||
* in the same order that they were added. If the parameter is not found in any YAML file, and the use_rosparam | ||
* flag of the constructor is true, the ParamProvider will attempt to load it from the ROS parameter server. | ||
* | ||
* \param param_name Name of the parameter to be loaded. Namespaces should be separated with a forward slash '/'. | ||
* \param value_out Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. | ||
* \return Returns true iff the parameter was successfully loaded. | ||
*/ | ||
template <typename T> | ||
bool getParam(const std::string& param_name, T& value_out) const; | ||
|
||
/*! | ||
* \brief Specialization of getParam() for the XmlRpcValue type. | ||
* | ||
* The XmlRpc::XmlRpcValue can be useful for manual parsing of more complex types. | ||
* | ||
* \warning XmlRpc::XmlRpcValue parameters cannot be loaded from a YAML file - only from ROS! | ||
* | ||
* \param param_name Name of the parameter to be loaded. Namespaces should be separated with a forward slash '/'. | ||
* \param value_out Output argument that will hold the value of the loaded parameter, if successfull. Not modified otherwise. | ||
* \return Returns true iff the parameter was successfully loaded. | ||
*/ | ||
bool getParam(const std::string& param_name, XmlRpc::XmlRpcValue& value_out) const; | ||
|
||
ParamProvider(const ros::NodeHandle& nh, std::string node_name, const bool use_rosparam = true); | ||
|
||
bool addYamlFile(const std::string& filepath); | ||
|
||
private: | ||
|
||
std::vector<YAML::Node> m_yamls; | ||
|
@@ -35,7 +86,7 @@ namespace mrs_lib | |
|
||
std::optional<YAML::Node> findYamlNode(const std::string& param_name) const; | ||
}; | ||
|
||
//} | ||
} | ||
|
||
#include "mrs_lib/impl/param_provider.hpp" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ test_param_matrix: [] | |
|
||
services: | ||
complex_structure: ["asd"] | ||
|
||
rosparam_xmlrpc_value: "somestuff" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ static_param: ["a", "b", "c", "d"] | |
ns1: | ||
ns2: | ||
a: 5.0 | ||
static_xmlrpc_value: "someotherstuff" |