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         
00008         
00009 
00010         
00011         
00012         
00013         
00014         
00015         
00016         
00017         
00018         
00019         
00020         
00021 }
00022 
00023 MopedActionclientAlgNode::~MopedActionclientAlgNode(void)
00024 {
00025         
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         
00033         
00034         
00035         
00036         
00037         mopedMakeActionRequest();
00038 
00039         
00040 }
00041 
00042 
00043 
00044 
00045 
00046 
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         
00055 } 
00056 
00057 void MopedActionclientAlgNode::mopedActive() 
00058 { 
00059         
00060 } 
00061 
00062 void MopedActionclientAlgNode::mopedFeedback(const iri_moped_actionserver::mopedFeedbackConstPtr& feedback) 
00063 { 
00064         
00065 
00066         bool feedback_is_ok = true; 
00067 
00068         
00069         
00070 
00071         
00072         if( !feedback_is_ok ) 
00073         { 
00074                 moped_client_.cancelGoal(); 
00075                 
00076         } 
00077 }
00078 
00079 
00080 void MopedActionclientAlgNode::mopedMakeActionRequest() 
00081 { 
00082         ROS_INFO("MopedActionclientAlgNode::mopedMakeActionRequest: Starting New Request!"); 
00083 
00084         
00085         
00086         moped_client_.waitForServer();  
00087         ROS_INFO("MopedActionclientAlgNode::mopedMakeActionRequest: Server is Available!"); 
00088 
00089         
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         
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 
00130 int main(int argc,char *argv[])
00131 {
00132         return algorithm_base::main<MopedActionclientAlgNode>(argc, argv, "moped_actionclient_alg_node");
00133 }