Command line boolean parameters to ros node

asked 2019-07-18 10:01:19 -0600

Elric gravatar image

updated 2019-07-18 11:36:00 -0600

jayess gravatar image

I'm working with ROS melodic and Gazebo 9.9.0 on an Ubuntu 18.04.2 LTS.

I want to get two boolean parameters from command line. To do it, I have this code:

int main(int argc, char **argv)
  bool doDiagonalSteps = false;

  bool checkDiagonalCornerUnBlocked = false;
   * We must call one of the versions of ros::init() before using any other
   * part of the ROS system.
  ros::init(argc, argv, "astar_controller");

   * NodeHandle is the main access point to communications with the ROS system.
  ros::NodeHandle n;

   * Get parameters (if there are parameters to get.)
  if (!n.getParam("diagonalSteps", doDiagonalSteps))
    doDiagonalSteps = false;
    std::cout << "Diagonal steps: " <<  std::endl;

  if (!n.getParam("checkDiagonalStepCorner", checkDiagonalCornerUnBlocked))
    checkDiagonalCornerUnBlocked = false;
    std::cout << "Diagonal Corner: " << checkDiagonalCornerUnBlocked << std::endl;

When I run this command on terminal:

rosrun nav_astar_nodes astar_controller _diagonalSteps:=true _checkDiagonalStepCorner:=false

I don't get anything on the output.

How can I get a boolean parameter from command line?

edit retag flag offensive close merge delete



I believe this is caused by the fact that _diagonalSteps creates a private parameter in the nodes namespace, but you don't create a private NodeHandle, which causes the parameters to not be found.

gvdhoorn gravatar image gvdhoorn  ( 2019-07-18 10:08:49 -0600 )edit

I was going to ask you something, but you never answer my questions.

Elric gravatar image Elric  ( 2019-07-18 10:10:08 -0600 )edit

I don't understand what you're trying to say here.

gvdhoorn gravatar image gvdhoorn  ( 2019-07-18 10:18:02 -0600 )edit

@gvdhoorn is correct, you're not looking in the right namespace in your code

stevemacenski gravatar image stevemacenski  ( 2019-07-18 16:36:49 -0600 )edit