我想将海龟绕圈移动两次,制作两个不同的圆圈,并且我正在使用 Twist() 但是当我为同一个发布者提供两种不同的扭曲和值时,即使我尝试过使用两个不同的发布者,但获得相同的输出。所以任何人都可以请告诉我如何发布具有两个不同值的 Twist()。
pub = rospy.Publisher('turtle1/cmd_vel', Twist, queue_size=10)
pub_1 = rospy.Publisher('turtle1/cmd_vel', Twist, queue_size=10)
# Create a Twist message and add linear x and angular z values
move_cmd = Twist()
move_cmd.linear.x = 1.0
move_cmd.linear.y = 0.0
move_cmd.angular.z = -1.0
move_cmd_1 = Twist()
move_cmd_1.linear.x = 1.0
move_cmd_1.linear.y = 0.0
move_cmd_1.angular.z = 1.0
# Save current time and set publish rate at 10 Hz
now = rospy.Time.now()
rate = rospy.Rate(10)
# For the next 6 seconds publish cmd_vel move commands to Turtlesim
while rospy.Time.now() < now + rospy.Duration.from_sec(10.5):
pub.publish(move_cmd_1)
pub_1.publish(move_cmd_1)
rate.sleep()