VScode配置ROS python编程环境

小灰灰 2022-12-02 01:22 373阅读 0赞

VScode配置ROS python编程环境

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

必装插件:

Chinese (Simplified) Language Pack for Visual Studio Code

20201010163708660.png

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

20201010163533624.png

测试程序talker.py

  1. #!/usr/bin/env python
  2. import rospy
  3. from std_msgs.msg import String
  4. def talker():
  5. pub = rospy.Publisher('chatter', String, queue_size=10)
  6. rospy.init_node('talker', anonymous=True)
  7. rate = rospy.Rate(10) # 10hz
  8. while not rospy.is_shutdown():
  9. hello_str = "hello world %s" % rospy.get_time()
  10. rospy.loginfo(hello_str)
  11. pub.publish(hello_str)
  12. rate.sleep()
  13. if __name__ == '__main__':
  14. try:
  15. talker()
  16. except rospy.ROSInterruptException:
  17. pass

listener.py

  1. #!/usr/bin/env python
  2. import rospy
  3. from std_msgs.msg import String
  4. def callback(data):
  5. rospy.loginfo(rospy.get_caller_id() + 'I heard %s', data.data)
  6. def listener():
  7. rospy.init_node('listener', anonymous=True)
  8. rospy.Subscriber('chatter', String, callback)
  9. rospy.spin()
  10. if __name__ == '__main__':
  11. listener()

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

自动格式化工具

pip install yapf

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

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

高亮缩进

indent-rainbow 插件

发表评论

表情:
评论列表 (有 0 条评论,373人围观)

还没有评论,来说两句吧...

相关阅读