Ask Your Question
0

QT creator UI to run roslaunch by clicking a button

asked 2020-09-02 04:21:19 -0500

frizh gravatar image

Hello I'm quite new on this ROS and QT. I have difficulty when i follow this.

I want to launch a file when i clicked a button. I know i must use QProcess for that, but when I follow the forum below, my UI doesn't do anything (sometimes it exit by itself).

any help please

here is my code

QString program = "roslaunch jackal_gazebo jackal_world.launch";
 QProcess *myProcess = new QProcess(this);
 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
 env.insert("launch","/opt/ros/melodic/share/jackal_gazebo");
 myProcess->setProcessEnvironment(env);
 myProcess->start(program);
myProcess->waitForStarted(-1);

thank you best reagrds

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-09-02 07:37:17 -0500

dtyugin gravatar image

First of all roslaunch is not an executable file, it's just python script, so you should run python program with args pointed to roslaunch script. Second please read carefully QT docs about argument list, here an example from docs:

  QObject *parent;
  ...
  QString program = "./path/to/Qt/examples/widgets/analogclock";
  QStringList arguments;
  arguments << "-style" << "fusion";

  QProcess *myProcess = new QProcess(parent);
  myProcess->start(program, arguments);

And finally I suggest you start your program from terminal where ros environment already set (open terminal, source setup.bash from ros workspace). If it works then you can try to add this environment directly to QProcess, but it's can be tricky since setup.bash executes multiple environment changes.

So I believe it should be like this

QString program = "python";
QStringList arguments;
arguments << "roslaunch" << "jackal_gazebo"<<"jackal_world.launch";

And environment for ros should be already set in the terminal where you run your app.

edit flag offensive delete link more
0

answered 2020-09-02 22:07:10 -0500

frizh gravatar image

updated 2020-09-04 04:02:47 -0500

@dtyugin Thank you for the answer dtyugin

I'm sory I'm new in this topic, but I'm still confused how to make a roslaunch becoming an executable file? is there any example for it?

the roslaunch I use is workable in terminal. so, in the ROS side I'm pretty confidence there is no mistake.

edit flag offensive delete link more

Comments

Well, as for terminal roslaunch is executable, since it has executable flag in file permissions. But actually it's a python script with extra comment inside "#!/usr/bin/python" which claims that this file should be executed via python. So there is no difference in terminal when you run "roslaunch" or "python roslaunch", they do the same stuff. As for qt runner I'm not sure it will work the same. But you can try as well. I'm pretty sure command "python roslaunch" will work always.

dtyugin gravatar image dtyugin  ( 2020-09-04 04:22:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-09-02 04:21:19 -0500

Seen: 301 times

Last updated: Sep 04 '20