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

autostart a launchfile after/while boot

asked 2013-01-11 09:42:28 -0500

dinamex gravatar image

updated 2013-01-11 09:43:25 -0500

Hi,

I looking for a solution to just turn on my system (ubuntu 11.04 server/headless) and launch a launchfile automatically.

I tried the solution posted here with a boot startup script but it didn't work. Would be great to get your thoughts.

here is my script in /etc/init.d/:

start_ros () {
#Get ROS bash commands
  source /opt/ros/electric/setup.sh
#Get custom packages (this script will launch with 'sudo', so it'll be the root user
  export ROS_PACKAGE_PATH=/home/panda:$ROS_PACKAGE_PATH
#Home directory of your user for logging
  export HOME="/home/panda"
#Home directory for your user for logging
  export ROS_HOME="/home/panda/.ros"

#I run ROS on a headless machine, so I want to be able to connect to it remotely
  export ROS_IP="192.168.9.123"
#I like to log things, so this creates a new log for this script
  LOG="/var/log/panda.log"

#Time/Date stamp the log
  echo -e "\n$(date +%Y:%m:%d-%T) - Starting ROS daemon at system startup" >> $LOG
  echo "This launch will export ROS's IP as $ip" >> $LOG

#For bootup time calculations
  START=$(date +%s.%N)

#This is important. You must wait until the IP address of the machine is actually configured by all of the Ubuntu process. Otherwise, you will get an error and launch will fail. This loop just loops until the IP comes up. 
  while true; do
        IP="`ifconfig  | grep 'inet addr:'192.168.9.123''| cut -d: -f2 | awk '{ print $1}'`"

        if [ "$IP" ] ; then
                echo "Found"
                break
        fi
  done
#For bootup time calculations
  END=$(date +%s.%N)

  echo "It took $(echo "$END - $START"|bc ) seconds for an IP to come up" >> $LOG

  echo "Launching default_package default_launch into a screen with name 'ros'." >> $LOG
  screen -dmS ros roslaunch panda_cam high.launch

}

case "$1" in
  start)
        start_ros
esac

exit 0

after that I called and rebooted

$sudo update-rc.d panda_cam_startup defaults 99

while bootup i get the following output

/etc/rc2.d/S99panda_cam_startup: 45: source: not found 
Found
/etc/rc2.d/S99panda_cam_startup: 45: bc: not found
/etc/rc2.d/S99panda_cam_startup: 45: screen: not found

But the sourcepath is definitely righ. No idea whats wrong

edit retag flag offensive close merge delete

Comments

dbworth gravatar image dbworth  ( 2013-01-11 10:14:46 -0500 )edit

6 Answers

Sort by ยป oldest newest most voted
1

answered 2013-01-12 05:51:00 -0500

Eric Perko gravatar image

Take a look at ros-system-daemon-groovy. That is a recent package that should do what you are looking for.

edit flag offensive delete link more

Comments

Is the name indicating the ROS version compatibility? I'm using electric...

dinamex gravatar image dinamex  ( 2013-01-13 06:09:02 -0500 )edit

It looks like a lot of the files reference groovy specifically, but, if you changed that, after a quick glance it looks like it would work.

Eric Perko gravatar image Eric Perko  ( 2013-01-13 06:12:24 -0500 )edit
3

answered 2013-08-28 09:07:20 -0500

An old question, but others may also be interested in our just-released robot_upstart package.

It's along the same line as ros-system-daemon, but more directly modelled after the scripts in turtlebot_bringup. Clearpath will definitely be supporting it going forward, as Husky, Grizzly, and Kingfisher's bring up packages all depend on it.

edit flag offensive delete link more

Comments

Will it work for groovy? I notice the branch name is called 'hydro-devel'.

Andrew.A gravatar image Andrew.A  ( 2013-11-10 14:34:01 -0500 )edit
0

answered 2013-01-31 16:49:30 -0500

rocklinsuv gravatar image

updated 2013-01-31 16:49:52 -0500

What I found out is "sudo" doesn't work on ROS commands. @ dinamex

edit flag offensive delete link more

Comments

sudo doesn't work on the normal setup but you can insert the ros setup.sh in your sudo-bash.rc. After that you can use ROS as superuser.

dinamex gravatar image dinamex  ( 2013-02-01 04:04:00 -0500 )edit
0

answered 2013-01-29 03:17:31 -0500

zumili gravatar image

We used a script like this for the ros diamondback version running under ubuntu 10.04 on a PandaBoard. It worked like it should without any problems. Maybe it will help you. But for the newer ros groovy I get also an error which I will discribe later.

#! /bin/bash
# /etc/init.d/carobot
source /opt/ros/diamondback/setup.bash
export ROS_PACKAGE_PATH=/home/robolab/ros/carobot:$ROS_PACKAGE_PATH
export ROS_IP=192.168.0.1
# initialze the pidfile
CAROBOT_PIDFILE='/var/run/carobot.pid'
ROS_USER=robolab
touch $CAROBOT_PIDFILE
/bin/chown $ROS_USER\:$ROS_USER $CAROBOT_PIDFILE
# roslaunch vars
ROSLAUNCH_BIN="/opt/ros/diamondback/ros/bin/roslaunch"
ROSLAUNCH_ARGS="--pid=$CAROBOT_PIDFILE"
# set path to launchfile
ROSLAUNCH_FILE="/home/robolab/ros/carobot/carobot_motorControl/launch/bootup.launch"
# carry out specific functions when asked by the system
case "$1" in
  start)
    echo "Starting carobot service ..."
    su -c "$ROSLAUNCH_BIN $ROSLAUNCH_ARGS $ROSLAUNCH_FILE" $ROS_USER &
    ;;  
  stop)
    kill -2 $(cat $CAROBOT_PIDFILE) > /dev/null
    echo -n "" > $CAROBOT_PIDFILE
    echo "Stopping carobot services ..."
    ;;  
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;  
  *)  
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;  
esac
exit 0

