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

how to pass params from launch file to cpp file

asked 2017-04-05 11:37:37 -0600

zubair gravatar image

updated 2017-04-05 13:15:28 -0600

ahendrix gravatar image

hi all

i have some params which i defined in my launch file as below :

<node name="tfs" pkg="ctt_tools" type="tfs" respawn="true" />
<param name = "point_x_1" value = "23" />
<param name = "point_x_2" value = "26" />
<param name = "point_y_1" value = "-4.70" />
<param name = "point_y_2" value = "4.50" />
</node>

and i want to use these params in my cpp file in the code as below :

        if(m.point.x > 23 && m.point.x < 26 && m.point.y > -4.70 && m.point.y < 4.50 )
        { 
            for (int i=0; i<palletdrop.size();i++)
            {
                if(palletdrop[i].isInside(m.point.x,m.point.y))
                {
                    palletdrop[i].setOccupied();
                    //std::cout<<"Another on area "<<i<<std::endl;
                }
            }

        }

in place of values 23 , 26 etc i want o use params i defined in launch file... how can i do that ???

any suggestions?

thanks all ..

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
5

answered 2017-04-05 13:09:46 -0600

huanxiner gravatar image

Here is an example of how to do that.

<node name="tfs" pkg="ctt_tools" type="tfs" respawn="true"/> 
    <param name="param_1" value="23.0" />
</node>

and

double param_1;
node_handle.getParam("/tfs/param_1", param_1);      
if(m.point.x > param_1 && m.point.x < 26 && m.point.y > -4.70 && m.point.y < 4.50 )
{ 
   ...
}

You could also refer to Parameters in launch file and Use parameters in roscpp for more details.

edit flag offensive delete link more

Comments

thanks a lot,, it worked absolutely fine ..

zubair gravatar image zubair  ( 2017-04-06 06:39:31 -0600 )edit
0

answered 2017-04-05 11:38:16 -0600

zubair gravatar image

<node name="tfs" pkg="ctt_tools" type="tfs" respawn="true"/>

</node>

these are my params in launch file

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-05 11:36:38 -0600

Seen: 7,106 times

Last updated: Apr 05 '17