Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <sstream>
00039 #include <ros/ros.h>
00040 #include <move_base_msgs/MoveBaseAction.h>
00041 #include <actionlib/client/simple_action_client.h>
00042 #include <tf/transform_broadcaster.h>
00043 #include <tf/transform_listener.h>
00044 #include <nav_msgs/Odometry.h>
00045
00046 #include "PatrolAgent.h"
00047
00048 #include "algorithms.h"
00049
00050 class Conscientious_Cognitive_Agent: public PatrolAgent {
00051 private:
00052 bool inpath;
00053 uint *path;
00054 uint elem_s_path, i_path;
00055 public:
00056 virtual void init(int argc, char** argv);
00057 virtual int compute_next_vertex();
00058 virtual void onGoalComplete();
00059
00060
00061 };
00062
00063 void Conscientious_Cognitive_Agent::init(int argc, char** argv)
00064 {
00065 PatrolAgent::init(argc,argv);
00066
00067 inpath = false;
00068 path = new uint[dimension];
00069 elem_s_path=0; i_path=0;
00070 }
00071
00072 int Conscientious_Cognitive_Agent::compute_next_vertex() {
00073 return heuristic_pathfinder_conscientious_cognitive(current_vertex, vertex_web, instantaneous_idleness, dimension, path);
00074 }
00075
00076
00077 void Conscientious_Cognitive_Agent::onGoalComplete()
00078 {
00079
00080 if (i_path>0) {
00081
00082 update_idleness();
00083 current_vertex = next_vertex;
00084 }
00085
00086 if (inpath){
00087
00088 i_path++;
00089
00090 if (i_path<elem_s_path){
00091 next_vertex=path[i_path];
00092 }else{
00093 inpath = false;
00094 }
00095 }
00096
00097 if (!inpath){
00098 elem_s_path = compute_next_vertex();
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 i_path=1;
00112 next_vertex = path[i_path];
00113 inpath = true;
00114
00115 }
00116
00118 send_goal_reached();
00119 send_results();
00120
00121 if (inpath){
00122
00123 ROS_INFO("Sending goal - Vertex %d (%f,%f)\n", next_vertex, vertex_web[next_vertex].x, vertex_web[next_vertex].y);
00124 sendGoal(next_vertex);
00125 }
00126
00127 goal_complete = false;
00128
00129
00130 ros::spinOnce();
00131
00132 }
00133
00134 #if 0
00135
00136 void Conscientious_Cognitive_Agent::send_results() {
00137 ros::spinOnce();
00138 }
00139
00140
00141 void Conscientious_Cognitive_Agent::receive_results() {
00142 ros::spinOnce();
00143 }
00144 #endif
00145
00146 int main(int argc, char** argv) {
00147
00148 Conscientious_Cognitive_Agent agent;
00149 agent.init(argc,argv);
00150 agent.run();
00151
00152 return 0;
00153 }
00154