Ask Your Question
0

How to start a roscore at system boot so that nodes run automatically when system is up?

asked 2017-10-03 14:23:30 -0500

i_robot_flight gravatar image

I am working on a Ubuntu 14.04 system with ROS Indigo. I currently have a python script in the /home/usr path that is launched by a desktop file using auto-start. I use roslaunch inside the python script to bring up other ROS nodes/packages elsewhere in the system using import roslaunch and rospy. I have sourced the ROS package (/opt/ros/indigo/setup.bash) in bashrc as well as the other packages I am running through the script. The problem is that when I reboot the system, my python script executes but comes up with the error message "no module named rospy" (or roslaunch). I tried starting a roscore using the subprocess.Popen('roscore') in the python script as well but the error was "No such file". I want to run some operations in the python program before the "roslaunch" operation and all this needs to execute at system boot each time. Any help is appreciated, thanks in advance!

  • Sneha
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-10-03 16:20:52 -0500

updated 2017-10-04 02:26:29 -0500

gvdhoorn gravatar image

You should probably add your autostart desktop file. The issue is likely that the Python script isn't being run from a bash environment that has sourced your .bashrc. Possible fixes: source the relevant workspace setup.bash files earlier in the boot process so that future processes inherit the env. This is done in the robot_upstart package. Easier might be to add an executable bash script (with #!/bin/bash as first line), that first sources the .bashrc, and then executes the Python script, and then put this in your autostart desktop file.

Could also probably get away with a one-liner to execute the Python script... something like bash -i -c "/home/user/Desktop/run_process.py"

edit flag offensive delete link more

Comments

@jarvisschultz you were completely right. At boot the bash environment had not started the bashrc before this desktop file executed. I modified my script to switch the order. Thank you very much!

i_robot_flight gravatar image i_robot_flight  ( 2017-10-03 17:27:02 -0500 )edit

@i_robot_flight: as @jarvisschultz answered your question, please accept his answer by ticking the checkmark to the left of his answer.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:27:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-03 14:23:30 -0500

Seen: 733 times

Last updated: Oct 04 '17