#!/usr/bin/env python import rospy from geometrymsgs.msg import Twist import time…
- User
#!/usr/bin/env python
import rospy from geometry_msgs.msg import Twist import time
rospy.init_node('move_bot_myplan') pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1) rate = rospy.Rate(2)
move = Twist() move.linear.x = 0.2 move.angular.z = 0
while not rospy.is_shutdown(): pub.publish(move) rate.sleep()
set interval for 10 secoond then stop moving
- Assistant
To make the robot move for a set interval (10 seconds in this case) and then stop, you need to integrate a simple timing mechanism to keep track of the elapsed time. You can use the
timemodule orrospy.get_time()for this purpose.In this code snippet, I will show you how to use
rospy.Timefor timing. This approach is better integrated within the ROS ecosystem.Here's an updated version of your script that will move the robot for 10 seconds and then stop: