00001
00002
00003 import rospy
00004 import actionlib
00005 from actionlib import GoalStatus
00006 from geometry_msgs.msg import Pose, Point, Quaternion, Twist
00007 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal, MoveBaseActionFeedback
00008 from tf.transformations import quaternion_from_euler
00009 from visualization_msgs.msg import Marker
00010 from math import pi
00011 from collections import OrderedDict
00012
00013 def setup_task_environment(self):
00014
00015 self.square_size = rospy.get_param("~square_size", 1.0)
00016
00017
00018 self.low_battery_threshold = rospy.get_param('~low_battery_threshold', 50)
00019
00020
00021 self.n_patrols = rospy.get_param("~n_patrols", 2)
00022
00023
00024 self.move_base_timeout = rospy.get_param("~move_base_timeout", 10)
00025
00026
00027 self.patrol_count = 0
00028
00029
00030 self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
00031
00032 rospy.loginfo("Waiting for move_base action server...")
00033
00034
00035 self.move_base.wait_for_server(rospy.Duration(60))
00036
00037 rospy.loginfo("Connected to move_base action server")
00038
00039
00040 quaternions = list()
00041
00042
00043 euler_angles = (pi/2, pi, 3*pi/2, 0)
00044
00045
00046 for angle in euler_angles:
00047 q_angle = quaternion_from_euler(0, 0, angle, axes='sxyz')
00048 q = Quaternion(*q_angle)
00049 quaternions.append(q)
00050
00051
00052 self.waypoints = list()
00053
00054
00055
00056 self.waypoints.append(Pose(Point(0.0, 0.0, 0.0), quaternions[3]))
00057 self.waypoints.append(Pose(Point(self.square_size, 0.0, 0.0), quaternions[0]))
00058 self.waypoints.append(Pose(Point(self.square_size, self.square_size, 0.0), quaternions[1]))
00059 self.waypoints.append(Pose(Point(0.0, self.square_size, 0.0), quaternions[2]))
00060
00061
00062 room_locations = (('hallway', self.waypoints[0]),
00063 ('living_room', self.waypoints[1]),
00064 ('kitchen', self.waypoints[2]),
00065 ('bathroom', self.waypoints[3]))
00066
00067
00068 self.room_locations = OrderedDict(room_locations)
00069
00070
00071 self.docking_station_pose = (Pose(Point(0.5, 0.5, 0.0), Quaternion(0.0, 0.0, 0.0, 1.0)))
00072
00073
00074 init_waypoint_markers(self)
00075
00076
00077 for waypoint in self.waypoints:
00078 p = Point()
00079 p = waypoint.position
00080 self.waypoint_markers.points.append(p)
00081
00082
00083 init_docking_station_marker(self)
00084
00085
00086 self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=5)
00087
00088 rospy.loginfo("Starting Tasks")
00089
00090
00091 self.marker_pub.publish(self.waypoint_markers)
00092 rospy.sleep(1)
00093 self.marker_pub.publish(self.waypoint_markers)
00094
00095
00096 self.docking_station_marker_pub.publish(self.docking_station_marker)
00097 rospy.sleep(1)
00098
00099 def init_waypoint_markers(self):
00100
00101 marker_scale = 0.2
00102 marker_lifetime = 0
00103 marker_ns = 'waypoints'
00104 marker_id = 0
00105 marker_color = {'r': 1.0, 'g': 0.7, 'b': 1.0, 'a': 1.0}
00106
00107
00108 self.marker_pub = rospy.Publisher('waypoint_markers', Marker, queue_size=5)
00109
00110
00111 self.waypoint_markers = Marker()
00112 self.waypoint_markers.ns = marker_ns
00113 self.waypoint_markers.id = marker_id
00114 self.waypoint_markers.type = Marker.CUBE_LIST
00115 self.waypoint_markers.action = Marker.ADD
00116 self.waypoint_markers.lifetime = rospy.Duration(marker_lifetime)
00117 self.waypoint_markers.scale.x = marker_scale
00118 self.waypoint_markers.scale.y = marker_scale
00119 self.waypoint_markers.color.r = marker_color['r']
00120 self.waypoint_markers.color.g = marker_color['g']
00121 self.waypoint_markers.color.b = marker_color['b']
00122 self.waypoint_markers.color.a = marker_color['a']
00123
00124 self.waypoint_markers.header.frame_id = 'odom'
00125 self.waypoint_markers.header.stamp = rospy.Time.now()
00126 self.waypoint_markers.points = list()
00127
00128 def init_docking_station_marker(self):
00129
00130 marker_scale = 0.3
00131 marker_lifetime = 0
00132 marker_ns = 'waypoints'
00133 marker_id = 0
00134 marker_color = {'r': 0.7, 'g': 0.7, 'b': 0.0, 'a': 1.0}
00135
00136 self.docking_station_marker_pub = rospy.Publisher('docking_station_marker', Marker, queue_size=5)
00137
00138 self.docking_station_marker = Marker()
00139 self.docking_station_marker.ns = marker_ns
00140 self.docking_station_marker.id = marker_id
00141 self.docking_station_marker.type = Marker.CYLINDER
00142 self.docking_station_marker.action = Marker.ADD
00143 self.docking_station_marker.lifetime = rospy.Duration(marker_lifetime)
00144 self.docking_station_marker.scale.x = marker_scale
00145 self.docking_station_marker.scale.y = marker_scale
00146 self.docking_station_marker.scale.z = 0.02
00147 self.docking_station_marker.color.r = marker_color['r']
00148 self.docking_station_marker.color.g = marker_color['g']
00149 self.docking_station_marker.color.b = marker_color['b']
00150 self.docking_station_marker.color.a = marker_color['a']
00151
00152 self.docking_station_marker.header.frame_id = 'odom'
00153 self.docking_station_marker.header.stamp = rospy.Time.now()
00154 self.docking_station_marker.pose = self.docking_station_pose