bob
bob

Reputation: 369

How to get parameter from ros launch file and use it in Qt?

Im using ROS Fuerte and qt_ros so can integrate ROS in Qt GUI. I would like to use

some parameters from the ROS launch file in my Qt GUI. in the main.cpp file of the GUI Im using the ROS launch file to start the prcess like this:

int main(int argc, char **argv) {
    //Roslaunch
    QProcess process;
    process.start("roslaunch", QStringList() << "/home/launch/pow.launch");
    //GUI
    QApplication app(argc, argv);
    pow_gui::MainWindow w(argc,argv);
       w.show();
    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    int result = app.exec();
    std::cout << "q application finished" << std::endl;
    return result;
}

So in my pow.launch

<launch>
    <param name="/use_sim_time" value="true"/>
    <node name="hector_mapping" pkg="hector_mapping" type="hector_mapping" output="screen">
 <param name="pub_map_odom_transform" value="false"/>
    <remap from="scan" to="scan_2"/>
 <param name="map_frame" value="map"/>

 </node>

    <node name="foo_throttler" type="throttle" pkg="topic_tools" args="messages /scan 10/scan_throttle" /> 
    <node name="foo_throttler1" type="throttle" pkg="topic_tools" args="messages /raw_imu 10/raw_imu_throttle" /> 

    <node name="rosplay" pkg="rosbag" type="play" args="/home/10m_forward5.bag --clock"/>
    <node pkg="tf" type="static_transform_publisher" name="corner_duhhu" args="-0.17 -0.2 0 0 0 0 base_link laser 20"/> 

    <node pkg="tf" type="static_transform_publisher" name="raw_tf" args="0 0 0 0 0 0 /map /raw_frame 10"/> 

    <!--node pkg="analyzer" type="parking"  name="parking" output="screen"/>  -->
    <node pkg="analyzer" type="wst_forward10m"  name="wst_forward10m" output="screen"/> 
    <!--node pkg="analyzer" type="wst_turn"  name="wst_turn" output="screen"/>  -->

</launch>

when Im using the node pkg="analyzer" type="wst_forward10m" name="wst_forward10m" I would like to have a tab in QT saying that Im using that node and when using node pkg="analyzer" type="wst_turn" name="wst_turn" would like to have that displayed in QT.

Any help?

Upvotes: 2

Views: 6108

Answers (2)

Vtik
Vtik

Reputation: 3130

As you may have seen in qt_ros, there's a threaded ROS node working in the background. so, it will be cleaner to use that node to store parameters in a parameter server as done in this ROS Parameter Server Overview and all the launched nodes afterwards require their parameters from this server. (It's been a long time since i have done this and i couldn't find the source codes :\ )

Upvotes: 1

cassinaj
cassinaj

Reputation: 1043

A way to do that is by adding two parameters to your QT application, say argv[1] specifying the node type and argv[2] takes the node name. Then you start the ros node via

std::string node_type("node_type:=");
std::string node_name("node_name:=");
node_type += argv[1];
node_name += argv[2];
process.start("roslaunch", QStringList() << "/home/launch/pow.launch" 
                                         << node_type 
                                         << node_name);

and the node within the launch file looks as follows

...
<arg name="node_type" default="wst_forward10m" />
<arg name="node_name" default="wst_forward10m" /> 
<node pkg="analyzer" type="$(arg node_type)" name="$(arg node_type)" output="screen"/> 
...

finally you use the parameter values of argv[1] and argv[2] in your QT application to create the according tabs.

Upvotes: 1

Related Questions