0
$\begingroup$

Rosanswers logo

ROS: groovy OS: ubuntu 12.04

What we are trying to do is have roscore start upon boot (have this working now) and then execute a launch file. I am not a linux person, so I feel I am really not approaching this the right way. Currently, this is what I have attempted:

  1. roscore is launched via a script in /etc/init.d. This is fine.

  2. I want to launch my launch file on boot. Manually, I do it like this: roslaunch rover.launch. It works great.

  3. I would like this to start on boot, so I tried the following: inside new script (boot.sh) - note i disabled password prompt for sudo:

    sudo su - roboops /home/roboops/groovycat/scripts/bootRoverLaunch.sh

    bootRoverLaunch.sh:

    cd /home/roboops/groovycat/ source devel/setup.sh sleep 5 roslaunch rover.launch > /home/roboops/groovycat/scripts/startup.log

  4. I went to "startup applications" and added "bash /home/roboops/groovycat/scripts/boot.sh"

  5. Tried rebooting. Roscore starts, and the launch files executes. However, the nodes malfunction and don't work correctly (They work fine when started using the launch file directly in a terminal window. Oddly, it also works fine if I log out and back in once)

More specifically, here is the problem when using the above script to launch:

I am trying to run two nodes:

-joystick node (publishes joy topic) -motor control node (listens to joy topic and outputs commands to motor controllers via serial)

Joystick node starts successfully and If I do rostopic echo joy, I can see the values. Motor control node is listed as running but if I run roswtf it says:

Found 3 error(s).

ERROR Could not contact the following nodes:
 * /Drivetrain

ERROR The following nodes should be connected but aren't:
 * /Drivetrain->/rosout (/rosout)

ERROR Errors connecting to the following services:
 * service [/Drivetrain/get_loggers] appears to be malfunctioning: Unable to communicate with service [/Drivetrain/get_loggers], address [rosrpc://Rover:58631]
 * service [/Drivetrain/set_logger_level] appears to be malfunctioning: Unable to communicate with service [/Drivetrain/set_logger_level], address [rosrpc://Rover:58631]

The idea is, I need everything to automatically start on power-up. There will be no input devices/monitor connected to it when it is in use.


Originally posted by rb on ROS Answers with karma: 130 on 2014-03-15

Post score: 2

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

We recommend using the robot_upstart package we developed. It's simple, seems to do everything you need, and has already been deployed on dozens of robots.


Originally posted by Ryan with karma: 3248 on 2014-03-17

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Andrew.A on 2014-05-29:
I notice the package only has a hydro/devel branch. Does this work for groovy?

Comment by mikepurvis on 2014-07-07:
Hi Andrew, yes, robot_upstart should work with groovy as well as hydro, as long as you don't mind doing a source install of it in your workspace.

Comment by julien on 2015-02-02:
Hi Mike,

I'm also trying to use robot_upstart since 3hours without results.... is it possible to use this package with indigo???

Tks

Comment by Ryan on 2015-02-05:
@julien: I'm not Mike, but I know we use it to run our Jackal, which is Indigo-only. Have you tried using

sudo apt-get install ros-indigo-robot-upstart

to install it? Instructions to use it are on both the ROS wiki and its github page.

Comment by Cerin on 2016-08-14:
Note, this package is no longer supported on Kinetic.

Comment by kmhallen on 2017-04-09:
Support for Kinetic has been added

$\endgroup$
0
$\begingroup$

Rosanswers logo

I start my roslaunch on start up using cron (http://wiki.ubuntuusers.de/Cron) and screen (http://wiki.ubuntuusers.de/screen).

I have a /home/user/autostart/autostart_screens.sh that get executed by cron @reboot (Meaning whenever the PC is booted). You can set these startup files via crontab command. See crontab --help. My current crontab -l gives:

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
@reboot bash /home/user/autostart/autostart_screens.sh

My autostart_screens.sh starts and detaches two screen sessions and logs any thing happening inbetween to a log file. It looks like:

# !/bin/bash
LOG_FILE=/home/user/autostart/logs/log_autostart_screens.txt

echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "Running autostart_screens.sh" >> ${LOG_FILE}
echo $(date) >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "Logs:" >> ${LOG_FILE}

set -e
set -v

{

screen -d -m bash /home/user/autostart/start_roscore.sh
screen -d -m bash /home/user/autostart/start_roslaunch.sh

} &>> ${LOG_FILE}

Note that it is not blocking as it just starts the screens.

The start_roscore.sh looks like:

# !/bin/bash
LOG_FILE=/home/user/autostart/logs/log_start_roscore.txt
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "Running start_roscore.sh" >> ${LOG_FILE}
echo $(date) >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "Logs:" >> ${LOG_FILE}

set -e

{

source /opt/ros/hydro/setup.bash
source /home/user/workspace/ros_hydro/catkin/devel/setup.bash

export ROS_WORKSPACE=/home/user/workspace/ros_hydro/catkin

export ROS_MASTER_URI=http://192.168.1.10:11311/ ##e. g. Master
export ROS_IP=192.168.1.15                   ##e. g. Own IP

sleep 5

} &>> ${LOG_FILE}

set -v

{

roscore

} &>> ${LOG_FILE}

The start_roslaunch.sh looks like:

# !/bin/bash
LOG_FILE=/home/user/autostart/logs/log_start_roslaunch.txt
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "Running start_roslaunch.sh" >> ${LOG_FILE}
echo $(date) >> ${LOG_FILE}
echo "#############################################" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
echo "Logs:" >> ${LOG_FILE}

set -e

{
source /opt/ros/hydro/setup.bash
source /home/user/workspace/ros_hydro/catkin/devel/setup.bash

export ROS_WORKSPACE=/home/user/workspace/ros_hydro/catkin

export ROS_MASTER_URI=http://192.168.1.10:11311/
export ROS_IP=192.168.1.15

sleep 8

} &>> ${LOG_FILE}

set -v

{

roslaunch my_pkg my_launch.launch

} &>> ${LOG_FILE}

All logs go to /home/user/autostart/logs. After start youn can verify your ros being up using rosnode list. You can monitor your screens using screen -ls. Note that the timeout in start_roslaunch.sh is longer than in start_roscore.sh. In order for shutting down the nodes on my computer if I want to use it for something else I use this script:

# !/bin/bash

for session in $(screen -ls | grep -o '[0-9]\{5\}')
do
    screen -S "${session}" -X quit;
done

It sends a Crlt+C to all running screen sessions.


Originally posted by Wolf with karma: 7555 on 2014-03-17

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by Cerin on 2016-08-14:
Why are you running both roscore and roslaunch in separate scripts? roslaunch will automatically run roscore if needed.

$\endgroup$
0
$\begingroup$

Rosanswers logo

I start my roscore on boot simply by adding this line in "/etc/rc.local" before "exit0":

su pi -c "source /home/pi/YOURWS/devel/setup.sh ; roscore  > /dev/null 2>&1 &"

the "> /dev/null" means its logs dont get stored anywhere and "&" at the end means it starts in the background. You cant start roscore in root mode, that's why "su pi -c" is at the start of the command. Replace "/home/pi/YOURWS" with your workspace name and destination.


Originally posted by CimeROS with karma: 41 on 2017-04-09

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by elpidiovaldez on 2018-05-24:
Works, and it's simple ! I have spent hours trying to use robot_upstart, but it needs too many files and devices to have their permissions changed. I used a launch file: su ubuntu -c "source /home/ubuntu/catkin_ws/devel/setup.sh ; roslaunch biped biped_robot.launch > /dev/null 2>&1 &"

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.