Skip to content

Instantly share code, notes, and snippets.

@syanyong
Last active January 31, 2021 07:16
Show Gist options
  • Save syanyong/38fa87499bbea3edfb85a84ef7be87af to your computer and use it in GitHub Desktop.
Save syanyong/38fa87499bbea3edfb85a84ef7be87af to your computer and use it in GitHub Desktop.
Jan 31, 2021 ROS Day 2
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# Noted
# Topic: /turtle1/cmd_vel
# Type: geometry_msgs/Twist
def main ():
rospy.init_node('turtle_commander', anonymous=True)
rate = rospy.Rate(10) # 10 Hz
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
timestart = time.time() # Get current time in ms
while not rospy.is_shutdown():
# TODO
time_sec = time.time() - timestart # time counting in second
vel_data = Twist() # New variable
print (time_sec)
if (time_sec <= 2):
vel_data.angular.z = 1
else:
vel_data.angular.z = 0
pub.publish(vel_data)
# END
rate.sleep()
if __name__ == '__main__':
try:
main()
except rospy.ROSInterruptException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment