Advertisement
softwarety6

Untitled

Dec 24th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import rospy
  4. import actionlib
  5. ##from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
  6. from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
  7. from geometry_msgs.msg import PoseStamped
  8. from nav_msgs.msg import Odometry
  9. from math import sqrt
  10. ##from std_msgs.msg import Empty
  11.  
  12. class mbSmoother():
  13.     def __init__(self):
  14.         rospy.init_node('mbSmoother', anonymous=True)
  15.  
  16.         self.move_base = actionlib.SimpleActionClient("/move_base", MoveBaseAction)
  17.         rospy.loginfo("Waiting for move_base action server...")
  18.         # Wait 60 seconds for the action server to become available
  19.         self.move_base.wait_for_server(rospy.Duration(60))
  20.         rospy.loginfo("Connected to move base server")
  21.         rospy.loginfo("Starting move base goals smoother")
  22.  
  23.         rospy.Subscriber("/odom", Odometry, self.odomCallback)
  24.         rospy.Subscriber("/move_base/current_goal", PoseStamped, self.goalCallback)
  25.  
  26.         rospy.spin()
  27.  
  28.     def odomCallback(self, msg):
  29.         self.robot_pose = msg.pose.pose
  30.         ##print "odom:"
  31.         ##print self.robot_pose
  32.  
  33.     def goalCallback(self, msg):
  34.         self.goal_pose = msg.pose
  35.         ##print "goal:"
  36.         ##print self.goal_pose
  37.         while True:
  38.             self.distance = sqrt(pow(self.goal_pose.position.x - self.robot_pose.position.x, 2) + pow(self.goal_pose.position.y - self.robot_pose.position.y, 2))
  39.             print self.distance
  40.             if self.distance < 0.5:
  41.                 self.move_base.cancel_goal()
  42.                 ##rospy.sleep(4)
  43.                 ##wait = self.move_base.wait_for_result()
  44.                 rospy.loginfo("goal has been canceled")
  45.                 break
  46.                
  47.         ##while self.goal_pose.position.x
  48.  
  49. if __name__ == "__main__":
  50.     mbSmoother()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement