Ask Your Question
0

getParam returning wrong values

asked 2017-08-25 12:11:01 -0500

jbeck28 gravatar image

updated 2017-08-28 06:57:11 -0500

I'm currently trying to get user and tool frame information from the parameter server. They're arrays with 6 doubles, [x,y,z,w,p,r]... when I'm use nh.getParam("userframe",std::vector<double> TFvalue), it properly returns all 6 objects. However, using the same lines of code for the userframe vector, the last two elements, [p,r] are both set to 0 for some reason. When I use rosparam get in the command line, however, the user frame values are not 0... so I'm not exactly sure what's going on here. Any help will be appreciated.

Here are the relevant lines of code:

ros::init(argc, argv, "simulate_toolpath");
  ros::NodeHandle nh;
  // Required for communication with moveit components
  ros::AsyncSpinner spinner (1);
  spinner.start();
  ros::Rate loop_rate(10);
  std::string fileLocation;
  std::string fileName;
  std::string robotName;
  std::string userFrame;
  std::string toolFrame;
  std::vector<double> UFvalue;
  std::vector<double> TFvalue;
  std::vector<float> asdf;
  double uf,tf;

  nh.getParam("robot_name",robotName);
  nh.getParam("toolpath_location",fileLocation);
  nh.getParam("toolpath_file",fileName);
  nh.getParam("toolFrame",tf);
  nh.getParam("userFrame",uf);
  // converst tool frame and user frame number to a string!
  std::ostringstream tfstr, ufstr;
  tfstr << tf;
  std::string temp = tfstr.str();
  ufstr << uf;
  std::string temp2 = ufstr.str();
  // tfstring is the name of the parameter which stores the tool frame info
  std::string tfstring = "tool_frames/";
  tfstring = tfstring + robotName + "/tf"; //should be something like tool_frames/KBXX/
  tfstring = tfstring + temp;
  //std::cout << tfstring<<std::endl;

  std::string ufstring = "user_frames/";
  ufstring = ufstring + robotName + "/uf"; //should be something like user_frames/KBXX/
  ufstring = ufstring + temp2;
  std::cout << ufstring << std::endl;

  nh.getParam(tfstring,TFvalue);
  nh.getParam(ufstring,UFvalue);
  // location of toolpath.dt file
  fileLocation = fileLocation + fileName;
  nh.getParam(ufstring,asdf);
  //std::cout<<asdf[0]<< " " <<asdf[1] << " " << asdf[2] << " " << asdf[3] << " "
  //<< asdf[4] << " " << asdf[5] << std::endl;
  std::cout << asdf.back()<< std::endl;
  std::cout<<UFvalue[0]<< " " <<UFvalue[1] << " " << UFvalue[2] << " " << UFvalue[3] << " "
  << UFvalue[4] << " " << UFvalue[5] << std::endl;
  std::cout<<TFvalue[0]<< " " <<TFvalue[1] << " " << TFvalue[2] << " " << TFvalue[3] << " "
  << TFvalue[4] << " " << TFvalue[5] << std::endl;

Thanks, Josh

edit retag flag offensive close merge delete

Comments

This is difficult to answer without source code. I can tell you that if you're using private parameters you'll need to use a node handle with the private namespace http://wiki.ros.org/roscpp/Overview/P...

jayess gravatar image jayess  ( 2017-08-25 15:13:00 -0500 )edit

I've updated the question with the relevant lines of code.

jbeck28 gravatar image jbeck28  ( 2017-08-28 06:57:15 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-09-25 12:34:48 -0500

yash_5 gravatar image

One of the reasons this is happening is because you are using a public nodehandle, instead of a private one. For the difference between the two, go through this page - http://wiki.ros.org/roscpp/Overview/N...

A private nodehandle is initialized as so - ros::NodeHandle nh_private("~");

edit flag offensive delete link more
0

answered 2022-01-19 21:41:17 -0500

blaine141 gravatar image

I recently had this issue and it was because my values in my yaml file were strings rather than numbers. getParam was also returning false to indicate there was an error getting the parameter.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-08-25 12:11:01 -0500

Seen: 1,020 times

Last updated: Jan 19