ros wiki tutorials中在安装好ros后,首先会让运行乌龟turtle的小例子,而其中首先就是让执行roscore命令。那么其内部原理到底是什么?后续将陆续分析。

roscore的wiki介绍,
roscore is a collection of nodes and programs that are pre-requisites of a ROS-based system. You must have a roscore running in order for ROS nodes to communicate. It is launched using the roscore command.

下面看看执行了roscore命令后发生了什么,roscore本身是个python脚本。

lyf@lyf:~$ which roscore
/opt/ros/hydro/bin/roscore
lyf@lyf:~$ file /opt/ros/hydro/bin/roscore
/opt/ros/hydro/bin/roscore: a /usr/bin/python script, ASCII text executable

命令执行后通过log可以看到执行过程中的一些主要步骤,

lyf@lyf:~$ roscore
#①首先是log的文件夹
... logging to /home/lyf/.ros/log/f67227ba-685e-11e7-a44d-08002734e31e/roslaunch-lyf-2382.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

#②启动了roslunch server
started roslaunch server http://lyf:48578/
ros_comm version 1.10.12


SUMMARY
========

PARAMETERS
 * /rosdistro
 * /rosversion

NODES
#③启动了两个进程,master,pid为2396,rosout-1,pid为2409
auto-starting new master
process[master]: started with pid [2396]
ROS_MASTER_URI=http://lyf:11311/

setting /run_id to f67227ba-685e-11e7-a44d-08002734e31e
process[rosout-1]: started with pid [2409]
started core service [/rosout]
  1. 首先是log的文件夹,log文件对阅读源代码的作用还是比较大;
  2. 启动了roslunch server,url为http://lyf:48578/
  3. 启动了两个进程,master,pid为2396,rosout-1,pid为2409

后续,将通过源代码分析该过程。roscore的源代码的git地址为https://github.com/ros/ros_comm.git

ros源码分析(1)—roscore概况_源码分析

ros_comm中包含了ros很多的基础框架的组件,

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam)

而roscore就在tools下的roslaunch中,

ros源码分析(1)—roscore概况_ROS源码分析_02

roslaunch脚本只有两句话,其实是导入了roslaunch包,执行了roslaunch.main()函数,所以后续先分析roslaunch package。

#ros_comm\tools\roslaunch\scripts\roslaunch
import roslaunch
roslaunch.main()