【ROS学习】使用python编写简单的节点

mkdir -p ros_ws/src

cd ros_ws

catkin_make

cd src

catkin_create_pkg beginner_tutorials rospy

cd ..

catkin_make

source devel/setup.bash

roscd beginner_tutorials

cd src

gedit hello.py

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

if __name__ == '__main__':
    rospy.init_node('talker', anonymous=True)
    pub = rospy.Publisher('chat', String, queue_size=10)
    rate = rospy.Rate(10)

    while not rospy.is_shutdown():
        hello_str = "hello world! %s" % rospy.get_time()
        pub.publish(hello_str)
        rospy.loginfo(hello_str)
        rate.sleep()

 

回到工作空间目录

打开一个终端 运行

roscore

打开另一个终端

在工作空间运行

source devel/setup.bash

rosrun beginner_tutorials hello.py

 

上一篇:动态表单


下一篇:关于catkin