00001
00002
00003
00004
00005
00006
00007
00008 #include <ros/ros.h>
00009 #include <nodelet/nodelet.h>
00010 #include <iostream>
00011 #include <pluginlib/class_list_macros.h>
00012 #include <vector>
00013 #include <micros_mars_task_alloc/MoveBaseAction.h>
00014 #include <micros_mars_task_alloc/MoveBaseGoal.h>
00015 #include <actionlib/client/simple_action_client.h>
00016 #include <std_msgs/Bool.h>
00017
00018 namespace micros_mars_task_alloc {
00019 using namespace std;
00020
00021 class RobotPatrol : public nodelet::Nodelet
00022 {
00023 public:
00024 RobotPatrol():goal_count_(0), goal_time_interval_(10.0){}
00025 virtual ~RobotPatrol(){}
00026 virtual void onInit();
00027 void timerCallback(const ros::TimerEvent&);
00028 private:
00029 typedef actionlib::SimpleActionClient<micros_mars_task_alloc::MoveBaseAction> Client;
00030 boost::shared_ptr<Client> client_;
00031 ros::Timer timer_;
00032 ros::NodeHandle nh_;
00033
00034 float goal_0_pos_x_, goal_0_pos_y_, goal_0_ori_z_, goal_0_ori_w_;
00035 float goal_1_pos_x_, goal_1_pos_y_, goal_1_ori_z_, goal_1_ori_w_;
00036 float goal_2_pos_x_, goal_2_pos_y_, goal_2_ori_z_, goal_2_ori_w_;
00037 float goal_3_pos_x_, goal_3_pos_y_, goal_3_ori_z_, goal_3_ori_w_;
00038
00039 micros_mars_task_alloc::MoveBaseGoal goal_0_;
00040 micros_mars_task_alloc::MoveBaseGoal goal_1_;
00041 micros_mars_task_alloc::MoveBaseGoal goal_2_;
00042 micros_mars_task_alloc::MoveBaseGoal goal_3_;
00043
00044 int goal_count_;
00045 double goal_time_interval_;
00046 };
00047
00048 void RobotPatrol::onInit()
00049 {
00050 nh_ = getMTPrivateNodeHandle();
00051 std::string goal_topic;
00052 nh_.param<std::string>("goal_topic", goal_topic, "default_topic");
00053 client_.reset(new actionlib::SimpleActionClient<micros_mars_task_alloc::MoveBaseAction>(goal_topic, true));
00054 double x0, y0, z0, w0, x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3;
00055
00056 nh_.param<double>("goal_0_pos_x", x0, 0.0);
00057 nh_.param<double>("goal_0_pos_y", y0, 0.0);
00058 nh_.param<double>("goal_0_ori_z", z0, 0.0);
00059 nh_.param<double>("goal_0_ori_w", w0, 0.0);
00060
00061 nh_.param<double>("goal_1_pos_x", x1, 0.0);
00062 nh_.param<double>("goal_1_pos_y", y1, 0.0);
00063 nh_.param<double>("goal_1_ori_z", z1, 0.0);
00064 nh_.param<double>("goal_1_ori_w", w1, 0.0);
00065
00066 nh_.param<double>("goal_2_pos_x", x2, 0.0);
00067 nh_.param<double>("goal_2_pos_y", y2, 0.0);
00068 nh_.param<double>("goal_2_ori_z", z2, 0.0);
00069 nh_.param<double>("goal_2_ori_w", w2, 0.0);
00070
00071 nh_.param<double>("goal_3_pos_x", x3, 0.0);
00072 nh_.param<double>("goal_3_pos_y", y3, 0.0);
00073 nh_.param<double>("goal_3_ori_z", z3, 0.0);
00074 nh_.param<double>("goal_3_ori_w", w3, 0.0);
00075
00076 goal_0_pos_x_ = (float)x0;
00077 goal_0_pos_y_ = (float)y0;
00078 goal_0_ori_z_ = (float)z0;
00079 goal_0_ori_w_ = (float)w0;
00080
00081 goal_1_pos_x_ = (float)x1;
00082 goal_1_pos_y_ = (float)y1;
00083 goal_1_ori_z_ = (float)z1;
00084 goal_1_ori_w_ = (float)w1;
00085
00086 goal_2_pos_x_ = (float)x2;
00087 goal_2_pos_y_ = (float)y2;
00088 goal_2_ori_z_ = (float)z2;
00089 goal_2_ori_w_ = (float)w2;
00090
00091 goal_3_pos_x_ = (float)x3;
00092 goal_3_pos_y_ = (float)y3;
00093 goal_3_ori_z_ = (float)z3;
00094 goal_3_ori_w_ = (float)w3;
00095
00096 goal_0_.target_pose.header.frame_id = "map";
00097 goal_0_.target_pose.pose.position.x = goal_0_pos_x_;
00098 goal_0_.target_pose.pose.position.y = goal_0_pos_y_;
00099 goal_0_.target_pose.pose.position.z = 0.0;
00100 goal_0_.target_pose.pose.orientation.x = 0.0;
00101 goal_0_.target_pose.pose.orientation.y = 0.0;
00102 goal_0_.target_pose.pose.orientation.z = goal_0_ori_z_;
00103 goal_0_.target_pose.pose.orientation.w = goal_0_ori_w_;
00104
00105 goal_1_.target_pose.header.frame_id = "map";
00106 goal_1_.target_pose.pose.position.x = goal_1_pos_x_;
00107 goal_1_.target_pose.pose.position.y = goal_1_pos_y_;
00108 goal_1_.target_pose.pose.position.z = 0.0;
00109 goal_1_.target_pose.pose.orientation.x = 0.0;
00110 goal_1_.target_pose.pose.orientation.y = 0.0;
00111 goal_1_.target_pose.pose.orientation.z = goal_1_ori_z_;
00112 goal_1_.target_pose.pose.orientation.w = goal_1_ori_w_;
00113
00114 goal_2_.target_pose.header.frame_id = "map";
00115 goal_2_.target_pose.pose.position.x = goal_2_pos_x_;
00116 goal_2_.target_pose.pose.position.y = goal_2_pos_y_;
00117 goal_2_.target_pose.pose.position.z = 0.0;
00118 goal_2_.target_pose.pose.orientation.x = 0.0;
00119 goal_2_.target_pose.pose.orientation.y = 0.0;
00120 goal_2_.target_pose.pose.orientation.z = goal_2_ori_z_;
00121 goal_2_.target_pose.pose.orientation.w = goal_2_ori_w_;
00122
00123 goal_3_.target_pose.header.frame_id = "map";
00124 goal_3_.target_pose.pose.position.x = goal_3_pos_x_;
00125 goal_3_.target_pose.pose.position.y = goal_3_pos_y_;
00126 goal_3_.target_pose.pose.position.z = 0.0;
00127 goal_3_.target_pose.pose.orientation.x = 0.0;
00128 goal_3_.target_pose.pose.orientation.y = 0.0;
00129 goal_3_.target_pose.pose.orientation.z = goal_3_ori_z_;
00130 goal_3_.target_pose.pose.orientation.w = goal_3_ori_w_;
00131
00132 timer_ = nh_.createTimer(ros::Duration(goal_time_interval_), &RobotPatrol::timerCallback, this);
00133 }
00134
00135 void RobotPatrol::timerCallback(const ros::TimerEvent&)
00136 {
00137 switch(goal_count_)
00138 {
00139 case 0:
00140 {
00141 client_ -> sendGoal(goal_0_);
00142 break;
00143 }
00144 case 1:
00145 {
00146 client_ -> sendGoal(goal_1_);
00147 break;
00148 }
00149 case 2:
00150 {
00151 client_ -> sendGoal(goal_2_);
00152 break;
00153 }
00154 case 3:
00155 {
00156 client_ -> sendGoal(goal_3_);
00157 break;
00158 }
00159 default:
00160 std::cout << "ERROR!" << endl;
00161 }
00162 goal_count_ += 1;
00163 if(goal_count_ == 4)
00164 goal_count_ = 0;
00165 }
00166 }
00167 PLUGINLIB_EXPORT_CLASS(micros_mars_task_alloc::RobotPatrol, nodelet::Nodelet)