VScode配置ROS python编程环境

VScode配置ROS python编程环境

VScode官网:https://code.visualstudio.com/

必装插件:

Chinese (Simplified) Language Pack for Visual Studio Code

这里强调一下,不要用新版,新版的没成功。 

测试程序talker.py 

#!/usr/bin/env python


import rospy
from std_msgs.msg import String

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        hello_str = "hello world %s" % rospy.get_time()
        rospy.loginfo(hello_str)
        pub.publish(hello_str)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

listener.py

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + 'I heard %s', data.data)

def listener():

    
    rospy.init_node('listener', anonymous=True)

    rospy.Subscriber('chatter', String, callback)

    rospy.spin()

if __name__ == '__main__':
    listener()

注意启动顺序,先启动roscore,再启动talker.py 最后启动listener.py并在合适地方加入断点。

自动格式化工具

pip install yapf

左下角:管理——setting(Ctrl+逗号)——搜索:formatting.provider——由autopep8改为:yapf

格式化快捷键:Ctrl + Shift + F

扫描二维码关注公众号,回复: 13305115 查看本文章

高亮缩进

indent-rainbow 插件

猜你喜欢

转载自blog.csdn.net/yaked/article/details/108291864