Skip to content

踩坑Robotics Stack Exchange2024-08-18

如何从命令行发布 ros::Time::now()? ​

本文由 AI 根据公开内容整理,可能有误,请以原文为准:Is there an easy way to publish std_msgs::Time from cli?(Robotics Stack Exchange #83748)

状态:已解决

问题 ​

想从命令行向某话题发布等价于 ros::Time::now() 的 std_msgs::Time,用于测试订阅该消息的节点报错。

环境 ​

Linux / ROS 机器人软件与控制通用开发环境

解决办法 ​

  1. 使用 rostopic pub 的 -s 或 --substitute-keywords 启用关键字替换。
  2. 用 now 作为消息内容发布当前时间,例如:rostopic pub -s -r 1 /some_topic std_msgs/Time 'now',以 1 Hz 发布 ros::Time::now()。
  3. 若只需发布固定时间,可用 rostopic pub -r 1 /some_topic std_msgs/Time 'data: { secs: 1, nsecs: 2 }'。

原问题作者:seanarm;采纳答案作者:gvdhoorn-rse。原内容依 CC BY-SA 4.0 授权,本页摘要同样依 CC BY-SA 4.0 授权。

来源

本页事实对应的公开页面,以原文为准。

  1. Robotics Stack Exchange #83748:Is there an easy way to publish std_msgs::Time from cli?访问 2026-10-22