#!/usr/bin/env python3
import rospy, sys, time
from geometry_msgs.msg import Twist
rospy.init_node('cmd_vel_test_pub')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1, tcp_nodelay=True)
time.sleep(0.5) # 等订阅者发现
duration = float(sys.argv[1] if len(sys.argv) > 1 else 4)
msg = Twist()
msg.linear.x = 0.5
msg.angular.z = 0.2
rate = rospy.Rate(20)
n = int(duration * 20)
print(f"[PUB] 发 /cmd_vel {n} 次 (lx=0.5, az=0.2)")
for i in range(n):
pub.publish(msg)
rate.sleep()
print("[PUB] 完成")