Go to the documentation of this file.00001 #include "dynamixel_gripper_driver_node.h"
00002
00003 DynamixelGripperDriverNode::DynamixelGripperDriverNode(ros::NodeHandle &nh) :
00004 iri_base_driver::IriBaseNodeDriver<DynamixelGripperDriver>(nh),
00005 close_action__aserver_(public_node_handle_, "close_action_"),
00006 open_action__aserver_(public_node_handle_, "open_action_"),
00007 max_torque_it_(0),
00008 last_action_successful_(false)
00009 {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 close_action__aserver_.registerStartCallback(boost::bind(&DynamixelGripperDriverNode::close_action_StartCallback, this, _1));
00021 close_action__aserver_.registerStopCallback(boost::bind(&DynamixelGripperDriverNode::close_action_StopCallback, this));
00022 close_action__aserver_.registerIsFinishedCallback(boost::bind(&DynamixelGripperDriverNode::close_action_IsFinishedCallback, this));
00023 close_action__aserver_.registerHasSucceedCallback(boost::bind(&DynamixelGripperDriverNode::close_action_HasSucceedCallback, this));
00024 close_action__aserver_.registerGetResultCallback(boost::bind(&DynamixelGripperDriverNode::close_action_GetResultCallback, this, _1));
00025 close_action__aserver_.registerGetFeedbackCallback(boost::bind(&DynamixelGripperDriverNode::close_action_GetFeedbackCallback, this, _1));
00026
00027 close_action__aserver_.start();
00028
00029
00030
00031
00032 open_action__aserver_.registerStartCallback(boost::bind(&DynamixelGripperDriverNode::open_action_StartCallback, this, _1));
00033 open_action__aserver_.registerStopCallback(boost::bind(&DynamixelGripperDriverNode::close_action_StopCallback, this));
00034 open_action__aserver_.registerIsFinishedCallback(boost::bind(&DynamixelGripperDriverNode::open_action_IsFinishedCallback, this));
00035 open_action__aserver_.registerHasSucceedCallback(boost::bind(&DynamixelGripperDriverNode::close_action_HasSucceedCallback, this));
00036 open_action__aserver_.registerGetResultCallback(boost::bind(&DynamixelGripperDriverNode::open_action_GetResultCallback, this, _1));
00037 open_action__aserver_.registerGetFeedbackCallback(boost::bind(&DynamixelGripperDriverNode::open_action_GetFeedbackCallback, this, _1));
00038
00039 open_action__aserver_.start();
00040 }
00041
00042 void
00043 DynamixelGripperDriverNode::mainNodeThread(void)
00044 { }
00045
00046
00047
00048
00049
00050
00051 void
00052 DynamixelGripperDriverNode::open_action_StartCallback(const iri_dynamixel_gripper::openGoalConstPtr& goal)
00053 {
00054 driver_.lock();
00055
00056 try{
00057 last_action_successful_ = true;
00058
00059 if (! driver_.open_gripper()) {
00060 ROS_ERROR("Unable to open gripper");
00061 last_action_successful_ = false;
00062 }
00063 }catch(...){
00064 ROS_WARN("Uncatched exception");
00065 }
00066
00067 driver_.unlock();
00068 }
00069
00070 bool
00071 DynamixelGripperDriverNode::open_action_IsFinishedCallback()
00072 {
00073 driver_.lock();
00074
00075 bool ret = false;
00076
00077 if (! driver_.is_moving())
00078 ret = true;
00079
00080 driver_.unlock();
00081 return ret;
00082 }
00083
00084 void
00085 DynamixelGripperDriverNode::open_action_GetResultCallback(iri_dynamixel_gripper::openResultPtr& result)
00086 {
00087 result->successful = last_action_successful_;
00088 }
00089
00090 void
00091 DynamixelGripperDriverNode::open_action_GetFeedbackCallback(iri_dynamixel_gripper::openFeedbackPtr& feedback)
00092 {
00093 driver_.lock();
00094
00095 try{
00096 feedback->angle = driver_.get_angle();
00097 feedback->effort = driver_.get_effort();
00098 }catch(...){
00099 ROS_WARN("Uncatched exception");
00100 }
00101
00102 driver_.unlock();
00103 }
00104
00105
00106 void
00107 DynamixelGripperDriverNode::close_action_StartCallback(const iri_dynamixel_gripper::closeGoalConstPtr& goal)
00108 {
00109 driver_.lock();
00110
00111 try{
00112 max_torque_it_ = 0;
00113 last_action_successful_ = true;
00114
00115 if (! driver_.close_gripper()) {
00116 ROS_ERROR("Unable to close gripper");
00117 last_action_successful_ = false;
00118 }
00119 }catch(...){
00120 ROS_WARN("Uncatched exception");
00121 }
00122
00123 driver_.unlock();
00124 }
00125
00126 void
00127 DynamixelGripperDriverNode::close_action_StopCallback(void)
00128 {
00129 driver_.lock();
00130 try{
00131 driver_.stop_gripper();
00132 }catch(...){
00133 ROS_WARN("Uncatched exception");
00134 }
00135 driver_.unlock();
00136 }
00137
00138 bool
00139 DynamixelGripperDriverNode::close_action_IsFinishedCallback(void)
00140 {
00141 driver_.lock();
00142
00143 if (! driver_.is_moving()) {
00144 driver_.unlock();
00145 return true;
00146 }
00147
00148 try{
00149 float current_effort = driver_.get_effort();
00150
00151 if (fabs(current_effort) > (0.9 * driver_.get_max_effort())) {
00152 max_torque_it_++;
00153
00154 if (max_torque_it_ < 5) {
00155 driver_.unlock();
00156 return false;
00157 }
00158
00159
00160
00161
00162 driver_.unlock();
00163 return true;
00164 }
00165 }catch(...){
00166 ROS_WARN("Uncatched exception");
00167 }
00168
00169 driver_.unlock();
00170 return false;
00171 }
00172
00173 bool
00174 DynamixelGripperDriverNode::close_action_HasSucceedCallback(void)
00175 {
00176 return true;
00177 }
00178
00179 void
00180 DynamixelGripperDriverNode::close_action_GetResultCallback(iri_dynamixel_gripper::closeResultPtr& result)
00181 {
00182 result->successful = last_action_successful_;
00183 }
00184
00185 void
00186 DynamixelGripperDriverNode::close_action_GetFeedbackCallback(iri_dynamixel_gripper::closeFeedbackPtr& feedback)
00187 {
00188 driver_.lock();
00189
00190 try{
00191 feedback->angle = driver_.get_angle();
00192 feedback->effort = driver_.get_effort();
00193 }catch(...){
00194 ROS_WARN("Uncatched exception");
00195 }
00196
00197 driver_.unlock();
00198 }
00199
00200
00201
00202 void DynamixelGripperDriverNode::postNodeOpenHook(void)
00203 {
00204 }
00205
00206 void DynamixelGripperDriverNode::addNodeDiagnostics(void)
00207 {
00208 }
00209
00210 void DynamixelGripperDriverNode::addNodeOpenedTests(void)
00211 {
00212 }
00213
00214 void DynamixelGripperDriverNode::addNodeStoppedTests(void)
00215 {
00216 }
00217
00218 void DynamixelGripperDriverNode::addNodeRunningTests(void)
00219 {
00220 }
00221
00222 void DynamixelGripperDriverNode::reconfigureNodeHook(int level)
00223 {
00224 }
00225
00226 DynamixelGripperDriverNode::~DynamixelGripperDriverNode(void)
00227 {
00228
00229 }
00230
00231
00232 int main(int argc,char *argv[])
00233 {
00234 return driver_base::main<DynamixelGripperDriverNode>(argc, argv, "dynamixel_gripper_driver_node");
00235 }