Go to the documentation of this file.00001 #include "moped_actionserver_alg_node.h"
00002
00003 MopedActionserverAlgNode::MopedActionserverAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<MopedActionserverAlgorithm>(),
00005 moped_aserver_(public_node_handle_, "moped")
00006 {
00007
00008 this->image_sent = false;
00009
00010
00011 this->Image_publisher_ = this->public_node_handle_.advertise<sensor_msgs::Image>("/moped/image", 10);
00012
00013
00014 this->object_poses_subscriber_ = this->public_node_handle_.subscribe("object_poses", 10, &MopedActionserverAlgNode::object_poses_callback, this);
00015
00016
00017
00018
00019
00020
00021 moped_aserver_.registerStartCallback(boost::bind(&MopedActionserverAlgNode::mopedStartCallback, this, _1));
00022 moped_aserver_.registerStopCallback(boost::bind(&MopedActionserverAlgNode::mopedStopCallback, this));
00023 moped_aserver_.registerIsFinishedCallback(boost::bind(&MopedActionserverAlgNode::mopedIsFinishedCallback, this));
00024 moped_aserver_.registerHasSucceedCallback(boost::bind(&MopedActionserverAlgNode::mopedHasSucceedCallback, this));
00025 moped_aserver_.registerGetResultCallback(boost::bind(&MopedActionserverAlgNode::mopedGetResultCallback, this, _1));
00026 moped_aserver_.registerGetFeedbackCallback(boost::bind(&MopedActionserverAlgNode::mopedGetFeedbackCallback, this, _1));
00027 moped_aserver_.start();
00028
00029
00030 }
00031
00032 MopedActionserverAlgNode::~MopedActionserverAlgNode(void)
00033 {
00034
00035 }
00036
00037 void MopedActionserverAlgNode::mainNodeThread(void)
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 }
00049
00050
00051 void MopedActionserverAlgNode::object_poses_callback(const pr_msgs::ObjectPoseList::ConstPtr& msg)
00052 {
00053 ROS_INFO("MopedActionserverAlgNode::object_poses_callback: New Message Received");
00054
00055
00056
00057
00058
00059
00060 if( not this->image_sent )
00061 {
00062 ROS_ERROR("New moped result received but wasn't requested.");
00063 return;
00064 }
00065
00066 this->image_sent = false;
00067 this->result = (*msg);
00068
00069
00070
00071
00072 }
00073
00074
00075
00076
00077 void MopedActionserverAlgNode::mopedStartCallback(const iri_moped_actionserver::mopedGoalConstPtr& goal)
00078 {
00079 alg_.lock();
00080
00081
00082 if( this->image_sent )
00083 {
00084 ROS_ERROR("Still processing last image.");
00085 alg_.unlock();
00086 return;
00087 }
00088
00089
00090 this->Image_msg_ = goal->image;
00091
00092
00093 this->Image_publisher_.publish(this->Image_msg_);
00094
00095
00096 this->image_sent = true;
00097
00098
00099 alg_.unlock();
00100 }
00101
00102 void MopedActionserverAlgNode::mopedStopCallback(void)
00103 {
00104 alg_.lock();
00105
00106
00107 if( this->image_sent == false )
00108 {
00109 ROS_ERROR("Received a stop request but Moped wasn't running.");
00110 alg_.unlock();
00111 return;
00112 }
00113
00114
00115 this->image_sent = false;
00116
00117 alg_.unlock();
00118 }
00119
00120 bool MopedActionserverAlgNode::mopedIsFinishedCallback(void)
00121 {
00122 bool ret = false;
00123
00124 alg_.lock();
00125
00126 ret = not this->image_sent;
00127
00128 alg_.unlock();
00129
00130 return ret;
00131 }
00132
00133 bool MopedActionserverAlgNode::mopedHasSucceedCallback(void)
00134 {
00135 bool ret = false;
00136
00137 alg_.lock();
00138
00139 ret = not this->image_sent;
00140
00141 alg_.unlock();
00142
00143 return ret;
00144 }
00145
00146 void MopedActionserverAlgNode::mopedGetResultCallback(iri_moped_actionserver::mopedResultPtr& result)
00147 {
00148 alg_.lock();
00149
00150
00151 result->pose = this->result;
00152
00153 alg_.unlock();
00154 }
00155
00156 void MopedActionserverAlgNode::mopedGetFeedbackCallback(iri_moped_actionserver::mopedFeedbackPtr& feedback)
00157 {
00158 alg_.lock();
00159
00160
00161 alg_.unlock();
00162 }
00163
00164
00165
00166 void MopedActionserverAlgNode::node_config_update(Config &config, uint32_t level)
00167 {
00168 this->alg_.lock();
00169
00170 this->alg_.unlock();
00171 }
00172
00173 void MopedActionserverAlgNode::addNodeDiagnostics(void)
00174 {
00175 }
00176
00177
00178 int main(int argc,char *argv[])
00179 {
00180 return algorithm_base::main<MopedActionserverAlgNode>(argc, argv, "moped_actionserver_alg_node");
00181 }