Go to the documentation of this file.00001 #include "dynamixel_nc_gripper_driver_node.h"
00002
00003 DynamixelNcGripperDriverNode::DynamixelNcGripperDriverNode(ros::NodeHandle &nh) :
00004 iri_base_driver::IriBaseNodeDriver<DynamixelNcGripperDriver>(nh),
00005 is_opened_(false),
00006 is_closed_(false),
00007 tool_open_action_aserver_(public_node_handle_, "tool_open_action"),
00008 tool_close_action_aserver_(public_node_handle_, "tool_close_action")
00009 {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 tool_open_action_aserver_.registerStartCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionStartCallback, this, _1));
00023 tool_open_action_aserver_.registerStopCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionStopCallback, this));
00024 tool_open_action_aserver_.registerIsFinishedCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionIsFinishedCallback, this));
00025 tool_open_action_aserver_.registerHasSucceedCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionHasSucceedCallback, this));
00026 tool_open_action_aserver_.registerGetResultCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionGetResultCallback, this, _1));
00027 tool_open_action_aserver_.registerGetFeedbackCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_open_actionGetFeedbackCallback, this, _1));
00028 tool_open_action_aserver_.start();
00029
00030 tool_close_action_aserver_.registerStartCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionStartCallback, this, _1));
00031 tool_close_action_aserver_.registerStopCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionStopCallback, this));
00032 tool_close_action_aserver_.registerIsFinishedCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionIsFinishedCallback, this));
00033 tool_close_action_aserver_.registerHasSucceedCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionHasSucceedCallback, this));
00034 tool_close_action_aserver_.registerGetResultCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionGetResultCallback, this, _1));
00035 tool_close_action_aserver_.registerGetFeedbackCallback(boost::bind(&DynamixelNcGripperDriverNode::tool_close_actionGetFeedbackCallback, this, _1));
00036 tool_close_action_aserver_.start();
00037
00038
00039 }
00040
00041 void DynamixelNcGripperDriverNode::mainNodeThread(void)
00042 {
00043
00044 this->driver_.lock();
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 this->driver_.unlock();
00060 }
00061
00062
00063
00064
00065
00066
00067 void DynamixelNcGripperDriverNode::tool_open_actionStartCallback(const iri_common_drivers_msgs::tool_openGoalConstPtr& goal)
00068 {
00069 driver_.lock();
00070
00071 try
00072 {
00073 is_opened_ = true;
00074
00075 if (!driver_.open_gripper())
00076 {
00077 ROS_ERROR("Unable to open gripper");
00078 is_opened_ = false;
00079 }
00080 }
00081 catch(...)
00082 {
00083 ROS_WARN("Uncatched exception");
00084 }
00085
00086 driver_.unlock();
00087 }
00088
00089 void DynamixelNcGripperDriverNode::tool_open_actionStopCallback(void)
00090 {
00091 driver_.lock();
00092
00093 try{
00094 driver_.stop_gripper();
00095 driver_.disable_gripper();
00096 }catch(...){
00097 ROS_WARN("Uncatched exception");
00098 }
00099 driver_.unlock();
00100 }
00101
00102 bool DynamixelNcGripperDriverNode::tool_open_actionIsFinishedCallback(void)
00103 {
00104 bool ret = false;
00105
00106 driver_.lock();
00107
00108 if (driver_.is_at_max_angle())
00109 {
00110 ret = true;
00111 }
00112
00113 driver_.unlock();
00114
00115 return ret;
00116 }
00117
00118 bool DynamixelNcGripperDriverNode::tool_open_actionHasSucceedCallback(void)
00119 {
00120 bool ret = false;
00121
00122 driver_.lock();
00123
00124 ret = true;
00125 driver_.unlock();
00126
00127 return ret;
00128 }
00129
00130 void DynamixelNcGripperDriverNode::tool_open_actionGetResultCallback(iri_common_drivers_msgs::tool_openResultPtr& result)
00131 {
00132 driver_.lock();
00133
00134 result->successful = is_opened_;
00135 driver_.unlock();
00136 }
00137
00138 void DynamixelNcGripperDriverNode::tool_open_actionGetFeedbackCallback(iri_common_drivers_msgs::tool_openFeedbackPtr& feedback)
00139 {
00140 driver_.lock();
00141 try
00142 {
00143 feedback->angle = driver_.get_current_angle();
00144 feedback->effort = driver_.get_current_effort();
00145 ROS_INFO("[angle]: %f, [effort]: %f", feedback->angle, feedback->effort);
00146 }
00147 catch(...)
00148 {
00149 ROS_WARN("Uncatched exception");
00150 }
00151 driver_.unlock();
00152 }
00153
00154 void DynamixelNcGripperDriverNode::tool_close_actionStartCallback(const iri_common_drivers_msgs::tool_closeGoalConstPtr& goal)
00155 {
00156 driver_.lock();
00157
00158 try
00159 {
00160 is_closed_ = true;
00161
00162 if (!driver_.close_gripper())
00163 {
00164 ROS_ERROR("Unable to close gripper");
00165 is_closed_ = false;
00166 }
00167 }
00168 catch(...)
00169 {
00170 ROS_WARN("Uncatched exception");
00171 }
00172
00173 driver_.unlock();
00174 }
00175
00176 void DynamixelNcGripperDriverNode::tool_close_actionStopCallback(void)
00177 {
00178 driver_.lock();
00179
00180 try{
00181 driver_.stop_gripper();
00182 driver_.disable_gripper();
00183 }catch(...){
00184 ROS_WARN("Uncatched exception");
00185 }
00186 driver_.unlock();
00187 }
00188
00189 bool DynamixelNcGripperDriverNode::tool_close_actionIsFinishedCallback(void)
00190 {
00191 bool ret = false;
00192
00193 driver_.lock();
00194
00195 if (driver_.is_at_min_angle())
00196 {
00197 ret = true;
00198 }
00199
00200 driver_.unlock();
00201
00202 return ret;
00203 }
00204
00205 bool DynamixelNcGripperDriverNode::tool_close_actionHasSucceedCallback(void)
00206 {
00207 bool ret = false;
00208
00209 driver_.lock();
00210
00211 driver_.disable_gripper();
00212 ret = true;
00213 driver_.unlock();
00214
00215 return ret;
00216 }
00217
00218 void DynamixelNcGripperDriverNode::tool_close_actionGetResultCallback(iri_common_drivers_msgs::tool_closeResultPtr& result)
00219 {
00220 driver_.lock();
00221
00222 result->successful = is_closed_;
00223 driver_.unlock();
00224 }
00225
00226 void DynamixelNcGripperDriverNode::tool_close_actionGetFeedbackCallback(iri_common_drivers_msgs::tool_closeFeedbackPtr& feedback)
00227 {
00228 driver_.lock();
00229 try
00230 {
00231 feedback->angle = driver_.get_current_angle();
00232 feedback->effort = driver_.get_current_effort();
00233 ROS_INFO("[angle]: %f, [effort]: %f", feedback->angle, feedback->effort);
00234 }
00235 catch(...)
00236 {
00237 ROS_WARN("Uncatched exception");
00238 }
00239 driver_.unlock();
00240 }
00241
00242
00243
00244 void DynamixelNcGripperDriverNode::postNodeOpenHook(void)
00245 {
00246 }
00247
00248 void DynamixelNcGripperDriverNode::addNodeDiagnostics(void)
00249 {
00250 }
00251
00252 void DynamixelNcGripperDriverNode::addNodeOpenedTests(void)
00253 {
00254 }
00255
00256 void DynamixelNcGripperDriverNode::addNodeStoppedTests(void)
00257 {
00258 }
00259
00260 void DynamixelNcGripperDriverNode::addNodeRunningTests(void)
00261 {
00262 }
00263
00264 void DynamixelNcGripperDriverNode::reconfigureNodeHook(int level)
00265 {
00266 }
00267
00268 DynamixelNcGripperDriverNode::~DynamixelNcGripperDriverNode(void)
00269 {
00270
00271 }
00272
00273
00274 int main(int argc,char *argv[])
00275 {
00276 return driver_base::main<DynamixelNcGripperDriverNode>(argc, argv, "dynamixel_nc_gripper_driver_node");
00277 }