darwin_simple_nav_client_alg_node.cpp
Go to the documentation of this file.
00001 #include "darwin_simple_nav_client_alg_node.h"
00002 
00003 DarwinSimpleNavClientAlgNode::DarwinSimpleNavClientAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<DarwinSimpleNavClientAlgorithm>(),
00005   move_base_client_("move_base", true)
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009 
00010   // [init publishers]
00011   
00012   // [init subscribers]
00013   this->target_pose_subscriber_ = this->public_node_handle_.subscribe("target_pose", 100, &DarwinSimpleNavClientAlgNode::target_pose_callback, this);
00014   
00015   // [init services]
00016   
00017   // [init clients]
00018   
00019   // [init action servers]
00020   
00021   // [init action clients]
00022   this->motion_done=true;
00023 }
00024 
00025 DarwinSimpleNavClientAlgNode::~DarwinSimpleNavClientAlgNode(void)
00026 {
00027   // [free dynamic memory]
00028 }
00029 
00030 void DarwinSimpleNavClientAlgNode::mainNodeThread(void)
00031 {
00032   // [fill msg structures]
00033   
00034   // [fill srv structure and make request to the server]
00035   
00036   // [fill action structure and make request to the action server]
00037 
00038   // [publish messages]
00039 }
00040 
00041 /*  [subscriber callbacks] */
00042 void DarwinSimpleNavClientAlgNode::target_pose_callback(const geometry_msgs::PoseStamped::ConstPtr& msg) 
00043 { 
00044   ROS_INFO("DarwinSimpleNavClientAlgNode::target_pose_callback: New Message Received"); 
00045 
00046   //use appropiate mutex to shared variables if necessary 
00047   //this->alg_.lock(); 
00048   //this->target_pose_mutex_.enter(); 
00049 
00050   //std::cout << msg->data << std::endl; 
00051   if(motion_done)
00052   {
00053     move_base_goal_.target_pose.header=msg->header;
00054     move_base_goal_.target_pose.pose.position.x=msg->pose.position.x;
00055     move_base_goal_.target_pose.pose.position.y=msg->pose.position.y;
00056     move_base_goal_.target_pose.pose.position.z=0.0;
00057     move_base_goal_.target_pose.pose.orientation=msg->pose.orientation;
00058     move_baseMakeActionRequest();
00059   }
00060 
00061   //unlock previously blocked shared variables 
00062   //this->alg_.unlock(); 
00063   //this->target_pose_mutex_.exit(); 
00064 }
00065 
00066 /*  [service callbacks] */
00067 
00068 /*  [action callbacks] */
00069 void DarwinSimpleNavClientAlgNode::move_baseDone(const actionlib::SimpleClientGoalState& state,  const move_base_msgs::MoveBaseResultConstPtr& result) 
00070 { 
00071   if( state.toString().compare("SUCCEEDED") == 0 ) 
00072     ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseDone: Goal Achieved!"); 
00073   else 
00074     ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseDone: %s", state.toString().c_str()); 
00075 
00076   //copy & work with requested result 
00077   this->motion_done=true;
00078 } 
00079 
00080 void DarwinSimpleNavClientAlgNode::move_baseActive() 
00081 { 
00082   //ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseActive: Goal just went active!"); 
00083 } 
00084 
00085 void DarwinSimpleNavClientAlgNode::move_baseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback) 
00086 { 
00087   //ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseFeedback: Got Feedback!"); 
00088 
00089   bool feedback_is_ok = true; 
00090 
00091   //analyze feedback 
00092   //my_var = feedback->var; 
00093   std::cout << "Current position : (" << feedback->base_position.pose.position.x << "," << feedback->base_position.pose.position.y << ")" << std::endl;
00094 
00095   //if feedback is not what expected, cancel requested goal 
00096   if( !feedback_is_ok ) 
00097   { 
00098     move_base_client_.cancelGoal(); 
00099     //ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseFeedback: Cancelling Action!"); 
00100   } 
00101 }
00102 
00103 /*  [action requests] */
00104 void DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest() 
00105 { 
00106   ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Starting New Request!"); 
00107 
00108   //wait for the action server to start 
00109   //will wait for infinite time 
00110   move_base_client_.waitForServer();  
00111   ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Server is Available!"); 
00112 
00113   this->motion_done=false;
00114   //send a goal to the action 
00115   //move_base_goal_.data = my_desired_goal; 
00116   move_base_client_.sendGoal(move_base_goal_, 
00117               boost::bind(&DarwinSimpleNavClientAlgNode::move_baseDone,     this, _1, _2), 
00118               boost::bind(&DarwinSimpleNavClientAlgNode::move_baseActive,   this), 
00119               boost::bind(&DarwinSimpleNavClientAlgNode::move_baseFeedback, this, _1)); 
00120   ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Goal Sent. Wait for Result!"); 
00121 }
00122 
00123 void DarwinSimpleNavClientAlgNode::node_config_update(Config &config, uint32_t level)
00124 {
00125   this->alg_.lock();
00126 
00127   this->alg_.unlock();
00128 }
00129 
00130 void DarwinSimpleNavClientAlgNode::addNodeDiagnostics(void)
00131 {
00132 }
00133 
00134 /* main function */
00135 int main(int argc,char *argv[])
00136 {
00137   return algorithm_base::main<DarwinSimpleNavClientAlgNode>(argc, argv, "darwin_simple_nav_client_alg_node");
00138 }


darwin_simple_nav_client
Author(s): darwin
autogenerated on Fri Dec 6 2013 22:09:40