Create a shell script
- In the ROS workspace package, e.g. /path/to/workspace/package/script/ folder, create a shell script e.g. run_script.sh.
- Type in the script commands, e.g. see the code listing below.
Note 1: ensure the shebang statement is at the top i.e. #!/bin/bash and a exit status code (0 for success or other values) is returned from the script.
Note 2: Use the chmod command to make the script executable, e.g. $ chmod a+x run_script.sh
#!/bin/bash # just print this out echo "Hello ROS world" # exit gracefully by returning a status exit 0
Create a launch file
- In the ROS workspace package launch folder, create a launch file e.g. /path/to/workspace/package/launch/hello_script.launch.
- Using a text editor, type in the following:
Note: fill in the package name, e.g. beginner_tutorials, and the type, which should be the shell script name; name is any label you want to associate with the script node.
<launch> <node pkg="beginner_tutorials" type="run_script.sh" name="run_script" output="screen" /> </launch>
Run the launch file