Skip to content

Instantly share code, notes, and snippets.

@syanyong
Last active December 27, 2020 15:03
Show Gist options
  • Save syanyong/d7e7271b795dd7a620b3c55d5f6131e3 to your computer and use it in GitHub Desktop.
Save syanyong/d7e7271b795dd7a620b3c55d5f6131e3 to your computer and use it in GitHub Desktop.
Non-Degree Day2 Group 2B for practice
#!/usr/bin/env python
"""
รันด้วยคำสั่ง rosrun my_turtlesim pub.py
"""
import rospy
from geometry_msgs.msg import Twist
import time
vel = Twist() # Variable 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()
while not rospy.is_shutdown():
timenow = time.time()
counter = timenow - timestart
# TODO
print("Turtle is running.", counter)
# if (counter >0 and counter <= 2):
# vel.linear.x = 1
# elif (counter >2 and counter <= 5):
# vel.linear.x = 0
# vel.angular.z = 1
# else:
# vel.linear.x = 0
# vel.angular.z = 0
# break
# END
pub.publish(vel)
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