我是靠谱客的博主 愤怒康乃馨,最近开发中收集的这篇文章主要介绍ros一键启动autostart.sh,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

ros开发机器人系统,通过以下方法实现一键启动

步骤:

1.将autostart.sh 拷贝到 /etc/init.d/ 的目录下
2.在 /etc/rc.local文件中最后添加 /etc/init.d/autostart.sh &

备注:1.将autostart.sh中的launchStart.py修改为实际存放路径
2.将launchStart.py中的logging文件修改为实际存放位置,将launch文件修改为实际的启动launch文件。
3.为了安全起见,最好在launch文件中的主要node节点中添加参数 required=“true” (当某个节点死的时候,会杀死整个launch文件中的节点)
如:

文件:

autostart.sh

#!/bin/bash
#sleep 20
source /opt/ros/kinetic/setup.sh
source /home/huike/robot_ws/devel/setup.sh
export ROS_MASTER_URI=http://192.168.12.1:11311
export ROS_HOSTNAME=192.168.12.1

#ROS_PACKAGE_PATH=/home/utry/robot_ws/src:$ROS_PACKAGE_PATH
#ROS_WORKSPACE=/home/utry/robot_ws/src
LOGPATH=/home/huike/mh_logger.log
echo `date` >> $LOGPATH
sleep 3
# Start roscore
roscore & >> $LOGPATH
sleep 5
echo "roslaunch begin ..." >> $LOGPATH
#guarantee launchStart.py runned
INDEX=0
RET=
while [ $INDEX -le 2 ]
do
    RET=`ps -ef|grep -v grep|grep launchStart.py`
    if [ "" == "$RET" ];then
        echo "launchStart.py is null" >> $LOGPATH 
        /usr/bin/python2.7 /home/huike/robot_ws/launchStart.py &  >> $LOGPATH
    else
        echo "launchStart.py is start okkkkkkkk" >> $LOGPATH
        break
    fi
    let INDEX++
    sleep 30
done
#roslaunch huanyu_robot_start Huanyu_robot_start.launch & >> $LOGPATH
echo "roslaunch end ..." >> $LOGPATH
#roslaunch huanyu_robot_start navigation_slam.launch & >> $LOGPATH
sleep 5
echo `date` >> $LOGPATH
#sh /home/utry/robot_ws/devel/autostart.sh

launchStart.py

import subprocess
import time
import logging
import rospy
import roslaunch

#roscore_process = subprocess.Popen('roscore')
#guarantee the roscore started
while True:                       
    time.sleep(10)
    if rospy.has_param('/run_id'):
        print("find run_id############")
        time.sleep(1)
        break
try:
    
    #rospy.init_node('Clean the car', anonymous=True)
    uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
    #roslaunch.configure_logging(uuid)

    logging.basicConfig(filename='/home/huike/xiaoyuan_logger.log',filemode="w",format="%(asctime)s %(name)s:%(levelname)s:%(message)s",datefmt="%d-%M-%Y %H:%M:%S",level=logging.INFO)
   
     
    #launch = roslaunch.scriptapi.ROSLaunch()
    
    launch = roslaunch.parent.ROSLaunchParent(uuid, ["/home/huike/robot_ws/src/huanyu_robot_start/launch/Huanyu_robot_start.launch"])
    
    launch2 = roslaunch.parent.ROSLaunchParent(uuid, ["/home/huike/robot_ws/src/huanyu_robot_start/launch/navigation_slam.launch"])
    
    launch.start()
    time.sleep(5)

    launch2.start()
    rospy.loginfo("rospy.loginfo ##########")
    logging.info("logging.info ##########")
    
    launch.spin()
    launch2.spin()


except Exception as e:
    print('I am except')
    rospy.logfatal(e)
    #logging.info("###### Exception occurred")
   
finally:
    print('I am finally')
  # After Ctrl+C, stop all nodes from running
    launch.shutdown()
    launch2.shutdown()

最后

以上就是愤怒康乃馨为你收集整理的ros一键启动autostart.sh的全部内容,希望文章能够帮你解决ros一键启动autostart.sh所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部