Advertisement
Guest User

ROS boot script

a guest
Nov 1st, 2011
2,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. start_ros () {
  2. #Get ROS bash commands
  3. source /opt/ros/diamondback/setup.sh
  4. #Get custom packages (this script will launch with 'sudo', so it'll be the root user
  5. export ROS_PACKAGE_PATH=/home/my_user/custom_package_directory:$ROS_PACKAGE_PATH
  6. #Home directory of your user for logging
  7. export HOME="/home/user"
  8. #Home directory for your user for logging
  9. export ROS_HOME="/home/user"
  10.  
  11. #I run ROS on a headless machine, so I want to be able to connect to it remotely
  12. export ROS_IP="192.168.1.10"
  13. #I like to log things, so this creates a new log for this script
  14. LOG="/var/log/my_robot.log"
  15.  
  16. #Time/Date stamp the log
  17. echo -e "\n$(date +%Y:%m:%d-%T) - Starting ROS daemon at system startup" >> $LOG
  18. echo "This launch will export ROS's IP as $ip" >> $LOG
  19.  
  20. #For bootup time calculations
  21. START=$(date +%s.%N)
  22.  
  23. #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.
  24. while true; do
  25. IP="`ifconfig | grep 'inet addr:'192.168.1.10''| cut -d: -f2 | awk '{ print $1}'`"
  26.  
  27. if [ "$IP" ] ; then
  28. echo "Found"
  29. break
  30. fi
  31. done
  32. #For bootup time calculations
  33. END=$(date +%s.%N)
  34.  
  35. echo "It took $(echo "$END - $START"|bc ) seconds for an IP to come up" >> $LOG
  36.  
  37. echo "Launching default_package default_launch into a screen with name 'ros'." >> $LOG
  38. screen -dmS ros roslaunch "default_package" "default_launch_file"
  39.  
  40. }
  41.  
  42. case "$1" in
  43. start)
  44. start_ros
  45. esac
  46.  
  47. exit 0
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement