00001 #include "dummy_pomdp.h" 00002 00003 DummyPomdp::DummyPomdp(){ 00004 00005 //init class attributes if necessary 00006 this->execution_flag = false; 00007 00008 //string for port names 00009 00010 // [init publishers] 00011 this->focused_obj_label_publisher = this->node_handle_.advertise<std_msgs::Int32>("/dummy_pomdp/focused_obj_label", 5); 00012 00013 // [init subscribers] 00014 00015 // [init services] 00016 this->execution_flow_control_server = this->node_handle_.advertiseService("/dummy_pomdp/execution_flow_control", &DummyPomdp::execution_flow_controlCallback, this); 00017 00018 // [init clients] 00019 obs_client = this->node_handle_.serviceClient<iri_wam_common_msgs::obs_request>("/dummy_pomdp/obs_client"); 00020 wam_action_client = this->node_handle_.serviceClient<iri_wam_common_msgs::wamaction>("/dummy_pomdp/wam_action"); 00021 00022 // [init action servers] 00023 00024 // [init action clients] 00025 } 00026 00027 void DummyPomdp::mainLoop(void){ 00028 00029 execution_mutex.enter(); 00030 if(execution_flag){ 00031 execution_mutex.exit(); 00032 if(obs_client.call(obs_request_srv)) 00033 { 00034 ROS_INFO("Service result: %d", obs_request_srv.response.num_objects); 00035 } else { 00036 ROS_ERROR("Failed to call service observation client"); 00037 return; 00038 } 00039 00040 //process observation 00041 //update state 00042 //retrieve action 00043 00044 this->ObjLabel_msg.data = 1; 00045 //publish focused object 00046 focused_obj_label_publisher.publish(this->ObjLabel_msg); 00047 00048 //request action 00049 wam_actions_client_srv.request.action = 0; 00050 if(wam_action_client.call(wam_actions_client_srv)) 00051 { 00052 ROS_INFO("Service result: %d", wam_actions_client_srv.response.success); 00053 } else { 00054 ROS_ERROR("Failed to call service wam actions service"); 00055 return; 00056 } 00057 00058 }else{ 00059 execution_mutex.exit(); 00060 //sleep 00061 ROS_INFO("Awaiting trigger"); 00062 sleep(5); 00063 00064 } 00065 00066 } 00067 00068 bool DummyPomdp::execution_flow_controlCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res){ 00069 00070 //stop execution when called 00071 execution_mutex.enter(); 00072 this->execution_flag = !this->execution_flag; 00073 execution_mutex.exit(); 00074 //TODO free execution mutex 00075 return true; 00076 00077 } 00078 00079 /* main function */ 00080 int main(int argc,char *argv[]) 00081 { 00082 ros::init(argc, argv, "dummy_pomdp"); 00083 DummyPomdp dummy_pomdp; 00084 ros::Rate loop_rate(10); 00085 while(ros::ok()){ 00086 dummy_pomdp.mainLoop(); 00087 ros::spinOnce(); 00088 loop_rate.sleep(); 00089 } 00090 }