ros源码对应的github 网址为https://github.com/ros
我们知道在ros 安装好后,首先要跑一下roscore命令,如果没有在这个命令的话,可能先调用source xx/ros/xx/setup.bash 初始化环境。
roscore其实是一个python脚本,其实现的路径在ros/ros_comm/blob/melodic-devel/tools/roslaunch/scripts/roscore
其源码如下:
import sys
from optparse import OptionParser
from rosmaster.master_api import NUM_WORKERS
NAME = 'roscore'
def _get_optparse():
parser = OptionParser(usage="usage: %prog [options]",
prog=NAME,
description="roscore will start up a ROS Master, a ROS Parameter Server and a rosout logging node",
epilog="See http://wiki.ros.org/roscore"
)
parser.add_option("-p", "--port",
dest="port", default=None,
help="master port. Only valid if master is launched", metavar="PORT")
parser.add_option("-v", action="store_true",
dest="verbose", default=False,
help="verbose printing")
parser.add_option("-w", "--numworkers",
dest="num_workers", default=NUM_WORKERS, type=int,
help="override number of worker threads", metavar="NUM_WORKERS")
parser.add_option("-t", "--timeout",
dest="timeout",
help="override the socket connection timeout (in seconds).", metavar="TIMEOUT")
parser.add_option("--master-logger-level",
dest="master_logger_level", default=False, type=str,
help="set rosmaster.master logger level ('debug', 'info', 'warn', 'error', 'fatal')")
return parser
parser = _get_optparse()
(options, args) = parser.parse_args(sys.argv[1:])
#从这里知道roscore 并不支持参数
if len(args) > 0:
parser.error("roscore does not take arguments")
#原来roscore就只是调用调用roslanch.main
import roslaunch
roslaunch.main(['roscore', '--core'] + sys.argv[1:])
通过后续可以知道roslaunch.main 其实主要做了几件事,
1,创建保存log的文件夹。
2,启动roslunch server
3,启动roscores master和resout