00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "parameter_pa/parameter_pa_ros.h"
00048
00049
00050 #include <ros/package.h>
00051 #include <XmlRpcValue.h>
00052
00053
00054 #include <sstream>
00055
00056
00057 bool cParameterPaRos::load (const std::string name,
00058 bool &value,
00059 const bool print_default) const {
00060 bool result;
00061
00062 result = nh_.getParam(ros::names::resolve(name), value);
00063
00064 loadSub(name, bool_to_str(value), print_default, result);
00065
00066 return result;
00067 }
00068
00069
00070 bool cParameterPaRos::load (const std::string name,
00071 std::string &value,
00072 const bool print_default) const {
00073 bool result;
00074
00075 result = nh_.getParam(ros::names::resolve(name), value);
00076
00077 loadSub(name, value, print_default, result);
00078
00079 return result;
00080 }
00081
00082
00083 bool cParameterPaRos::load_topic (const std::string name,
00084 std::string &value,
00085 const bool print_default) const {
00086 bool result;
00087
00088 result = nh_.getParam(ros::names::resolve(name), value);
00089 if (value != "") {
00090 resolve_ressourcename(value);
00091 }
00092
00093 loadSub(name, value, print_default, result);
00094
00095 return result;
00096 }
00097
00098
00099 bool cParameterPaRos::load_path (const std::string name,
00100 std::string &value,
00101 const bool print_default) const {
00102 bool result;
00103
00104 result = nh_.getParam(ros::names::resolve(name), value);
00105 replace_findpack(value);
00106
00107 loadSub(name, value, print_default, result);
00108
00109 return result;
00110 }
00111
00112
00113 bool cParameterPaRos::load (const std::string name,
00114 int &value,
00115 const bool print_default) const {
00116 bool result;
00117
00118 result = nh_.getParam(ros::names::resolve(name), value);
00119
00120 std::stringstream value_s;
00121 value_s << value;
00122 loadSub(name, value_s.str(), print_default, result);
00123
00124 return result;
00125 }
00126
00127
00128 bool cParameterPaRos::load (const std::string name,
00129 double &value,
00130 const bool print_default) const {
00131 bool result;
00132
00133 result = nh_.getParam(ros::names::resolve(name), value);
00134
00135 std::stringstream value_s;
00136 value_s << value;
00137 loadSub(name, value_s.str(), print_default, result);
00138
00139 return result;
00140 }
00141
00142
00143 bool cParameterPaRos::load (const std::string name,
00144 std::vector<bool> &value,
00145 const bool print_default) const {
00146 bool result;
00147
00148 std::vector<bool> value_temp;
00149 result = nh_.getParam(ros::names::resolve(name), value_temp);
00150 if (result) {value = value_temp;}
00151
00152 std::stringstream value_s;
00153 value_s << "[";
00154 if (value.size() > 0) {
00155 value_s << bool_to_str(value[0]);
00156 for (int i = 1; i < value.size(); i++) {
00157 value_s << ", " << bool_to_str(value[i]);
00158 }
00159 }
00160 value_s << "]";
00161 loadSub(name, value_s.str(), print_default, result);
00162
00163 return result;
00164 }
00165
00166
00167 bool cParameterPaRos::load (const std::string name,
00168 std::vector<std::string> &value,
00169 const bool print_default) const {
00170 bool result;
00171
00172 std::vector<std::string> value_temp;
00173 result = nh_.getParam(ros::names::resolve(name), value_temp);
00174 if (result) {value = value_temp;}
00175
00176 std::stringstream value_s;
00177 value_s << "[";
00178 if (value.size() > 0) {
00179 value_s << value[0];
00180 for (int i = 1; i < value.size(); i++) {
00181 value_s << ", " << value[i];
00182 }
00183 }
00184 value_s << "]";
00185 loadSub(name, value_s.str(), print_default, result);
00186
00187 return result;
00188 }
00189
00190
00191 bool cParameterPaRos::load (const std::string name,
00192 std::vector<int> &value,
00193 const bool print_default) const {
00194 bool result;
00195
00196 std::vector<int> value_temp;
00197 result = nh_.getParam(ros::names::resolve(name), value_temp);
00198 if (result) {value = value_temp;}
00199
00200 std::stringstream value_s;
00201 value_s << "[";
00202 if (value.size() > 0) {
00203 value_s << value[0];
00204 for (int i = 1; i < value.size(); i++) {
00205 value_s << ", " << value[i];
00206 }
00207 }
00208 value_s << "]";
00209 loadSub(name, value_s.str(), print_default, result);
00210
00211 return result;
00212 }
00213
00214
00215 bool cParameterPaRos::load (const std::string name,
00216 std::vector<double> &value,
00217 const bool print_default) const {
00218 bool result;
00219
00220 std::vector<double> value_temp;
00221 result = nh_.getParam(ros::names::resolve(name), value_temp);
00222 if (result) {value = value_temp;}
00223
00224 std::stringstream value_s;
00225 value_s << "[";
00226 if (value.size() > 0) {
00227 value_s << value[0];
00228 for (int i = 1; i < value.size(); i++) {
00229 value_s << ", " << value[i];
00230 }
00231 }
00232 value_s << "]";
00233 loadSub(name, value_s.str(), print_default, result);
00234
00235 return result;
00236 }
00237
00238
00239 bool cParameterPaRos::load (const std::string name,
00240 Eigen::MatrixXf &value,
00241 const bool print_default) const {
00242 bool result = true;
00243
00244 Eigen::MatrixXf mat;
00245
00246 XmlRpc::XmlRpcValue xml;
00247 nh_.getParam(ros::names::resolve(name), xml);
00248
00249
00250 if((xml.getType() != XmlRpc::XmlRpcValue::TypeArray) ||
00251 (xml.size() < 1)) {
00252 result = false;
00253 } else {
00254 for (int y = 0; y < xml.size(); y++) {
00255
00256 if ((xml[y].getType() != XmlRpc::XmlRpcValue::TypeArray) ||
00257 (xml[y].size() < 1)) {
00258 result = false;
00259 break;
00260 }
00261
00262
00263 if (y == 0) {
00264 mat.resize((int) xml.size(),(int) xml[y].size());
00265 } else if (xml[y].size() != mat.cols()){
00266 result = false;
00267 break;
00268 }
00269
00270 for (int x = 0; x < xml[y].size(); x++) {
00271 if (result == false) {break;}
00272
00273 switch (xml[y][x].getType()) {
00274 case XmlRpc::XmlRpcValue::TypeDouble:
00275 mat(y,x) = (double) xml[y][x];
00276 break;
00277 case XmlRpc::XmlRpcValue::TypeInt:
00278 mat(y,x) = (int) xml[y][x];
00279 break;
00280
00281 default:
00282 result = false;
00283 break;
00284 }
00285 }
00286 if (result == false) {
00287 break;
00288 }
00289 }
00290 }
00291
00292 if (result) {value = mat;}
00293
00294 std::stringstream value_s;
00295 value_s << '[';
00296 for (int y = 0; y < value.rows(); y++) {
00297 if (y > 0) { value_s << ", ";}
00298 value_s << '[';
00299 for (int x = 0; x < value.cols(); x++) {
00300 if (x > 0) { value_s << ", ";}
00301 value_s << value(y,x);
00302 }
00303 value_s << ']';
00304 }
00305 value_s << ']';
00306
00307
00308 value_s << std::endl << "Vergleich:" << std::endl << value;
00309
00310 loadSub(name, value_s.str(), print_default, result);
00311
00312 return result;
00313 }
00314
00315
00316 void cParameterPaRos::loadSub(const std::string &n, const std::string &v,
00317 const bool p, const bool r) const {
00318 std::string result;
00319
00320 if (r) {
00321 result = "load parameter " + n + " (" + v + ")";
00322 } else {
00323 result = "parameter " + n + " not set";
00324
00325 if (p) {
00326 result+= " (defaults to " + v + ")";
00327 }
00328 }
00329
00330 ROS_INFO_STREAM(result);
00331 }
00332
00333
00334 bool cParameterPaRos::replace_findpack(std::string &path) {
00335
00336 while(1) {
00337
00338 std::string::size_type start;
00339 start = (int) path.find("$(find ");
00340 if ((start < 0) || (start >= path.length())) {return true;}
00341
00342 std::string::size_type end;
00343 end = path.find(")", (std::string::size_type) start);
00344 if ((end < 0) || (end >= path.length())) {return false;}
00345
00346
00347 std::string replace;
00348 try {
00349 replace = ros::package::command(
00350 path.substr(start + 2, end - start - 2));
00351 } catch (std::runtime_error &e) {
00352 return false;
00353 }
00354 if (replace == "") { return false;}
00355
00356
00357 std::string::size_type pos_save = 0;
00358 std::string::size_type pos_current;
00359 for (pos_current = 0; pos_current < replace.length(); pos_current++) {
00360 char c;
00361 c = replace[pos_current];
00362
00363 if ((c == '\r') || (c == '\n') || (c == ' ') || (c == '\t')) {
00364 continue;
00365 }
00366
00367 if (pos_save != pos_current) {
00368 replace[pos_save] = c;
00369 }
00370 pos_save++;
00371 }
00372 if (pos_save != replace.length()) {
00373 replace.resize(pos_save);
00374 }
00375
00376
00377 path = path.substr(0,start) + replace + path.substr(end + 1);
00378 }
00379
00380 }
00381
00382
00383 void cParameterPaRos::resolve_ressourcename(std::string &name) {
00384 name = ros::names::resolve(name);
00385 }
00386
00387
00388 std::string cParameterPaRos::bool_to_str(const bool value) {
00389 if (value) {
00390 return "true";
00391 } else {
00392 return "false";
00393 }
00394 }