$search
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Southwest Research Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the Southwest Research Institute, nor the names 00016 * of its contributors may be used to endorse or promote products derived 00017 * from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #include "gripper_handler.h" 00033 #include "shared_types.h" 00034 #include "log_wrapper.h" 00035 #include "armadillo.h" 00036 #include "gripper_message.h" 00037 #include "motoPlus.h" 00038 00039 using namespace industrial::simple_message; 00040 using namespace industrial::shared_types; 00041 using namespace industrial::armadillo; 00042 using namespace industrial::gripper_message; 00043 using namespace motoman::controller; 00044 00045 namespace armadillo 00046 { 00047 namespace gripper_handler 00048 { 00049 00050 00051 bool GripperHandler::init(industrial::smpl_msg_connection::SmplMsgConnection* connection, 00052 motoman::controller::Controller* ctrl) 00053 { 00054 this->ctrl_ = ctrl; 00055 return this->init(ArmadilloMsgTypes::GRIPPER, connection); 00056 } 00057 00058 bool GripperHandler::internalCB(industrial::simple_message::SimpleMessage & in) 00059 { 00060 00061 bool rtn = false; 00062 ReplyType code = ReplyTypes::INVALID; 00063 SimpleMessage reply; 00064 GripperMessage gMsg; 00065 00066 gMsg.init(in); 00067 00068 switch( gMsg.operation_ ) 00069 { 00070 case GripperOperationTypes::INIT: 00071 LOG_INFO("Initializing gripper"); 00072 this->ctrl_->setDigitalOut(this->GRIPPER_INIT_, true); 00073 this->ctrl_->delayTicks(MOTION_START_DELAY); 00074 this->ctrl_->waitDigitalIn(this->GRIPPER_INITIALIZED_, true); 00075 code = ReplyTypes::SUCCESS; 00076 break; 00077 00078 case GripperOperationTypes::OPEN: 00079 LOG_DEBUG("Opening gripper"); 00080 this->ctrl_->setDigitalOut(this->GRIPPER_OPEN_, true); 00081 this->ctrl_->setDigitalOut(this->GRIPPER_CLOSE_, false); 00082 this->ctrl_->delayTicks(MOTION_START_DELAY); 00083 this->ctrl_->waitDigitalIn(this->GRIPPER_OPENING_, true); 00084 this->ctrl_->waitDigitalIn(this->GRIPPER_MOTION_IN_PROGRESS_, true); 00085 this->ctrl_->waitDigitalIn(this->GRIPPER_MOTION_COMPLETE_, true); 00086 code = ReplyTypes::SUCCESS; 00087 break; 00088 00089 case GripperOperationTypes::CLOSE: 00090 LOG_DEBUG("Closing gripper"); 00091 this->ctrl_->setDigitalOut(this->GRIPPER_OPEN_, false); 00092 this->ctrl_->setDigitalOut(this->GRIPPER_CLOSE_, true); 00093 this->ctrl_->delayTicks(MOTION_START_DELAY); 00094 this->ctrl_->waitDigitalIn(this->GRIPPER_CLOSING_, true); 00095 this->ctrl_->waitDigitalIn(this->GRIPPER_MOTION_IN_PROGRESS_, true); 00096 this->ctrl_->waitDigitalIn(this->GRIPPER_MOTION_COMPLETE_, true); 00097 code = ReplyTypes::SUCCESS; 00098 break; 00099 00100 default: 00101 LOG_ERROR("Unknown gripper request: %d", gMsg.operation_); 00102 code = ReplyTypes::FAILURE; 00103 break; 00104 } 00105 00106 reply.init(ArmadilloMsgTypes::GRIPPER, CommTypes::SERVICE_REPLY, code); 00107 rtn = this->getConnection()->sendMsg(reply); 00108 00109 return rtn; 00110 00111 } 00112 00113 00114 00115 }//namespace gripper_handler 00116 }//namespace motoman 00117 00118