00001 #include "Gripper.hpp"
00002 #include <rtt/Logger.hpp>
00003 #include <rtt/Command.hpp>
00004 #include <ocl/ComponentLoader.hpp>
00005
00006 #include "../staubli/ComediDevices.hpp"
00007
00008 #include <math.h>
00009
00010 ORO_CREATE_COMPONENT( OCL::Gripper )
00011
00012 namespace OCL{
00013
00014 Gripper::Gripper(const std::string& name) :
00015 TaskContext(name),
00016 opening(false),closing(false),opened(false),closed(false),
00017 voltage_value("voltage","",9.9),
00018 eps("eps","",0.01),
00019 min_time("min_time","",1.0),
00020 actuated_grip("actuated_grip","",true)
00021 {
00022 this->commands()->addCommand(command("open", &Gripper::openGripper, &Gripper::gripperOpened, this), "Opening gripper.");
00023 this->commands()->addCommand(command("close", &Gripper::closeGripper, &Gripper::gripperClosed, this), "Closing gripper.");
00024
00025 this->properties()->addProperty(&voltage_value);
00026 this->properties()->addProperty(&eps);
00027 this->properties()->addProperty(&min_time);
00028 this->properties()->addProperty(&actuated_grip);
00029 #if (defined OROPKG_OS_LXRT)
00030 ComediLoader::Instance()->CreateComediDevices();
00031
00032 ni6527_dout = DigitalOutInterface::nameserver.getObject("DigitalOut");
00033 ni6713_aout = AnalogOutInterface::nameserver.getObject("AnalogOut");
00034 encoder_if = EncoderInterface::nameserver.getObject("Counter6");
00035
00036 encoder = new IncrementalEncoderSensor(encoder_if,1.0,0.0,0.0,0.0,1);
00037 enable = new DigitalOutput(ni6527_dout,0);
00038 voltage = new AnalogOutput(ni6713_aout,6);
00039 gripper_driver = new AnalogDrive(voltage,enable);
00040 gripper_axis = new Axis(gripper_driver);
00041 #endif
00042 }
00043
00044 bool Gripper::configureHook(){
00045 return true;
00046 }
00047
00048 Gripper::~Gripper()
00049 {
00050 #if (defined OROPKG_OS_LXRT)
00051 delete gripper_axis;
00052 delete encoder;
00053 ComediLoader::Instance()->DestroyComediDevices();
00054 #endif
00055 }
00056
00057 bool Gripper::openGripper()
00058 {
00059 opening=true;
00060 closing=false;
00061 opened=false;
00062 time_begin=TimeService::Instance()->getTicks();
00063 return true;
00064 }
00065
00066 bool Gripper::closeGripper()
00067 {
00068 closing=true;
00069 opening=false;
00070 closed=false;
00071 time_begin=TimeService::Instance()->getTicks();
00072 return true;
00073 }
00074
00075 bool Gripper::gripperOpened() const
00076 {
00077 return opened;
00078 }
00079
00080 bool Gripper::gripperClosed() const
00081 {
00082 return closed;
00083 }
00084
00085 bool Gripper::startHook()
00086 {
00087 bool ok=true;
00088 #if (defined OROPKG_OS_LXRT)
00089 ok &= gripper_axis->unlock();
00090 ok &= gripper_axis->drive(0.0);
00091 #endif
00092 return ok;
00093 }
00094
00095 void Gripper::updateHook()
00096 {
00097 #if (defined OROPKG_OS_LXRT)
00098
00099 prev_pos=pos;
00100 pos=encoder->readSensor();
00101 bool stopped = false;
00102 time_passed = TimeService::Instance()->secondsSince(time_begin);
00103
00104 if(time_passed>min_time.rvalue())
00105 stopped = (std::abs(prev_pos-pos)/getPeriod())<eps.rvalue();
00106 #endif
00107 if(opening){
00108 #if (defined OROPKG_OS_LXRT)
00109 gripper_axis->drive(voltage_value.rvalue());
00110 if(stopped)
00111 #endif
00112 {
00113 opening=false;
00114 opened=true;
00115 }
00116 }
00117 else if(closing){
00118 #if (defined OROPKG_OS_LXRT)
00119 gripper_axis->drive(-voltage_value.rvalue());
00120 if(stopped)
00121 #endif
00122 {
00123 closed=true;
00124 if(!actuated_grip.rvalue())
00125 closing=false;
00126 }
00127 }else{
00128 #if (defined OROPKG_OS_LXRT)
00129 gripper_axis->drive(0.0);
00130 #endif
00131 }
00132 }
00133
00134 void Gripper::stopHook()
00135 {
00136 #if (defined OROPKG_OS_LXRT)
00137 gripper_axis->stop();
00138 gripper_axis->lock();
00139 #endif
00140 }
00141
00142 void Gripper::cleanupHook()
00143 {
00144
00145 }
00146
00147 }