moped_actionclient_alg_node.cpp
Go to the documentation of this file.
00001 #include "moped_actionclient_alg_node.h"
00002 
00003 MopedActionclientAlgNode::MopedActionclientAlgNode(void) :
00004         algorithm_base::IriBaseAlgorithm<MopedActionclientAlgorithm>(),
00005         moped_client_("moped", true)
00006 {
00007         //init class attributes if necessary
00008         //this->loop_rate_ = 2;//in [Hz]
00009 
00010         // [init publishers]
00011         
00012         // [init subscribers]
00013         
00014         // [init services]
00015         
00016         // [init clients]
00017         
00018         // [init action servers]
00019         
00020         // [init action clients]
00021 }
00022 
00023 MopedActionclientAlgNode::~MopedActionclientAlgNode(void)
00024 {
00025         // [free dynamic memory]
00026 }
00027 
00028 void MopedActionclientAlgNode::mainNodeThread(void)
00029 {
00030         this->image = cv::imread("/home/frigual/ros/stacks/moped/moped-example/test/query-close.jpg", 0 );
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         mopedMakeActionRequest();
00038 
00039         // [publish messages]
00040 }
00041 
00042 /*      [subscriber callbacks] */
00043 
00044 /*      [service callbacks] */
00045 
00046 /*      [action callbacks] */
00047 void MopedActionclientAlgNode::mopedDone(const actionlib::SimpleClientGoalState& state, const iri_moped_actionserver::mopedResultConstPtr& result) 
00048 { 
00049         if( state.toString().compare("SUCCEEDED") == 0 ) 
00050                 ROS_INFO("MopedActionclientAlgNode::mopedDone: Goal Achieved!"); 
00051         else 
00052                 ROS_INFO("MopedActionclientAlgNode::mopedDone: %s", state.toString().c_str()); 
00053 
00054         //copy & work with requested result 
00055 } 
00056 
00057 void MopedActionclientAlgNode::mopedActive() 
00058 { 
00059         //ROS_INFO("MopedActionclientAlgNode::mopedActive: Goal just went active!"); 
00060 } 
00061 
00062 void MopedActionclientAlgNode::mopedFeedback(const iri_moped_actionserver::mopedFeedbackConstPtr& feedback) 
00063 { 
00064         //ROS_INFO("MopedActionclientAlgNode::mopedFeedback: Got Feedback!"); 
00065 
00066         bool feedback_is_ok = true; 
00067 
00068         //analyze feedback 
00069         //my_var = feedback->var; 
00070 
00071         //if feedback is not what expected, cancel requested goal 
00072         if( !feedback_is_ok ) 
00073         { 
00074                 moped_client_.cancelGoal(); 
00075                 //ROS_INFO("MopedActionclientAlgNode::mopedFeedback: Cancelling Action!"); 
00076         } 
00077 }
00078 
00079 /*      [action requests] */
00080 void MopedActionclientAlgNode::mopedMakeActionRequest() 
00081 { 
00082         ROS_INFO("MopedActionclientAlgNode::mopedMakeActionRequest: Starting New Request!"); 
00083 
00084         //wait for the action server to start 
00085         //will wait for infinite time 
00086         moped_client_.waitForServer();  
00087         ROS_INFO("MopedActionclientAlgNode::mopedMakeActionRequest: Server is Available!"); 
00088 
00089         // Check if image is loaded
00090         if( this->image.empty() )
00091         {
00092                 ROS_ERROR("Trying to send image but it's not loaded.");
00093                 return;
00094         }
00095         else
00096         {
00097                 cv::namedWindow("title", CV_WINDOW_NORMAL);
00098                 cv::imshow("title",this->image);
00099                 cv::waitKey(0);
00100                 cv::destroyWindow("title");
00101         }
00102 
00103         //send a goal to the action 
00104         cv_bridge::CvImagePtr cv_ptr(new cv_bridge::CvImage);
00105         cv_ptr->image = this->image;
00106         cv_ptr->encoding = "mono8";
00107 
00108         moped_goal_.image = *(cv_ptr->toImageMsg());
00109 
00110         moped_client_.sendGoal(moped_goal_, 
00111                                                         boost::bind(&MopedActionclientAlgNode::mopedDone,                this, _1, _2), 
00112                                                         boost::bind(&MopedActionclientAlgNode::mopedActive,      this), 
00113                                                         boost::bind(&MopedActionclientAlgNode::mopedFeedback, this, _1)); 
00114 
00115         ROS_INFO("MopedActionclientAlgNode::mopedMakeActionRequest: Goal Sent. Wait for Result!"); 
00116 }
00117 
00118 void MopedActionclientAlgNode::node_config_update(Config &config, uint32_t level)
00119 {
00120         this->alg_.lock();
00121 
00122         this->alg_.unlock();
00123 }
00124 
00125 void MopedActionclientAlgNode::addNodeDiagnostics(void)
00126 {
00127 }
00128 
00129 /* main function */
00130 int main(int argc,char *argv[])
00131 {
00132         return algorithm_base::main<MopedActionclientAlgNode>(argc, argv, "moped_actionclient_alg_node");
00133 }


iri_moped_actionclient
Author(s): frigual
autogenerated on Fri Dec 6 2013 22:18:44