ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

asked 2014-07-15 21:53:06 -0600

pilot71 gravatar image

Hi 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) {
    QProcess process;
    process.start("roslaunch", QStringList() << "/home/launch/pow.launch");
    QApplication app(argc, argv);
    pow_gui::MainWindow w(argc,argv);;
    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 fle


    <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 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"/>  -->


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 node displayed in QT.

Any help?

edit retag flag offensive close merge delete


What are you trying to achieve? Calling roslaunch from within a binary seems very much backwards from its intended use.

dornhege gravatar image dornhege  ( 2014-07-16 06:16:19 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-07-16 12:00:14 -0600

kramer gravatar image

As you know, you need to get the contents of the launch file into a Qt for display. I'd think that the easiest way to do this would be to create your QStringList before the process.start line, then 'send' it to the MainWindow (by whatever means you'd like).

For instance -- and note that this is just a sketch, not implemented/tested -- you might have a QTextEdit widget as a member of the MainWindow. After MainWindow creation, you could simply do a MainWindow->QTextEdit->setText(QStringList.join("\n")).

@dornhege, if one wants to be able to run everything in a single Qt executable, starting a roslaunch process is a decent option -- although in this case, because the launch file selection isn't embedded in the MainWindow and thus can't be chosen via Qt widget, I'd agree with you.

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

1 follower


Asked: 2014-07-15 21:53:06 -0600

Seen: 992 times

Last updated: Jul 16 '14