Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python
  3. # license removed for brevity
  4. import rospy
  5. from nav_msgs.msg import Odometry
  6. from std_msgs.msg import String, Header
  7. from geometry_msgs.msg import Twist, Point, PoseStamped, Pose
  8.  
  9. goal = Point()
  10.  
  11. def newOdom(msg):
  12.  
  13. goal.x = round(msg.pose.pose.position.x + 0.1)
  14. goal.y = round(msg.pose.pose.position.y + 0.1)
  15.  
  16.  
  17.  
  18.  
  19. def talker():
  20. pub = rospy.Publisher('/r2/move_base_simple/goal', PoseStamped, queue_size = 1)
  21. sub = rospy.Subscriber("/r1/odom", Odometry, newOdom)
  22. rospy.init_node('follow_r1')
  23. rate = rospy.Rate(3) # 10hz
  24. while not rospy.is_shutdown():
  25. odom = PoseStamped()
  26. odom.header.frame_id = "/map"
  27. odom.pose.position.x = goal.x
  28. odom.pose.position.y = goal.y
  29. odom.pose.orientation.w = 1.0
  30. pub.publish(odom)
  31. rate.sleep()
  32.  
  33. if __name__ == '__main__':
  34. try:
  35. talker()
  36. except rospy.ROSInterruptException:
  37. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement