00001 #include "bhand_driver.h" 00002 00003 using namespace std; 00004 00005 BhandDriver::BhandDriver() 00006 { 00007 //setDriverId(driver string id); 00008 this->bhserver_ip = "192.168.101.1"; 00009 this->server_port = 4322; 00010 } 00011 00012 bool BhandDriver::openDriver(void) 00013 { 00014 string input; 00015 //setDriverId(driver string id); 00016 try{ 00017 if(this->state_ != OPENED){ 00018 this->bhand = new BarrettHand(this->bhserver_ip, this->server_port); 00019 bhand->open(); 00020 this->state_ = OPENED; 00021 ROS_INFO("bhand opened"); 00022 return true; 00023 }else{ 00024 ROS_ERROR("WAM was already opened!"); 00025 return false; 00026 } 00027 }catch(CException &e){ 00028 ROS_ERROR("%s",e.what().c_str()); 00029 return false; 00030 } 00031 } 00032 00033 bool BhandDriver::closeDriver(void) 00034 { 00035 bhand->close(); 00036 ROS_INFO("[APP] Barrett hand closed."); 00037 this->state_ = CLOSED; 00038 return true; 00039 } 00040 00041 bool BhandDriver::startDriver(void) 00042 { 00043 try{ 00044 //gravity and go to position? 00045 ROS_INFO("Switching to Running"); 00046 this->state_ = RUNNING; 00047 return true; 00048 }catch(CException &e){ 00049 ROS_ERROR("%s",e.what().c_str()); 00050 return false; 00051 } 00052 return true; 00053 } 00054 00055 bool BhandDriver::stopDriver(void) 00056 { 00057 return true; 00058 } 00059 00060 void BhandDriver::config_update(const Config& new_cfg, uint32_t level) 00061 { 00062 this->lock(); 00063 00064 // depending on current state 00065 // update driver with new_cfg data 00066 switch(this->getState()) 00067 { 00068 case BhandDriver::CLOSED: 00069 break; 00070 00071 case BhandDriver::OPENED: 00072 break; 00073 00074 case BhandDriver::RUNNING: 00075 break; 00076 } 00077 00078 // save the current configuration 00079 this->config_=new_cfg; 00080 00081 this->unlock(); 00082 } 00083 00084 int BhandDriver::rawCommand(string data){ 00085 00086 return bhand->rawCommand(data); 00087 00088 } 00089 00090 BhandDriver::~BhandDriver() 00091 { 00092 }