Navigation

    蓝鲸ROS机器人论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    ROS交流群
    ROS Group
    产品服务
    Product Service
    开源代码库
    Github
    官网
    Official website
    技术交流
    Technological exchanges
    激光雷达
    LIDAR
    ROS教程
    ROS Tourials
    深度学习
    Deep Learning
    机器视觉
    Computer Vision

    写了脚本让机器人运动,但它停不下来。

    技术交流
    2
    2
    523
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jasen
      jasen last edited by

      如题,我自己写了个python小程序控制小车运动,代码如下:

      #!/usr/bin/env python
      
      import rospy
      from geometry_msgs.msg import Twist
      
      def vel_publisher():
          rospy.init_node('turtlebot_automove',anonymous=True)
          vel_pub=rospy.Publisher('cmd_vel',Twist,queue_size=10)
          rate=rospy.Rate(10)
          while not rospy.is_shutdown():
              vel_msg=Twist()
              vel_msg.linear.x = 0.04
      
              vel_pub.publish(vel_msg)
              rospy.loginfo("burger is moving at speed[%0.2f m/s, %0.2f rad/s]", vel_msg.linear.x, vel_msg.angular.z)
              rate.sleep()
      if __name__=='__main__':
          try:
              vel_publisher()
          except rospy.ROSInterruptException:
              pass
      
      

      最终小车是可以按照预期速度直线行走了,但是当我Ctrl+C关闭节点时,小车并没有停止下来,还是在一直走,我使用rostopic echo 查看速度发布话题数据,终端也不给任何反馈信息。

      weijiz 1 Reply Last reply Reply Quote 0
      • weijiz
        weijiz @jasen last edited by

        @jasen 想要停下来需要发送0速度。否则就一直按照之前的速度指令运行

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright © 2015-2021 BlueWhale community