roscd tutorial/ # 进入 tutorial packagecd src # 进入 srctouch helloworld.py # 创建 helloworld.py 档案
撰写
打开喜欢的 IDE 开始撰写第一个 helloworld 程式码
#! /usr/bin/env python## 指定直译器## 1. importimport rospy## 2. 编写 mainif __name__ == "__main__":## 3. 初始化 ROS 节点rospy.init_node("hello")## 4. 输出rospy.loginfo("Hello World!")
更改权限并执行
roscd tutorial/ # 进入 tutorial packagecd src # 进入 srcchmod +x helloworld.py # 更改 helloworld.py 的权限变成可执行档rosrun tutorial helloworld.py # 执行 helloworld.py 档案
Reference
Autolabor 初级教程 ROS 机器人入门