8 from sensor_msgs.msg
import Joy
9 from geometry_msgs.msg
import Twist, PoseWithCovarianceStamped
10 from actionlib_msgs.msg
import GoalStatus, GoalStatusArray
11 from move_base_msgs.msg
import MoveBaseAction, MoveBaseGoal
15 ping_fail_count = rospy.get_param(
'~ping_fail_count', 2)
16 ping_command =
"ping -c %s -n -W 1 %s" % (ping_fail_count, host)
18 p = subprocess.Popen(ping_command,
19 stdout=subprocess.PIPE,
20 stderr=subprocess.PIPE,
22 (output, error) = p.communicate()
23 returncode = p.returncode
24 return output, error, returncode
30 self.recovery_pose.pose.pose.position.x = 0.0
31 self.recovery_pose.pose.pose.position.y = 0.0
32 self.recovery_pose.pose.pose.position.z = 0.0
33 self.recovery_pose.pose.pose.orientation.x = 0.0
34 self.recovery_pose.pose.pose.orientation.y = 0.0
35 self.recovery_pose.pose.pose.orientation.z = 0.0
36 self.recovery_pose.pose.pose.orientation.w = 1
38 rospy.Subscriber(
'recovery_pose', PoseWithCovarianceStamped,
44 rospy.loginfo(
"Not connected to move_base.")
49 for ip
in self.ips.split(
','):
50 (output, error, returncode) =
ping_host(ip)
56 rospy.loginfo(
'Zeroing joystick.')
60 joy.buttons = [0] * 25
61 self.joy_publisher.publish(joy)
64 rospy.loginfo(
'Stopping motors.')
66 self.twist_publisher.publish(twist)
70 if self.move_base.wait_for_server(timeout=rospy.Duration(3)):
71 rospy.loginfo(
"Connected to move_base.")
74 rospy.loginfo(
"Not connected to move_base.")
81 goal.target_pose.pose = pose.pose.pose
82 goal.target_pose.header.frame_id = rospy.get_param(
'~goal_frame_id',
'map')
83 rospy.loginfo(
'Executing move_base goal to position (x,y) %s, %s.' %
84 (goal.target_pose.pose.position.x, goal.target_pose.pose.position.y))
87 self.move_base.send_goal(goal)
88 rospy.loginfo(
'Inital goal status: %s' % GoalStatus.to_string(self.move_base.get_state()))
89 status = self.move_base.get_goal_status_text()
94 self.move_base.wait_for_result()
95 rospy.loginfo(
'Final goal status: %s' % GoalStatus.to_string(self.move_base.get_state()))
96 status = self.move_base.get_goal_status_text()
101 data = rospy.wait_for_message(
'/move_base/status', GoalStatusArray)
102 if data.status_list == []:
107 status_codes = [status.status
for status
in data.status_list]
108 if PENDING
in status_codes:
110 if ACTIVE
in status_codes:
115 if rospy.is_shutdown():
return 116 rospy.logerr(
'No connection to base station.')
119 rospy.loginfo(
"Navigation in progress, not recovering until finished...")
127 while not rospy.is_shutdown():
131 rospy.loginfo(
'Connected to base station.')
136 rospy.init_node(
"lost_comms_recovery")
138 Controller.ips = rospy.get_param(
'~ips_to_monitor')
139 rospy.loginfo(
'Monitoring base station on IP(s): %s.' % Controller.ips)
140 Controller.main_loop()
def connect_to_move_base(self)
def recovery_pose_callback(self, data)
def navigation_goal_to(self, pose)
def goal_in_progress(self)