robot_patrol.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 __author__ = "Minglong Li"
00004 
00005 import sys
00006 sys.path.append("..")
00007 from middle_abstraction.function_unit import FunctionUnit
00008 import actionlib
00009 import micros_mars_task_alloc.msg
00010 import rospy
00011 
00012 class RobotPatrol(FunctionUnit):
00013     def __init__(self, node_name, pose_0, pose_1, pose_2, pose_3, topic, wait_time):
00014         FunctionUnit.__init__(self, node_name)
00015         #self._node_name = node_name
00016         self._pose_0 = pose_0
00017         self._pose_1 = pose_1
00018         self._pose_2 = pose_2
00019         self._pose_3 = pose_3
00020         self._topic = topic
00021         self._wait_time = wait_time
00022         
00023     def run(self):
00024         pass
00025 
00026     def start_patrol(self):
00027         FunctionUnit.init_node(self) 
00028         self._client = actionlib.SimpleActionClient(self._topic, micros_mars_task_alloc.msg.MoveBaseAction)#use 'super' to call the method of his father class.
00029         #FunctionUnit.init() #use class name to call the father method
00030         #print 'Patroller 0 starts!'
00031         
00032         #client.wait_for_server()
00033         #Several goals to be sent to the action server.
00034         goal_0 = micros_mars_task_alloc.msg.MoveBaseGoal()
00035         goal_0.target_pose.header.frame_id = 'map'
00036         goal_0.target_pose.pose.position.x = self._pose_0[0]
00037         goal_0.target_pose.pose.position.y = self._pose_0[1]
00038         goal_0.target_pose.pose.position.z = 0.0
00039         goal_0.target_pose.pose.orientation.x = 0.0
00040         goal_0.target_pose.pose.orientation.y = 0.0
00041         goal_0.target_pose.pose.orientation.z = self._pose_0[2]
00042         goal_0.target_pose.pose.orientation.w = self._pose_0[3] 
00043 
00044         goal_1 = micros_mars_task_alloc.msg.MoveBaseGoal()
00045         goal_1.target_pose.header.frame_id = 'map'
00046         goal_1.target_pose.pose.position.x = self._pose_1[0]
00047         goal_1.target_pose.pose.position.y = self._pose_1[1]
00048         goal_1.target_pose.pose.position.z = 0.0
00049         goal_1.target_pose.pose.orientation.x = 0.0
00050         goal_1.target_pose.pose.orientation.y = 0.0
00051         goal_1.target_pose.pose.orientation.z = self._pose_1[2]
00052         goal_1.target_pose.pose.orientation.w = self._pose_1[3]
00053 
00054         goal_2 = micros_mars_task_alloc.msg.MoveBaseGoal()
00055         goal_2.target_pose.header.frame_id = 'map'
00056         goal_2.target_pose.pose.position.x = self._pose_2[0]
00057         goal_2.target_pose.pose.position.y = self._pose_2[1]
00058         goal_2.target_pose.pose.position.z =  0.0
00059         goal_2.target_pose.pose.orientation.x = 0.0
00060         goal_2.target_pose.pose.orientation.y = 0.0
00061         goal_2.target_pose.pose.orientation.z = self._pose_2[2]
00062         goal_2.target_pose.pose.orientation.w = self._pose_2[3]         
00063 
00064         goal_3 = micros_mars_task_alloc.msg.MoveBaseGoal()
00065         goal_3.target_pose.header.frame_id = 'map'
00066         goal_3.target_pose.pose.position.x = self._pose_3[0]
00067         goal_3.target_pose.pose.position.y = self._pose_3[1]
00068         goal_3.target_pose.pose.position.z = 0.0
00069         goal_3.target_pose.pose.orientation.x = 0.0
00070         goal_3.target_pose.pose.orientation.y = 0.0
00071         goal_3.target_pose.pose.orientation.z = self._pose_3[2]
00072         goal_3.target_pose.pose.orientation.w = self._pose_3[3]
00073 
00074         while not rospy.is_shutdown():
00075             self._client.send_goal(goal_0)
00076             self._client.wait_for_result(rospy.Duration.from_sec(self._wait_time))
00077 
00078             self._client.send_goal(goal_1)
00079             self._client.wait_for_result(rospy.Duration.from_sec(self._wait_time))
00080             
00081             self._client.send_goal(goal_2)
00082             self._client.wait_for_result(rospy.Duration.from_sec(self._wait_time))
00083             
00084             self._client.send_goal(goal_3)
00085             self._client.cancel_all_goals()
00086             self._client.wait_for_result(rospy.Duration.from_sec(self._wait_time))
00087 
00088    # def cancel_goal(self):
00089          #self._client.cancel_all_goals()
00090         


micros_mars_task_alloc
Author(s): Minglong Li , Xiaodong Yi , Yanzhen Wang , Zhongxuan Cai
autogenerated on Mon Jul 1 2019 19:55:03