简体   繁体   中英

Using a shell script to call a ROS launch file

I want create a file *.sh and run it as an executable like any other software with double click on it. The command is the follwing

roslaunch my_pro test_qt.launch

I simply run it in the terminal and it launches my software. Now I want to make it as an executable, so I tried this but it didn't work

gnome-terminal -e roslaunch my_pro test_qt.launch &

it said:

# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.# 
# Use “-- ” to terminate the options and put the command line to execute after it.# 

How can I write my *.sh file?

EDIT Something like that?

#!/bin/bash
gnome-terminal -e
roslaunch my_pro test_qt.launch

I know this post is old, but i recently wanted to do a similar thing (roslaunch using desktop shortcut ) and gave me some trouble the past few days so I decided to write the steps i took for anyone that might be interested in the future.

First of, I created a hidden folder in my home directory to place the script and image I was going to use for the shortcut:

mkdir .dir_name

I then placed the image I wanted to use in there and created a script using the sublime text editor ( my choice, you can use your favourite one - it makes absolutely no difference at all )

subl .dir_name/launch.sh

The launch file looks like this:

#!/usr/bin/env bash

# Launch the robot
source /opt/ros/melodic/setup.bash 
source /home/user/ros_ws/devel/setup.bash 

echo "Launching application, please wait!"
roslaunch your_pkg your_launch.launch 

Important note: you MUST include the sourcing of the bash files, otherwise the roslaunch command is not recognised!

Important note 2: you MUST make the script executable

chmod +x .my_dir/launch.sh

The next step is to create the desktop shortcut:

subl ~/Desktop/my_shortcut.desktop

and adding the following inside the file what we just created:

[Desktop Entry]
Type=Application
Terminal=false $ true opens extra gnome-terminal
Name=Robot Launch
Icon=/home/user/.my_dir/logo.png
Exec=terminator -e "bash -c '/home/user/.my_dir/launch.sh;$SHELL'" 
$Exec=gnome-terminal -e "bash -c '/home/user/.my_dir/launch.sh;$SHELL'"

Note: I am using terminator, if you are using the default gnome terminal, comment the terminator line and uncomment the gnome-terminal line.

Finally, you need to right click the desktop shortcut ( icon will appear after it has been run once ) and go to permissions tab. There you must click

allow executing file as program

Once the shortcut is now double clicked it will run. The very first time you double click the system will ask you again if you want to execute this file (for security reasons) and you must click yes ( after all its your file ;) )

That's it! Enjoy your desktop shortcut launching ros code!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM