ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

use ros commands in bash script

asked 2014-07-09 15:42:32 -0500

GWall gravatar image

updated 2014-07-09 20:15:19 -0500

allenh1 gravatar image

Hey, so I need to compile my workspace every time I add it into my computer. This proves to be very time consuming. I would like to write a script that runs these commands:

roscd /directory/build
cmake ..
make

This is what I type into the terminal to compile all the directories and it works perfectly! But, when I tried just adding these commands to a script and running it I would get errors basically saying it didn't recognize the commands (i.e. roscd). I'm not sure if I'm supposed to source something so it will recognize the commands or something.

Any help is appreciated! George

edit retag flag offensive close merge delete

Comments

1

You have a good answer down there... But, I must ask... Why are you using cmake at all? With a catkin workspace, catkin builds (invoking CMake) all packages in the source directory in topological order. This is mainly for my own curiosity.

allenh1 gravatar image allenh1  ( 2014-07-09 20:17:24 -0500 )edit

Hey, thanks for your curiosity! When we started with ROS a catkin didn't exist. Then when it did we never made the transition, but we are planning on switching over pretty soon. Even with catkin I would like to have a script because its one less thing I need to setup when I install the system!

GWall gravatar image GWall  ( 2014-07-10 08:09:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2014-07-09 16:11:43 -0500

tgd gravatar image

You need to source your ros workspace's startup script in your own script's instance for all of your package/stack names to be recognized by roscd.

Just add the following snippet before your commands:

source ~/ros_ws/devel/setup.bash

Replace ros_ws with the path to your workspace.

edit flag offensive delete link more

Comments

Not only that, but probably he also needs to source the ROS setup script before sourcing the workspace's startup script: source /opt/ros/<your_ros_distro>/setup.bash

Martin Peris gravatar image Martin Peris  ( 2014-07-09 21:09:29 -0500 )edit

worked like a charm! Thanks!! @tgd

GWall gravatar image GWall  ( 2014-07-10 08:18:22 -0500 )edit

Mini bash script to test this:

#!/bin/bash

echo "Ros Test START"
source /opt/ros/kinetic/setup.bash
source /home/user/catkin_ws/devel/setup.bash
roscd
pwd
roscd my_package
pwd
echo "Ros test END"
RDaneelOlivaw gravatar image RDaneelOlivaw  ( 2018-04-17 04:13:24 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-09 15:42:32 -0500

Seen: 4,387 times

Last updated: Jul 09 '14