You can start this script with :

$sudo /etc/init.d/carobot start

And of course call also

$sudo update-rc.d carobot defaults 99

Now we use the newer Ros Groovy under Ubuntu 12.04 on the PandaBoard and I have modified the startup script like this:

#! /bin/bash
# /etc/init.d/carobot
source /home/robolab/ros_ws/setup.bash
export ROS_PACKAGE_PATH=/home/robolab/ros_ws:$ROS_PACKAGE_PATH
export ROS_IP=192.168.2.40
# initialze the pidfile
CAROBOT_PIDFILE='/var/run/carobot.pid'
# or alternativ use
#CAROBOT_PIDFILE='/home/robolab/carobot.pid'
ROS_USER=robolab
touch $CAROBOT_PIDFILE
/bin/chown $ROS_USER\:$ROS_USER $CAROBOT_PIDFILE
# roslaunch vars
ROSLAUNCH_BIN="/opt/ros/groovy/ros_catkin_ws/install_isolated/bin/roslaunch"
ROSLAUNCH_ARGS="--pid=$CAROBOT_PIDFILE"
# set path to launchfile
ROSLAUNCH_FILE="/home/robolab/ros_ws/carobot/trunk/carobot_motorControl/launch/bootup_joy2.launch"
# carry out specific functions when asked by the system
case "$1" in
  start)
    echo "Starting carobot service ..."
    su -c "$ROSLAUNCH_BIN $ROSLAUNCH_ARGS $ROSLAUNCH_FILE" $ROS_USER &
    ;;  
  stop)
    kill -2 $(cat $CAROBOT_PIDFILE) > /dev/null
    echo -n "" > $CAROBOT_PIDFILE
    echo "Stopping carobot services ..."
    ;;  
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;  
  *)  
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;  
esac
exit 0

No there is a problem by using this newer script. Please have a look at the complete output at: h++p://pastebin.com/GjXyaQad

After starting the script with:

$sudo /etc/init.d/carobot start

all nodes and parameters are listed so I think the launchfile is correctly loaded but then after "auto-starting new master" an error occurs:

auto-starting new master
Roslaunch got a 'No such file or directory' error while attempting to run:

rosmaster --core -p 11311 __log:=/home/robolab/.ros/log/0d59cac4-6a1b-11e2-9a62-2a0092823b0a/master.log

Please make sure that all the executables in this command exist and have
executable permission. This is often caused by a bad launch-prefix.
[master] killing on exit

But if I start the launchfile by hand

/opt/ros/groovy/ros_catkin_ws/install_isolated/bin/roslaunch /home/robolab/ros_ws/carobot/trunk/carobot_motorControl/launch/bootup_joy2.launch

or

roslaunch /home/robolab/ros_ws/carobot/trunk/carobot_motorControl/launch/bootup_joy2.launch

everything works fine without any ... (more)

edit flag offensive delete link more

Comments

could it be that the script is executing as root? in this case the ROS_PATH and ROS_Workspace is not set.

dinamex gravatar image dinamex  ( 2013-01-29 06:36:34 -0500 )edit

I think the line: su -c "$ROSLAUNCH_BIN $ROSLAUNCH_ARGS $ROSLAUNCH_FILE" $ROS_USER & is doing the trick. Normaly you have to start an init.d script with sudo or as root but I think with the described su line you change the user and then execute the command. And it worked in Diamond butnot in groovy

zumili gravatar image zumili  ( 2013-02-01 01:24:13 -0500 )edit
0

answered 2013-02-19 08:40:08 -0500

dinamex gravatar image

updated 2013-02-19 08:59:57 -0500

I tried zumilis script with the same error message. Is there an other way to start a launchfile. so everytime I open a shell it launches the program. Since I have a headless system and automatic login to tty1 (which will be the only window) it shouldn't interfere with any other processes, am i right?

edit flag offensive delete link more
0

answered 2013-08-28 08:23:09 -0500

In case people are still looking for the solution on how to get zumili's init.d script to work:

It seems that roslaunch does not find rosmaster. I quickly checked and saw that it is not in /usr/bin (and possibly it is not meant to be there). I checked my environment variables and everything seemed to be fine. Also python (as used in roslaunch) is supposed to look for executables in the PATH variable. But even adding /opt/ros/groovy/bin (where rosmaster is located) did not help.

So I went for the workaround of putting a symlink to rosmaster in /usr/bin:

sudo ln -s /opt/ros/groovy/bin/rosmaster /usr/bin/rosmaster

It is a workaround but it does the job (at least for me).

edit flag offensive delete link more

Question Tools

7 followers

Stats

Asked: 2013-01-11 09:42:28 -0500

Seen: 22,994 times

Last updated: Aug 28 '13