ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to avoid hard coding the node name prefixes while setting ros parameter ?

asked 2022-09-30 05:08:57 -0500

ros_user_ak gravatar image

I'm working on robot_localization package.

I have requirement now.

I want to set all the parameters as in this node test_ekf_localization_node_bag1_ekf in my main() function at the position /* set parameters here */ The main() is as follows:

int main(int argc, char** argv)
{
  ros::init(argc, argv, "ekf_node");

  ros::NodeHandle nh;
  ros::NodeHandle nh_priv("~");

  **/* set parameters here */**

  if (!nh.ok()) return 1;

  RobotLocalization::RosEkf ekf(nh, nh_priv);
  ekf.initialize();
  ros::spin();
}

However, If I want to do so, I need to prefix all the parameters with node name, which I don't want to do.

Example:

int main(int argc, char** argv)
{
  ros::init(argc, argv, "ekf_node");

  ros::NodeHandle nh;
  ros::NodeHandle nh_priv("~");

  nh.setParam("ekf_node/frequency", 30);
  nh.setParam("ekf_node/sensor_timeout", 0.1);
  nh.setParam("ekf_node/two_d_mode", false);

  RobotLocalization::RosEkf ekf(nh, nh_priv);
  ekf.initialize();
  ros::spin();
}

Any solution to avoid this prefix and set these parameters in main() here ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-30 05:11:45 -0500

gvdhoorn gravatar image

You already create a private nodehandle with ros::NodeHandle nh_priv("~").

If you'd use that, you'd get what you're asking.

edit flag offensive delete link more

Comments

PS: I assume the code you show is a minimal example? It seems rather strange to run RobotLocalization like this, instead of just using the nodes it provides.

gvdhoorn gravatar image gvdhoorn  ( 2022-09-30 05:12:35 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-09-30 05:08:57 -0500

Seen: 32 times

Last updated: Sep 30 '22