Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #! usr#!/usr/bin/env python
  2.  
  3. import rospy
  4. from sensor_msgs.msg import LaserScan
  5. from geometry_msgs.msg import Twist
  6.  
  7. import time
  8. import math
  9.  
  10. def shutdown():
  11. rospy.loginfo("Stop TurtleBot")
  12. pub.publish(Twist())
  13. rospy.sleep(1)
  14.  
  15. rospy.init_node('move_forward')
  16. rospy.loginfo("To stop TurtleBot CTRL + C")
  17. rospy.on_shutdown(shutdown)
  18. pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
  19. move = Twist()
  20. r = rospy.Rate(10)
  21.  
  22. #
  23. # 1.2s for 90 deg
  24. #
  25. def fwd(t=3, v=0.22):
  26. move.linear.x = v
  27. move.angular.z = 0.0
  28. print("making forward")
  29. curr_time = time.time()
  30. while time.time()-curr_time <= t:
  31. pub.publish(move)
  32. r.sleep()
  33. move.linear.x = 0.0
  34. move.angular.z = 0.0
  35. pub.publish(move)
  36.  
  37. def rgt():
  38. print("biglang liko")
  39. move.linear.x = 0.0
  40. move.angular.z = -1*math.pi/2
  41. curr_time = time.time()
  42. while time.time()-curr_time <= 1.2:
  43. pub.publish(move)
  44. r.sleep()
  45. move.linear.x = 0.0
  46. move.angular.z = 0.0
  47. pub.publish(move)
  48.  
  49. def lft():
  50. print("biglang liko")
  51. move.linear.x = 0.0
  52. move.angular.z = 1*math.pi/2
  53. curr_time = time.time()
  54. while time.time()-curr_time <= 1.05:
  55. pub.publish(move)
  56. r.sleep()
  57. pub.publish(Twist())
  58. move.linear.x = 0.0
  59. move.angular.z = 0.0
  60. pub.publish(move)
  61.  
  62. def e():
  63. print("\n--------------------------------------------")
  64. print("Drawing E")
  65. print("--------------------------------------------\n")
  66. fwd(1)
  67. lft()
  68. fwd(1)
  69. lft()
  70. fwd(1)
  71. lft()
  72. fwd(2)
  73. lft()
  74. fwd(1)
  75.  
  76. def i():
  77. print("\n--------------------------------------------")
  78. print("Drawing I")
  79. print("--------------------------------------------\n")
  80. fwd(2)
  81.  
  82. def l():
  83. print("\n--------------------------------------------")
  84. print("Drawing L")
  85. print("--------------------------------------------\n")
  86. fwd(2, -0.22)
  87.  
  88. def c():
  89. print("\n--------------------------------------------")
  90. print("Drawing C")
  91. print("--------------------------------------------\n")
  92. lft()
  93. fwd(1)
  94.  
  95.  
  96. #e()
  97. #l()
  98. #e()
  99. #c()
  100. #t()
  101. #r()
  102. #i()
  103. #c()
  104. #a()
  105. #l()
  106. #a()
  107. #n()
  108. #d()
  109. #e()
  110. #l()
  111. #e()
  112. #c()
  113. #t()
  114. #r()
  115. #i()
  116. #c()
  117. #a()
  118. #l()
  119. #e()
  120. #n()
  121. #g()
  122. #i()
  123. #n()
  124. #e()
  125. #e()
  126. #r()
  127. #i()
  128. #n()
  129. #g()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement