- #!/usr/bin/env python3
- import rospy
- from geometry_msgs.msg import Twist
- cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
- rospy.init_node('red_light_green_light')
- rospy.loginfo("started")
- red_light_twist = Twist()
- green_light_twist = Twist()
- green_light_twist.linear.x = 0.5
- driving_forward = False
- light_change_time = rospy.Time.now()
- rate = rospy.Rate(10)
- while not rospy.is_shutdown():
- if driving_forward:
- cmd_vel_pub.publish(green_light_twist)
- else:
- cmd_vel_pub.publish(red_light_twist)
- if light_change_time < rospy.Time.now():
- driving_forward = not driving_forward
- light_change_time = rospy.Time.now() + rospy.Duration(3)
- rate.sleep()
[text] wanderbot
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- wanderbot
- Paste Code
- 17 Apr-2024
- 745 Bytes
You can Share it:
Latest Code Pastes