导航

    蓝鲸ROS机器人论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 热门
    ROS交流群
    ROS Group
    产品服务
    Product Service
    开源代码库
    Github
    官网
    Official website
    技术交流
    Technological exchanges
    激光雷达
    LIDAR
    ROS教程
    ROS Tourials
    深度学习
    Deep Learning
    机器视觉
    Computer Vision

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

    技术交流
    2
    2
    1204
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • jasen
      jasen 最后由 编辑

      如题,我自己写了个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 条回复 最后回复 回复 引用 0
      • weijiz
        weijiz @jasen 最后由 编辑

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

        1 条回复 最后回复 回复 引用 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2015-2023 BlueWhale community