38 #ifndef POLICY_IMPROVEMENT_UTILITIES_PARAM_SERVER_H_
39 #define POLICY_IMPROVEMENT_UTILITIES_PARAM_SERVER_H_
50 namespace stomp_motion_planner
53 inline bool readDoubleArray(ros::NodeHandle& node_handle,
const std::string& parameter_name, std::vector<double>& array)
55 XmlRpc::XmlRpcValue list;
56 node_handle.getParam(parameter_name, list);
58 if (list.getType() != XmlRpc::XmlRpcValue::TypeArray)
60 ROS_ERROR(
"Parameter %s/%s needs to be an *array* of doubles", node_handle.getNamespace().c_str(), parameter_name.c_str());
65 for (int32_t i = 0; i < list.size(); ++i)
67 if (list[i].getType() != XmlRpc::XmlRpcValue::TypeDouble &&
68 list[i].getType() != XmlRpc::XmlRpcValue::TypeInt)
70 ROS_ERROR(
"Parameter %s/%s needs to be an array of *doubles*", node_handle.getNamespace().c_str(), parameter_name.c_str());
74 if (list[i].getType() == XmlRpc::XmlRpcValue::TypeInt)
75 value = static_cast<double>(static_cast<int>(list[i]));
76 else value =
static_cast<double>(list[i]);
77 array.push_back(value);
82 inline bool readEigenVector(ros::NodeHandle& node_handle,
const std::string& parameter_name, Eigen::VectorXd& vector)
84 std::vector<double> array;
85 if (!readDoubleArray(node_handle, parameter_name, array))
90 vector = Eigen::VectorXd::Zero(array.size());
91 for (
int i=0; i<int(array.size()); ++i)
100 inline bool read(ros::NodeHandle& node_handle,
const std::string& parameter_name, std::string& parameter_value)
102 if (!node_handle.getParam(parameter_name, parameter_value))
104 ROS_ERROR(
"Parameter %s/%s not found!", node_handle.getNamespace().c_str(), parameter_name.c_str());
109 inline bool read(ros::NodeHandle& node_handle,
const std::string& parameter_name,
double& parameter_value)
111 if (!node_handle.getParam(parameter_name, parameter_value))
113 ROS_ERROR(
"Parameter %s/%s not found!", node_handle.getNamespace().c_str(), parameter_name.c_str());
118 inline bool read(ros::NodeHandle& node_handle,
const std::string& parameter_name,
int& parameter_value)
120 if (!node_handle.getParam(parameter_name, parameter_value))
122 ROS_ERROR(
"Parameter %s/%s not found!", node_handle.getNamespace().c_str(), parameter_name.c_str());
127 inline bool read(ros::NodeHandle& node_handle,
const std::string& parameter_name,
bool& parameter_value)
129 if (!node_handle.getParam(parameter_name, parameter_value))
131 ROS_ERROR(
"Parameter %s/%s not found!", node_handle.getNamespace().c_str(), parameter_name.c_str());
137 inline bool readStringArraySpaceSeparated(ros::NodeHandle& node_handle,
const std::string& parameter_name, std::vector<std::string>& array)
139 std::string str_array;
141 if (!node_handle.getParam(parameter_name, str_array))
143 ROS_ERROR(
"Parameter %s/%s not found!", node_handle.getNamespace().c_str(), parameter_name.c_str());
148 std::stringstream str_stream(str_array);
150 while (str_stream >> item)
152 array.push_back(item);
157 inline void appendTrailingSlash(std::string& directory_name)
159 if (directory_name.compare(directory_name.size() - 1, 1,
"/") != 0)
161 directory_name.append(
"/");
164 inline void removeLeadingSlash(std::string& topic_name)
166 if (topic_name.compare(0, 1,
"/") == 0)
168 topic_name.assign(topic_name.substr(1, topic_name.length()));
172 inline std::string getString(
const int number)
174 std::stringstream ss;