看懂roslunch输出
自编了一个demo
第一步:创建功能包
cd ~/catkin_ws/src
catkin_create_pkg param_demo roscpp
第二步:写 main.cpp
创建文件:param_demo/src/param_node.cpp
#include <ros/ros.h>
#include <string>
int main(int argc, char** argv) {
ros::init(argc, argv, "param_node");
ros::NodeHandle nh;
std::string robot_name;
int robot_id;
bool use_sim;
nh.param<std::string>("robot_name", robot_name, "default_bot");
nh.param<int>("robot_id", robot_id, -1);
nh.param<bool>("use_sim", use_sim, false);
ROS_INFO_STREAM("Robot Name: " << robot_name);
ROS_INFO_STREAM("Robot ID: " << robot_id);
ROS_INFO_STREAM("Use Simulation: " << (use_sim ? "true" : "false"));
ros::spinOnce();
return 0;
}
第三步:写 config.yaml
创建文件:param_demo/config/config.yaml
robot_name: "titan"
robot_id: 42
use_sim: true
第四步:写 launch
文件
创建文件:param_demo/launch/test_param.launch
<launch>
<!-- 加载 YAML 配置文件 -->
<rosparam file="$(find param_demo)/config/config.yaml" command="load" />
<!-- 启动节点 -->
<node pkg="param_demo" type="param_node" name="param_node" output="screen"/>
</launch>
第五步:修改 CMakeLists.txt 添加编译指令
打开 param_demo/CMakeLists.txt
,找到这几行:
add_executable(param_node src/param_node.cpp)
target_link_libraries(param_node ${catkin_LIBRARIES})
第六步:编译 & 运行
cd ~/catkin_ws
catkin_make
source devel/setup.bash
roslaunch param_demo test_param.launch
输出:
~/桌面/textdemo$ roslaunch param_demo test_param.launch
... logging to /home/fengzelin/.ros/log/a949ff4a-0bd4-11f0-8c0b-591112ba82b6/roslaunch-feng-25454.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://feng:43369/
SUMMARY
========
PARAMETERS
* /robot_id: 42
* /robot_name: titan
* /rosdistro: noetic
* /rosversion: 1.17.0
* /use_sim: True
NODES
/
param_node (param_demo/param_node)
auto-starting new master
process[master]: started with pid [25462]
ROS_MASTER_URI=http://localhost:11311
setting /run_id to a949ff4a-0bd4-11f0-8c0b-591112ba82b6
process[rosout-1]: started with pid [25472]
started core service [/rosout]
process[param_node-2]: started with pid [25475]
[ INFO] [1743166845.534552329]: Robot Name: titan
[ INFO] [1743166845.535322541]: Robot ID: 42
[ INFO] [1743166845.535337417]: Use Simulation: true
[param_node-2] process has finished cleanly
log file: /home/fengzelin/.ros/log/a949ff4a-0bd4-11f0-8c0b-591112ba82b6/param_node-2*.log
解释输出
... logging to /home/fengzelin/.ros/log/a949ff4a-0bd4-11f0-8c0b-591112ba82b6/roslaunch-feng-25454.log
🔹 ROS 会把启动的过程和日志写入一个日志文件
🔹 日志存在 ~/.ros/log/ 目录下,以时间戳区分
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
🔹 启动前会检查一下日志目录是否占用过多磁盘空间(默认设置)
🔹 这里提示:日志使用 < 1GB,问题不大
started roslaunch server http://feng:43369/
🔹 启动了 roslaunch 的服务端(可以支持多机 ROS)
🔹 feng 是你的主机名,43369 是分配的端口号
SUMMARY 区块
PARAMETERS
* /robot_id: 42
* /robot_name: titan
* /rosdistro: noetic
* /rosversion: 1.17.0
* /use_sim: True
每一项就是你在 .yaml
或 .launch
文件中设置的参数项
它们被加载到 ROS 参数服务器中了,供节点读取
NODES
/
param_node (param_demo/param_node)
意思是:
-
在根命名空间
/
下,启动了一个名为param_node
的节点 -
它来自包
param_demo
,可执行文件名也是param_node
启动核心进程信息
auto-starting new master
process[master]: started with pid [25462]
🔹 ROS master 启动了(负责协调节点通信)
🔹 PID 是 Linux 下的进程 ID(这里是 25462)
ROS_MASTER_URI=http://localhost:11311
master 的地址和端口号(本机本端口)
setting /run_id to a949ff4a-0bd4-11f0-8c0b-591112ba82b6
🔹 本次运行的唯一 ID,用于日志目录区分
process[rosout-1]: started with pid [25472]
started core service [/rosout]
🔹 rosout 是 ROS 的系统日志节点,用来收集日志信息
🔹 所有 ROS_INFO, ROS_WARN 都会发到它
process[param_node-2]: started with pid [25475]
🔹 写的 param_node 节点被启动了,进程 ID 为 25475
程序运行输出(节点打印的日志):
[ INFO] [1743166845.534552329]: Robot Name: titan
[ INFO] [1743166845.535322541]: Robot ID: 42
[ INFO] [1743166845.535337417]: Use Simulation: true
退出
[param_node-2] process has finished cleanly
log file: /home/fengzelin/.ros/log/a949ff4a-0bd4-11f0-8c0b-591112ba82b6/param_node-2*.log