Go to the documentation of this file.00001 #include "zyonz_chlorophyll_meter_client_alg_node.h"
00002
00003 ZyonzChlorophyllMeterClientAlgNode::ZyonzChlorophyllMeterClientAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<ZyonzChlorophyllMeterClientAlgorithm>(),
00005 take_sample_client_("take_sample", true)
00006 {
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 this->action_done=true;
00023 }
00024
00025 ZyonzChlorophyllMeterClientAlgNode::~ZyonzChlorophyllMeterClientAlgNode(void)
00026 {
00027
00028 }
00029
00030 void ZyonzChlorophyllMeterClientAlgNode::mainNodeThread(void)
00031 {
00032 static bool close=false;
00033
00034
00035
00036
00037
00038
00039 if(action_done)
00040 {
00041 if(close)
00042 {
00043 this->take_sample_goal_.close=true;
00044 close=false;
00045 }
00046 else
00047 {
00048 this->take_sample_goal_.close=false;
00049 close=true;
00050 }
00051 take_sampleMakeActionRequest();
00052 }
00053
00054
00055 }
00056
00057
00058
00059
00060
00061
00062 void ZyonzChlorophyllMeterClientAlgNode::take_sampleDone(const actionlib::SimpleClientGoalState& state, const zyonz_msgs::chlorophyll_sampleResultConstPtr& result)
00063 {
00064 if( state.toString().compare("SUCCEEDED") == 0 )
00065 ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleDone: Goal Achieved!");
00066 else
00067 ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleDone: %s", state.toString().c_str());
00068 this->action_done=true;
00069
00070 }
00071
00072 void ZyonzChlorophyllMeterClientAlgNode::take_sampleActive()
00073 {
00074
00075 }
00076
00077 void ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback(const zyonz_msgs::chlorophyll_sampleFeedbackConstPtr& feedback)
00078 {
00079
00080
00081 bool feedback_is_ok = true;
00082
00083
00084
00085 std::cout << "Current meter angle: " << feedback->angle << std::endl;
00086 std::cout << "Current meter effort: " << feedback->effort << std::endl;
00087
00088
00089 if( !feedback_is_ok )
00090 {
00091 take_sample_client_.cancelGoal();
00092
00093 }
00094 }
00095
00096
00097 void ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest()
00098 {
00099 ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Starting New Request!");
00100
00101
00102
00103 take_sample_client_.waitForServer();
00104 ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Server is Available!");
00105
00106
00107
00108 sleep(1);
00109 take_sample_client_.sendGoal(take_sample_goal_,
00110 boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleDone, this, _1, _2),
00111 boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleActive, this),
00112 boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback, this, _1));
00113 this->action_done=false;
00114 ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Goal Sent. Wait for Result!");
00115 }
00116
00117 void ZyonzChlorophyllMeterClientAlgNode::node_config_update(Config &config, uint32_t level)
00118 {
00119 this->alg_.lock();
00120
00121 this->alg_.unlock();
00122 }
00123
00124 void ZyonzChlorophyllMeterClientAlgNode::addNodeDiagnostics(void)
00125 {
00126 }
00127
00128
00129 int main(int argc,char *argv[])
00130 {
00131 return algorithm_base::main<ZyonzChlorophyllMeterClientAlgNode>(argc, argv, "zyonz_chlorophyll_meter_client_alg_node");
00132 }